Skip to content

Commit

Permalink
Merge pull request #2601 from Swan/recalc-local-scores
Browse files Browse the repository at this point in the history
Recalculate performance rating of outdated local scores
  • Loading branch information
Swan committed Aug 27, 2020
2 parents cd9801a + 249b69e commit 497223b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Quaver.Shared/Database/Scores/Score.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ public class Score
/// </summary>
public double RankedAccuracy { get; set; }

/// <summary>
/// The version of the difficulty calculator used for this score
/// </summary>
public string DifficultyProcessorVersion { get; set; }

/// <summary>
/// If the score is an online score.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions Quaver.Shared/Database/Scores/ScoreDatabaseCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ internal static int InsertScoreIntoDatabase(Score score)
return -1;
}

/// <summary>
/// Updates an individual map in the database.
/// </summary>
public static void UpdateScore(Score score)
{
try
{
DatabaseManager.Connection.Update(score);
Logger.Debug($"Updated score: {score.Id} in the cache", LogType.Runtime);
}
catch (Exception e)
{
Logger.Error(e, LogType.Runtime);
}
}

/// <summary>
/// Responsible for removing a score from the database
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Quaver.Shared/Screens/Results/ResultsScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Xna.Framework.Input;
using Quaver.API.Enums;
using Quaver.API.Helpers;
using Quaver.API.Maps.Processors.Difficulty.Rulesets.Keys;
using Quaver.API.Maps.Processors.Rating;
using Quaver.API.Maps.Processors.Scoring;
using Quaver.API.Maps.Processors.Scoring.Data;
Expand Down Expand Up @@ -687,6 +688,7 @@ private void SubmitLocalScore(GameplayScreen screen, Replay replay)
screen.PauseCount, screen.Map.RandomizeModifierSeed, JudgementWindowsDatabaseCache.Selected.Value);

// Calculate performance rating
score.DifficultyProcessorVersion = DifficultyProcessorKeys.Version;
score.RatingProcessorVersion = RatingProcessorKeys.Version;
score.PerformanceRating = processor.Failed ? 0 : new RatingProcessorKeys(Map.DifficultyFromMods(processor.Mods)).CalculateRating(rankedAccuracy);
score.RankedAccuracy = rankedAccuracy;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Quaver.API.Enums;
using Quaver.API.Maps.Processors.Difficulty.Rulesets.Keys;
using Quaver.API.Maps.Processors.Rating;
using Quaver.Shared.Database.Maps;
using Quaver.Shared.Database.Scores;
using Quaver.Shared.Screens.Select.UI.Leaderboard;
Expand All @@ -18,6 +21,29 @@ public FetchedScoreStore Fetch(Map map)
try
{
var scores = ScoreDatabaseCache.FetchMapScores(map.Md5Checksum);

if (map.DifficultyProcessorVersion == DifficultyProcessorKeys.Version)
{
foreach (var score in scores)
{
if (score.DifficultyProcessorVersion == DifficultyProcessorKeys.Version)
continue;

score.DifficultyProcessorVersion = DifficultyProcessorKeys.Version;
score.RatingProcessorVersion = RatingProcessorKeys.Version;
var oldRating = score.PerformanceRating;

var diff = map.DifficultyFromMods((ModIdentifier) score.Mods);
var rating = new RatingProcessorKeys(diff).CalculateRating(score.Accuracy, score.Grade == Grade.F);

score.PerformanceRating = rating;
ScoreDatabaseCache.UpdateScore(score);

Logger.Important($"Rating of score: {score.Id} recalculated to {score.PerformanceRating} from {oldRating}",
LogType.Runtime, false);
}
}

return new FetchedScoreStore(scores, scores?.Count != 0 ? scores?.First() : null);
}
catch (Exception e)
Expand Down

0 comments on commit 497223b

Please sign in to comment.