private static void RecalculateUserScores(int userId, int totalUsers) { Logger.Log($"Recalculating scores for user: {userId}..."); var scores = FetchUserScores(userId); var sum = 0; Parallel.ForEach(scores, score => { var map = MapCache.Fetch(score.MapId); if (map == null) { Console.WriteLine($"Skipping score: {score}. Failed to retrieve map!"); return; } var diff = map.SolveDifficulty(score.Mods, true); var rating = new RatingProcessorKeys(diff.OverallDifficulty).CalculateRating(score.Accuracy); using var conn = new MySqlConnection(SqlDatabase.GetConnString(Configuration.Instance)); using (var cmd = conn.CreateCommand()) { conn.Open(); cmd.CommandText = "UPDATE scores SET performance_rating = @r, difficulty_processor_version = @d, " + "performance_processor_version = @p " + "WHERE id = @i"; cmd.Parameters.AddWithValue("@r", rating); cmd.Parameters.AddWithValue("@d", DifficultyProcessorKeys.Version); cmd.Parameters.AddWithValue("@p", RatingProcessorKeys.Version); cmd.Parameters.AddWithValue("@i", score.Id); cmd.ExecuteNonQuery(); } sum++; Console.WriteLine($"[{userId}/{totalUsers}] [{(float)sum / scores.Count:0.00%}%] #{score.Id} -> {rating}"); }); }
private static void RecalculateMap(int id) { var map = MapCache.Fetch(id); if (map == null) { Console.WriteLine($"Could not fetch map: {id}"); return; } var diff = map.SolveDifficulty().OverallDifficulty; using var conn = new MySqlConnection(SqlDatabase.GetConnString(Configuration.Instance)); using var cmd = conn.CreateCommand(); conn.Open(); cmd.CommandText = "UPDATE maps SET difficulty_rating = @d WHERE id = @i"; cmd.Parameters.AddWithValue("@d", diff); cmd.Parameters.AddWithValue("@i", id); cmd.ExecuteNonQuery(); Console.WriteLine($"#{id} -> {diff}"); }