private Tuple <int, int, int> GetSuccessRateOfPrediction(TeamsInfoModel model)
        {
            int successScorePredictions  = 0;
            int successResultPredictions = 0;
            int allMatches   = 0;
            var teamName     = model.Team1;
            var actualSeason = SeasonHelper.GetCurrentSeason(DateTime.Today);

            using (var ctx = new FootballEntities())
            {
                var actualRound = MatchweekHelper.GetCurrentMatchweek();
                var teamId      = ctx.Teams.FirstOrDefault(e => e.FullName.Equals(teamName)).Id;

                foreach (var match in ctx.Matches.Where(e => (e.HomeId == teamId || e.AwayId == teamId) &&
                                                        DateTime.Compare(e.Date, DateTime.Today) < 0))
                {
                    var scoreOfMatch = match.Scores.FirstOrDefault();
                    if (scoreOfMatch == null)
                    {
                        continue;
                    }

                    if (!SeasonsComapare(model.SeasonSince, model.SeasonTo, match.Season))
                    {
                        continue;
                    }
                    if (match.AwayGoalsPredicted == null || match.HomeGoalsPredicted == null)
                    {
                        continue;
                    }

                    if ((scoreOfMatch.HomeGoals > scoreOfMatch.AwayGoals &&
                         match.HomeGoalsPredicted > match.AwayGoalsPredicted) ||
                        (scoreOfMatch.HomeGoals < scoreOfMatch.AwayGoals &&
                         match.HomeGoalsPredicted < match.AwayGoalsPredicted) ||
                        (scoreOfMatch.HomeGoals == scoreOfMatch.AwayGoals &&
                         match.HomeGoalsPredicted == match.AwayGoalsPredicted))
                    {
                        successResultPredictions++;
                    }

                    if (scoreOfMatch.HomeGoals == match.HomeGoalsPredicted &&
                        scoreOfMatch.AwayGoals == match.AwayGoalsPredicted)
                    {
                        successScorePredictions++;
                    }

                    allMatches++;
                }
            }
            return(Tuple.Create(allMatches, successResultPredictions, successScorePredictions));
        }
 public ActionResult NextRound()
 {
     using (var ctx = new FootballEntities())
     {
         var data         = new List <MainPageModel>();
         var actualSeason = SeasonHelper.GetCurrentSeason(DateTime.Today);
         var actualRound  = MatchweekHelper.GetCurrentMatchweek();
         //tu dodac jeszcze obrazek na koniec sezonu
         foreach (var x in ctx.Matches.Where(d => (d.Matchweek == actualRound) && d.Season.Equals(actualSeason))) // to zmienic żeby na koniec sezonu wyswietlalo obrazek
         {
             data.Add(new MainPageModel(x.Team1.FullName, x.Team.FullName, x.HomeGoalsPredicted, x.AwayGoalsPredicted, null, null, x.Date.Date));
         }
         ViewBag.round = actualRound;
         return(View(data));
     }
 }
예제 #3
0
        private void SetEffectiveness()
        {
            try
            {
                // Current Effectiveness = effectiveness of completed matchweek
                int    currentMatchweek     = MatchweekHelper.GetCurrentMatchweek() - 1;
                double currentEffectiveness = new ScoreEffectivenessService().Compute(currentMatchweek, SeasonHelper.GetCurrentSeason(DateTime.Now)) * 100;

                double previouslyEffectiveness = currentEffectiveness;
                if (currentMatchweek > 1)
                {
                    previouslyEffectiveness = new ScoreEffectivenessService().Compute(currentMatchweek - 1, SeasonHelper.GetCurrentSeason(DateTime.Now)) * 100;
                }

                string compareEffectiveness = "";
                double difference           = currentEffectiveness - previouslyEffectiveness;
                if (difference > 0)
                {
                    compareEffectiveness             = "+";
                    CompareEfficiencyLabel.ForeColor = System.Drawing.Color.Green;
                }
                else if (difference < 0)
                {
                    CompareEfficiencyLabel.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    CompareEfficiencyLabel.ForeColor = System.Drawing.Color.Black;
                }
                compareEffectiveness += difference.ToString();

                CurrentEfficiencyLabel.Text     = currentEffectiveness.ToString() + "%";
                CompareEfficiencyLabel.Location = new Point(CurrentEfficiencyLabel.Location.X + CurrentEfficiencyLabel.Width + 1, CurrentEfficiencyLabel.Location.Y);
                CompareEfficiencyLabel.Text     = compareEffectiveness + "%";

                Log("Skuteczność systemu została zaktualizowana.");
            }
            catch (Exception)
            {  }
        }
예제 #4
0
        public static void Main(string[] args)
        {
            string _filepath = "";

            var date = ExecutionDateHelper.GetLastExecutionDate();

            try
            {
                Console.WriteLine("\nDownloading csv stared...");
                var csv = new CsvDownloader();
                _filepath = csv.GetScoresCsv(DateTime.Now);
                logger.Info("Csv file has been saved as: " + _filepath);
                Console.WriteLine("Downloading csv succeeded. File is located in: {0}", _filepath);
            }
            catch (Exception e)
            {
                logger.Error("Error while downloading csv file", e);
                Console.WriteLine("Downloading csv file failed.");
                return;
            }

            try
            {
                Console.WriteLine("\nParsing csv started...");
                var cs = new CsvService();
                var n  = cs.InsertScores(_filepath, date);
                logger.Info(n + " score records have been added to database");
                Console.WriteLine("Inserting scores to database succeeded.\n{0} records have been added", n);
                if (n > 0)
                {
                    ExecutionDateHelper.SetExecutionDate();
                }
            }
            catch (Exception e)
            {
                logger.Error("Error while inserting scores.", e);
                Console.WriteLine("Inserting scores to database failed.");
                return;
            }

            try
            {
                Console.WriteLine("\nPredicting scores started...");
                var    p         = new Predictor();
                string season    = SeasonHelper.GetCurrentSeason(DateTime.Now);
                int    matchweek = MatchweekHelper.GetCurrentMatchweek();

                if (matchweek == 0 || matchweek == 38)
                {
                    season    = SeasonHelper.GetNextSeason(season);
                    matchweek = 1;
                }

                logger.InfoFormat("Prediction will be run for matchweek {0} of season {1}", matchweek, season);
                List <Match> sc = p.Predict(season, matchweek);
                logger.Info("Prediction finished successfully");
                Console.WriteLine("Predicting process succeeded.");
                Console.WriteLine("Predicted scores are:\n");
                foreach (var s in sc)
                {
                    Console.WriteLine("{0} - {1}\t\t{2}:{3}", s.Team1.Name, s.Team.Name, s.HomeGoalsPredicted, s.AwayGoalsPredicted);
                }
            }
            catch (Exception e)
            {
                logger.Error("Error while predicting.", e);
                Console.WriteLine("\nAn error occured while predicting scores.");
                return;
            }

            logger.Info("Bye");
            Console.WriteLine("\nProgram finished.");
        }
        public ActionResult TeamStatistics(TeamsInfoModel model)
        {
            if (model.Team1 == null)
            {
                model.Team1 = "";
            }
            using (var ctx = new FootballEntities())
            {
                var seasonStatsOfTeam = new List <TeamModel>();
                var teams             = ctx.Teams.Select(x => x.FullName).ToList();
                ViewBag.teams      = teams;
                ViewBag.allSeasons = GetListOfAvailablesSeasons(ctx);
                if (model.Team1.Equals(""))
                {
                    return(View());
                }

                var today             = DateTime.UtcNow.Date;
                var season            = SeasonHelper.GetCurrentSeason(today);
                var seasonTwoYearsAgo = SeasonHelper.GetCurrentSeason(DateTime.Today.AddYears(-2));
                if (model.SeasonTo == null)
                {
                    model.SeasonTo = season;
                }
                if (model.SeasonSince == null)
                {
                    model.SeasonSince = seasonTwoYearsAgo;
                }

                var iFrom = Int32.Parse(model.SeasonSince.Remove(4));
                var iTo   = Int32.Parse(model.SeasonTo.Remove(4));
                if (iFrom > iTo)
                {
                    var tmp = model.SeasonSince;
                    model.SeasonSince = model.SeasonTo;
                    model.SeasonTo    = tmp;
                }
                var statsOfPrediction = GetSuccessRateOfPrediction(model);
                ViewBag.matchesPredicted      = statsOfPrediction.Item1;
                ViewBag.rightResultPrediction = statsOfPrediction.Item2;
                ViewBag.rightScoresPrediction = statsOfPrediction.Item3;


                var teamId = ctx.Teams.FirstOrDefault(e => e.FullName.Equals(model.Team1)).Id;
                //dodac liczenia miejsca w tabeli
                foreach (var singleTeam in ctx.FullStatistics.Where(e => e.TeamId == teamId).OrderByDescending(d => d.Season))
                {
                    if (!SeasonsComapare(model.SeasonSince, model.SeasonTo, singleTeam.Season))
                    {
                        continue;
                    }
                    var name = singleTeam.Team.FullName;
                    var team = new TeamModel(name, 0, singleTeam.MatchesPlayed, singleTeam.Points,
                                             singleTeam.MatchesWon,
                                             singleTeam.MatchesDrawn, singleTeam.MatchesLost, singleTeam.GoalsScored,
                                             singleTeam.GoalsLost,
                                             singleTeam.GoalsScored - singleTeam.GoalsLost, singleTeam.Season);
                    seasonStatsOfTeam.Add(team);
                }
                ViewBag.SeasonStats = seasonStatsOfTeam;


                var singleMatchStats = new List <MatchStatisticsModel>();
                var actualRound      = MatchweekHelper.GetCurrentMatchweek();

                foreach (var match in ctx.Matches.Where(e => (e.HomeId == teamId || e.AwayId == teamId) &&
                                                        DateTime.Compare(e.Date, today) < 0).OrderByDescending(d => d.Date))
                {
                    if (!SeasonsComapare(model.SeasonSince, model.SeasonTo, match.Season))
                    {
                        continue;
                    }
                    var homeTeam      = ctx.Teams.First(q => q.Id == match.HomeId).FullName;
                    var awayTeam      = ctx.Teams.First(q => q.Id == match.AwayId).FullName;
                    var seasonOfMatch = SeasonHelper.GetCurrentSeason(match.Date);
                    var stats         = ctx.Scores.FirstOrDefault(q => q.MatchId == match.Id);

                    if (stats == null)
                    {
                        continue;
                    }

                    singleMatchStats.Add(new MatchStatisticsModel(homeTeam, awayTeam, match.Date,
                                                                  match.AwayGoalsPredicted, match.HomeGoalsPredicted, match.Matchweek, stats.HomeGoals, stats.AwayGoals,
                                                                  stats.HomeShots, stats.AwayShots, stats.HomeShotsOnTarget, stats.AwayShotsOnTarget, stats.HomeCorners,
                                                                  stats.AwayCorners, stats.HomeFouls, stats.AwayFouls, stats.HomeYellowCards, stats.AwayYellowCards,
                                                                  stats.HomeRedCards, stats.AwayRedCards, stats.HalfTimeHomeGoals, stats.HalfTimeAwayGoals,
                                                                  stats.Referee, seasonOfMatch));
                }

                ViewBag.Matches = singleMatchStats;

                //url
                var url = ctx.Teams.FirstOrDefault(x => x.FullName.Equals(model.Team1)).ImageURL;
                ViewBag.url = url;

                return(View());
            }
        }