Ejemplo n.º 1
0
        private async Task <List <GameUpdate> > FetchGamesAt(string sim, int tournament, int season, int day)
        {
            var sw = new Stopwatch();

            sw.Start();

            var cacheBust = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            var url     = $"https://api.blaseball.com/database/games?season={season}&day={day}&tournament={tournament}&cache={cacheBust}";
            var jsonStr = await _client.GetStringAsync(url);

            sw.Stop();
            var timestamp = _clock.GetCurrentInstant();

            var json  = JArray.Parse(jsonStr);
            var games = json.Where(g => g["sim"].Value <string?>() == sim).ToList();

            var maxPlayCount = games.Count > 0 ? games.Max(t => t["playCount"].Value <int?>() ?? -1) : -1;

            _logger.Information("Polled games endpoint at sim {Sim} season {Season} tournament {Tournament} day {Day} (combined hash {Hash}, max PC {MaxPlayCount}, took {Duration})",
                                sim, season, tournament,
                                day, SibrHash.HashAsGuid(json), maxPlayCount, sw.Elapsed);

            var updates = games
                          .Select(game => GameUpdate.From(_sourceId, timestamp, game))
                          .ToList();

            return(updates);
        }
Ejemplo n.º 2
0
 public static SiteUpdate From(Guid sourceId, string path, Instant timestamp, byte[] data, Instant?lastModified)
 {
     return(new SiteUpdate
     {
         SourceId = sourceId,
         Path = path,
         Timestamp = timestamp,
         Hash = SibrHash.HashAsGuid(data),
         Data = data,
         LastModified = lastModified
     });
 }
Ejemplo n.º 3
0
        private async Task <List <GameUpdate> > FetchGamesAt(int season, int day)
        {
            var sw = new Stopwatch();

            sw.Start();
            var jsonStr = await _client.GetStringAsync($"https://www.blaseball.com/database/games?season={season}&day={day}");

            sw.Stop();
            var timestamp = _clock.GetCurrentInstant();

            var json = JArray.Parse(jsonStr);

            _logger.Information("Polled games endpoint at season {Season} day {Day} (combined hash {Hash}, took {Duration})",
                                season,
                                day, SibrHash.HashAsGuid(json), sw.Elapsed);

            var updates = json
                          .Select(game => GameUpdate.From(_sourceId, timestamp, game))
                          .ToList();

            return(updates);
        }