UNPKG

osu-api-extended

Version:

Advanced osu! api wrapper cover all V2 and V1 endpoints, and provide useful tools

98 lines (97 loc) 4.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.calculate_accuracy = void 0; const enums_1 = require("../types/enums"); const handleErrors_1 = require("../utility/handleErrors"); function calculate_accuracy(hits, p2, p3, p4) { let mode; let max_hits; let lazer = false; if (hits && p2 != null && p3 != null) { max_hits = p2; mode = p3; lazer = p4; } else if (hits && p2 != null) { max_hits = undefined; mode = p2; } ; if (Object.keys(hits).length == 0) { return (0, handleErrors_1.handleErrors)(new Error('Provide hits (300, 100, 50, etc)')); } ; const geki = parseInt(hits.perfect || hits.count_geki || (hits === null || hits === void 0 ? void 0 : hits.geki) || '0'); const h300 = parseInt(hits.great || hits.count_300 || (hits === null || hits === void 0 ? void 0 : hits[300]) || '0'); let katu = parseInt(hits.good || hits.count_katu || (hits === null || hits === void 0 ? void 0 : hits.katu) || '0'); let h100 = parseInt(hits.ok || hits.count_100 || (hits === null || hits === void 0 ? void 0 : hits[100]) || '0'); let h50 = parseInt(hits.meh || hits.count_50 || (hits === null || hits === void 0 ? void 0 : hits[50]) || '0'); const h0 = parseInt(hits.miss || hits.count_miss || (hits === null || hits === void 0 ? void 0 : hits[0]) || '0'); const slider_tick_hits = parseInt((hits === null || hits === void 0 ? void 0 : hits.large_tick_hit) || '0'); const slider_end_hits = parseInt((hits === null || hits === void 0 ? void 0 : hits.slider_tail_hit) || '0'); const max_slider_tick_hits = parseInt((max_hits === null || max_hits === void 0 ? void 0 : max_hits.large_tick_hit) || '0'); const max_slider_end_hits = parseInt((max_hits === null || max_hits === void 0 ? void 0 : max_hits.slider_tail_hit) || '0'); let accuracy = 0.0; let fc_accuracy = 0.0; switch (mode) { case 'osu': case enums_1.GamemodeEnum.osu: if (lazer) { accuracy = (300 * h300 + 100 * h100 + 50 * h50 + 150 * slider_end_hits + 30 * slider_tick_hits) / (300 * h300 + 300 * h100 + 300 * h50 + 300 * h0 + 150 * max_slider_end_hits + 30 * max_slider_tick_hits); fc_accuracy = (300 * (h300 + h0) + 100 * h100 + 50 * h50 + 150 * slider_end_hits + 30 * slider_tick_hits) / (300 * (h300 + h0) + 300 * h100 + 300 * h50 + 300 * 0 + 150 * max_slider_end_hits + 30 * max_slider_tick_hits); } else { accuracy = (6 * h300 + 2 * h100 + h50) / (6 * (h300 + h100 + h50 + h0)); fc_accuracy = (6 * (h300 + h0) + 2 * h100 + h50) / (6 * (h50 + h100 + (h300 + h0) + 0)); } ; break; case 'taiko': case enums_1.GamemodeEnum.taiko: accuracy = (2 * h300 + h100) / (2 * (h300 + h100 + h0)); fc_accuracy = (2 * (h300 + h0) + h100) / (2 * ((h300 + h0) + h100 + 0)); break; case 'fruits': case enums_1.GamemodeEnum.fruits: if (hits.small_tick_miss) katu = parseInt(hits.small_tick_miss); if (hits.large_tick_hit) h100 = parseInt(hits.large_tick_hit); if (hits.small_tick_hit) h50 = parseInt(hits.small_tick_hit); accuracy = (h300 + h100 + h50) / ((h300 + h100 + h50) + katu + h0); fc_accuracy = ((h300 + h0) + h100 + h50) / (((h300 + h0) + h100 + h50) + katu + 0); break; case 'mania': case enums_1.GamemodeEnum.mania: accuracy = (6 * (geki + h300) + 4 * katu + 2 * h100 + h50) / (6 * (geki + h300 + katu + h100 + h50 + h0)); // IT'S NOT CORRECT PLEASE SOMEONE FIX IT fc_accuracy = (6 * (geki + h0) + 6 * h300 + 4 * katu + 2 * h100 + h50) / (6 * (h50 + h100 + h300 + 0 + (geki + h0) + katu)); break; default: return (0, handleErrors_1.handleErrors)(new Error(`Unsupported gamemode: ${mode}`)); } ; return { accuracy: accuracy * 100, fc_accuracy: fc_accuracy * 100, }; } exports.calculate_accuracy = calculate_accuracy; ;