Skip to content

Commit

Permalink
Add support for displaying strain graph in beatmap calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Rian8337 committed Jul 13, 2024
1 parent 546d71e commit dd1ddf5
Show file tree
Hide file tree
Showing 16 changed files with 462 additions and 218 deletions.
66 changes: 38 additions & 28 deletions src/database/utils/aliceDb/Challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ export class Challenge extends Manager {

const pass = await this.verifyPassCompletion(
score,
droidAttribs,
osuAttribs,
droidAttribs.attributes,
osuAttribs.attributes,
replay.calculateHitError()!,
);

Expand Down Expand Up @@ -698,18 +698,23 @@ export class Challenge extends Manager {
);

droidAttribs =
await DPPProcessorRESTManager.getPerformanceAttributes(
this.beatmapid,
Modes.droid,
PPCalculationMethod.live,
calcParams,
);
osuAttribs = await DPPProcessorRESTManager.getPerformanceAttributes(
this.beatmapid,
Modes.osu,
PPCalculationMethod.live,
calcParams,
);
(
await DPPProcessorRESTManager.getPerformanceAttributes(
this.beatmapid,
Modes.droid,
PPCalculationMethod.live,
calcParams,
)
)?.attributes ?? null;
osuAttribs =
(
await DPPProcessorRESTManager.getPerformanceAttributes(
this.beatmapid,
Modes.osu,
PPCalculationMethod.live,
calcParams,
)
)?.attributes ?? null;
} else if (scoreOrReplay instanceof ReplayAnalyzer) {
const attribs =
await this.getReplayCalculationResult(scoreOrReplay);
Expand All @@ -724,19 +729,24 @@ export class Challenge extends Manager {
);

droidAttribs =
await DPPProcessorRESTManager.getPerformanceAttributes(
this.beatmapid,
Modes.droid,
PPCalculationMethod.live,
calcParams,
);

osuAttribs = await DPPProcessorRESTManager.getPerformanceAttributes(
this.beatmapid,
Modes.osu,
PPCalculationMethod.live,
calcParams,
);
(
await DPPProcessorRESTManager.getPerformanceAttributes(
this.beatmapid,
Modes.droid,
PPCalculationMethod.live,
calcParams,
)
)?.attributes ?? null;

osuAttribs =
(
await DPPProcessorRESTManager.getPerformanceAttributes(
this.beatmapid,
Modes.osu,
PPCalculationMethod.live,
calcParams,
)
)?.attributes ?? null;
}

if (!droidAttribs || !osuAttribs) {
Expand Down Expand Up @@ -1458,7 +1468,7 @@ export class Challenge extends Manager {
return null;
}

return [droidAttribs, osuAttribs];
return [droidAttribs.attributes, osuAttribs.attributes];
}

/**
Expand Down
43 changes: 28 additions & 15 deletions src/database/utils/elainaDb/UserBind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,24 @@ export class UserBind extends Manager {
continue;
}

const { attributes } = attribs;

await HelperFunctions.sleep(0.1);

const [needsPersistence] = DPPHelper.insertScore(newList, [
DPPHelper.scoreToPPEntry(beatmapInfo.fullTitle, score, attribs),
DPPHelper.scoreToPPEntry(
beatmapInfo.fullTitle,
score,
attributes,
),
]);

if (needsPersistence) {
if (attribs.localReplayMD5) {
if (attributes.localReplayMD5) {
await DPPProcessorRESTManager.persistLocalReplay(
ppEntry.uid,
beatmapInfo.hash,
attribs.localReplayMD5,
attributes.localReplayMD5,
);
} else {
await DPPProcessorRESTManager.persistOnlineReplay(
Expand Down Expand Up @@ -467,7 +473,8 @@ export class UserBind extends Manager {

++playCount;

const { difficulty, performance, params } = attribs;
const { difficulty, performance, params } =
attribs.attributes;
const accuracy = new Accuracy(params.accuracy);

const ppEntry: PPEntry = {
Expand All @@ -477,7 +484,7 @@ export class UserBind extends Manager {
pp: NumberHelper.round(performance.total, 2),
mods: difficulty.mods,
accuracy: NumberHelper.round(accuracy.value() * 100, 2),
combo: attribs.params.combo,
combo: params.combo,
miss: accuracy.nmiss,
speedMultiplier:
params.customSpeedMultiplier !== 1
Expand Down Expand Up @@ -647,9 +654,9 @@ export class UserBind extends Manager {
continue;
}

const { performance: perfResult, params } = liveAttribs;
const { performance: perfResult, params } = liveAttribs.attributes;
const { performance: rebalPerfResult, params: rebalParams } =
rebalAttribs;
rebalAttribs.attributes;

const accuracy = new Accuracy(params.accuracy);

Expand All @@ -658,7 +665,7 @@ export class UserBind extends Manager {
hash: beatmapInfo.hash,
title: beatmapInfo.fullTitle,
pp: NumberHelper.round(perfResult.total, 2),
mods: liveAttribs.difficulty.mods,
mods: liveAttribs.attributes.difficulty.mods,
accuracy: NumberHelper.round(accuracy.value() * 100, 2),
combo: params.combo,
miss: accuracy.nmiss,
Expand All @@ -678,7 +685,7 @@ export class UserBind extends Manager {
prevTap: NumberHelper.round(perfResult.tap, 2),
prevAccuracy: NumberHelper.round(perfResult.accuracy, 2),
prevVisual: NumberHelper.round(perfResult.visual, 2),
mods: rebalAttribs.difficulty.mods,
mods: rebalAttribs.attributes.difficulty.mods,
accuracy: NumberHelper.round(accuracy.value() * 100, 2),
combo: params.combo,
miss: accuracy.nmiss,
Expand All @@ -695,7 +702,8 @@ export class UserBind extends Manager {
rebalPerfResult.tapDeviation * 10,
2,
),
overallDifficulty: rebalAttribs.difficulty.overallDifficulty,
overallDifficulty:
rebalAttribs.attributes.difficulty.overallDifficulty,
hit300: accuracy.n300,
hit100: accuracy.n100,
hit50: accuracy.n50,
Expand All @@ -704,11 +712,14 @@ export class UserBind extends Manager {
rebalPerfResult.flashlightSliderCheesePenalty,
visualSliderCheesePenalty:
rebalPerfResult.visualSliderCheesePenalty,
speedNoteCount: rebalAttribs.difficulty.speedNoteCount,
speedNoteCount:
rebalAttribs.attributes.difficulty.speedNoteCount,
liveTapPenalty: params.tapPenalty,
rebalanceTapPenalty: rebalParams.tapPenalty,
averageBPM:
60000 / 4 / rebalAttribs.difficulty.averageSpeedDeltaTime,
60000 /
4 /
rebalAttribs.attributes.difficulty.averageSpeedDeltaTime,
};

consola.info(
Expand Down Expand Up @@ -854,24 +865,26 @@ export class UserBind extends Manager {
continue;
}

const { attributes } = attribs;

this.playc = ++playCount;

const ppEntry = DPPHelper.scoreToPPEntry(
beatmapInfo.fullTitle,
score,
attribs,
attributes,
);

const [needsPersistence] = DPPHelper.insertScore(newList, [
ppEntry,
]);

if (needsPersistence) {
if (attribs.localReplayMD5) {
if (attributes.localReplayMD5) {
await DPPProcessorRESTManager.persistLocalReplay(
ppEntry.uid,
beatmapInfo.hash,
attribs.localReplayMD5,
attributes.localReplayMD5,
);
} else {
await DPPProcessorRESTManager.persistOnlineReplay(
Expand Down
26 changes: 14 additions & 12 deletions src/events/messageCreate/utils/userBeatmapCalculation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const run: EventUtil["run"] = async (_, message: Message) => {
Modes.droid,
PPCalculationMethod.live,
calcParams,
true,
);

if (!droidAttribs) {
Expand All @@ -91,11 +92,12 @@ export const run: EventUtil["run"] = async (_, message: Message) => {
const calcEmbedOptions = EmbedCreator.createCalculationEmbed(
beatmapInfo,
calcParams,
droidAttribs.difficulty,
osuAttribs.difficulty,
droidAttribs.performance,
osuAttribs.performance,
droidAttribs.attributes.difficulty,
osuAttribs.attributes.difficulty,
droidAttribs.attributes.performance,
osuAttribs.attributes.performance,
localization.language,
Buffer.from(droidAttribs.strainChart),
);

let string = "";
Expand All @@ -104,23 +106,23 @@ export const run: EventUtil["run"] = async (_, message: Message) => {
string += `${localization.getTranslation(
"droidStars",
)}: ${DPPHelper.getDroidDifficultyAttributesInfo(
droidAttribs.difficulty,
droidAttribs.attributes.difficulty,
)}\n${localization.getTranslation(
"droidPP",
)}: ${DPPHelper.getDroidPerformanceAttributesInfo(
droidAttribs.performance,
droidAttribs.attributes.performance,
)}\n`;
}

if (message.content.includes("-p")) {
string += `${localization.getTranslation(
"pcStars",
)}: ${DPPHelper.getOsuDifficultyAttributesInfo(
osuAttribs.difficulty,
osuAttribs.attributes.difficulty,
)}\n${localization.getTranslation(
"pcPP",
)}: ${DPPHelper.getOsuPerformanceAttributesInfo(
osuAttribs.performance,
osuAttribs.attributes.performance,
)}`;
}

Expand Down Expand Up @@ -229,9 +231,9 @@ export const run: EventUtil["run"] = async (_, message: Message) => {
embed.addFields({
name: `${underscore(
beatmapInfo.version,
)} (${droidDiffAttribs.starRating.toFixed(2)} ${
)} (${droidDiffAttribs.attributes.starRating.toFixed(2)} ${
Symbols.star
} | ${osuDiffAttribs.starRating.toFixed(2)} ${
} | ${osuDiffAttribs.attributes.starRating.toFixed(2)} ${
Symbols.star
})`,
value:
Expand All @@ -251,8 +253,8 @@ export const run: EventUtil["run"] = async (_, message: Message) => {
difficultyStatisticsCalculatorOptions,
)}\n` +
`${bold(
droidDiffAttribs.starRating.toFixed(2),
)}dpp - ${osuDiffAttribs.starRating.toFixed(2)}pp`,
droidDiffAttribs.attributes.starRating.toFixed(2),
)}dpp - ${osuDiffAttribs.attributes.starRating.toFixed(2)}pp`,
});
}

Expand Down
8 changes: 4 additions & 4 deletions src/events/messageCreate/utils/youtubeBeatmapFinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ export const run: EventUtil["run"] = async (_, message: Message) => {
embed.addFields({
name: `${underscore(
beatmapInfo.version,
)} (${droidAttribs.starRating.toFixed(2)} ${
)} (${droidAttribs.attributes.starRating.toFixed(2)} ${
Symbols.star
} | ${osuAttribs.starRating.toFixed(2)} ${
} | ${osuAttribs.attributes.starRating.toFixed(2)} ${
Symbols.star
})`,
value:
Expand All @@ -206,8 +206,8 @@ export const run: EventUtil["run"] = async (_, message: Message) => {
4,
)}\n` +
`${bold(
droidAttribs.starRating.toFixed(2),
)}dpp - ${osuAttribs.starRating.toFixed(2)}pp`,
droidAttribs.attributes.starRating.toFixed(2),
)}dpp - ${osuAttribs.attributes.starRating.toFixed(2)}pp`,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const run: ButtonCommand["run"] = async (_, interaction) => {
? player.avatarURL
: DroidHelper.getAvatarURL(player.id),
interaction.member.displayColor,
scoreAttribs,
scoreAttribs?.attributes,
undefined,
localization.language,
);
Expand Down
Loading

0 comments on commit dd1ddf5

Please sign in to comment.