public static Models.v0.Team ToModel(this Entities.Team entity) { if (entity == null) { return(null); } return(new Models.v0.Team { Id = entity.Id, Name = entity.Name }); }
public async Task ProcessTeams(List <Models.Team> teams, int season, Competition competition, IDbConnection connection) { _logger.LogInformation($"Processing {teams.Count} teams for season {season} and competition {competition.Name}"); var teamEntities = new List <Entities.Team>(); var teamSummaryEntities = new List <Entities.TeamSummary>(); foreach (var team in teams) { var teamEntity = new Entities.Team(); teamEntity.Id = team.Id; teamEntity.Name = team.Name; teamEntity.ShortName = String.Empty; teamEntities.Add(teamEntity); var teamSummaryEntity = new Entities.TeamSummary(); teamSummaryEntity.Team = teamEntity; teamSummaryEntity.Season = season; teamSummaryEntity.Competition = competition; teamSummaryEntity.Games = team.History.Count(); teamSummaryEntity.Won = team.History.Sum(h => h.Wins); teamSummaryEntity.Drawn = team.History.Sum(h => h.Draws); teamSummaryEntity.Lost = team.History.Sum(h => h.Loses); teamSummaryEntity.GoalsFor = team.History.Sum(h => h.Scored); teamSummaryEntity.GoalsAgainst = team.History.Sum(h => h.Missed); teamSummaryEntity.Points = team.History.Sum(h => h.Points); teamSummaryEntity.ExpectedGoals = team.History.Sum(h => h.ExpectedGoals); teamSummaryEntity.NonPenaltyExpectedGoals = team.History.Sum(h => h.NonPenaltyExpectedGoals); teamSummaryEntity.ExpectedGoalsAgainst = team.History.Sum(h => h.ExpectedGoalsAgainst); teamSummaryEntity.NonPenaltyExpectedGoalsAgainst = team.History.Sum(h => h.NonPenaltyExpectedGoalsAgainst); teamSummaryEntity.ExpectedPoints = team.History.Sum(h => h.ExpectedPoints); teamSummaryEntity.DeepPasses = team.History.Sum(h => h.Deep); teamSummaryEntity.OppositionDeepPasses = team.History.Sum(h => h.DeepAllowed); var oppositionPasses = team.History.Sum(h => h.PPDA.PassesAllowed); var defensiveActions = team.History.Sum(h => h.PPDA.DefensiveActions); teamSummaryEntity.Ppda = defensiveActions == 0 ? 0 : oppositionPasses / (double)defensiveActions; var passes = team.History.Sum(h => h.PPDAAllowed.PassesAllowed); var oppositionDefensiveActions = team.History.Sum(h => h.PPDAAllowed.DefensiveActions); teamSummaryEntity.OppositionPpda = oppositionDefensiveActions == 0 ? 0 : passes / (double)oppositionDefensiveActions; teamSummaryEntities.Add(teamSummaryEntity); } await _teamRepository.InsertMultipleAsync(teamEntities, connection); await _teamSummaryRepository.InsertMultipleAsync(teamSummaryEntities, connection); _logger.LogInformation($"Successfully processed {teams.Count} teams for season {season} and competition {competition.Name}"); }