private static BetRatesEntity GetGameRates(TeamStatisticsModel homeTeam, TeamStatisticsModel awayTeam, int leagueSize) { var positionDifference = GetPositionDifference(homeTeam, awayTeam); var probabilityInitialFactor = CalculateInitialProbabilityFactor(positionDifference); var initialProbability = GetInitialProbability(homeTeam, awayTeam, probabilityInitialFactor); var randomExtraProbability = GetRandomExtraProbability(positionDifference, leagueSize); var homeTeamWinProbability = initialProbability.HomeTeamWinFactor + randomExtraProbability.HomeTeamWinFactor; var awayTeamWinProbability = initialProbability.AwayTeamWinFactor + randomExtraProbability.AwayTeamWinFactor; var tieProbability = initialProbability.TieFactor + randomExtraProbability.TieFactor; homeTeamWinProbability = InverseNumber(homeTeamWinProbability); awayTeamWinProbability = InverseNumber(awayTeamWinProbability); tieProbability = InverseNumber(tieProbability); homeTeamWinProbability = SubtractGamblingCompanyFactor(homeTeamWinProbability); awayTeamWinProbability = SubtractGamblingCompanyFactor(awayTeamWinProbability); tieProbability = SubtractGamblingCompanyFactor(tieProbability); return(new BetRatesEntity { HomeTeamWinRate = (float)Math.Round(homeTeamWinProbability, 2), AwayTeamWinRate = (float)Math.Round(awayTeamWinProbability, 2), TieRate = (float)Math.Round(tieProbability, 2) }); }
private static ProbabilityFactorsModel GetInitialProbability(TeamStatisticsModel homeTeam, TeamStatisticsModel awayTeam, float probabilityInitialFactor) { var homeTeamWinInitialProbability = RatesConstants.WinInitialProbability + (homeTeam.Position < awayTeam.Position ? probabilityInitialFactor : -probabilityInitialFactor); var awayTeamWinInitialProbability = RatesConstants.WinInitialProbability + (homeTeam.Position > awayTeam.Position ? probabilityInitialFactor : -probabilityInitialFactor); var tieInitialProbability = RatesConstants.CertainEventProbability - (homeTeamWinInitialProbability + awayTeamWinInitialProbability); return(new ProbabilityFactorsModel { HomeTeamWinFactor = homeTeamWinInitialProbability, AwayTeamWinFactor = awayTeamWinInitialProbability, TieFactor = tieInitialProbability }); }
/// <summary> /// /// </summary> /// <param name="groupsToRetrieve">Groups sent in request</param> /// <returns></returns> public IList <ChampionsLeagueModel> CalculateStatistics(string groupsToRetrieve) { IList <ChampionsLeagueModel> championsLeagueScore = new List <ChampionsLeagueModel>(); IList <string> groups = FilterGroups(groupsToRetrieve); foreach (var group in groups) { IList <ScoreModel> teamsForGroup = RetrieveTeamsForGroup(group); IDictionary <string, int> teamScores = GetScoreForTeamsInGroup(teamsForGroup); string leagueName = teamsForGroup.Select(x => x.LeagueTitle).FirstOrDefault(); IList <TeamStatisticsModel> statisticsOfTeams = new List <TeamStatisticsModel>(); foreach (var team in teamScores.Keys) { int goalsSum = CountGoalsStatistics(team, EGoalsStatistics.Achieved); TeamStatisticsModel teamModel = new TeamStatisticsModel { Team = team, PlayedGames = CountPlayedGames(team), Points = teamScores.Where(x => x.Key.Equals(team)).Select(x => x.Value).First(), Goals = goalsSum, GoalsAgainst = CountGoalsStatistics(team, EGoalsStatistics.Against), GoalDifference = goalsSum - CountGoalsStatistics(team, EGoalsStatistics.Received), Win = CountGamesOutcomes(team, EGameOutcome.Win), Lose = CountGamesOutcomes(team, EGameOutcome.Lose), Draw = CountGamesOutcomes(team, EGameOutcome.Draw), }; statisticsOfTeams.Add(teamModel); } UpdateRanks(statisticsOfTeams); var sortedList = statisticsOfTeams.OrderBy(x => x.Rank).ToList(); ChampionsLeagueModel championsLeague = new ChampionsLeagueModel { LeagueTitle = leagueName, MatchDay = sortedList.Select(x => x.PlayedGames).FirstOrDefault(), Group = group, Standing = sortedList }; championsLeagueScore.Add(championsLeague); } return(championsLeagueScore); }
private static int GetPositionDifference(TeamStatisticsModel homeTeamStatistics, TeamStatisticsModel awayTeamStatistics) => Math.Abs(homeTeamStatistics.Position - awayTeamStatistics.Position);