osu-api-extended
Version:
Advanced osu! api wrapper for v1 and v2, with extra stuff
51 lines (50 loc) • 2.6 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculate_accuracy = void 0;
const enums_1 = require("../types/enums");
const handleErrors_1 = require("../utility/handleErrors");
const calculate_accuracy = (hits, mode) => {
if (Object.keys(hits).length == 0) {
return (0, handleErrors_1.handleErrors)('Provide hits (300, 100, 50, etc)');
}
;
const geki = parseInt((hits === null || hits === void 0 ? void 0 : hits.geki) || hits.perfect || '0');
const h300 = parseInt((hits === null || hits === void 0 ? void 0 : hits[300]) || hits.great || '0');
const katu = parseInt((hits === null || hits === void 0 ? void 0 : hits.katu) || hits.good || '0');
const h100 = parseInt((hits === null || hits === void 0 ? void 0 : hits[100]) || hits.ok || '0');
const h50 = parseInt((hits === null || hits === void 0 ? void 0 : hits[50]) || hits.meh || '0');
const h0 = parseInt((hits === null || hits === void 0 ? void 0 : hits[0]) || hits.miss || '0');
let accuracy = 0.0;
let fc_accuracy = 0.0;
switch (mode) {
case 'osu':
case enums_1.GamemodeEnum.osu:
accuracy = (100.0 * (6 * h300 + 2 * h100 + h50)) / (6 * (h50 + h100 + h300 + h0));
fc_accuracy = (100.0 * (6 * (h300 + h0) + 2 * h100 + h50)) / (6 * (h50 + h100 + (h300 + h0) + 0));
break;
case 'taiko':
case enums_1.GamemodeEnum.taiko:
accuracy = (100.0 * (2 * h300 + h100)) / (2 * (h300 + h100 + h0));
fc_accuracy = (100.0 * (2 * (h300 + h0) + h100)) / (2 * ((h300 + h0) + h100 + 0));
break;
case 'fruits':
case enums_1.GamemodeEnum.fruits:
accuracy = (100.0 * (h300 + h100 + h50)) / (h300 + h100 + h50 + katu + h0);
fc_accuracy = (100.0 * ((h300 + h0) + h100 + h50)) / ((h300 + h0) + h100 + h50 + katu + 0);
break;
case 'mania':
case enums_1.GamemodeEnum.mania:
accuracy = (100.0 * (6 * geki + 6 * h300 + 4 * katu + 2 * h100 + h50)) / (6 * (h50 + h100 + h300 + h0 + geki + katu));
// IT'S NOT CORRECT PLEASE SOMEONE FIX IT
fc_accuracy = (100.0 * (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)(`Unsupported gamemode: ${mode}}`);
}
;
return {
accuracy,
fc_accuracy,
};
};
exports.calculate_accuracy = calculate_accuracy;
;