public async Task <List <PlayersComparison> > ComparePlayers(int userId1, int userId2) { var os1 = await openStatService.GetOpenStat(userId1); var os2 = await openStatService.GetOpenStat(userId2); var results = new List <PlayersComparison>(); foreach (var mode in os1.Value.Gametypes) { var comparison = new PlayersComparison() { Mode = new Mode(mode.Key, mode.Value.Name), Stat1 = GetStatBase(mode.Value), Stat2 = new ComparisonStat() }; results.Add(comparison); } foreach (var mode in os2.Value.Gametypes) { var entry = results.Find(x => x.Mode.ModeId == mode.Key); if (entry != null) { entry.Stat2 = GetStatBase(mode.Value); if (entry.Stat1.Record.HasValue && entry.Stat2.Record.HasValue) { entry.Difference = new StatDifference(entry.Stat1.Record.Value - entry.Stat2.Record.Value, entry.Stat1.AvgSpeed.Value - entry.Stat2.AvgSpeed.Value); } } else { var ps = new PlayersComparison() { Mode = new Mode(mode.Key, mode.Value.Name), Stat1 = new ComparisonStat(), Stat2 = GetStatBase(mode.Value) }; results.Add(ps); } } return(results); ComparisonStat GetStatBase(OpenStat.Mode mode) { return(new ComparisonStat { Record = mode.Info.BestSpeed, AvgSpeed = (int)mode.Info.AvgSpeed, AvgErRate = mode.Info.AvgError, Mileage = mode.NumRaces }); } }
private async Task <List <HrustPlayer> > GetHrustResults(List <User> users) { List <string> closed = new List <string>(); List <HrustPlayer> results = new List <HrustPlayer>(); int counter = 0; ChangeProgress(new Progress(0, users.Count)); foreach (var user in users) { var os = await openStatService.GetOpenStat(user.Id); HrustPlayer hs; if (os.IsOpen) { string userNick = user.Nick; if (string.IsNullOrEmpty(user.Nick)) { var normalQs = await quickStatService.GetQuickStat(user.Id); userNick = normalQs.Value.Nick; } hs = new HrustPlayer(user.Id, userNick, false); hs.NormalStat.Mileage = os.Value.Gametypes["normal"].Info.NumRaces; hs.NormalStat.Record = os.Value.Gametypes["normal"].Info.BestSpeed.Value; hs.NormalStat.Rank = Rank.GetByRecord(os.Value.Gametypes["normal"].Info.BestSpeed.Value); for (int i = 0; i < HrustConstants.ModeIds.Length; i++) { if (os.Value.Gametypes.ContainsKey(HrustConstants.ModeIds[i])) { hs.ExercisesStat[i].Record = os.Value.Gametypes[HrustConstants.ModeIds[i]].Info.BestSpeed.Value; hs.ExercisesStat[i].Mileage = os.Value.Gametypes[HrustConstants.ModeIds[i]].Info.NumRaces; } } } else { var normalQs = await quickStatService.GetQuickStat(user.Id); hs = new HrustPlayer(user.Id, normalQs.Value.Nick, true); hs.NormalStat.Record = normalQs.Value.Record; hs.NormalStat.Mileage = normalQs.Value.Mileage; hs.NormalStat.Rank = normalQs.Value.Rank; for (int i = 23; i >= 0; i--) { var qs = await quickStatService.GetQuickStat(user.Id, HrustConstants.ModeIds[i]); if (qs.Value.Mileage == 0) { closed.Add(user.Nick); continue; } else { hs.ExercisesStat[i].Record = qs.Value.Record; hs.ExercisesStat[i].Mileage = qs.Value.Mileage; } } } hs.Calculate(); results.Add(hs); ChangeProgress(new Progress(++counter, users.Count)); } results.Sort(); return(results); }