Esempio n. 1
0
        public NflPerformance( int seasonIn, int weekIn, string teamIn, NFLPlayer myPlayer )
        {
            // constructor
             TeamCode = teamIn;
             Season = seasonIn;
             Week = weekIn;
             _thePlayer = myPlayer;
             _tflWs = Utility.TflWs;

             PerfStats = new PlayerStats();

              	if (teamIn == "??") return;

              	// What was the result
              	var ds = _tflWs.ResultFor( TeamCode, seasonIn, weekIn );
              	if ( ds.Tables[ 0 ].Rows.Count > 0 )
              	{
              		var dr = ds.Tables[ 0 ].Rows[ 0 ];
              		var gameCode = string.Format( "{0}:{1}-{2}", seasonIn, dr[ "WEEK" ], dr[ "GAMENO" ] );

              		Game = Masters.Gm.GetGame( gameCode ) ?? new NFLGame( dr );
              		LoadScores();
              		LoadStats();
              	}
              	else
              		TeamCode = "bye";
        }
Esempio n. 2
0
        private decimal StarsFor( NFLPlayer plyr )
        {
            //  You get a star for 300+YDp or 3+TDps
            decimal nStars = 0M;

            //  Have to do it week by week
            for (int w = Week.WeekNo; w <= Week.WeekNo; w++)
            {
                if (
                      ( TDpForWeek( w, plyr ) > 2 ) ||
                      ( TDrForWeek( w, plyr ) > 1 ) ||
                      (  TDcForWeek(w, plyr ) > 1 ) ||
                      ( CalculateStats(plyr, w, RosterLib.Constants.K_STATCODE_PASSING_YARDS) >= 300 ) ||
                      ( CalculateStats(plyr, w, RosterLib.Constants.K_STATCODE_RUSHING_YARDS) >= 160 ) ||
                      ( CalculateStats(plyr, w, RosterLib.Constants.K_STATCODE_PASSES_CAUGHT) >= 10  ) ||
                      ( CalculateStats(plyr, w, RosterLib.Constants.K_STATCODE_RECEPTION_YARDS) >= 160 )
                    )
                    nStars++;
            }

            RosterLib.Utility.Announce( string.Format( "{0,-15} in week {2,-2} has {1} stars",
                plyr.PlayerName, nStars, Week.WeekNo ) );

            return nStars;
        }
Esempio n. 3
0
 private int CalculateScore( NFLPlayer plyr, int w, string scoreType, string playerId )
 {
     int nTDp = 0;
     DataSet ds = plyr.LastScores( scoreType, w, w, Season, playerId );
     if ( ds != null ) nTDp = ds.Tables[0].Rows.Count;
     return nTDp;
 }
Esempio n. 4
0
        public Decimal RatePlayer( NFLPlayer plyr, NFLWeek week )
        {
            // Points for Scores and points for stats
            if (week.WeekNo.Equals(0)) return 0;

            Week = week;  //  set the global week, other wise u will get the same week all the time
            plyr.Points = 0;  //  start from scratch

            #region  Punt Returns

            //  1 pt for a Punt return
            plyr.Points += PointsFor( plyr, 1, RosterLib.Constants.K_SCORE_PUNT_RETURN );
            //RosterLib.Utility.Announce( string.Format( "  {0} has {1} points for {2} in {3}:{4:0#}",
            //   plyr.PlayerName, plyr.Points, RosterLib.Constants.K_SCORE_PUNT_RETURN, week.Season, week.WeekNo ) );

            #endregion

            #region  Kick Off Returns

            //  1 pts for a Kick-off return
            plyr.Points += PointsFor( plyr, 1, RosterLib.Constants.K_SCORE_KICK_RETURN );
            //RosterLib.Utility.Announce( string.Format( "  {0} has {1} points for {2} in {3}:{4:0#}",
            //   plyr.PlayerName, plyr.Points, RosterLib.Constants.K_SCORE_KICK_RETURN, week.Season, week.WeekNo ) );

            #endregion

            RosterLib.Utility.Announce( string.Format( "    {0} has {1} returns in week {2}:{3}",
                plyr.PlayerName, plyr.Points, week.Season, week.Week ) );

            return plyr.Points;
        }
 public void TestPlayerTallyingRushingYards()
 {
     var sut = new NFLPlayer("KAEPCO01");
      sut.TallyStats("2014", 1);
      Console.WriteLine(sut.CurrentGameMetrics);
      Assert.IsTrue(sut.CurrentGameMetrics.YDr == 11);
 }
        public Int32 PredictTDr(NFLPlayer plyr, string season, int week)
        {
            //  Predict the number of FGs this player will kick
             int tDr = 0;
             //  starters only
             if (plyr.IsStarter() && (plyr.PlayerCat == RosterLib.Constants.K_RUNNINGBACK_CAT) && plyr.IsRusher() )
             {
            if (plyr.CurrTeam.Ratings.Equals("CCCCCC")) plyr.CurrTeam.SetRecord(season, skipPostseason:false);

            //  who are the opponents
            NflTeam opponent = plyr.CurrTeam.OpponentFor(season, week);
            if (opponent != null)
            {
               if (opponent.Ratings.Equals("CCCCCC")) opponent.SetRecord(season, skipPostseason: false);  // Incase not initialised
               //  not on a bye
               tDr = 1;
               int diff = ConvertRating(plyr.CurrTeam.RoRating()) - ConvertRating(opponent.RdRating());
               if (diff > 1) tDr += 1;
               if (diff > 3) tDr += 1;
               if (diff < -1) tDr -= 1;
            }

            //  What is the Game
            NFLGame game = plyr.CurrTeam.GameFor(season, week);
            if (game != null)
            {
               if (game.IsHome(plyr.CurrTeam.TeamCode)) tDr += 1;
               if (game.IsBadWeather()) tDr -= 1;
            }

             }
             return tDr;
        }
 public void TestEddieLacy()
 {
     var sut = new NFLPlayer("LACYED01");
      var outcome = sut.PlayerReport();
      Console.WriteLine( "Report generated to {0}", outcome );
      Assert.IsFalse( string.IsNullOrEmpty( outcome ) );
 }
 public void TestMattForte()
 {
     var sut = new NFLPlayer( "FORTMA01" );
      var outcome = sut.PlayerReport( true );
      Console.WriteLine( "Report generated to {0}", outcome );
      Assert.IsFalse( string.IsNullOrEmpty( outcome ) );
 }
 public void TestDoPerformanceJordanReedWeek06()
 {
     var p = new NFLPlayer("REEDJO02");
     var week06 = new NFLWeek("2015", 6);
     var _scorer = new YahooScorer(week06);
     var nScore = _scorer.RatePlayer( p, week06 );
     Assert.IsTrue( nScore == 0 );
 }
Esempio n. 10
0
        public decimal RatePlayer( NFLPlayer plyr, NFLWeek week )
        {
            Week = week;

            plyr.Points = StarsFor( plyr );

            return plyr.Points;
        }
Esempio n. 11
0
 public void TestGS4Scorer()
 {
     var player = new NFLPlayer("MANNPE01");
      var week = new NFLWeek("2014", 1);
      var sut = new GS4Scorer(week);
      var score = sut.RatePlayer(player, week);
      Assert.IsTrue(score.Equals(12.0M));
 }
 public void TestDoPerformanceDeAngeloWeek09()
 {
     var p = new NFLPlayer("WILLDE02");
     var week = new NFLWeek("2015", 9);
     var _scorer = new YahooScorer(week);
     var nScore = _scorer.RatePlayer(p, week);
     Assert.IsTrue(nScore > 0);
 }
Esempio n. 13
0
 public void TestScoresPerYear()
 {
     var sut = new NFLPlayer("MANNPE01");
      var s = sut.ScoresPerYear();
      var testStr = s.ToString();
      var decSpot = testStr.IndexOf('.');
      var numDecPoints = testStr.Length - decSpot - 1;
      Assert.IsTrue(numDecPoints.Equals(2));
 }
 public void TestPlayerTallying()
 {
     var sut = new NFLPlayer("KAEPCO01");
      sut.TallyScores("2014", 1);
      Console.WriteLine(sut.CurrentGameMetrics);
      Assert.IsTrue( sut.CurrentGameMetrics.TDp == 2);
      Assert.IsTrue(sut.CurrentGameMetrics.TDr == 0);
      Assert.IsTrue(sut.CurrentGameMetrics.TDc == 0);
 }
Esempio n. 15
0
 public PlayerCell(NFLPlayer playerIn, string slotIn, CellStyle style, string teamCode)
 {
     _mSlot = slotIn;
     _mStyle = style;
     _mPlayer = playerIn;
     _mTeamCode = teamCode;
     _mName = _mPlayer == null ? String.Empty : _mPlayer.PlayerName.Trim();
     _mBgColour = "MOCCASIN";
 }
        public Int32 PredictYDr(NFLPlayer plyr, string season, int week)
        {
            int YDr = 0;
             //  starters only
             if (plyr.IsStarter() && (plyr.PlayerCat == RosterLib.Constants.K_RUNNINGBACK_CAT) && plyr.IsRusher())
             {
            int gamesOppPlayed = 0;
            NflTeam opponent = plyr.CurrTeam.OpponentFor(season, week);
            if (opponent != null)  //  not on a bye
            {
               //  Workout Team YDr average
               int teamTotYDr = 0;
               int gamesPlayed = 0;
               plyr.CurrTeam.LoadGames(plyr.CurrTeam.TeamCode, season);
               foreach (NFLGame g in plyr.CurrTeam.GameList)
               {
                  if (g.Played())
                  {
                     g.TallyMetrics("Y");
                     teamTotYDr += g.IsHome(plyr.CurrTeam.TeamCode) ? g.HomeYDr : g.AwayYDr;
                     gamesPlayed++;
                  }
               }

               //  work out the average that the oppenent gives up
               int teamTotYDrAllowed = 0;

               opponent.LoadGames(opponent.TeamCode, season);
               foreach (NFLGame g in opponent.GameList)
               {
                  if (g.Played())
                  {
                     g.TallyMetrics("Y");
                     teamTotYDrAllowed += g.IsHome(plyr.CurrTeam.TeamCode) ? g.AwayYDr : g.HomeYDr;  //  switch it around
                     gamesOppPlayed++;
                  }
               }

               Decimal predictedYDr;
               if ((gamesPlayed > 0) && (gamesOppPlayed > 0))
               {
                  //  Average the averages

                  predictedYDr = ((teamTotYDr / gamesPlayed) +
                                           (teamTotYDrAllowed / gamesOppPlayed)) / 2;
               }
               else
                  predictedYDr = 0.0M;

               //  find out how many carries the starter usually has
               //  YDr is the proportion of the whole
               YDr = Convert.ToInt32(predictedYDr * .8M);
            }
             }
             return YDr;
        }
 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 );
 }
Esempio n. 19
0
        public void TestPmetricsGet()
        {
            var player = new NFLPlayer("MANNPE01");
             var week = new NFLWeek("2014", 1);
             var gameCode = week.GameCodeFor("DB");
             var dao = new DbfPlayerGameMetricsDao();
             var pgm = dao.GetPlayerWeek(gameCode, player.PlayerCode);

             Assert.IsTrue(pgm.ProjYDp.Equals(300));
        }
 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 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 );
 }
Esempio n. 22
0
 public void TestYahooScorerOnAPlayer()
 {
     var w = new NFLWeek( 2014, 8 );
      var scorer = new YahooScorer( w );
      var plyr = new NFLPlayer( "LACYED01" );
      var score = scorer.RatePlayer( plyr, w );
      Assert.IsTrue( score == 17.0M );
      var gameKey = w.GameCodeFor( plyr.TeamCode );
      var msg = plyr.MetricsOut(gameKey);
      Console.WriteLine( msg );
 }
Esempio n. 23
0
 private decimal CalculateStats( NFLPlayer plyr, int w, string statType )
 {
     decimal nStats = 0.0M;
     DataSet ds = plyr.LastStats( statType, w, w, Season);
     if (ds != null)
     {
         foreach (DataRow dr in ds.Tables[0].Rows)
             nStats += Decimal.Parse(dr["QTY"].ToString());
     }
     return nStats;
 }
 public void TestPlayerTallyingFieldGoals()
 {
     var sut = new NFLPlayer("BAILDA01");
      sut.TallyScores("2014", 1);
      Console.WriteLine(sut.CurrentGameMetrics);
      Assert.IsTrue(sut.CurrentGameMetrics.TDp == 0);
      Assert.IsTrue(sut.CurrentGameMetrics.TDr == 0);
      Assert.IsTrue(sut.CurrentGameMetrics.TDc == 0);
      Assert.IsTrue(sut.CurrentGameMetrics.FG == 1);
      Assert.IsTrue(sut.CurrentGameMetrics.Pat == 2);
 }
Esempio n. 25
0
 public void TestRatePlayerProjection()
 {
     var p = new NFLPlayer( "TAYLTY01" );
      var sut = new DbfPlayerGameMetricsDao();
      var pgms = sut.GetSeason("2016", "TAYLTY01");
      var totalPoints = 0.0M;
      foreach ( var pgm in pgms )
      {
     pgm.CalculateProjectedFantasyPoints( p );
     totalPoints += p.Points;
      }
      Assert.IsTrue(p.Points < 400M);
 }
Esempio n. 26
0
        public YahooProjectedPointsMessage Calculate( NFLPlayer p, NFLGame g )
        {
            if ( yahooPipeline == null ) InitialiseThePipeLine();

             var msg = new YahooProjectedPointsMessage { Player = p };
              if (g.IsBye()) return msg;

              msg.Player.Points = 0.0M;
              msg.Game = g;

              if (yahooPipeline != null) yahooPipeline.Execute( msg );
              return msg;
        }
Esempio n. 27
0
        private bool IsEligible(
            NFLPlayer p,
            IEnumerable <string> slotTypes)
        {
            var isEligible = false;

            if (!IsAvailable(p))
            {
                return(false);
            }

            if (p.PlayerRole.Equals(Constants.K_ROLE_BACKUP) ||
                p.PlayerRole.Equals(Constants.K_ROLE_STARTER))
            {
                foreach (var slottype in slotTypes)
                {
                    if (slottype.Equals("2"))
                    {
                        if (p.PlayerCat.Equals("2") &&
                            (p.PlayerPos.Contains("RB") || p.PlayerPos.Contains("HB")))
                        {
                            isEligible = true;
                            break;
                        }
                        break;
                    }
                    if (slottype.Equals("T"))
                    {
                        if (p.PlayerCat.Equals("3") && p.PlayerPos.Contains("TE"))
                        {
                            isEligible = true;
                            break;
                        }
                    }
                    if (slottype.Equals("W"))
                    {
                        if (p.PlayerCat.Equals("3") && p.PlayerPos.Contains("WR"))
                        {
                            isEligible = true;
                            break;
                        }
                    }
                    if (p.PlayerCat.Equals(slottype))
                    {
                        isEligible = true;
                        break;
                    }
                }
            }
            return(isEligible);
        }
Esempio n. 28
0
        public void Load()
        {
            _ft = new FrequencyTable( string.Format("{2} output week {0} to {1}",
                wRange.startWeek.WeekKey("-"), wRange.endWeek.WeekKey("-"), PlayerType ) );

            if (string.IsNullOrEmpty(SinglePlayer))
            {
                //  get players who appeared in this range
                var ds = Utility.TflWs.GetPlayersScoring(
                    ScoreType, wRange.startWeek.Season, wRange.endWeek.Season, ScoreSlot);
                var dt = ds.Tables["score"];
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        var player = new NFLPlayer(dr[string.Format("PLAYERID{0}", ScoreSlot)].ToString());
                        if (player.IsStarter())
                        {
                            playerList.Add(player);
                            Utility.Announce(string.Format("  Adding {0,-15} to the list of {1}",
                                player.PlayerNameShort, PlayerType));
                        }
                    }
                }
            }
            else
            {
                //  single player
                var player = new NFLPlayer( SinglePlayer );
                playerList.Add( player );
                Utility.Announce(string.Format("  Adding {0,-15} to the list of {1}",
                        player.PlayerNameShort, PlayerType));
            }
            Utility.Announce(string.Format("    Examining {0:#0} players", playerList.Count));

            //  do the counting, so get all the performances for
            foreach (NFLPlayer p in playerList)
            {
                var week = wRange.startWeek;
                while ( wRange.endWeek.IsBefore( week ) )
                {
                    var amount = Scorer.RatePlayer( p, week );
                    _ft.Add( amount );
                    Utility.Announce( string.Format( "  {0,-15} got {1,2} in {2}",
                        p.PlayerNameShort, amount, week.WeekKey() ) );
                    week = week.NextWeek( week );
                }
            }
            _ft.Calculate();
        }
Esempio n. 29
0
        public void Load()
        {
            _ft = new FrequencyTable(string.Format("{2} output week {0} to {1}",
                                                   wRange.startWeek.WeekKey("-"), wRange.endWeek.WeekKey("-"), PlayerType));

            if (string.IsNullOrEmpty(SinglePlayer))
            {
                //  get players who appeared in this range
                var ds = Utility.TflWs.GetPlayersScoring(
                    ScoreType, wRange.startWeek.Season, wRange.endWeek.Season, ScoreSlot);
                var dt = ds.Tables["score"];
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        var player = new NFLPlayer(dr[string.Format("PLAYERID{0}", ScoreSlot)].ToString());
                        if (player.IsStarter())
                        {
                            playerList.Add(player);
                            Utility.Announce(string.Format("  Adding {0,-15} to the list of {1}",
                                                           player.PlayerNameShort, PlayerType));
                        }
                    }
                }
            }
            else
            {
                //  single player
                var player = new NFLPlayer(SinglePlayer);
                playerList.Add(player);
                Utility.Announce(string.Format("  Adding {0,-15} to the list of {1}",
                                               player.PlayerNameShort, PlayerType));
            }
            Utility.Announce(string.Format("    Examining {0:#0} players", playerList.Count));

            //  do the counting, so get all the performances for
            foreach (NFLPlayer p in playerList)
            {
                var week = wRange.startWeek;
                while (wRange.endWeek.IsBefore(week))
                {
                    var amount = Scorer.RatePlayer(p, week);
                    _ft.Add(amount);
                    Utility.Announce(string.Format("  {0,-15} got {1,2} in {2}",
                                                   p.PlayerNameShort, amount, week.WeekKey()));
                    week = week.NextWeek(week);
                }
            }
            _ft.Calculate();
        }
 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");
 }
Esempio n. 31
0
        private void VarianceLine(
            StringBuilder sb,
            NFLPlayer player,
            List <PlayerGameMetrics> season)
        {
            sb.Append(new String(' ', 19));
//			sb.Append(VarianceFor(season, player));
            sb.Append(new String(' ', 11));
            for (int w = 1; w <= Int32.Parse(Week); w++)
            {
                sb.Append(VarianceFor(w, season, player));
            }
            sb.AppendLine();
        }
Esempio n. 32
0
        private static string GetTeamCode(NFLPlayer player)
        {
            var teamCode = player.TeamCode;

            if (player.IsNewbie())
            {
                teamCode += "*";
            }
            else
            {
                teamCode += " ";
            }
            return(teamCode);
        }
Esempio n. 33
0
        private decimal TotalPredictonFor(
            List <PlayerGameMetrics> season,
            NFLPlayer player)
        {
            var predictedPts = 0.0M;

            foreach (var pgm in season)
            {
                predictedPts += PredictPlayer(
                    player,
                    pgm);
            }
            return(predictedPts);
        }
Esempio n. 34
0
        private static string PlayerOut(NFLPlayer p)
        {
            string name;

            name = p == null ? "" : p.PlayerName;
            if (string.IsNullOrEmpty(name))
            {
                return("<unknown>");
            }
            else
            {
                return(name);
            }
        }
Esempio n. 35
0
 private static int CompareTeamsByCarries(
     NFLPlayer x,
     NFLPlayer y)
 {
     if (x == null)
     {
         if (y == null)
         {
             return(0);
         }
         return(-1);
     }
     return(y == null ? 1 : y.TotStats.Rushes.CompareTo(x.TotStats.Rushes));
 }
Esempio n. 36
0
        private decimal CalculateStats(NFLPlayer plyr, int w, string statType)
        {
            decimal nStats = 0.0M;
            DataSet ds     = plyr.LastStats(statType, w, w, Season);

            if (ds != null)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    nStats += Decimal.Parse(dr["QTY"].ToString());
                }
            }
            return(nStats);
        }
Esempio n. 37
0
        private bool IsUsed(NFLPlayer p)
        {
            bool isUsed = false;

            foreach (NFLPlayer up in _usedPlayers)
            {
                if (p.PlayerCode.Equals(up.PlayerCode))
                {
                    isUsed = true;
                    break;
                }
            }
            return(isUsed);
        }
Esempio n. 38
0
        private static bool HasPos(string posDesc, NFLPlayer player, string desiredRole)
        {
            if (desiredRole == "I" || desiredRole == "X" || desiredRole == "H")
            {
                return(player.PlayerRole == desiredRole);
            }

            if (posDesc == "RB" || posDesc == "R2")
            {
                return(player.Contains("RB", player.PlayerPos) || player.Contains("HB", player.PlayerPos));
            }
            else if (posDesc == "SH")
            {
                return(player.Contains("SH", player.PlayerPos));
            }
            else if (posDesc == "RR")
            {
                return(player.Contains("RB", player.PlayerPos) || player.Contains("HB", player.PlayerPos));
            }
            else if (posDesc == "3D")
            {
                return(player.Contains("3D", player.PlayerPos));
            }
            else if (posDesc == "PR")
            {
                return(player.Contains("PR", player.PlayerPos));
            }
            else if (posDesc == "KR")
            {
                return(player.Contains("KR", player.PlayerPos));
            }
            else if (posDesc == "Q2")
            {
                return(player.Contains("QB", player.PlayerPos));
            }
            else if (posDesc == "T2")
            {
                return(player.Contains("TE", player.PlayerPos));
            }
            else if (posDesc == "WR")
            {
                return(player.Contains("WR", player.PlayerPos) || player.Contains("SE", player.PlayerPos) || player.Contains("FL", player.PlayerPos));
            }
            else if (posDesc == "PK")
            {
                return(player.Contains("PK", player.PlayerPos) || (player.Contains("K", player.PlayerPos) && player.PlayerCat == "4"));
            }
            return(player.Contains(posDesc, player.PlayerPos));
        }
Esempio n. 39
0
 public NFLOutputMetric(string metricIn, NFLPlayer playerIn, NflTeam teamIn)
 {
     _metricName  = metricIn;
     _player      = playerIn;
     _team        = teamIn;
     _team.Wins   = 0;
     _team.Losses = 0;
     _prevOpp     = new SeasonOpposition[KOpponents];
     _opps        = new SeasonOpposition[KOpponents];
     for (var i = 0; i < KOpponents; i++)
     {
         _opps[i]    = new SeasonOpposition("BYE", true, 0);
         _prevOpp[i] = new SeasonOpposition("   ", true, 0);
     }
 }
Esempio n. 40
0
        //  Units
        //  player + Pos + Start

        public NFLLineup(DataSet lineupDs, string teamCode, string season, string week)
        {
            PlayerList = new ArrayList();
            lineupDs   = Utility.TflWs.GetLineup(teamCode, season, Int32.Parse(week));
            DataTable dt = lineupDs.Tables["lineup"];

            foreach (DataRow dr in dt.Rows)
            {
                NFLPlayer  p         = Masters.Pm.GetPlayer(dr["PLAYERID"].ToString());
                string     pos       = dr["POS"].ToString();
                bool       isStarter = dr["START"].ToString().ToUpper().Equals("TRUE") ? true : false;
                LineupRole r         = new LineupRole(p, pos, isStarter);
                PlayerList.Add(p);
            }
        }
Esempio n. 41
0
 private void TallyActuals(
     ScoreCard scorecard,
     NFLPlayer player,
     List <PlayerGameMetrics> season)
 {
     foreach (var pgm in season)
     {
         scorecard.TotalPoints += pgm.CalculateActualFantasyPoints(
             player);
     }
     for (int w = 1; w < 17; w++)
     {
         scorecard.Week[w - 1] = Decimal.Parse(
             TotalFor(w, season, player));
     }
 }
 public static int AllowForInjuryRisk( NFLPlayer p, int proj )
 {
     if ( p == null )
     Utility.Announce("AllowForInjuryRisk:Null Player");
      else {
     int nInjury;
     Int32.TryParse( p.Injuries(), out nInjury );
     if ( nInjury > 0 )
     {
        var injChance = ( ( nInjury * 10.0M ) / 100.0M );
        var effectiveness = 1 - injChance;
        proj = (int) ( proj * effectiveness );
     }
      }
      return proj;
 }
Esempio n. 43
0
        private decimal PredictonFor(
            int week,
            List <PlayerGameMetrics> season,
            NFLPlayer player)
        {
            var predictedPts = 0.0M;

            foreach (var pgm in season)
            {
                if (pgm.Week().Equals($"{week:0#}"))
                {
                    predictedPts = PredictPlayer(player, pgm);
                }
            }
            return(predictedPts);
        }
Esempio n. 44
0
        public YahooProjectedPointsMessage Calculate(NFLPlayer p, NFLGame g)
        {
            if (yahooPipeline == null)
            {
                InitialiseThePipeLine();
            }

            var msg = new YahooProjectedPointsMessage();

            msg.Player        = p;
            msg.Player.Points = 0;
            msg.Game          = g;

            yahooPipeline.Execute(msg);
            return(msg);
        }
Esempio n. 45
0
        public List<string> Load(string teamCode)
        {
            TeamCode = teamCode;
            var ds = Utility.TflWs.GetTeamPlayers(teamCode, Constants.K_KICKER_CAT);
            var dt = ds.Tables["player"];
            if (dt.Rows.Count == 0) return DumpUnit();
            foreach (DataRow dr in dt.Rows)
            {
                var newPlayer = new NFLPlayer(dr["PLAYERID"].ToString());
                Add(newPlayer);
                if (newPlayer.IsStarter())
                    PlaceKicker = newPlayer;
            }

            return DumpUnit();
        }
Esempio n. 46
0
        public PlayerLister(string catCode,
                            bool faOnly,
                            [Optional] string fantasyLeague,
                            [Optional] bool startersOnly
                            )
        {
            PrimariesOnly  = true;
            ActivesOnly    = true;
            FreeAgentsOnly = false;
            StartersOnly   = startersOnly;
            PlayerList     = new ArrayList();
            var ds = Utility.TflWs.GetPlayers(catCode);
            var dt = ds.Tables[0];

            foreach (DataRow dr in dt.Rows)
            {
                var p    = new NFLPlayer(dr, fantasyLeague);
                var bAdd = !(faOnly) || p.IsFreeAgent();
                if (ActivesOnly)
                {
                    bAdd = (bAdd) && p.IsActive();
                }
                if (StartersOnly)
                {
                    bAdd = (bAdd) && p.IsStarter();
                }
                if (PlayoffsOnly)
                {
                    bAdd = (bAdd) && p.IsPlayoffBound();
                }
                if (PrimariesOnly)
                {
                    bAdd = (bAdd) && !p.IsItalic();                      //  dont want FB, TE or punters
                }
                if (OnesAndTwosOnly)
                {
                    bAdd = (bAdd) && p.IsOneOrTwo();
                }

                if (bAdd)
                {
                    PlayerList.Add(p);
                }
            }
            WeeksToGoBack = Constants.K_WEEKS_IN_A_SEASON;             //  default
        }
Esempio n. 47
0
        public string GetPlayerWikiBit(
            NFLPlayer player,
            IWinOrLose team,
            YahooCalculator calculator,
            bool bLinks = true)
        {
            var bit = NoneBit(team, bLinks);

            if (player != null)
            {
                bit = PlayerWikiPiece(
                    player: player,
                    game: team.Game,
                    calculator: calculator);
            }
            return(string.Format("{0,-28}", bit));
        }
Esempio n. 48
0
        private string TotalFor(
            int week,
            List <PlayerGameMetrics> season,
            NFLPlayer player)
        {
            var Pts = 0.0M;

            foreach (var pgm in season)
            {
                if (pgm.Week().Equals($"{week:0#}"))
                {
                    Pts = pgm.CalculateActualFantasyPoints(
                        player);
                }
            }
            return($"{Pts,9:0.0}");
        }
Esempio n. 49
0
        private string DomeBit(NFLGame g, NFLPlayer p)
        {
            var bit = " ";

            if (p.IsKicker())
            {
                if (g.IsDomeGame())
                {
                    bit = "+";
                }
                else if (g.IsBadWeather())
                {
                    bit = "-";
                }
            }
            return(bit);
        }
Esempio n. 50
0
        public PlayerPos CreatePos(string categoryIn, NFLPlayer p)
        {
            PlayerPos pp;

            switch (categoryIn)
            {
            case RosterLib.Constants.K_QUARTERBACK_CAT:
                pp = new QuarterbackCategory();
                break;

            case RosterLib.Constants.K_RUNNINGBACK_CAT:
                pp = new RunningbackCategory();
                break;

            case RosterLib.Constants.K_RECEIVER_CAT:
                pp = new ReceiverCategory();
                break;

            case RosterLib.Constants.K_KICKER_CAT:
                pp = new KickerCategory();
                break;

            case RosterLib.Constants.K_LINEMAN_CAT:
                pp = new DefensiveLineCategory();
                break;

            case RosterLib.Constants.K_DEFENSIVEBACK_CAT:
                pp = new DefensiveBackCategory();
                break;

            case RosterLib.Constants.K_OFFENSIVELINE_CAT:
                pp = new OffensiveLineCategory();
                break;

            case RosterLib.Constants.K_DEFENSIVETEAM_CAT:
                pp = new DefensiveTeamCategory();
                break;

            default:
                RosterLib.Utility.Announce(string.Format("Unknown Category>{0} player - {1}", categoryIn, p.PlayerName));
                pp = new DefensiveLineCategory();
                break;
            }
            pp.Category = categoryIn;
            return(pp);
        }
Esempio n. 51
0
        public decimal CalculateActualFantasyPoints(NFLPlayer p)
        {
            var scorer = new YahooProjectionScorer();

            p.ProjectedTDp = TDp;
            p.ProjectedYDp = YDp;
            p.ProjectedYDr = YDr;
            p.ProjectedTDr = TDr;
            p.ProjectedYDc = YDc;
            p.ProjectedTDc = TDc;
            p.ProjectedFg  = FG;
            p.ProjectedPat = Pat;

            var pts = scorer.RatePlayer(p, new NFLWeek(Season(), 99, loadGames: false));

            return(pts);
        }
Esempio n. 52
0
        private static void AddGoallineScorer(DataRow dr, NflTeam t)
        {
            var scorer = dr["PLAYERID1"].ToString();
            var player = new NFLPlayer(scorer);

            scorer = player.PlayerNameShort;
            var htKey = dr["WEEK"].ToString();                //  data is stored 01

            if (t.MetricsHt.ContainsKey(htKey))
            {
                AppendScorer(t, scorer, htKey);
            }
            else
            {
                t.MetricsHt.Add(htKey, scorer);
            }
        }
Esempio n. 53
0
        private PlayerViewModel ConvertToViewModel(NFLPlayer player)
        {
            int    points               = 0;
            int    games                = 0;
            int    por                  = 0;
            int    wpor                 = 0;
            int    cpor                 = 0;
            double mean                 = 0;
            double standardDeviation    = 0;
            double variationCoefficient = 0;

            points = player.FanastyPoints();
            games  = player.GamesPlayed();

            if (games > 0)
            {
                int replacementScore = _replacementScores[player.Position];

                por  = (points / games) - replacementScore;
                wpor = (player.FanastyPointsInRecentGames(3) / 3) - replacementScore;

                mean = player.FanastyPointsPerGame().Mean();
                if (mean > 0)
                {
                    standardDeviation    = player.FanastyPointsPerGame().StandardDeviation();
                    variationCoefficient = standardDeviation / mean;


                    double multiplier = 1 - Math.Min(variationCoefficient, 1);

                    cpor = (RoundToInt(points * multiplier) / games) - replacementScore;
                }
            }

            PlayerViewModel vm = new PlayerViewModel(player);

            vm.PointsOverReplacement           = por;
            vm.WeightedPointsOverReplacement   = wpor;
            vm.ConsistentPointsOverReplacement = cpor;
            vm.FanastyPoints          = points;
            vm.TotalBonuses           = player.TotalBonuses();
            vm.Mean                   = RoundToInt(mean);
            vm.StandardDeviation      = RoundToInt(standardDeviation);
            vm.CoefficientOfVariation = RoundToInt(variationCoefficient * 100);
            return(vm);
        }
Esempio n. 54
0
        public bool EndContract(
            NFLPlayer p,
            DateTime when,
            bool isRetirement)
        {
            Logger.Trace($@"EndContract on {
				p.PlayerName
				} when: {
				when
				} retirement: {
				isRetirement
				}"                );
            try
            {
                if (p.TeamCode.Equals("??"))
                {
                    Logger.Info($"{p.PlayerName} already ended service");
                    return(false);
                }
                else
                {
                    if (isRetirement)
                    {
                        TflDataLibrarian.RetirePlayer(
                            when,
                            p.PlayerCode);
                        Logger.Info($"{p.PlayerName} retired");
                    }
                    else
                    {
                        TflDataLibrarian.CloseServitude(
                            when,
                            p.PlayerCode);
                        Logger.Info($"{p.PlayerName} contract with {p.TeamCode} ended");
                    }
                    TflDataLibrarian.SetCurrentTeam(p.PlayerCode, "??");
                }
            }
            catch (Exception ex)
            {
                Logger.Error($"Error in End Contract {ex.Message}");
                return(false);
            }
            return(true);
        }
        public static int AllowForInjuryRisk(NFLPlayer p, int proj)
        {
#if DEBUG
            if (p == null)
            {
                Utility.Announce("AllowForInjuryRisk:Null Player");
            }
#endif
            var nInjury = 0;
            Int32.TryParse(p.Injuries(), out nInjury);
            if (nInjury > 0)
            {
                decimal injChance     = ((nInjury * 10.0M) / 100.0M);
                decimal effectiveness = 1 - injChance;
                proj = (int)(proj * effectiveness);
            }
            return(proj);
        }
Esempio n. 56
0
 private void TallyPredictions(
     ScoreCard scorecard,
     NFLPlayer player,
     List <PlayerGameMetrics> season)
 {
     scorecard.TotalPoints = TotalPredictonFor(
         season,
         player);
     for (int w = 1; w < 17; w++)
     {
         scorecard.Week[w]
             = PredictonFor(w, season, player)
               * player.HealthRating()
               * player.AgeRating();
         TotalScoreCard.Week[w]     += scorecard.Week[w];
         TotalScoreCard.TotalPoints += scorecard.Week[w];
     }
 }
Esempio n. 57
0
        private string VarianceFor(
            List <PlayerGameMetrics> season,
            NFLPlayer player)
        {
            var predicted = 0.0M;
            var Pts       = 0.0M;

            foreach (var pgm in season)
            {
                predicted += pgm.CalculateProjectedFantasyPoints(
                    player);
                Pts += pgm.CalculateActualFantasyPoints(
                    player);
            }
            var variance = Pts - predicted;

            return($"{variance,11:+0.0}");
        }
Esempio n. 58
0
        private string PlusMatchup(NFLPlayer p, NflTeam nextOppTeam, NflTeam pTeam)
        {
            var matchUp   = "-";
            var oppRating = nextOppTeam.DefensiveRating(p.PlayerCat);
            var oppNumber = GetAsciiValue(oppRating);
            var plrRating = pTeam.OffensiveRating(p.PlayerCat);
            var plrNumber = GetAsciiValue(plrRating);

            if (plrNumber <= oppNumber)
            {
                matchUp = "+";
                if (oppNumber - plrNumber >= 3)
                {
                    matchUp = "*";                      //  big mismatch
                }
            }
            return(matchUp);
        }
Esempio n. 59
0
 public static int AllowForInjuryRisk(NFLPlayer p, int proj)
 {
     if (p == null)
     {
         Utility.Announce("AllowForInjuryRisk:Null Player");
     }
     else
     {
         Int32.TryParse(p.Injuries(), out int nInjury);
         if (nInjury > 0)
         {
             var injChance     = ((nInjury * 10.0M) / 100.0M);
             var effectiveness = 1 - injChance;
             proj = ( int )(proj * effectiveness);
         }
     }
     return(proj);
 }
Esempio n. 60
0
 private static void WriteEpList(XmlTextWriter writer, NFLPlayer p)
 {
     writer.WriteStartElement("ep-list");
     foreach (NflPerformance g in p.PerformanceList)
     {
         if (g.Game != null)
         {
             if (g.ExperiencePoints > 0.0M)
             {
                 writer.WriteStartElement("week");
                 WriteElement(writer, "weekcode", g.Game.WeekCodeOut());
                 WriteElement(writer, "ep", g.ExperiencePoints.ToString());
                 writer.WriteEndElement();
             }
         }
     }
     writer.WriteEndElement();
 }