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.");
                }
            }
        }
Beispiel #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;
            }
        }
Beispiel #3
0
        private void SaveFootballDataModelToDb(FootballDataModel match, ref int processedGames)
        {
            bool onlyCreated;
            var  leagueSeason = leagueDataRepo.CreateAndSaveLeagueSeason(_startYear, leagueDataRepo.GetLaLiga());
            var  homeTeam     = leagueDataRepo.GetFootballTeam(match.HomeTeam, leagueSeason, "FootballData");
            var  awayTeam     = leagueDataRepo.GetFootballTeam(match.AwayTeam, leagueSeason, "FootballData");
            Game matchDb      = null;

            try
            {
                matchDb = leagueDataRepo.GetGame(homeTeam, awayTeam, match.MatchDate, leagueSeason, out onlyCreated);
            }
            catch (Exception ex)
            {
                return;
            }

            if (onlyCreated || matchDb.Result == 0) //update game record
            {
                //Console.WriteLine("Game record only created - will be processed");
                matchDb.AwayTeamGoals = match.FullTimeAwayTeamGoals;
                matchDb.HomeTeamGoals = match.FullTimeHomeTeamGoals;
                if (matchDb.HomeTeamGoals > matchDb.AwayTeamGoals)
                {
                    matchDb.Result = GameResult.HomeWin;
                }
                else if (matchDb.HomeTeamGoals < matchDb.AwayTeamGoals)
                {
                    matchDb.Result = GameResult.AwayWin;
                }
                else
                {
                    matchDb.Result = GameResult.Draw;
                }

                leagueDataRepo.UpdateGameRecord(matchDb);
                processedGames++;
            }

            var matchStats = leagueDataRepo.GetGameStats(matchDb.GameId, out onlyCreated);

            if (onlyCreated) //update game stats
            {
                matchStats.Game = matchDb;
                matchStats.HalfTimeHomeGoals = match.HalfTimeHomeTeamGoals;
                matchStats.HalfTimeAwayGoals = match.HalfTimeAwayTeamGoals;
                if (matchStats.HalfTimeHomeGoals > matchStats.HalfTimeAwayGoals)
                {
                    matchStats.HalfTimeResult = GameResult.HomeWin;
                }
                else if (matchStats.HalfTimeHomeGoals < matchStats.HalfTimeAwayGoals)
                {
                    matchStats.HalfTimeResult = GameResult.AwayWin;
                }
                else
                {
                    matchStats.HalfTimeResult = GameResult.Draw;
                }

                matchStats.HomeTeamShots = match.HomeTeamShots;
                matchStats.AwayTeamShots = match.AwayTeamShots;

                matchStats.HomeTeamTargetShots = match.HomeTeamShotsOnTarget;
                matchStats.AwayTeamTargetShots = match.AwayTeamShotsOnTarget;

                matchStats.HomeTeamFouls = match.HomeTeamFouls;
                matchStats.AwayTeamFouls = match.AwayTeamFouls;

                matchStats.HomeTeamCorners = match.HomeTeamCorners;
                matchStats.AwayTeamCorners = match.AwayTeamCorners;

                matchStats.HomeTeamYCards   = match.HomeTeamYellowCards;
                matchStats.AwayTeamYCards   = match.AwayTeamYellowCards;
                matchStats.HomeTeamRedCards = match.HomeTeamRedCards;
                matchStats.AwayTeamRedCards = match.AwayTeamRedCards;

                matchStats.HomeTeamOffsides = match.HomeTeamOffsides;
                matchStats.AwayTeamOffsides = match.AwayTeamOffsides;

                leagueDataRepo.UpdateGameStats(matchStats);
            }

            var bookmaker    = bookmakerRepo.GetBookmaker("Bet365");
            var bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated);

            if (onlyCreated) //update game record
            {
                bookmakerOdd.HomeWinCoef = match.B365_HomeWin;
                bookmakerOdd.DrawCoef    = match.B365_Draw;
                bookmakerOdd.AwayWinCoef = match.B365_AwayWin;

                bookmakerOdd.Total2_5Over  = match.B365_TotalMore2_5;
                bookmakerOdd.Total2_5Under = match.B365_TotalLess2_5;

                bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd);
            }

            bookmaker    = bookmakerRepo.GetBookmaker("Blue Square");
            bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated);
            if (onlyCreated) //update game record
            {
                bookmakerOdd.HomeWinCoef = match.BS_HomeWin;
                bookmakerOdd.DrawCoef    = match.BS_Draw;
                bookmakerOdd.AwayWinCoef = match.BS_AwayWin;

                bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd);
            }

            bookmaker    = bookmakerRepo.GetBookmaker("Bet&Win");
            bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated);
            if (onlyCreated) //update game record
            {
                bookmakerOdd.HomeWinCoef = match.BW_HomeWin;
                bookmakerOdd.DrawCoef    = match.BW_Draw;
                bookmakerOdd.AwayWinCoef = match.BW_AwayWin;

                bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd);
            }

            bookmaker    = bookmakerRepo.GetBookmaker("Gamebookers");
            bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated);
            if (onlyCreated) //update game record
            {
                bookmakerOdd.HomeWinCoef = match.GB_HomeWin;
                bookmakerOdd.DrawCoef    = match.GB_Draw;
                bookmakerOdd.AwayWinCoef = match.GB_AwayWin;

                bookmakerOdd.Total2_5Over  = match.GB_TotalMore2_5;
                bookmakerOdd.Total2_5Under = match.GB_TotalLess2_5;

                bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd);
            }

            bookmaker    = bookmakerRepo.GetBookmaker("Interwetten");
            bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated);
            if (onlyCreated) //update game record
            {
                bookmakerOdd.HomeWinCoef = match.IW_HomeWin;
                bookmakerOdd.DrawCoef    = match.IW_Draw;
                bookmakerOdd.AwayWinCoef = match.IW_AwayWin;

                bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd);
            }

            bookmaker    = bookmakerRepo.GetBookmaker("Pinnacle");
            bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated);
            if (onlyCreated) //update game record
            {
                bookmakerOdd.HomeWinCoef = match.Pinnacle_HomeWin;
                bookmakerOdd.DrawCoef    = match.Pinnacle_Draw;
                bookmakerOdd.AwayWinCoef = match.Pinnacle_AwayWin;

                bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd);
            }

            bookmaker    = bookmakerRepo.GetBookmaker("Sporting Odds");
            bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated);
            if (onlyCreated) //update game record
            {
                bookmakerOdd.HomeWinCoef = match.SO_HomeWin;
                bookmakerOdd.DrawCoef    = match.SO_Draw;
                bookmakerOdd.AwayWinCoef = match.SO_AwayWin;

                bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd);
            }

            bookmaker    = bookmakerRepo.GetBookmaker("Sportingbet");
            bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated);
            if (onlyCreated) //update game record
            {
                bookmakerOdd.HomeWinCoef = match.SB_HomeWin;
                bookmakerOdd.DrawCoef    = match.SB_Draw;
                bookmakerOdd.AwayWinCoef = match.SB_AwayWin;

                bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd);
            }

            bookmaker    = bookmakerRepo.GetBookmaker("Stan James");
            bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated);
            if (onlyCreated) //update game record
            {
                bookmakerOdd.HomeWinCoef = match.SJ_HomeWin;
                bookmakerOdd.DrawCoef    = match.SJ_Draw;
                bookmakerOdd.AwayWinCoef = match.SJ_AwayWin;

                bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd);
            }

            bookmaker    = bookmakerRepo.GetBookmaker("Stanleybet");
            bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated);
            if (onlyCreated) //update game record
            {
                bookmakerOdd.HomeWinCoef = match.Stanleybet_HomeWin;
                bookmakerOdd.DrawCoef    = match.Stanleybet_Draw;
                bookmakerOdd.AwayWinCoef = match.Stanleybet_AwayWin;

                bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd);
            }

            bookmaker    = bookmakerRepo.GetBookmaker("VC");
            bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated);
            if (onlyCreated) //update game record
            {
                bookmakerOdd.HomeWinCoef = match.VC_HomeWin;
                bookmakerOdd.DrawCoef    = match.VC_Draw;
                bookmakerOdd.AwayWinCoef = match.VC_AwayWin;

                bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd);
            }

            bookmaker    = bookmakerRepo.GetBookmaker("William Hill");
            bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated);
            if (onlyCreated) //update game record
            {
                bookmakerOdd.HomeWinCoef = match.WH_HomeWin;
                bookmakerOdd.DrawCoef    = match.WH_Draw;
                bookmakerOdd.AwayWinCoef = match.WH_AwayWin;

                bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd);
            }

            bookmaker    = bookmakerRepo.GetBookmaker("Total average odds");
            bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated);
            if (onlyCreated) //update game record
            {
                bookmakerOdd.Total2_5Over  = match.Average_TotalMore2_5;
                bookmakerOdd.Total2_5Under = match.Average_TotalLess2_5;

                bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd);
            }

            bookmaker    = bookmakerRepo.GetBookmaker("Total maximal odds");
            bookmakerOdd = bookmakerRepo.GetBookmakerOdds(matchDb.GameId, bookmaker.BookmakerId, out onlyCreated);
            if (onlyCreated) //update game record
            {
                bookmakerOdd.Total2_5Over  = match.Max_TotalMore2_5;
                bookmakerOdd.Total2_5Under = match.Max_TotalLess2_5;

                bookmakerRepo.UpdateBookmakerOdds(bookmakerOdd);
            }
        }