public void Add(Statline statline) { _db.Insert(new StatlineDTO { Date = statline.Date, FaceoffWinPercentage = statline.FaceoffWinPercentage, GamesPlayed = statline.GamesPlayed, GoalsAgainst = statline.GoalsAgainst, GoalsAgainstPerGame = statline.GoalsAgainstPerGame, GoalsFor = statline.GoalsFor, GoalsForPerGame = statline.GoalsForPerGame, Points = statline.Points, Losses = statline.Losses, Wins = statline.Wins, OvertimeLosses = statline.OvertimeLosses, RegularPlusOvertimeWins = statline.RegularPlusOvertimeWins, PowerPlayPercentage = statline.PowerPlayPercentage, PenaltyKillPercentage = statline.PenaltyKillPercentage, PointPercentage = statline.PointPercentage, SeasonId = statline.SeasonId, ShotsForPerGame = statline.ShotsForPerGame, ShotsAgainstPerGame = statline.ShotsAgainstPerGame, Team = (int)statline.Team, }); }
/// <summary> /// Discover what is relevant by retroactively predicting and measuring, rather than using correlation /// </summary> private static void CrystalBall() { var lastGames = _gameRepository.GetLastResultedGames(100); var predictions = new List<Prediction>(); var homeAwayPredictions = new List<Prediction>(); var positiveStats = new Statline().PositiveStats; var negativeStats = new Statline().NegativeStats; foreach (var game in lastGames) { // get team statlines for date before game date var gameStatlines = _statlineRepository.GetStatlinesForGame(game); Game game1 = game; var home = gameStatlines.Single(s => s.Team == game1.HomeTeam); var away = gameStatlines.Single(s => s.Team == game1.AwayTeam); var actualWinner = game1.HomeScore > game1.AwayScore ? home.Team : away.Team; // REVISIT: Extend variables to have positive/negative. Write a comparison function that checks these foreach (var variable in positiveStats) { predictions.Add(new Prediction { GameId = game.Id, PredictedWinner = home.GetByName(variable.Name) > away.GetByName(variable.Name) ? home.Team : away.Team, ActualWinner = actualWinner, }); } foreach (var variable in negativeStats) { predictions.Add(new Prediction { GameId = game.Id, PredictedWinner = home.GetByName(variable.Name) < away.GetByName(variable.Name) ? home.Team : away.Team, ActualWinner = actualWinner, }); } var homeAwayPrediction = new Prediction { GameId = game.Id, PredictedWinner = home.HomeWins > away.AwayWins ? home.Team : away.Team, ActualWinner = actualWinner, }; predictions.Add(homeAwayPrediction); homeAwayPredictions.Add(homeAwayPrediction); } Console.WriteLine("Crystal ball performance: {0}/{1} = {2}%", predictions.Count(p => p.PredictedWinner == p.ActualWinner), predictions.Count, Math.Round((double) (predictions.Count(p => p.PredictedWinner == p.ActualWinner) / predictions.Count * 100), 2) ); Console.WriteLine("Crystal ball home & away performance: {0}/{1} = {2}%", homeAwayPredictions.Count(p => p.PredictedWinner == p.ActualWinner), homeAwayPredictions.Count, Math.Round((double)(homeAwayPredictions.Count(p => p.PredictedWinner == p.ActualWinner) / homeAwayPredictions.Count * 100), 2) ); }
public void Update(Statline statline) { var dto = _db.SingleOrDefault<StatlineDTO>("where Team = @0 and Date = @1", (int)statline.Team, statline.Date); if (dto != null) { dto.Date = statline.Date; dto.FaceoffWinPercentage = statline.FaceoffWinPercentage; dto.GamesPlayed = statline.GamesPlayed; dto.GoalsAgainst = statline.GoalsAgainst; dto.GoalsAgainstPerGame = statline.GoalsAgainstPerGame; dto.GoalsFor = statline.GoalsFor; dto.GoalsForPerGame = statline.GoalsForPerGame; dto.Points = statline.Points; dto.Losses = statline.Losses; dto.Wins = statline.Wins; dto.OvertimeLosses = statline.OvertimeLosses; dto.RegularPlusOvertimeWins = statline.RegularPlusOvertimeWins; dto.PowerPlayPercentage = statline.PowerPlayPercentage; dto.PenaltyKillPercentage = statline.PenaltyKillPercentage; dto.PointPercentage = statline.PointPercentage; dto.SeasonId = statline.SeasonId; dto.ShotsForPerGame = statline.ShotsForPerGame; dto.ShotsAgainstPerGame = statline.ShotsAgainstPerGame; dto.Team = (int) statline.Team; // REVISIT: Turn these fields into nullable fields if (statline.Rank > 0) { dto.Rank = statline.Rank; dto.PlusMinus = statline.PlusMinus; dto.HomeWins = statline.HomeWins; dto.HomeLosses = statline.HomeLosses; dto.HomeOvertimeLosses = statline.HomeOvertimeLosses; dto.AwayWins = statline.AwayWins; dto.AwayLosses = statline.AwayLosses; dto.AwayOvertimeLosses = statline.AwayOvertimeLosses; dto.ShootoutWins = statline.ShootoutWins; dto.ShootoutLosses = statline.ShootoutLosses; dto.WinsInLast10 = statline.WinsInLast10; dto.LossesInLast10 = statline.LossesInLast10; dto.OvertimeLossesInLast10 = statline.OvertimeLossesInLast10; dto.StreakType = (int) statline.StreakType; dto.StreakLength = statline.StreakLength; } _db.Save(dto); } }