private void CalculateGoalkeeperAdditionalStats(Person person, PersonCareer personCareerItem, IEnumerable <ProtocolRecordPersonInfo> protocolPersonInfo, ref PersonStatistics personStatistics) { if (person.roleId != PersonRoleId.rrGoalkeeper) { return; } ProtocolRecordPersonInfo recordIn = protocolPersonInfo.FirstOrDefault(pr => pr.IsStartMain || pr.IsSubstitutionIn); if (recordIn == null) { return; } // The value will be always present because pr.IsStartMain || pr.IsSubstitutionIn check it int minuteIn = recordIn.ProtocolRecord.Minute.Value; ProtocolRecordPersonInfo recordOut = protocolPersonInfo.FirstOrDefault(pr => pr.IsSubstitutionOut); int minuteOut = recordOut != null ? recordOut.ProtocolRecord.Minute.Value : GameDefinitions.MaxGameDurationInMinutes; IEnumerable <ProtocolRecordInfo> goalsAgainstProtocol = protocolPersonInfo.Where(pr => pr.ProtocolRecord.teamId != personCareerItem.teamId) .Select(pr => new ProtocolRecordInfo(pr.ProtocolRecord)) .Where(pr => pr.IsGoal); personStatistics.CustomIntValue = (short)goalsAgainstProtocol.Count(gp => gp.ProtocolRecord.Minute >= minuteIn && gp.ProtocolRecord.Minute <= minuteOut); }
/// <summary> /// Calculate statistic. Person should be filled with person career /// </summary> /// <param name="person">Person. Should be filled with person career</param> /// <returns></returns> public PersonStatistics Calculate(Person person) { PersonCareer personCareerItem = GetPersonCareerItemOfTheGame(person); if (personCareerItem == null || game.ProtocolRecord == null) { return(null); } IEnumerable <ProtocolRecordPersonInfo> protocolPersonInfo = game.ProtocolRecord.Select(pr => new ProtocolRecordPersonInfo(person, pr)); var personStats = new PersonStatistics() { teamId = personCareerItem.teamId, personId = personCareerItem.personId }; CalculatePlayerOnThePitchStats(person, personCareerItem, protocolPersonInfo, ref personStats); if (personStats.Games > 0) { CalculateGoalkeeperAdditionalStats(person, personCareerItem, protocolPersonInfo, ref personStats); } return(personStats.Games > 0 ? personStats : null); }
private void CalculatePlayerOnThePitchStats(Person person, PersonCareer personCareerItem, IEnumerable <ProtocolRecordPersonInfo> protocolPersonInfo, ref PersonStatistics personStatistics) { IEnumerable <ProtocolRecordPersonInfo> playerOnPitchProtocol = protocolPersonInfo.Where(pr => pr.ProtocolRecord.teamId == personCareerItem.teamId && (pr.ProtocolRecord.personId == personCareerItem.personId || pr.ProtocolRecord.CustomIntValue == personCareerItem.personId)); if (Guard.IsEmptyIEnumerable(playerOnPitchProtocol)) { return; } foreach (ProtocolRecordPersonInfo prInfo in playerOnPitchProtocol) { if (prInfo.IsGoal && person.roleId.HasValue) { //if (PersonRoleGroupId.rgTeamPitchPlayer.Contains(person.roleId.Value)) //{ personStatistics.Goals++; //} //else if (person.roleId.Value == PersonRoleId.rrGoalkeeper) //{ //personStatistics.CustomIntValue = (short)(personStatistics.CustomIntValue.HasValue ? personStatistics.CustomIntValue.Value + 1 : 1); //} } else if (prInfo.IsAssist) { personStatistics.Assists++; } else if (prInfo.IsStartMain) { personStatistics.Games++; } else if (prInfo.IsSubstitutionIn) { personStatistics.Games++; personStatistics.Substitutes++; } else if (prInfo.IsYellowCard) { personStatistics.Yellows++; } else if (prInfo.IsRedCard) { personStatistics.Reds++; } } }
public static PersonCareerViewModel ToViewModel(this PersonCareer personCareer) { if (personCareer == null) { return(null); } return(new PersonCareerViewModel() { id = personCareer.Id, dateFinish = personCareer.DateFinish, dateStart = personCareer.DateStart, personId = personCareer.personId, teamId = personCareer.teamId, teamName = personCareer?.team?.Name ?? string.Empty }); }
private void FillRelations(IEnumerable <Person> persons) { if (Guard.IsEmptyIEnumerable(persons)) { return; } IEnumerable <Team> teams = new Team[0]; IEnumerable <City> cities = new City[0]; IEnumerable <PersonRole> personRoles = new PersonRole[0]; IEnumerable <PersonCareer> personCareers = new PersonCareer[0]; if (FillTeams) { var teamDal = new TeamDal(); teamDal.FillCities = true; teamDal.SetContext(Context); var teamIds = new List <int>(); teamIds.AddRange(persons.Where(p => p.teamId.HasValue).Select(p => p.teamId.Value).Distinct()); teams = teamDal.GetTeams(teamIds).ToList(); } if (FillCities) { var cityDal = new CityDal(); cityDal.FillCountries = true; cityDal.SetContext(Context); var cityIds = new List <int>(); cityIds.AddRange(persons.Where(p => p.cityId.HasValue).Select(p => p.cityId.Value).Distinct()); cities = cityDal.GetCities(cityIds).ToList(); } if (FillPersonRoles) { var personRoleDal = new PersonRoleDal(); personRoleDal.SetContext(Context); var personRoleIds = new List <int>(); personRoleIds.AddRange(persons.Where(p => p.roleId.HasValue).Select(p => (int)p.roleId.Value).Distinct()); personRoles = personRoleDal.GetPersonRoles(personRoleIds).ToList(); } if (FillPersonCareer) { var personCareerDal = new PersonCareerDal(); personCareerDal.SetContext(Context); var personIds = new List <int>(); personIds.AddRange(persons.Select(p => p.Id).Distinct()); personCareers = personCareerDal.GetPersonCareer(personIds).ToList(); } if (teams.Any() || cities.Any() || personRoles.Any() || personCareers.Any()) { foreach (Person person in persons) { if (FillTeams && teams.Any()) { person.team = teams.FirstOrDefault(t => t.Id == person.teamId); if (person.teamId.HasValue && person.team == null) { throw new DalMappingException(nameof(person.team), typeof(Person)); } } if (FillCities && cities.Any()) { person.city = cities.FirstOrDefault(c => c.Id == person.cityId); if (person.cityId.HasValue && person.city == null) { throw new DalMappingException(nameof(person.city), typeof(Person)); } } if (FillPersonRoles && personRoles.Any()) { person.role = personRoles.FirstOrDefault(pr => pr.Id == person.roleId); if (person.roleId.HasValue && person.role == null) { throw new DalMappingException(nameof(person.role), typeof(Person)); } } if (FillPersonCareer && personCareers.Any()) { person.PersonCareer = personCareers.Where(pc => pc.personId == person.Id).ToList(); } } } }