예제 #1
0
        public static int GameProjection(NFLGame g, string playerTeamCode, string playerCategory, string playerRole)
        {
            var projection = 0;
              if (playerRole != Constants.K_ROLE_STARTER) return projection;

            //  is a starter
              switch (playerCategory)
              {
              case Constants.K_QUARTERBACK_CAT:
                  projection = g.IsHome(playerTeamCode) ? g.ProjectedHomeTdp : g.ProjectedAwayTdp;
                  break;
              case Constants.K_RUNNINGBACK_CAT:
                  projection = g.IsHome(playerTeamCode) ? g.ProjectedHomeTdr : g.ProjectedAwayTdr;
                  break;
              case Constants.K_RECEIVER_CAT:
                  projection = g.IsHome(playerTeamCode) ? g.ProjectedHomeTdp/2 : g.ProjectedAwayTdp/2;
                  break;
              case Constants.K_KICKER_CAT:
                  projection = g.IsHome( playerTeamCode ) ? g.ProjectedHomeFg : g.ProjectedAwayFg;
                  break;
              }
            #if DEBUG
              Utility.Announce(string.Format("Game {0} projection for {1} {2} {3} is {4}",
              g.GameKey(), playerTeamCode, playerCategory, playerRole, projection ) );
            #endif
              return projection;
        }
        public NFLResult PredictGame(NFLGame game, IStorePredictions persistor, DateTime predictionDate)
        {
            if (game.HomeNflTeam == null) game.HomeNflTeam = Masters.Tm.GetTeam(game.Season + game.HomeTeam);
             if (game.AwayNflTeam == null) game.AwayNflTeam = Masters.Tm.GetTeam(game.Season + game.AwayTeam);

             game.HomeNflTeam.LetterRating = Masters.Sm.GetGordan(game.Season, game.Season + game.HomeTeam);
             game.AwayNflTeam.LetterRating = Masters.Sm.GetGordan(game.Season, game.Season + game.AwayTeam);

             var weekIndex = Int32.Parse(game.Week) - 1;
             var homeLetter = game.HomeNflTeam.LetterRating[weekIndex].Trim();
             var awayLetter = game.AwayNflTeam.LetterRating[weekIndex].Trim();
             //  home team
             var ratingGap = DanGordan.RatingGap(homeLetter, awayLetter);
             //  home teams get 2.5 points home field advantage
             ratingGap += 2.5M;
             //
             //  I give 3/4 strength to the letter power rating because it is adjusted every week and
             //  better takes into account a team's current form.  The number power ratings though more
             //  objective, are totally dependant on Scores, which at times can be deceptive.
             var homeNumberAvgRating = ( game.HomeNflTeam.NumberRating[ 0 ] +
            game.HomeNflTeam.NumberRating[ weekIndex ] ) / 2.0M;
             var awayNumberAvgRating = ( game.AwayNflTeam.NumberRating[ 0 ] +
            game.AwayNflTeam.NumberRating[ weekIndex ] ) / 2.0M;
             //  home advantage
             homeNumberAvgRating += 2.5M;
             var numberRating = ( homeNumberAvgRating - awayNumberAvgRating );

             //  if the rating gap is positive its a home win
             game.GordanLine = RoundToNearestHalfPoint((0.75M * ratingGap) + (0.25M * numberRating));

             var homeScore = 21 + Convert.ToInt32((ratingGap / 2));
             var awayScore = 21 + Convert.ToInt32((ratingGap * -1) / 2);

             return new NFLResult(game.HomeTeam, homeScore, game.AwayTeam, awayScore);
        }
 public void TestSingleGameProjection()
 {
     var game = new NFLGame( "2015:01-A" );
      var ppg = new PlayerProjectionGenerator(null);
      ppg.Execute( game );
      Assert.IsTrue(  ppg != null );
 }
예제 #4
0
        public decimal BackTest()
        {
            //  for each instance that has a line
            #if DEBUG
            DataSet ds = _tflWs.GetGames( 2005, 13 );
            #else
            DataSet ds = _tflWs.GetAllGames();
            #endif

            DataTable dt = ds.Tables["sched"];
            foreach (DataRow dr in dt.Rows)
            {
                NFLGame game = new NFLGame(dr);
                NFLBet bet = IsBettable( game );

                if ( bet == null )
                {}
                else
                {
                    switch ( bet.Result() )
                    {
                        case "Win":
                            M_wins++;
                            break;
                        case "Loss":
                            Losses++;
                            break;
                        case "Push":
                            Pushes++;
                            break;
                    }
                }
            }
            return Utility.Clip( M_wins, Losses, Pushes );
        }
예제 #5
0
        public NFLResult PredictGame(NFLGame game, IStorePredictions persistor, DateTime predictionDate)
        {
            const int avgScore = 21;

            var homeRating = RatingsService.GetNibbleRatingFor( game.HomeNflTeam, predictionDate );
            var awayRating = RatingsService.GetNibbleRatingFor( game.AwayNflTeam, predictionDate );

            var homeOff = homeRating.Offence;
            var homeDef = homeRating.Defence;
            var awayOff = awayRating.Offence;
            var awayDef = awayRating.Defence;

            var homeScore = avgScore + ((homeOff + awayDef) / 2) + 3;  //  3pts home field advantage
            var awayScore = avgScore + ((awayOff + homeDef) / 2);

            homeScore = Utility.PickAScore(homeScore);
            awayScore = Utility.PickAScore(awayScore);

            if (homeScore == awayScore) homeScore++;  //  no ties
            var res = new NFLResult( game.HomeTeam, homeScore, game.AwayTeam, awayScore );

            //TODO:  Nibble predictor does not predict Tdp or Tdr

            if (AuditTrail)
            {
                AuditPrediction(game, awayDef, awayOff, homeOff, res, homeDef);
                if ( StorePrediction )
                    StorePredictedResult( game, res );
            }
            return res;
        }
예제 #6
0
        public NFLResult PredictGame( NFLGame game, IStorePredictions persistor, DateTime predictionDate )
        {
            if ( persistor == null ) StorePrediction = false;

            var homePower = game.HomeNflTeam.GetPowerRating( game.Week );
            var awayPower = game.AwayNflTeam.GetPowerRating( game.Week );

            //Utility.Announce( string.Format( "PredictGame: Home Power {0} v Away Power {1}",
            //   homePower, awayPower ) );

            //  Add 2.5 to the Home teams power rating
            homePower += 2.5M;

            //  Compare Power Rating to get the line
            var line = homePower - awayPower;

            //  Estrapolate the score from the line using 21 point average
            var homeScore = 21.0M;
            var awayScore = 21.0M ;
            if ( line > 0 )
                homeScore += line;
            if ( line < 0 )
                awayScore -= line;

            var intHomeScore = Int32.Parse( Math.Round( homeScore, 0 ).ToString() ) ;
            var intAwayScore = Int32.Parse( Math.Round( awayScore, 0 ).ToString() );

            var res = new NFLResult( game.HomeTeam, intHomeScore, game.AwayTeam, intAwayScore );
            if ( StorePrediction )
                StorePredictedResult( game, res );

            //Utility.Announce( string.Format( "PredictGame: Result predicted - {0}", res.LogResult() ) );

            return res;
        }
예제 #7
0
        public NFLBet IsBettable( NFLGame game )
        {
            NFLBet bet = null;
             string revengeTeam = "";
             string revengeGame = "";
             TimeSpan aYear = new TimeSpan( 365, 0, 0, 0 );

             DataSet ds = tflWS.GetGamesBetween( game.HomeTeam, game.AwayTeam, DateTime.Now.Subtract( aYear ) );
             DataTable dt = ds.Tables["SCHED"];
             dt.DefaultView.Sort = "GAMEDATE ASC";
             foreach (DataRow dr in dt.Rows)
             {
            if ( dr.RowState != DataRowState.Deleted )
            {
               NFLGame aGame = new NFLGame( dr );
               revengeTeam = ( aGame.HomeWin() ) ? aGame.AwayTeam : aGame.HomeTeam;
               revengeGame = aGame.ScoreOut( revengeTeam ) + " " + aGame.GameCodeOut();
            }
             }

             if ( revengeTeam.Length > 0 )
            bet = new NFLBet( revengeTeam, game, Name + " - " + revengeGame, ConfidenceLevel() );

             return bet;
        }
예제 #8
0
        public NFLResult PredictGame(NFLGame game, IStorePredictions persistor, DateTime predictionDate)
        {
            var res = game.Played() ? new NFLResult( game.HomeTeam, game.HomeScore, game.AwayTeam, game.AwayScore )
                                : new NFLResult( game.HomeTeam, 21, game.AwayTeam, 17 );

            return res;
        }
예제 #9
0
        public NFLResult PredictGame(NFLGame game, IStorePredictions persistor, DateTime predictionDate)
        {
            if ( game.HomeNflTeam == null ) game.HomeNflTeam = Masters.Tm.GetTeam( game.Season + game.HomeTeam );
             if ( game.AwayNflTeam == null ) game.AwayNflTeam = Masters.Tm.GetTeam( game.Season + game.AwayTeam );

             var homeLetter = game.HomeNflTeam.LetterRating[ 0 ].Trim();
             var awayLetter = game.AwayNflTeam.LetterRating[ 0 ].Trim();
             //  home team
             var ratingGap = DanGordan.RatingGap( homeLetter, awayLetter );
             //  home teams get 2.5 points home field advantage
             ratingGap += 2.5M;
             //  if the rating gap is positive its a home win
             game.GordanLine = ratingGap;

             var decimalEquivalent = DanGordan.CalculateSpreadsAsDecimals( ratingGap );
             if ( ratingGap > 0 )
             {
            //  home win
            game.HomeDecEquivalent = decimalEquivalent; //  .5 pt win = .507 to home
            game.AwayDecEquivalent = 1.0M - decimalEquivalent; //              .493 to away
             }
             else
             {
            //  away win
            game.AwayDecEquivalent = decimalEquivalent; //  .5 pt win = .507 to away
            game.HomeDecEquivalent = 1.0M - decimalEquivalent; //              .493 to home
             }

             var homeScore = 21 + Convert.ToInt32( ( ratingGap/2 ) );
             var awayScore = 21 + Convert.ToInt32( ( ratingGap*-1 )/2 );

             return new NFLResult( game.HomeTeam, homeScore, game.AwayTeam, awayScore );
        }
예제 #10
0
        public decimal BackTest()
        {
            //  for each instance that has a line

            #if DEBUG
            DataSet ds = tflWS.GetGames( 2005, 13 );
            #else
            DataSet ds = tflWS.GetAllGames();
            #endif

            DataTable dt = ds.Tables["sched"];
            foreach (DataRow dr in dt.Rows)
            {
                NFLGame game = new NFLGame(dr);
                if ( HomeDog( game ) )
                {
                    switch ( game.ResultvsSpread( game.HomeTeam ) )
                    {
                        case "Win":
                            M_wins++;
                            break;
                        case "Loss":
                            Losses++;
                            break;
                        case "Push":
                            Pushes++;
                            break;
                    }
                }
            }
            return Utility.Clip( M_wins, Losses, Pushes );
        }
        public Prediction Get( string method, string season, string week, string gameCode )
        {
            var prediction = new Prediction();

            var ds = Utility.TflWs.GetPrediction(method, season, week, gameCode);

            if (ds.Tables[ 0 ].Rows.Count != 1) return prediction;

            var game = new NFLGame( string.Format( "{0}:{1}-{2}", season, week, gameCode ) );
            prediction.Method = method;
            prediction.Season = season;
            prediction.Week = week;
            prediction.GameCode = gameCode;
            prediction.HomeScore = IntValue( ds, "HomeScore" );
            prediction.AwayScore = IntValue( ds, "AwayScore" );
            //  also do a result
            var result = new NFLResult( home: game.HomeTeam, homePts: prediction.HomeScore,
                away: game.AwayTeam, awayPts: prediction.AwayScore )
            {
                HomeTDp = IntValue( ds, "htdp" ), HomeTDr = IntValue( ds, "htdr" ),
                HomeTDd = IntValue( ds, "htdd" ), HomeTDs = IntValue( ds, "htds" ),
                AwayTDp = IntValue( ds, "atdp" ), AwayTDr = IntValue( ds, "atdr" ),
                AwayTDd = IntValue( ds, "atdd" ), AwayTDs = IntValue( ds, "atds" ),
                HomeYDp = IntValue( ds, "hydp" ), AwayYDp = IntValue( ds, "aydp" ),
                HomeYDr = IntValue( ds, "hydr" ), AwayYDr = IntValue( ds, "aydr" ),
                AwayFg = IntValue( ds, "afg" ), HomeFg = IntValue( ds, "hfg" )
            };
            prediction.NflResult = result;
            return prediction;
        }
 public void TestUpdateGameActuals()
 {
     var g = new NFLGame( "2016:09-A" );
      g.RefreshTotals();
      var g2 = new NFLGame( "2016:09-A" );
      Assert.IsTrue( g2.Spread == g.Spread );
 }
예제 #13
0
 public void TestMatchUpReportSeasonOpener2014()
 {
     var g = new NFLGame("2014:01-A");
      var mur = new MatchupReport(g);
      mur.Render(writeProjection: false);
      Assert.IsTrue(File.Exists(mur.FileOut), string.Format("Cannot find {0}", mur.FileOut));
 }
 public void TestPlayerGameProjection()
 {
     var g = new NFLGame("2014:01-N");  //  IC@DB
      g.LoadPrediction();
      var p = PlayerProjection.GameProjection( g, "DB", Constants.K_QUARTERBACK_CAT, Constants.K_ROLE_STARTER );
      Assert.IsTrue(p.Equals(2));
 }
        public void Execute( NFLGame game )
        {
            if ( pipeline == null ) InitialiseThePipeLine();

             var msg = new PlayerGameProjectionMessage {Game = game, PlayerCache = PlayerCache};
             msg.Game.PlayerGameMetrics = new List<PlayerGameMetrics>();
             if (pipeline != null) pipeline.Execute( msg );
        }
예제 #16
0
 public NflPerformance( string seasonIn, string weekIn, decimal epIn )
 {
     // constructor
      Season = Int32.Parse( seasonIn );
      Week = Int32.Parse( weekIn );
      ExperiencePoints = epIn;
      Game = new NFLGame( seasonIn, weekIn );
 }
예제 #17
0
 public void AddGame(NFLGame g)
 {
     if (! _gameHt.ContainsKey(g.GameKey()))
     {
         _gameHt.Add(g.GameKey(), g);
         IsDirty = true;
     }
 }
예제 #18
0
 public void TestRenderOfGameProjection()
 {
     var game = new NFLGame("2016:01-I");  //  CH @ HT
      var cut = new GameProjection( game );
      cut.Render();
      Assert.IsTrue( File.Exists( cut.FileName() ),
     string.Format( "Cannot find {0}", cut.FileName() ) );
 }
 public void TestPlayerProjectionPrediction()
 {
     var g = new NFLGame( "2013:01-A" );  // YYYY:0W-X
      var prediction = g.GetPrediction( "unit" );
      Assert.IsNotNull( prediction );
      Assert.AreEqual( 0, prediction.AwayTDr, "Away TDr should be 0" );
      Assert.AreEqual( 1, prediction.AwayTDp, "Away TDp should be 1" );
      Assert.AreEqual( 1, prediction.AwayFg, "Away FG should be 1" );
 }
예제 #20
0
 public void TestDefensiveScoringCalculator()
 {
     var week = new NFLWeek( seasonIn: "2016", weekIn: "13" );
      var team = new NflTeam( "KC" );
      var game = new NFLGame( gameKey: "2016:13-B" );  // KC @ AF
      var sut = new DefensiveScoringCalculator( week, offset:0 );
      sut.Calculate( team: team, game: game );
      Assert.AreEqual( expected: 11.0M, actual: team.FantasyPoints );
 }
예제 #21
0
 public NFLBet( string teamCodeIn, NFLGame gameIn, string reason, Confidence confidenceIn )
 {
     TeamToBetOn = teamCodeIn;
     game = gameIn;
     reasonList = new ArrayList();
     confidence = confidenceIn;
     vigorish = 0.1D;   //  the amount that is raked off the winnings
     AddReason( reason );
 }
예제 #22
0
        public void TestGameSummary()
        {
            var game = new NFLGame("2014:01-A");

             var sut = new GameSummary(game);
             sut.Render();
             var fileOut = sut.FileName();

             Assert.IsTrue(File.Exists(fileOut), string.Format("Cannot find {0}", fileOut));
        }
 public void TestYahooProjectedPointsFrTomBrady2013Week01()
 {
     var p = new NFLPlayer( "BRADTO01" );
      var g = new NFLGame( "2013:01-B" );
      g.LoadPrediction();
      var c = new YahooCalculator();
      var msg = c.Calculate( p, g );
      var expected = 18;  //  2 TDp and 250 YDp
      Assert.AreEqual( expected, msg.Player.Points );
 }
 public void TestYahooProjectedPointsForSammyWatkinsWeek16()
 {
     var p = new NFLPlayer( "WATKSA01" );
      var g = new NFLGame( "2014:16-M" );
      g.LoadPrediction();
      var c = new YahooCalculator();
      var msg = c.Calculate( p, g );
      var expected = 13;  //  1 TDp and 75 YDc
      Assert.AreEqual( expected, msg.Player.Points );
 }
 public void TestYahooProjectedPointsForPeytonManning2014Week01()
 {
     var p = new NFLPlayer( "NEWTCA01" );
      var g = new NFLGame( "2015:08-N" );
      g.LoadPrediction();
      var c = new YahooCalculator();
      var msg = c.Calculate( p, g );
      var expected = 6;  //  0 TDp and 150 YDp
      Assert.AreEqual( expected, msg.Player.Points );
 }
 public void TestYahooProjectedPointsForLataviusMurray2016Week01()
 {
     var p = new NFLPlayer( "MURRLA01" );
      var g = new NFLGame( "2016:01-F" );
      g.LoadPrediction();
      var c = new YahooCalculator();
      var msg = c.Calculate( p, g );
      var expected = 18;  //  125(1)
      Assert.AreEqual( expected, msg.Player.Points );
 }
 public void TestJayCutler()
 {
     var g = new NFLGame( "2016:01-I" );
      var msg = new PlayerGameProjectionMessage();
      msg.Player = new NFLPlayer( "CUTLJA01" );
      msg.Game = g;
      msg.Prediction = g.GetPrediction( "unit" );
      var cut = new PullMetricsFromPrediction( msg );
      Assert.IsNotNull( msg.Game.PlayerGameMetrics.Count > 12 );
      msg.Dao = new DbfPlayerGameMetricsDao();
      var saveStep = new SavePlayerGameMetrics( msg );
 }
        public NFLBet IsBettable( NFLGame game )
        {
            NFLBet bet = null;

             if ( game.Dog() == game.HomeTeam )
             {
            //  Have they lost yet

            bet = new NFLBet( game.Dog(), game, Name + " - " + game.Spread, ConfidenceLevel() );
             }

             return bet;
        }
예제 #29
0
 public void TestPlayerRecordingMetrics()
 {
     var season = "2014";
      var week = "01";
      var gamecode = "M";
      var game = new NFLGame( string.Format("{0}:{1}-{2}", season, week, gamecode) );
      var sut = new RecordOfActualMetricsReport(season, week);
      var player = new NFLPlayer("KAEPCO01");
      player.TallyScores(season, Int32.Parse(week) );
      player.TallyStats(season, Int32.Parse(week) );
      Console.WriteLine(player.CurrentGameMetrics);
      var result = sut.RecordMetrics(player, game);
      Assert.IsTrue( result.Substring( 0, 4 ) != "Fail");
 }
예제 #30
0
        public NFLResult PredictGame(NFLGame game, IStorePredictions persistor, DateTime predictionDate)
        {
            NFLResult res;

             //RosterLib.Utility.Announce( string.Format( "WizPredictor.PredictGame: Wk{2} {0}@{1}",
             //   game.AwayTeam, game.HomeTeam, game.Week ) );

            if ( game.Played() )
                res = new NFLResult( game.HomeTeam, game.HomeScore, game.AwayTeam, game.AwayScore );
            else
            {
                if ( game.HomeNflTeam == null ) game.HomeNflTeam = Masters.Tm.GetTeam( game.Season, game.HomeTeam );
                if ( game.AwayNflTeam == null ) game.AwayNflTeam = Masters.Tm.GetTeam( game.Season, game.AwayTeam );
                var homeMatrix = game.HomeNflTeam.GetMatrix();
                var awayMatrix = game.AwayNflTeam.GetMatrix();

                //  Homescore = Tdp*7 + Tdr*7 + 3
                var homePointsPassing = Tdp( homeMatrix.PoPoints - awayMatrix.PdPoints );
                var homePointsRunning = Tdr( homeMatrix.RoPoints - awayMatrix.RdPoints );
                var homeScore = homePointsPassing + homePointsRunning + 3;

                //  Awayscore = Tdp*7 + Tdr*7
                var awayPointsPassing = Tdp( awayMatrix.PoPoints - homeMatrix.PdPoints );
                var awayPointsRunning = Tdr( awayMatrix.RoPoints - homeMatrix.RdPoints );
                var awayScore = awayPointsPassing + awayPointsRunning;

                if ( homeScore == awayScore ) homeScore++;  //  no ties

                res = new NFLResult(game.HomeTeam, homeScore, game.AwayTeam, awayScore)
                      	{
                      		AwayTDp = (awayPointsPassing/7),
                      		HomeTDp = (homePointsPassing/7),
                      		AwayTDr = (awayPointsRunning/7),
                      		HomeTDr = (homePointsRunning/7)
                      	};
                if ( AuditTrail )
                {
                    Utility.Announce( string.Format( "Wiz Prediction Wk{4} {0}@{1} {2}-{3} ",
                        game.AwayTeam, game.HomeTeam, res.AwayScore, res.HomeScore, game.Week ) );
                    Utility.Announce( string.Format( "  hTDr({0}) hTDp({1}) aTDr({2}) aTDp({3})",
                        res.HomeTDr, res.HomeTDp, res.AwayTDr, res.AwayTDp ));
                    Utility.Announce( string.Format( "  hPOpts({0:#.#}) hROpts({1:#.#}) aRDpts({2:#.#}) aPDpts({3:#.#})",
                        homeMatrix.PoPoints, homeMatrix.RoPoints, awayMatrix.RdPoints, awayMatrix.PdPoints ));
                    Utility.Announce( string.Format( "  aPOpts({0:#.#}) aROpts({1:#.#}) hRDpts({2:#.#}) hPDpts({3:#.#})",
                        awayMatrix.PoPoints, awayMatrix.RoPoints, homeMatrix.RdPoints, homeMatrix.PdPoints ));
                }
            }
             return res;
        }