示例#1
0
 public ServerStatistics(ServerStatisticsEntry statisticsEntry)
 {
     TotalMatchesPlayed   = statisticsEntry.TotalMatchesPlayed;
     MaximumMatchesPerDay = statisticsEntry.MaximumMatchesPerDay;
     AverageMatchesPerDay = statisticsEntry.AverageMatchesPerDay;
     MaximumPopulation    = statisticsEntry.MaximumPopulation;
     AveragePopulation    = statisticsEntry.AveragePopulation;
     Top5GameModes        = statisticsEntry.Top5GameModes.Select(x => x.String).ToList();
     Top5Maps             = statisticsEntry.Top5Maps.Select(x => x.String).ToList();
 }
        private void UpdateEntry(ServerStatisticsEntry previous, MatchInfoEntry infoEntry)
        {
            previous.MatchesPerDay.AddOrUpdate(x => x.Day == infoEntry.Timestamp.Date,
                                               () => new DayCountEntry {
                Day = infoEntry.Timestamp.Date, Count = 1
            }, x => x.Count++);
            previous.PopulationPerMatch.AddOrUpdate(x => x.Key == infoEntry.Endpoint + infoEntry.Timestamp,
                                                    () => new MatchCountEntry
            {
                Key       = infoEntry.Endpoint + infoEntry.Timestamp,
                Endpoint  = infoEntry.Endpoint,
                TimeStamp = infoEntry.Timestamp,
                Count     = infoEntry.Scoreboard.Count
            }, x => x.Count++);
            previous.GameModePopularity.AddOrUpdate(x => x.Name == infoEntry.GameMode,
                                                    () => new NameCountEntry {
                Name = infoEntry.GameMode, Count = 1
            }, x => x.Count++);
            previous.MapPopularity.AddOrUpdate(x => x.Name == infoEntry.Map,
                                               () => new NameCountEntry {
                Name = infoEntry.Map, Count = 1
            }, x => x.Count++);

            var totalDays = (previous.MatchesPerDay.Max(x => x.Day) - previous.MatchesPerDay.Min(x => x.Day)).TotalDays;

            previous.TotalMatchesPlayed   = previous.TotalMatchesPlayed + 1;
            previous.MaximumMatchesPerDay = previous.MatchesPerDay.Select(x => x.Count).Max();
            previous.AverageMatchesPerDay = Math.Abs(totalDays) < 0.00001 ? previous.MatchesPerDay.Select(x => x.Count).Sum() : previous.MatchesPerDay.Select(x => x.Count).Sum() / totalDays;
            previous.MaximumPopulation    = previous.PopulationPerMatch.Select(x => x.Count).Max();
            previous.AveragePopulation    = (double)previous.PopulationPerMatch.Select(x => x.Count).Sum() / previous.PopulationPerMatch.Count;

            previous.Top5GameModes = previous.GameModePopularity
                                     .OrderByDescending(x => x.Count)
                                     .Take(5)
                                     .Select(x => new StringEntry {
                String = x.Name
            })
                                     .ToList();
            previous.Top5Maps = previous.MapPopularity
                                .OrderByDescending(x => x.Count)
                                .Take(5)
                                .Select(x => new StringEntry {
                String = x.Name
            })
                                .ToList();
        }
示例#3
0
        public async Task GetServerStatistics_ReturnsCorrectStatistics()
        {
            var endpoint = "PutServerInfo_SavesInfo";

            var expected = new ServerStatisticsEntry
            {
                TotalMatchesPlayed   = 2,
                MaximumMatchesPerDay = 1,
                AverageMatchesPerDay = 2 / 6.0,
                MaximumPopulation    = 4,
                AveragePopulation    = 3,
                Top5GameModes        =
                    new List <StringEntry> {
                    new StringEntry {
                        String = "TM"
                    }, new StringEntry {
                        String = "TDM"
                    }
                },
                Top5Maps =
                    new List <StringEntry>
                {
                    new StringEntry {
                        String = "DM-HelloWorld"
                    },
                    new StringEntry {
                        String = "NewMap"
                    }
                }
            };

            var result = await statistics.GetServerStatistics(endpoint);

            result.ShouldBeEquivalentTo(expected, o =>
            {
                o.Excluding(x => x.Top5GameModes);
                o.Excluding(x => x.Top5Maps);
                o.Excluding(x => x.SelectedMemberPath.EndsWith("Id"));
                return(o);
            });
        }
示例#4
0
        public async Task GetServerStatistics_ReturnsCorrectTopMapsAndGameModes()
        {
            var endpoint  = "PutServerInfo_SavesInfo";
            var maps      = new[] { "Map1", "Map2", "Map3", "Map4", "Map5" };
            var gameModes = new[] { "GameMode1", "GameMode2", "GameMode3", "GameMode4", "GameMode5" };

            for (var i = 0; i < maps.Length * 2; i++)
            {
                await statistics.PutMatchInfo(endpoint, DateTime.UtcNow - TimeSpan.FromDays(i - 10), new MatchInfoEntry
                {
                    Map         = maps[i / 2],
                    GameMode    = gameModes[i / 2],
                    FragLimit   = 200,
                    TimeLimit   = 200,
                    TimeElapsed = 152.9,
                    Scoreboard  = new List <ScoreEntry>
                    {
                        new ScoreEntry {
                            Name = "Map", Frags = 20, Kills = 21, Deaths = 3
                        },
                        new ScoreEntry {
                            Name = "GameMode", Frags = 2, Kills = 2, Deaths = 21
                        },
                        new ScoreEntry {
                            Name = "Third", Frags = 2, Kills = 2, Deaths = 21
                        }
                    }
                });
            }

            var expected = new ServerStatisticsEntry
            {
                TotalMatchesPlayed   = 12,
                MaximumMatchesPerDay = 2,
                AverageMatchesPerDay = 0.92307692307692313,
                MaximumPopulation    = 4,
                AveragePopulation    = 3,
                Top5GameModes        =
                    new List <StringEntry>
                {
                    new StringEntry {
                        String = "GameMode1"
                    },
                    new StringEntry {
                        String = "GameMode2"
                    },
                    new StringEntry {
                        String = "GameMode3"
                    },
                    new StringEntry {
                        String = "GameMode4"
                    },
                    new StringEntry {
                        String = "GameMode5"
                    }
                },
                Top5Maps =
                    new List <StringEntry>
                {
                    new StringEntry {
                        String = "Map1"
                    },
                    new StringEntry {
                        String = "Map2"
                    },
                    new StringEntry {
                        String = "Map3"
                    },
                    new StringEntry {
                        String = "Map4"
                    },
                    new StringEntry {
                        String = "Map5"
                    }
                }
            };

            var result = await statistics.GetServerStatistics(endpoint);

            result.ShouldBeEquivalentTo(expected, o =>
            {
                o.Excluding(x => x.Top5GameModes);
                o.Excluding(x => x.Top5Maps);
                o.Excluding(x => x.SelectedMemberPath.EndsWith("Id"));
                return(o);
            });
            result.Top5GameModes.Count.ShouldBeEquivalentTo(expected.Top5GameModes.Count);
            for (var i = 0; i < result.Top5GameModes.Count; i++)
            {
                result.Top5GameModes[i].ShouldBeEquivalentTo(expected.Top5GameModes[i].String);
            }
            result.Top5Maps.Count.ShouldBeEquivalentTo(expected.Top5Maps.Count);
            for (var i = 0; i < result.Top5GameModes.Count; i++)
            {
                result.Top5Maps[i].ShouldBeEquivalentTo(expected.Top5Maps[i].String);
            }
        }