private static Tuple <string, string> getMostPlayed(Playtime stats) { var playtime = stats.merge(); var sortedList = (from entry in playtime orderby entry.Value descending select entry).ToList(); string leaderboard = ""; for (int i = 0; i < 5; i++) { if (sortedList[i].Value > 0.005) { leaderboard += $"{sortedList[i].Key}: {Math.Round(playtime[sortedList[i].Key], 2)}hrs\n"; } else { break; } } if (playtime[sortedList[0].Key] > 0.005) { return(Tuple.Create(sortedList[0].Key, leaderboard)); } return(Tuple.Create("CannotFetchArcade", "CannotFetchArcade")); }
/// <summary> /// Determines the most played Hero of the last play session /// </summary> /// <param Name="oldStats">Playtime of each hero before the Timer elapsed</param> /// <param Name="newStats">Playtime of each hero after the Timer elapsed</param> /// <returns>A Tuple with the Name of the most played Hero, and a string presenting the change in playtime</returns> private Tuple <string, string> getSessionMostPlayed(Playtime oldStats, Playtime newStats) { var New = newStats.merge(); var Old = oldStats.merge(); var difference = new Dictionary <string, double>(); foreach (string key in Old.Keys) { difference.Add(key, New[key] - Old[key]); } var sortedList = (from entry in difference orderby entry.Value descending select entry).ToList(); string leaderboard = ""; for (int i = 0; i < 5; i++) { if (sortedList[i].Value > 0.005) { leaderboard += $"{sortedList[i].Key}: {Math.Round(New[sortedList[i].Key], 2)}hrs (+{Math.Round(sortedList[i].Value, 2)})\n"; } else { break; } } if (difference[sortedList[0].Key] > 0.005) { return(Tuple.Create(sortedList[0].Key, leaderboard)); } return(Tuple.Create("CannotFetchArcade", "CannotFetchArcade")); }