track difficulty and characteristic for scoresaber scores
Some checks failed
Deploy Backend / docker (ubuntu-latest) (push) Failing after 32s
Deploy Website / docker (ubuntu-latest) (push) Failing after 30s

This commit is contained in:
Lee 2024-10-23 20:52:57 +01:00
parent 0a87877373
commit 2852e0c0ed
3 changed files with 26 additions and 10 deletions

@ -52,8 +52,8 @@ export class ScoreService {
} }
const { score: scoreToken, leaderboard: leaderboardToken } = playerScore; const { score: scoreToken, leaderboard: leaderboardToken } = playerScore;
const score = getScoreSaberScoreFromToken(scoreToken, leaderboardToken, scoreToken.leaderboardPlayerInfo.id);
const leaderboard = getScoreSaberLeaderboardFromToken(leaderboardToken); const leaderboard = getScoreSaberLeaderboardFromToken(leaderboardToken);
const score = getScoreSaberScoreFromToken(scoreToken, leaderboard, scoreToken.leaderboardPlayerInfo.id);
const playerInfo = score.playerInfo; const playerInfo = score.playerInfo;
// Not ranked // Not ranked
@ -124,7 +124,8 @@ export class ScoreService {
* @param score the score to track * @param score the score to track
* @param leaderboard the leaderboard to track * @param leaderboard the leaderboard to track
*/ */
public static async trackScoreSaberScore({ score, leaderboard }: ScoreSaberPlayerScoreToken) { public static async trackScoreSaberScore({ score, leaderboard: leaderboardToken }: ScoreSaberPlayerScoreToken) {
const leaderboard = getScoreSaberLeaderboardFromToken(leaderboardToken);
const playerId = score.leaderboardPlayerInfo.id; const playerId = score.leaderboardPlayerInfo.id;
const playerName = score.leaderboardPlayerInfo.name; const playerName = score.leaderboardPlayerInfo.name;
const player: PlayerDocument | null = await PlayerModel.findById(playerId); const player: PlayerDocument | null = await PlayerModel.findById(playerId);
@ -164,6 +165,8 @@ export class ScoreService {
playerId: playerId, playerId: playerId,
leaderboardId: leaderboard.id, leaderboardId: leaderboard.id,
score: scoreToken.score, score: scoreToken.score,
difficulty: leaderboard.difficulty.difficulty,
characteristic: leaderboard.difficulty.characteristic,
}) })
) { ) {
console.log( console.log(
@ -328,13 +331,13 @@ export class ScoreService {
); );
for (const token of leaderboardScores.playerScores) { for (const token of leaderboardScores.playerScores) {
const score = getScoreSaberScoreFromToken(token.score, token.leaderboard, playerId); const leaderboard = getScoreSaberLeaderboardFromToken(token.leaderboard);
if (score == undefined) { if (leaderboard == undefined) {
continue; continue;
} }
const leaderboard = getScoreSaberLeaderboardFromToken(token.leaderboard); const score = getScoreSaberScoreFromToken(token.score, leaderboard, playerId);
if (leaderboard == undefined) { if (score == undefined) {
continue; continue;
} }

@ -2,7 +2,6 @@ import { getModelForClass, modelOptions, plugin, Prop, ReturnModelType, Severity
import Score from "../score"; import Score from "../score";
import { Modifier } from "../../../score/modifier"; import { Modifier } from "../../../score/modifier";
import ScoreSaberScoreToken from "../../../types/token/scoresaber/score-saber-score-token"; import ScoreSaberScoreToken from "../../../types/token/scoresaber/score-saber-score-token";
import ScoreSaberLeaderboardToken from "../../../types/token/scoresaber/score-saber-leaderboard-token";
import ScoreSaberLeaderboard from "../../../leaderboard/impl/scoresaber-leaderboard"; import ScoreSaberLeaderboard from "../../../leaderboard/impl/scoresaber-leaderboard";
import { type ScoreSaberLeaderboardPlayerInfoToken } from "../../../types/token/scoresaber/score-saber-leaderboard-player-info-token"; import { type ScoreSaberLeaderboardPlayerInfoToken } from "../../../types/token/scoresaber/score-saber-leaderboard-player-info-token";
import { Document } from "mongoose"; import { Document } from "mongoose";
@ -82,7 +81,7 @@ export type ScoreSaberScore = InstanceType<typeof ScoreSaberScorePublic>;
*/ */
export function getScoreSaberScoreFromToken( export function getScoreSaberScoreFromToken(
token: ScoreSaberScoreToken, token: ScoreSaberScoreToken,
leaderboard: ScoreSaberLeaderboardToken | ScoreSaberLeaderboard, leaderboard: ScoreSaberLeaderboard,
playerId?: string playerId?: string
): ScoreSaberScore { ): ScoreSaberScore {
const modifiers: Modifier[] = const modifiers: Modifier[] =
@ -100,6 +99,8 @@ export function getScoreSaberScoreFromToken(
return { return {
playerId: playerId || token.leaderboardPlayerInfo.id, playerId: playerId || token.leaderboardPlayerInfo.id,
leaderboardId: leaderboard.id, leaderboardId: leaderboard.id,
difficulty: leaderboard.difficulty.difficulty,
characteristic: leaderboard.difficulty.characteristic,
score: token.baseScore, score: token.baseScore,
accuracy: (token.baseScore / leaderboard.maxScore) * 100, accuracy: (token.baseScore / leaderboard.maxScore) * 100,
rank: token.rank, rank: token.rank,

@ -1,7 +1,8 @@
import { Modifier } from "../../score/modifier"; import { Modifier } from "../../score/modifier";
import { AdditionalScoreData } from "../additional-score-data/additional-score-data"; import { AdditionalScoreData } from "../additional-score-data/additional-score-data";
import { type Leaderboards } from "../../leaderboard";
import { prop } from "@typegoose/typegoose"; import { prop } from "@typegoose/typegoose";
import { type MapDifficulty } from "@ssr/score/map-difficulty";
import { type MapCharacteristic } from "@ssr/types/map-characteristic";
/** /**
* The model for a score. * The model for a score.
@ -15,11 +16,22 @@ export default class Score {
/** /**
* The id of the player who set the score. * The id of the player who set the score.
* @private
*/ */
@prop({ required: true, index: true }) @prop({ required: true, index: true })
public readonly playerId!: string; public readonly playerId!: string;
/**
* The map difficulty played in the score.
*/
@prop({ required: true })
public readonly difficulty!: MapDifficulty;
/**
* The characteristic of the map.
*/
@prop({ required: true })
public readonly characteristic!: MapCharacteristic;
/** /**
* The base score for the score. * The base score for the score.
* @private * @private