コード例 #1
0
        private void InitReports()
        {
            logger.Info("Initialize reports");

            recentMatches = new DataIdentity <MatchInfo>()
                            .Report(MaxReportSize, m => m.EndTime, (m1, m2) => m1.GetIndex().CompareTo(m2.GetIndex()));

            popularServers = new DataIdentity <ServerInfo>()
                             .Select(s => new ServerReportResult
            {
                Server             = s,
                TotalMatchesPlayed = serverStatisticStorage.GetStatistics(s.Id)?.TotalMatchesPlayed ?? 0
            })
                             .Report(MaxReportSize,
                                     s => s.TotalMatchesPlayed,
                                     (s1, s2) => string.Compare(s1.Server.Id, s2.Server.Id, StringComparison.Ordinal));

            allServers = new DataIdentity <ServerInfo>()
                         .Report(s => s.Id, (s1, s2) => string.Compare(s1.Id, s2.Id, StringComparison.Ordinal));

            bestPlayers = new DataIdentity <PlayerInfo>().Where(p =>
            {
                var playerStat = playerStatisticStorage.GetStatistics(p.Name);
                return(playerStat.KillToDeathRatio != null && playerStat.TotalMatchesPlayed >= 10);
            })
                          .Select(p => new PlayerReportResult {
                Player = p, KillToDeathRatio = playerStatisticStorage.GetStatistics(p.Name).KillToDeathRatio
            })
                          .Report(MaxReportSize, p =>
            {
                if (p.KillToDeathRatio != null)
                {
                    return(p.KillToDeathRatio.Value);
                }
                throw new ArgumentException($"{nameof(p.KillToDeathRatio)} must be not null");
            },
                                  (p1, p2) => p1.Player.GetIndex().CompareTo(p2.Player.GetIndex()));
        }
コード例 #2
0
        private Task <IResponse> GetFullPlayerStatstic(string playerName)
        {
            var statistics = playerStatistics.GetStatistics(playerName);

            if (statistics.TotalMatchesPlayed == 0)
            {
                return(Task.FromResult <IResponse>(new HttpResponse(HttpStatusCode.NotFound)));
            }

            return(Task.FromResult <IResponse>(new JsonHttpResponse(HttpStatusCode.OK, new
            {
                statistics.TotalMatchesPlayed,
                statistics.AverageMatchesPerDay,
                statistics.AverageScoreboardPercent,
                statistics.FavoriteGameMode,
                statistics.FavoriteServer,
                lastMatchPlayed = statistics.LastMatchPlayed.ToUtcFormat(),
                statistics.MaximumMatchesPerDay,
                statistics.TotalMatchesWon,
                statistics.UniqueServers,
                statistics.KillToDeathRatio,
            })));
        }