public static void EstimateActivePlayers_Extract()
        {
            var seenMatches = new AutoDictionary <Region, HashSet <long> >(_ => new HashSet <long>());

            foreach (var f in DataStore.LosMatchJsons.SelectMany(kvpR => kvpR.Value.SelectMany(kvpV => kvpV.Value.Select(kvpQ => (region: kvpR.Key, version: kvpV.Key, queueId: kvpQ.Key, file: kvpQ.Value)))))
            {
                if (f.queueId == 0)
                {
                    continue;
                }
                Console.WriteLine($"Processing {f.file.FileName} ...");
                var count = new CountThread(10000);
                File.WriteAllLines($"ActivePlayersExtract-{f.region}-{f.version}-{f.queueId}.csv",
                                   f.file.ReadItems()
                                   .PassthroughCount(count.Count)
                                   .Where(js => seenMatches[f.region].Add(js["gameId"].GetLong()) && js.ContainsKey("participantIdentities") && js["participantIdentities"].Count > 0)
                                   .Select(js => $"{js["gameId"].GetLong()},{js["gameCreation"].GetLong()},{js["gameDuration"].GetLong()},{js["participantIdentities"].GetList().Select(p => p["player"]["accountId"].GetLong()).JoinString(",")}"));
                count.Stop();
            }
        }
Exemple #2
0
        public Downloader(ApiKeyWrapper[] apiKeys, Region region, IEnumerable <string> versions, int?queueId, long initialMatchId, long matchIdRange)
        {
            ApiKeys      = apiKeys;
            Region       = region;
            Versions     = versions?.ToHashSet();
            QueueId      = queueId;
            MatchIdRange = matchIdRange;

            _downloaders = ApiKeys.Select(key => new MatchDownloader(key, Region)).ToArray();
            foreach (var dl in _downloaders)
            {
                dl.OnEveryResponse = (_, __) => { }
            }
            ;

            Console.Write($"Loading {DataStore.LosMatchInfos[Region].FileName}... ");
            var thread = new CountThread(10000);

            foreach (var info in rebuildSlope(DataStore.LosMatchInfos[Region].ReadItems().PassthroughCount(thread.Count).OrderBy(x => x.GameCreation), 2 * 86_400_000))
            {
                if ((Versions == null || Versions.Contains(info.GameVersion)) && (QueueId == null || info.QueueId == QueueId))
                {
                    countMatch(info);
                }
            }
            thread.Stop();
            Console.WriteLine();
            Console.WriteLine($"  loaded {thread.Count.Count:#,0} matches in {thread.Duration.TotalSeconds:#,0} s ({thread.Rate:#,0}/s)");

            if (LatestMatchId == 0) // means not a single match within the filter parameters was in the store
            {
                InitialMatchId = initialMatchId;
            }
            else
            {
                InitialMatchId = (EarliestMatchId + LatestMatchId) / 2;
            }
            rebuild();
            printStats();
        }