public string GetPlayerStats(string playerName) { string name = playerName.ToLower(); Player player; using (var db = new LiteDatabase(statsDBConn)) { var col = db.GetCollection <Player> ("players"); player = col.FindOne(x => x.Name == name); } if (player == null) { throw new RequestException("Player not found"); } var s = JsonConvert.SerializeObject(new { totalMatchesPlayed = player.TotalMatches, totalMatchesWon = player.TotalMatchesWon, favouriteServer = player.ServerPlays.Aggregate((a, b) => a.Value > b.Value ? a : b).Key, uniqueServers = player.ServerPlays.Count, favouriteGameMode = player.GameModes.Aggregate((a, b) => a.Value > b.Value ? a : b).Key, averageScoreBoardPercernt = player.AverageScoreBoardPercent, maximumMatchesPerDay = player.MaximumMatchesPerDay, averageMatchesPerDay = player.TotalMatches / (double)(LastMatchTime.ToUniversalTime().Date.Subtract(player.FirstMatchPlayed.ToUniversalTime().Date).TotalDays + 1), lastMatchPlayed = player.LastMatchPlayed.ToUniversalTime(), killToDeathRatio = player.TotalKills / (double)player.TotalDeaths }); return(s); }
public string GetPopularServers(int count) { string s; count = Math.Min(Math.Max(count, 0), 50); using (var db = new LiteDatabase(statsDBConn)) { var col = db.GetCollection <Server> ("servers"); var ans = col.FindAll() .Select(server => new { endpoint = server.EndPoint, name = server.Name, averageMatchesPerDay = server.TotalMatches / ((LastMatchTime.ToUniversalTime().Date.Subtract(server.FirstMatchPlayed.ToUniversalTime().Date)).TotalDays + 1) }) .OrderByDescending( x => x.averageMatchesPerDay) .Take(count); s = JsonConvert.SerializeObject(ans); } return(s); }
public string GetServerStatistics(string endpoint) { Server server; using (var db = new LiteDatabase(statsDBConn)) { var col = db.GetCollection <Server> ("servers"); server = col.FindOne(x => x.EndPoint == endpoint); } if (server == null) { throw new RequestException("Server not found"); } var s = JsonConvert.SerializeObject(new { totalMatchesPlayed = server.TotalMatches, maximumMatchesPerDay = server.MaxPlaysPerDay, averageMatchesPerDay = server.TotalMatches / (double)(LastMatchTime.ToUniversalTime().Date.Subtract(server.FirstMatchPlayed.ToUniversalTime().Date).TotalDays + 1), maximumPopulation = server.MaxPopulation, averagePopulation = server.TotalPopulation / (double)server.TotalMatches, top5GameModes = server.GameModesPlays.OrderByDescending(x => x.Value).Take(5).Select(x => x.Key), top5Maps = server.MapsPlays.OrderByDescending(x => x.Value).Take(5).Select(x => x.Key) }); return(s); }