public async Task <StandingStats> GetStandingStats(string generation) { var contests = DataContext.Contests .Include(c => c.Submissions) .Where(c => c.Generation == generation); var stats = new StandingStats(); stats.Contests = contests .Select(c => c.Name) .OrderBy(name => name) .ToList(); stats.Results = contests.Select(c => c.Submissions .GroupBy(s => s.SubmitterId) .Select(g => new { StudentId = g.First().SubmitterId, Solved = g.Count(s => s.IsAccepted), ContestName = c.Name })) .SelectMany(c => c.Select(s => s)) .GroupBy(d => d.StudentId) .Select(d => new { Name = d.Key, TotalSolved = d.Sum(e => e.Solved), ContestSolved = d.ToDictionary(e => e.ContestName, e => e.Solved) }) .Select(v => new UserResult(v.Name, v.TotalSolved, stats.Contests.Select(c => v.ContestSolved.GetValueOrDefault(c, 0)).ToList())) .OrderByDescending(r => r.TotalSolved) .ToList(); return(await Task.FromResult(stats)); }
private Stats ParseHeader2(Stats tempStats, string header2) { Stats stats; Match match; if ((match = Regex.Match(header2, StandingRegex)).Success) { stats = new StandingStats { CompletedHills = Convert.ToInt32(match.Groups["completed_hills"].Value), TotalHills = Convert.ToInt32(match.Groups["total_hills"].Value) }; } else if ((match = Regex.Match(header2, FinalResultRegex)).Success) { if (tempStats.Type == "Team Cup") { stats = new TeamFinalResultStats { Hill = match.Groups["hill"].Value }; } else { stats = new FinalResultStats { Hill = match.Groups["hill"].Value, Knockout = header2.Contains("KO") }; } } else if ((match = Regex.Match(header2, QualRegex)).Success) { stats = new QualificationStats { Hill = match.Groups["hill"].Value, Knockout = header2.Contains("KO") }; } else { throw new StatParserException("Can't determine the type of stats"); } stats.Type = tempStats.Type; stats.Date = tempStats.Date; stats.GameVersion = tempStats.GameVersion; return(stats); }