public async IAsyncEnumerable <NflfastrPlayByPlay> GetPlayByPlaysAsync( int?season, string team, [EnumeratorCancellation] CancellationToken cancellationToken) { using var scope = _tracer.BuildTrace(nameof(GetPlayByPlaysAsync)); scope.LogStart(nameof(GetPlayByPlaysAsync)); var path = $"{RepositoryEndpoints.PlayByPlayEndpoint}/play_by_play_{season}.csv.gz?raw=true"; var response = await _requestHelper.GetRequestResponse(path, cancellationToken); _logger.LogInformation($"Fetching data. Url: {path}; Status: {response.StatusCode}"); if (!response.IsSuccessStatusCode) { yield return(new NflfastrPlayByPlay()); yield break; } _logger.LogInformation($"{nameof(GetPlayByPlaysAsync)}: before ReadCompressedStreamToString"); var responseString = await ResponseHelper.ReadCompressedStreamToString(response); _logger.LogInformation($"{nameof(GetPlayByPlaysAsync)}: after ReadCompressedStreamToString"); await foreach (var play in ProcessPlayByPlayResponse(responseString, team, scope) .WithCancellation(cancellationToken)) { yield return(play); } }
public async IAsyncEnumerable <GamePlays> GetGamePlaysAsync( PlayByPlayQueryParameter queryParameter, [EnumeratorCancellation] CancellationToken cancellationToken) { using var scope = _tracer.BuildTrace(nameof(GetGamePlaysAsync)); scope.LogStart(nameof(GetGamePlaysAsync)); await foreach (var game in QueryForGameStats(queryParameter, cancellationToken)) { if (game == null) { continue; } yield return(game.ToGamePlays()); } scope.LogEnd(nameof(GetGamePlaysAsync)); }
public async Task <GameDetail> GetGamePlaysAsync(Game game, CancellationToken cancellationToken) { using var scope = _tracer.BuildTrace(nameof(GetGamePlaysAsync)); scope.LogStart(nameof(GetGamePlaysAsync)); var url = GetGameUrl(game.GameId, game.Season); scope.LogEnd(nameof(GetGamePlaysAsync)); if (_gamesCache.TryGetValue(game, out var gameDetail)) { _logger.LogInformation($"Game found in cache: {game.GameId}"); return(gameDetail); } gameDetail = await GetGameJson(url, cancellationToken, scope); gameDetail.Game = game; _gamesCache[game] = gameDetail; return(gameDetail); }