Skip to content

Commit

Permalink
Merge pull request #219 from tosuapp/fix/beatmap-stats
Browse files Browse the repository at this point in the history
chore: fix beatmap stats
  • Loading branch information
KotRikD authored Nov 12, 2024
2 parents 4838a52 + 672186f commit cdd258e
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 52 deletions.
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@tosu/common": "workspace:*",
"@tosu/updater": "workspace:*",
"@kotrikd/rosu-pp": "2.0.0-alpha.9",
"@kotrikd/rosu-pp": "2.0.0-alpha.10",
"semver": "^7.5.4",
"ws": "^8.16.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/tosu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"osu-standard-stable": "^5.0.0",
"osu-taiko-stable": "^5.0.0",
"resedit": "^2.0.0",
"@kotrikd/rosu-pp": "2.0.0-alpha.9",
"@kotrikd/rosu-pp": "2.0.0-alpha.10",
"semver": "^7.5.4",
"tsprocess": "workspace:*"
},
Expand Down
24 changes: 16 additions & 8 deletions packages/tosu/src/api/utils/buildResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,18 @@ export const buildResult = (instanceManager: InstanceManager): ApiAnswer => {
difficulty: menu.difficulty
},
stats: {
AR: fixDecimals(beatmapPP.calculatedMapAttributes.ar),
CS: fixDecimals(beatmapPP.calculatedMapAttributes.cs),
OD: fixDecimals(beatmapPP.calculatedMapAttributes.od),
HP: fixDecimals(beatmapPP.calculatedMapAttributes.hp),
AR: fixDecimals(
beatmapPP.calculatedMapAttributes.arConverted
),
CS: fixDecimals(
beatmapPP.calculatedMapAttributes.csConverted
),
OD: fixDecimals(
beatmapPP.calculatedMapAttributes.odConverted
),
HP: fixDecimals(
beatmapPP.calculatedMapAttributes.hpConverted
),
SR: fixDecimals(beatmapPP.currAttributes.stars),
BPM: {
realtime: fixDecimals(beatmapPP.realtimeBPM),
Expand All @@ -128,10 +136,10 @@ export const buildResult = (instanceManager: InstanceManager): ApiAnswer => {
fullSR: fixDecimals(
beatmapPP.calculatedMapAttributes.fullStars
),
memoryAR: fixDecimals(menu.ar),
memoryCS: fixDecimals(menu.cs),
memoryOD: fixDecimals(menu.od),
memoryHP: fixDecimals(menu.hp)
memoryAR: fixDecimals(beatmapPP.calculatedMapAttributes.ar),
memoryCS: fixDecimals(beatmapPP.calculatedMapAttributes.cs),
memoryOD: fixDecimals(beatmapPP.calculatedMapAttributes.od),
memoryHP: fixDecimals(beatmapPP.calculatedMapAttributes.hp)
},
path: {
full: path.join(
Expand Down
16 changes: 8 additions & 8 deletions packages/tosu/src/api/utils/buildResultSC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ export const buildResult = (instanceManager: InstanceManager): ApiAnswer => {
liveStarRating: fixDecimals(beatmapPP.currAttributes.stars),
mStars: fixDecimals(beatmapPP.calculatedMapAttributes.fullStars),

ar: fixDecimals(menu.ar),
mAR: fixDecimals(beatmapPP.calculatedMapAttributes.ar),
ar: fixDecimals(beatmapPP.calculatedMapAttributes.ar),
mAR: fixDecimals(beatmapPP.calculatedMapAttributes.arConverted),

od: fixDecimals(menu.od),
mOD: fixDecimals(beatmapPP.calculatedMapAttributes.od),
od: fixDecimals(beatmapPP.calculatedMapAttributes.od),
mOD: fixDecimals(beatmapPP.calculatedMapAttributes.odConverted),

cs: fixDecimals(menu.cs),
mCS: fixDecimals(beatmapPP.calculatedMapAttributes.cs),
cs: fixDecimals(beatmapPP.calculatedMapAttributes.cs),
mCS: fixDecimals(beatmapPP.calculatedMapAttributes.csConverted),

hp: fixDecimals(menu.hp),
mHP: fixDecimals(beatmapPP.calculatedMapAttributes.hp),
hp: fixDecimals(beatmapPP.calculatedMapAttributes.hp),
mHP: fixDecimals(beatmapPP.calculatedMapAttributes.hpConverted),

currentBpm: Math.round(beatmapPP.realtimeBPM),
bpm: Math.round(beatmapPP.commonBPM),
Expand Down
33 changes: 19 additions & 14 deletions packages/tosu/src/api/utils/buildResultV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
import { InstanceManager } from '@/instances/manager';
import { BeatmapPP } from '@/states/beatmap';
import { Gameplay } from '@/states/gameplay';
import { Menu } from '@/states/menu';
import { LeaderboardPlayer as MemoryLeaderboardPlayer } from '@/states/types';
import { calculateAccuracy, calculateGrade } from '@/utils/calculators';
import { fixDecimals } from '@/utils/converters';
Expand Down Expand Up @@ -257,7 +256,7 @@ export const buildResult = (instanceManager: InstanceManager): ApiAnswer => {

version: menu.difficulty,

stats: buildBeatmapStats(beatmapPP, menu)
stats: buildBeatmapStats(beatmapPP)
},
play: buildPlay(gameplay, beatmapPP, currentMods),
leaderboard: gameplay.leaderboardScores.map((slot) =>
Expand Down Expand Up @@ -347,13 +346,11 @@ const buildTourneyData = (
global,
gameplay,
resultScreen,
menu,
tourneyManager,
beatmapPP
} = instance.getServices([
'global',
'gameplay',
'menu',
'resultScreen',
'tourneyManager',
'beatmapPP'
Expand Down Expand Up @@ -383,7 +380,7 @@ const buildTourneyData = (
totalPP: tourneyManager.userPP
},
beatmap: {
stats: buildBeatmapStats(beatmapPP, menu)
stats: buildBeatmapStats(beatmapPP)
},
play: buildPlay(gameplay, beatmapPP, currentMods)
};
Expand Down Expand Up @@ -438,7 +435,7 @@ const buildTourneyData = (
};
};

function buildBeatmapStats(beatmapPP: BeatmapPP, menu: Menu) {
function buildBeatmapStats(beatmapPP: BeatmapPP) {
return {
stars: {
live: fixDecimals(beatmapPP.currAttributes.stars),
Expand Down Expand Up @@ -473,20 +470,28 @@ function buildBeatmapStats(beatmapPP: BeatmapPP, menu: Menu) {
},

ar: {
original: fixDecimals(menu.ar),
converted: fixDecimals(beatmapPP.calculatedMapAttributes.ar)
original: fixDecimals(beatmapPP.calculatedMapAttributes.ar),
converted: fixDecimals(
beatmapPP.calculatedMapAttributes.arConverted
)
},
cs: {
original: fixDecimals(menu.cs),
converted: fixDecimals(beatmapPP.calculatedMapAttributes.cs)
original: fixDecimals(beatmapPP.calculatedMapAttributes.cs),
converted: fixDecimals(
beatmapPP.calculatedMapAttributes.csConverted
)
},
od: {
original: fixDecimals(menu.od),
converted: fixDecimals(beatmapPP.calculatedMapAttributes.od)
original: fixDecimals(beatmapPP.calculatedMapAttributes.od),
converted: fixDecimals(
beatmapPP.calculatedMapAttributes.odConverted
)
},
hp: {
original: fixDecimals(menu.hp),
converted: fixDecimals(beatmapPP.calculatedMapAttributes.hp)
original: fixDecimals(beatmapPP.calculatedMapAttributes.hp),
converted: fixDecimals(
beatmapPP.calculatedMapAttributes.hpConverted
)
},

bpm: {
Expand Down
2 changes: 1 addition & 1 deletion packages/tosu/src/instances/lazerInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class LazerInstance extends AbstractInstance {
this.previousMP3Length !== menu.mp3Length;
if (global.gameFolder && this.previousState !== currentState) {
const metadataUpdate = beatmapPP.updateMapMetadata(
currentMods.array,
currentMods,
currentMode,
true
);
Expand Down
2 changes: 1 addition & 1 deletion packages/tosu/src/instances/osuInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class OsuInstance extends AbstractInstance {
this.previousState !== currentState
) {
const metadataUpdate = beatmapPP.updateMapMetadata(
currentMods.array,
currentMods,
currentMode
);
if (metadataUpdate === 'not-ready') {
Expand Down
37 changes: 26 additions & 11 deletions packages/tosu/src/states/beatmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { BeatmapStrains } from '@/api/types/v1';
import { AbstractInstance } from '@/instances';
import { AbstractState } from '@/states';
import { fixDecimals } from '@/utils/converters';
import { ModsLazer } from '@/utils/osuMods.types';
import { CalculateMods, ModsLazer } from '@/utils/osuMods.types';

interface BeatmapPPAcc {
'100': number;
Expand All @@ -31,9 +31,13 @@ interface BeatmapPPAcc {

interface BeatmapAttributes {
ar: number;
arConverted: number;
cs: number;
csConverted: number;
hp: number;
hpConverted: number;
od: number;
odConverted: number;
circles: number;
sliders: number;
spinners: number;
Expand Down Expand Up @@ -153,9 +157,13 @@ export class BeatmapPP extends AbstractState {
};
this.calculatedMapAttributes = {
ar: 0.0,
arConverted: 0.0,
cs: 0.0,
csConverted: 0.0,
hp: 0.0,
hpConverted: 0.0,
od: 0.0,
odConverted: 0.0,
circles: 0,
sliders: 0,
spinners: 0,
Expand Down Expand Up @@ -268,7 +276,7 @@ export class BeatmapPP extends AbstractState {
}

updateMapMetadata(
currentMods: ModsLazer,
currentMods: CalculateMods,
currentMode: number,
lazerByPass: boolean = false
) {
Expand Down Expand Up @@ -332,7 +340,7 @@ export class BeatmapPP extends AbstractState {
`BPPD(updateMapMetadata) Can't get map`,
{
mapPath,
currentMods,
currentMods: currentMods.array,
currentMode
},
(error as Error).stack
Expand All @@ -351,26 +359,29 @@ export class BeatmapPP extends AbstractState {
);

const attributes = new rosu.BeatmapAttributesBuilder({
isConvert:
this.beatmap.mode === 0 &&
this.beatmap.mode !== currentMode,
map: this.beatmap,
mods: currentMods,
mods: currentMods.array,
mode: currentMode
}).build();

const fcPerformance = new rosu.Performance({
mods: currentMods,
mods: currentMods.array,
lazer: this.game.client === ClientType.lazer
}).calculate(this.beatmap);

this.performanceAttributes = fcPerformance;
this.clockRate = attributes.clockRate;
this.clockRate = currentMods.rate;

if (config.calculatePP) {
const ppAcc = {};
for (const acc of [
100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90
]) {
const calculate = new rosu.Performance({
mods: currentMods,
mods: currentMods.array,
accuracy: acc,
lazer: this.game.client === ClientType.lazer
}).calculate(fcPerformance);
Expand Down Expand Up @@ -465,10 +476,14 @@ export class BeatmapPP extends AbstractState {
);

this.calculatedMapAttributes = {
ar: attributes.ar,
cs: attributes.cs,
od: attributes.od,
hp: attributes.hp,
ar: this.beatmap.ar,
arConverted: attributes.ar,
cs: this.beatmap.cs,
csConverted: attributes.cs,
od: this.beatmap.od,
odConverted: attributes.od,
hp: this.beatmap.hp,
hpConverted: attributes.hp,
circles: this.lazerBeatmap.hittable,
sliders: this.lazerBeatmap.slidable,
spinners: this.lazerBeatmap.spinnable,
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cdd258e

Please sign in to comment.