コード例 #1
0
        public void RunAnalyzing()
        {
            var allSeasons = leagueRepo.GetAllLeagueSeasons(leagueRepo.GetLaLiga());

            foreach (var season in allSeasons)
            {
                var standingTable = systemRepo.GetStandingTable(season);
                if (!standingTable.AnalysisDone)
                {
                    AnalyzeLeagueSeason(season, standingTable);
                }
                else
                {
                    Console.WriteLine($"Season: {season.LeagueSeasonId} [{season.StartYear}-{season.StartYear + 1}] have been already analyzed. Skip.");
                }
            }
        }
コード例 #2
0
        public LeagueModule()
        {
            Get[SharedRoutes.AllLeagues] = x => {
                var model = leagueRepo.GetAllLeagues().Select(Mapper.Map <LeagueDto>);
                return(Response.AsJson(model));
            };

            Get[SharedRoutes.AllLeagueSeasons] = parameters => {
                var leagueId = (int)parameters.leagueId;
                var model    = leagueRepo.GetAllLeagueSeasons(leagueId).Select(Mapper.Map <LeagueSeasonDto>).OrderBy(x => x.StartYear);
                return(Response.AsJson(model));
            };

            Get[SharedRoutes.LeagueInfo] = parameters => {
                var leagueId = (int)parameters.leagueId;
                var model    = leagueRepo.GetAllLeagues().Where(l => l.LeagueId == leagueId).Select(Mapper.Map <LeagueInfoDto>).OrderBy(x => x.LeagueName);
                return(Response.AsJson(model));
            };
        }
コード例 #3
0
        public static void CheckRoundStats(PredictionData data, Game game)
        {
            var leagueRepo   = new LeagueDataRepository();
            var analysisRepo = new AnalysisDataRepository();
            var allSeasons   = leagueRepo.GetAllLeagueSeasons(leagueRepo.GetLaLiga()).OrderByDescending(s => s.StartYear).ToList();

            int currentSeasonId     = allSeasons.First().LeagueSeasonId;
            var currentSeasonRounds = leagueRepo.GetCurrentSeasonRounds(currentSeasonId);

            currentSeasonRounds = currentSeasonRounds.Where(r => r.RoundNumber <= game.SeasonRound.RoundNumber && CheckRound(r))
                                  .OrderByDescending(r => r.RoundNumber).Take(5).ToList();

            var currentSeasonRoundsStats   = analysisRepo.GetAverageRoundStats(currentSeasonId);
            var previousSeasonRoundsStats  = allSeasons.Count > 1 ? analysisRepo.GetAverageRoundStats(allSeasons[1].LeagueSeasonId) : null;
            var previous2SeasonRoundsStats = allSeasons.Count > 2 ? analysisRepo.GetAverageRoundStats(allSeasons[2].LeagueSeasonId) : null;

            //average
            var averageHomeWins = (previous2SeasonRoundsStats.HomeWinsCount_Average + previousSeasonRoundsStats.HomeWinsCount_Average) / 2;
            var averagDraws     = (previous2SeasonRoundsStats.DrawsCount_Average + previousSeasonRoundsStats.DrawsCount_Average) / 2;
            var averageAwayWins = (previous2SeasonRoundsStats.AwayWinsCount_Average + previousSeasonRoundsStats.AwayWinsCount_Average) / 2;

            var averageBttsYes = (previous2SeasonRoundsStats.BTTS_Yes_Average + previousSeasonRoundsStats.BTTS_Yes_Average) / 2;
            var averageBttsNo  = (previous2SeasonRoundsStats.BTTS_No_Average + previousSeasonRoundsStats.BTTS_No_Average) / 2;

            var averageTotalOver = (previous2SeasonRoundsStats.GamesOver2_5_Average + previousSeasonRoundsStats.GamesOver2_5_Average) / 2;
            var averagTotalUnder = (previous2SeasonRoundsStats.GamesUnder2_5_Average + previousSeasonRoundsStats.GamesUnder2_5_Average) / 2;

            //get maximal diff compared current season with last seasons
            var currentDiffHomeWins = averageHomeWins - currentSeasonRoundsStats.HomeWinsCount_Average;
            var currentDiffDraws    = averagDraws - currentSeasonRoundsStats.DrawsCount_Average;
            var currentDiffAwayWins = averageAwayWins - currentSeasonRoundsStats.AwayWinsCount_Average;

            var currentDiffBttsYes = averageBttsYes - currentSeasonRoundsStats.BTTS_Yes_Average;
            var currentDiffBttsNo  = averageBttsNo - currentSeasonRoundsStats.BTTS_No_Average;

            var currentDiffTotalOver  = averageTotalOver - currentSeasonRoundsStats.GamesOver2_5_Average;
            var currentDiffTotalUnder = averagTotalUnder - currentSeasonRoundsStats.GamesUnder2_5_Average;

            var maxDiff = currentDiffHomeWins;

            if (currentDiffDraws > maxDiff)
            {
                maxDiff = currentDiffDraws;
            }
            if (currentDiffAwayWins > maxDiff)
            {
                maxDiff = currentDiffAwayWins;
            }

            if (maxDiff == currentDiffHomeWins)
            {
                data.CalculatedProbabilities.HomeWinProbability *= RoundStatsCoef;
            }
            if (maxDiff == currentDiffDraws)
            {
                data.CalculatedProbabilities.DrawProbability *= RoundStatsCoef;
            }
            if (maxDiff == currentDiffAwayWins)
            {
                data.CalculatedProbabilities.AwayWinProbability *= RoundStatsCoef;
            }

            maxDiff = currentDiffBttsYes;
            if (currentDiffBttsNo > maxDiff)
            {
                maxDiff = currentDiffBttsNo;
            }

            if (maxDiff == currentDiffBttsYes)
            {
                data.CalculatedProbabilities.BttsYesProbability *= RoundStatsCoef;
            }
            if (maxDiff == currentDiffBttsNo)
            {
                data.CalculatedProbabilities.BttsNoProbability *= RoundStatsCoef;
            }

            maxDiff = currentDiffTotalOver;
            if (currentDiffTotalUnder > maxDiff)
            {
                maxDiff = currentDiffTotalUnder;
            }

            if (maxDiff == currentDiffTotalOver)
            {
                data.CalculatedProbabilities.TotalOverProbability *= RoundStatsCoef;
            }
            if (maxDiff == currentDiffTotalUnder)
            {
                data.CalculatedProbabilities.TotalUnderProbability *= RoundStatsCoef;
            }



            //get maximal diff compared last 5 rounds with last seasons
            currentDiffHomeWins   = 0;
            currentDiffDraws      = 0;
            currentDiffAwayWins   = 0;
            currentDiffBttsYes    = 0;
            currentDiffBttsNo     = 0;
            currentDiffTotalOver  = 0;
            currentDiffTotalUnder = 0;

            int i = 1;

            foreach (var round in currentSeasonRounds)
            {
                currentDiffHomeWins += (averageHomeWins - round.HomeWinsCount) / i;
                currentDiffDraws    += (averagDraws - round.DrawsCount) / i;
                currentDiffAwayWins += (averageAwayWins - round.AwayWinsCount) / i;

                currentDiffBttsYes += (averageBttsYes - round.BTTS_Yes) / i;
                currentDiffBttsNo  += (averageBttsNo - round.BTTS_No) / i;

                currentDiffTotalOver  += (averageTotalOver - round.GamesOver2_5) / i;
                currentDiffTotalUnder += (averagTotalUnder - round.GamesUnder2_5) / i;
                i++;
            }

            maxDiff = currentDiffHomeWins;
            if (currentDiffDraws > maxDiff)
            {
                maxDiff = currentDiffDraws;
            }
            if (currentDiffAwayWins > maxDiff)
            {
                maxDiff = currentDiffAwayWins;
            }

            if (maxDiff == currentDiffHomeWins)
            {
                data.CalculatedProbabilities.HomeWinProbability *= RoundStatsCoefLastRounds;
            }
            if (maxDiff == currentDiffDraws)
            {
                data.CalculatedProbabilities.DrawProbability *= RoundStatsCoefLastRounds;
            }
            if (maxDiff == currentDiffAwayWins)
            {
                data.CalculatedProbabilities.AwayWinProbability *= RoundStatsCoefLastRounds;
            }

            maxDiff = currentDiffBttsYes;
            if (currentDiffBttsNo > maxDiff)
            {
                maxDiff = currentDiffBttsNo;
            }

            if (maxDiff == currentDiffBttsYes)
            {
                data.CalculatedProbabilities.BttsYesProbability *= RoundStatsCoefLastRounds;
            }
            if (maxDiff == currentDiffBttsNo)
            {
                data.CalculatedProbabilities.BttsNoProbability *= RoundStatsCoefLastRounds;
            }

            maxDiff = currentDiffTotalOver;
            if (currentDiffTotalUnder > maxDiff)
            {
                maxDiff = currentDiffTotalUnder;
            }

            if (maxDiff == currentDiffTotalOver)
            {
                data.CalculatedProbabilities.TotalOverProbability *= RoundStatsCoefLastRounds;
            }
            if (maxDiff == currentDiffTotalUnder)
            {
                data.CalculatedProbabilities.TotalUnderProbability *= RoundStatsCoefLastRounds;
            }
        }