Beispiel #1
0
        public async Task ReprocessSeasonStatsAsync(short year, byte season)
        {
            var stats = (await GetSeasonTeamsStatsAsync(year, season)).ToDictionary(stat => stat.Id, stat => stat);

            foreach (var teamStats in stats)
            {
                teamStats.Value.Reset();
            }


            var seasonConfig = await _configService.GetConfig(year, season);

            for (byte round = 1; round <= seasonConfig.RoundsCount; round++)
            {
                var matches = await _matchesService.GetSeasonRoundMatchesAsync(year, season, round);

                foreach (var match in matches)
                {
                    var newMatchWinner = match.HomeScore > match.AwayScore ? WhoWon.Home :
                                         match.AwayScore > match.HomeScore ? WhoWon.Away : WhoWon.Draw;
                    var homeStats = stats[match.HomeTeamId];
                    var awayStats = stats[match.AwayTeamId];
                    homeStats.G++;
                    awayStats.G++;
                    homeStats.GF += match.HomeScore.GetValueOrDefault();
                    homeStats.GA += match.AwayScore.GetValueOrDefault();
                    awayStats.GF += match.AwayScore.GetValueOrDefault();
                    awayStats.GA += match.HomeScore.GetValueOrDefault();

                    switch (newMatchWinner)
                    {
                    case WhoWon.Home:
                        homeStats.W++;
                        awayStats.L++;
                        break;

                    case WhoWon.Away:
                        homeStats.L++;
                        awayStats.W++;
                        break;

                    case WhoWon.Draw:
                        homeStats.D++;
                        awayStats.D++;
                        break;
                    }
                }
            }

            await BulkUpsertTeamStats(year, season, stats.Values);
        }
Beispiel #2
0
        public async Task <IActionResult> GetSeasonRoundMatchesAsync([FromRoute] short year, [FromRoute] byte season,
                                                                     [FromRoute] byte round)
        {
            try
            {
                var matches = await _matchesService.GetSeasonRoundMatchesAsync(year, season, round);

                return(Ok(_mapper.Map <IEnumerable <MatchModel> >(matches)));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error getting teams for {year}:{season}:{round}.", ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, "Error getting round matches."));
            }
        }