示例#1
0
        internal Game(JsonDict json, SummonerInfo summoner)
        {
            Summoner = summoner;
            Id       = json["gameId"].GetLong().ToString();
            Queue    = Queues.GetInfo(json["queueId"].GetInt());
            if (Queue.Id != 0 /* Custom */) // this is the only queue type for which the map can't be inferred from the queue, but we don't care about those games when computing personal stats
            {
                Ut.Assert((int)Queue.Map == json["mapId"].GetInt());
            }
            DetailsUrl = "http://matchhistory.{0}.leagueoflegends.com/en/#match-details/{1}/{2}/{3}".Fmt(summoner.Region.ToLower(), summoner.RegionServer, Id, summoner.AccountId);
            DateUtc    = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc) + TimeSpan.FromSeconds(json["gameCreation"].GetLong() / 1000.0);
            Duration   = TimeSpan.FromSeconds(json["gameDuration"].GetInt());

            var teams =
                (from team in json["teams"].GetList()
                 let participants = json["participants"].GetList().Where(p => p["teamId"].GetInt() == team["teamId"].GetInt()).ToDictionary(p => p["participantId"].GetInt())
                                    let identities = json["participantIdentities"].GetList().Where(pi => participants.ContainsKey(pi["participantId"].GetInt())).ToDictionary(pi => pi["participantId"].GetInt())
                                                     select new Team(team, participants, identities, this)
                ).ToList();

            Ut.Assert(teams.Count == 2);

            Ally  = teams.Single(t => t.Players.Any(p => p.SummonerId == summoner.SummonerId));
            Enemy = teams.Single(t => t != Ally);
        }
示例#2
0
        public void Generate()
        {
            var verqueues = DataStore.LosMatchJsons
                            .SelectMany(kvp1 => kvp1.Value.SelectMany(kvp2 => kvp2.Value.Select(kvp3 => (version: kvp2.Key, queueId: kvp3.Key))))
                            .Distinct()
                            .ToLookup(x => x.queueId, x => x.version);
            var region  = DataStore.LosMatchJsons.Keys.Contains(Region.EUW) ? Region.EUW : DataStore.LosMatchJsons.Keys.First();
            var results = new AutoDictionary <int, List <eventResult> >(_ => new List <eventResult>());

            foreach (var queue in Queues.AllQueues.Where(q => q.IsPvp && q.IsEvent))
            {
                if (queue.Id == 700 /* Clash */)
                {
                    continue;
                }
                foreach (var versionGroup in verqueues[queue.Id].Select(v => Version.Parse(v)).Order().GroupConsecutive((v1, v2) => v1.Major == v2.Major && v1.Minor == v2.Minor - 1))
                {
                    var versions  = Enumerable.Range(0, versionGroup.Count).Reverse().Select(offset => new Version(versionGroup.Key.Major, versionGroup.Key.Minor - offset)).Select(v => v.ToString()).ToList();
                    var firstDate = DataStore.LosMatchJsons[region][versions.First()][queue.Id].ReadItems().Select(json => new BasicMatchInfo(json)).Take(50).Min(b => b.GameCreationDate);
                    var curQueue  = queue;
                    while (curQueue.ReplacedBy != null)
                    {
                        curQueue = Queues.GetInfo(curQueue.ReplacedBy.Value);
                    }
                    // Riot messed up URF queues by merging URF and ARURF into 900
                    if (queue.Id == 76 || queue.Id == 900 && $"{firstDate:yyMM}" == "1910")
                    {
                        curQueue = Queues.GetInfo(76);
                    }
                    Console.WriteLine($"{queue.Id} - {queue.QueueName} - {firstDate:MMMM yyyy} - {versions.JoinString(", ")}");
                    var result = GenerateEvent(queue.Id, versions, $"{curQueue.QueueName} - {firstDate:MMMM yyyy}", $"{curQueue.MicroName}--{firstDate:yyyy'-'MM}--{queue.Id}");
                    result.FirstDate = firstDate;
                    results[curQueue.Id].Add(result);
                }
            }

            var html = new List <object>();

            html.Add(new H1("League PvP Event Stats"));
            html.Add(new P($"Last updated: {DateTime.UtcNow:d' 'MMM' 'yyyy' at 'HH:mm' UTC'}"));
            foreach (var kvp in results.OrderByDescending(k => k.Value.Max(r => r.MatchCount)))
            {
                html.Add(new H3(Queues.GetInfo(kvp.Key).QueueName));
                html.Add(makeSortableTable(
                             new TR(colAsc("Date", true), colAsc("Version(s)"), colAsc("Winrates"), colAsc("Bans"), colDesc("Games"), colAsc("Best champ"), colDesc("Winrate"), colAsc("Worst champ"), colAsc("Winrate")),
                             kvp.Value.Select(result => new TR(
                                                  cell($"{result.FirstDate:MMMM yyyy}", $"{result.FirstDate:yyyy-MM}", false),
                                                  cell(result.Versions.JoinString(", "), $"{result.FirstDate:yyyy-MM}", true),
                                                  cell(new A("Winrates")
                {
                    href = result.LinkWinrates
                }, "", true),
                                                  cell(new A("Bans")
                {
                    href = result.LinkBans
                }, "", true),
                                                  cellInt(result.MatchCount),
                                                  cellStr(result.BestChamp < 0 ? "" : LeagueStaticData.Champions[result.BestChamp].Name),
                                                  cellPrc(result.BestChampWinrate, 1),
                                                  cellStr(result.WorstChamp < 0 ? "" : LeagueStaticData.Champions[result.WorstChamp].Name),
                                                  cellPrc(result.WorstChampWinrate, 1)
                                                  ))));
            }
            GenerateHtmlToFile(Path.Combine(_settings.OutputPath, $"index.html"), html, true);
        }