Пример #1
0
        private static TournamentRanking MakeRankingTable([NotNull] string tournamentId, [NotNull] List <BattlePlayerResult> results)
        {
            var rankingEntries = results
                                 .GroupBy(g => g.Player)
                                 .Select(g => new RankingEntry
            {
                Name    = g.Key.Name,
                Version = g.Key.Version,
                Score   = g.Sum(res => res.Score()),
                Wins    = g.Count(res => res.ResultType == BattlePlayerResultType.Win),
                Loses   = g.Count(res => res.ResultType == BattlePlayerResultType.Loss),
                Draws   = g.Count(res => res.ResultType == BattlePlayerResultType.Draw),
                Games   = g.Count(),
            })
                                 .OrderByDescending(t => t.Score)
                                 .ToArray();
            var ranking = new TournamentRanking
            {
                TournamentId = tournamentId,
                Timestamp    = DateTime.UtcNow,
                Places       = rankingEntries,
            };

            return(ranking);
        }
Пример #2
0
 private void SaveRanking([NotNull] string tournamentId, [NotNull] TournamentRanking ranking)
 {
     lock (gamesDir)
     {
         var rankingFile = GetRankingFile(tournamentId);
         File.WriteAllText(rankingFile, JsonConvert.SerializeObject(ranking, Formatting.Indented));
         File.Copy(rankingFile, GetRankingFile("last"), true);
     }
 }