Exemple #1
0
        public async Task ProcessPlayers(List <Models.Player> players, int season, Competition competition, IDbConnection conn)
        {
            _logger.LogInformation($"Processing {players.Count} players for season {season} and competition {competition.Name}");

            var playerEntities  = new List <Entities.Player>();
            var playerSummaries = new List <Entities.PlayerSummary>();

            var allTeams = await _teamRepository.GetAllTeamsAsync(conn);

            foreach (var playerModel in players)
            {
                var playerEntity = new Entities.Player();
                playerEntity.Id   = playerModel.Id;
                playerEntity.Name = playerModel.PlayerName.Replace("&#039;", "'");
                playerEntities.Add(playerEntity);

                var team = GetPlayersTeam(playerModel, allTeams);
                if (team == null)
                {
                    _logger.LogError($"Team not found for player {playerModel.PlayerName} with team title {playerModel.TeamTitle}");
                    continue;
                }

                var summary = new Entities.PlayerSummary();
                summary.Player                  = playerEntity;
                summary.Season                  = season;
                summary.Competition             = competition;
                summary.Team                    = team;
                summary.Games                   = playerModel.Games;
                summary.MinutesPlayed           = playerModel.Time;
                summary.Goals                   = playerModel.Goals;
                summary.ExpectedGoals           = playerModel.ExpectedGoals;
                summary.Assists                 = playerModel.Assists;
                summary.ExpectedAssists         = playerModel.ExpectedAssists;
                summary.Shots                   = playerModel.Shots;
                summary.KeyPasses               = playerModel.KeyPasses;
                summary.YellowCards             = playerModel.YellowCards;
                summary.RedCards                = playerModel.RedCards;
                summary.Position                = playerModel.Position;
                summary.NonPenaltyGoals         = playerModel.NonPenaltyGoals;
                summary.NonPenaltyExpectedGoals = playerModel.NonPenaltyExpectedGoals;
                summary.ExpectedGoalsChain      = playerModel.ExpectedGoalsChain;
                summary.ExpectedGoalsBuildup    = playerModel.ExpectedGoalsBuildup;
                playerSummaries.Add(summary);
            }

            await _playerRepository.InsertPlayersAsync(playerEntities, conn);

            await _playerSummaryRepository.InsertPlayerSummariesAsync(playerSummaries, conn);

            _logger.LogInformation($"Successfully processed {players.Count} players for season {season} and competition {competition.Name}");
        }
        public static Models.v0.PlayerSummaryBasic ToModel(this Entities.PlayerSummary entity)
        {
            if (entity == null)
            {
                return(null);
            }

            return(new Models.v0.PlayerSummaryBasic
            {
                Player = entity.Player.ToModel(),
                Games = entity.Games,
                MinutesPlayed = entity.MinutesPlayed,
                Goals = entity.Goals,
                Assists = entity.Assists,
                Shots = entity.Shots,
                KeyPasses = entity.KeyPasses,
                YellowCards = entity.YellowCards,
                RedCards = entity.RedCards,
                Position = entity.Position,
                Team = entity.Team.ToModel(),
                NonPenaltyGoals = entity.NonPenaltyGoals,
            });
        }