osu-api-extended
Version:
Advanced osu! api wrapper for v1 and v2, with extra stuff
40 lines (39 loc) • 1.79 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculate_net_pp = void 0;
const handleErrors_1 = require("../utility/handleErrors");
const calculate_net_pp = (params) => {
if (!Array.isArray(params.scores)) {
return (0, handleErrors_1.handleErrors)(`Provide array of scores or numbers`);
}
;
if (!isFinite(params.pp_value) || params.pp_value == null) {
return (0, handleErrors_1.handleErrors)(`Specify pp`);
}
;
const pp_values = typeof params.scores[0] == 'number' ? params.scores : params.scores.map(r => r.pp);
pp_values.sort((a, b) => b - a);
// weight the user's current scores. (see https://osu.ppy.sh/wiki/en/Performance_points/Weighting_system)
const weighted_before = pp_values.slice(0, 100).map((x, i) => x * Math.pow(0.95, i));
// sum up the total pp value of the user's current scores.
const total_pp_old = weighted_before.reduce((a, b) => a + b, 0);
if (params.pp_value < Math.min(pp_values[pp_values.length - 1]))
return {
pp: 0,
totalNow: total_pp_old,
totalBefore: total_pp_old,
};
// Push new pp_value
pp_values.push(params.pp_value);
pp_values.sort((a, b) => b - a);
// weight the new scores. (see https://osu.ppy.sh/wiki/en/Performance_points/Weighting_system)
const weighted_after = pp_values.slice(0, 100).map((x, i) => x * Math.pow(0.95, i));
// sum up the total pp value of the user's new simulated scores.
const total_pp_new = weighted_after.reduce((a, b) => a + b, 0);
return {
pp: total_pp_new - total_pp_old,
totalNow: total_pp_new,
totalBefore: total_pp_old,
};
};
exports.calculate_net_pp = calculate_net_pp;
;