示例#1
0
        public LeagueRoundModule()
        {
            Get[SharedRoutes.SeasonAllRounds] = parameters => {
                var seasonId = (int)parameters.seasonId;
                var rounds = leagueRepo.GetCurrentSeasonRounds(seasonId).Select(Mapper.Map<RoundDto>).ToList();
                return Response.AsJson(rounds);
            };

            Get[SharedRoutes.RoundGames] = parameters => {
                var seasonId = (int)parameters.seasonId;
                var roundId = (int)parameters.roundId;
                var gameRoundsDb = leagueRepo.GetAllRoundGames(roundId);
                if (gameRoundsDb.Any(g => g.SeasonRound.LeagueSeasonId != seasonId))
                    return HttpStatusCode.Conflict;
                var games = gameRoundsDb.Select(Mapper.Map<GameDto>).ToList();
                return Response.AsJson(games);
            };

            Get[SharedRoutes.CurrentRoundGames] = parameters => {
                var seasonId = (int)parameters.seasonId;
                var season = leagueRepo.GetLeagueSeasonById(seasonId);
                var currentRound = leagueRepo.GetCurrentSeasonRound(season);
                var gameRoundsDb = leagueRepo.GetAllRoundGames(currentRound.RoundId);
                if (gameRoundsDb.Any(g => g.SeasonRound.LeagueSeasonId != seasonId))
                    return HttpStatusCode.Conflict;
                var games = gameRoundsDb.Select(Mapper.Map<GameDto>).ToList();
                return Response.AsJson(games);
            };

            Get[SharedRoutes.SeasonRoundsTable] = parameters => {
                var seasonId = (int)parameters.seasonId;
                var rounds = leagueRepo.GetCurrentSeasonRounds(seasonId).Select(Mapper.Map<RoundStatsDto>).OrderBy(r => r.RoundNumber).ToList();
                var roundTable = new RoundsTable
                {
                    LeagueSeasonId = seasonId,
                    IsFinished = rounds.Count >= 38,
                    Rounds = rounds,
                    StartDate = rounds.FirstOrDefault()?.StartDate,
                    EndDate = rounds.LastOrDefault()?.EndDate,
                };
                return Response.AsJson(roundTable);
            };

            Get[SharedRoutes.SeasonRoundsStats] = parameters => {
                var seasonId = (int)parameters.seasonId;
                var averageRoundStats = Mapper.Map<SeasonAverageRoundDto>(analysisRepo.GetAverageRoundStats(seasonId));
                return Response.AsJson(averageRoundStats);
            };

        }
示例#2
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;
            }
        }