public ActionResult Schedule(int selectedRound = -1) { using (var ctx = new FootballEntities()) { var actualSeason = SeasonHelper.GetCurrentSeason(DateTime.Today); var actualRound = MatchweekHelper.GetMatchweekToDisplayInSchedule(); var data = new List <MainPageModel>(); if (!(selectedRound >= 1 && selectedRound <= 38)) { selectedRound = actualRound; } int success = 0; int notPlayed = 0; foreach (var x in ctx.Matches.Where(d => (d.Matchweek == selectedRound) && d.Season.Equals(actualSeason))) { if (selectedRound <= actualRound) { var score = ctx.Scores.FirstOrDefault(w => w.MatchId == x.Id); int?homeGoals, awayGoals; if (score != null) { homeGoals = score.HomeGoals; awayGoals = score.AwayGoals; bool rightPredicted = CompareScores((int)homeGoals, (int)awayGoals, x.HomeGoalsPredicted, x.AwayGoalsPredicted); if (rightPredicted) { success++; } } else { notPlayed++; homeGoals = null; awayGoals = null; } data.Add(new MainPageModel(x.Team1.FullName, x.Team.FullName, x.HomeGoalsPredicted, x.AwayGoalsPredicted, awayGoals, homeGoals, x.Date.Date)); } else { data.Add(new MainPageModel(x.Team1.FullName, x.Team.FullName, x.HomeGoalsPredicted, x.AwayGoalsPredicted, null, null, x.Date.Date)); } } ViewBag.actualRound = actualRound; ViewBag.selectedRound = selectedRound; if (selectedRound <= actualRound && notPlayed < 10) { var successPercent = (success / (10.0 - notPlayed)) * 100.0; ViewBag.success = Math.Round(successPercent, 2); } return(View(data.Distinct())); } }
public void CheckSeasonForDate() { var jan = SeasonHelper.GetCurrentSeason(new DateTime(2017, 1, 10)); var july = SeasonHelper.GetCurrentSeason(new DateTime(2017, 7, 10)); var nov = SeasonHelper.GetCurrentSeason(new DateTime(2017, 11, 10)); Assert.AreEqual(jan, "2016/2017"); Assert.AreEqual(july, "2017/2018"); Assert.AreEqual(nov, "2017/2018"); }
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 void CanFoundCorrectSeason() { DateTime currDate = new DateTime(2010, 1, 1); Assert.IsTrue(Season.Winter == SeasonHelper.GetCurrentSeason(currDate)); currDate = new DateTime(2010, 4, 1); Assert.IsTrue(Season.Spring == SeasonHelper.GetCurrentSeason(currDate)); currDate = new DateTime(2010, 9, 21); Assert.IsTrue(Season.Fall == SeasonHelper.GetCurrentSeason(currDate)); currDate = new DateTime(2010, 8, 24); Assert.IsTrue(Season.Summer == SeasonHelper.GetCurrentSeason(currDate)); }
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)); } }
public ActionResult Table() { using (var ctx = new FootballEntities()) { var actualSeason = SeasonHelper.GetCurrentSeason(DateTime.UtcNow); var teams = new List <TeamModel>(); var position = 1; foreach (var singleTeam in ctx.FullStatistics.Where(e => e.Season == actualSeason).OrderByDescending(e => e.Points)) { var name = singleTeam.Team.FullName; var team = new TeamModel(name, position++, singleTeam.MatchesPlayed, singleTeam.Points, singleTeam.MatchesWon, singleTeam.MatchesDrawn, singleTeam.MatchesLost, singleTeam.GoalsScored, singleTeam.GoalsLost, singleTeam.GoalsScored - singleTeam.GoalsLost, null); teams.Add(team); } return(View(teams)); } }
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 H2H(TeamsInfoModel model) { using (var ctx = new FootballEntities()) { var teams = ctx.Teams.Select(x => x.FullName).ToList(); ViewBag.Teams = teams; ViewBag.allSeasons = GetListOfAvailablesSeasons(ctx); if (model.Team1 == null || model.Team2 == null || model.Team1.Equals(model.Team2)) { return(View()); } var team1Id = ctx.Teams.FirstOrDefault(e => e.FullName.Equals(model.Team1)).Id; var team2Id = ctx.Teams.FirstOrDefault(e => e.FullName.Equals(model.Team2)).Id; var singleMatchStats = new List <MatchStatisticsModel>(); var today = DateTime.UtcNow.Date; var actualSeason = SeasonHelper.GetCurrentSeason(today); var seasonTwoYearsAgo = SeasonHelper.GetCurrentSeason(DateTime.Today.AddYears(-2)); if (model.SeasonTo == null) { model.SeasonTo = actualSeason; } 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; } foreach (var match in ctx.Matches.Where(e => ((e.HomeId == team1Id && e.AwayId == team2Id) || e.HomeId == team2Id && e.AwayId == team1Id) && 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 stats = ctx.Scores.FirstOrDefault(q => q.MatchId == match.Id); if (stats == null) { continue; } var season = SeasonHelper.GetCurrentSeason(match.Date); singleMatchStats.Add(new MatchStatisticsModel(homeTeam, awayTeam, match.Date, match.HomeGoalsPredicted, match.AwayGoalsPredicted, 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, season)); } ViewBag.Matches = singleMatchStats; return(View()); } }
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()); } }
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) { } }