private decimal TallyPts(
            List <NFLPlayer> playerList,
            NFLWeek week,
            string teamCode)
        {
            var pts          = 0.0M;
            var scorer       = new YahooXmlScorer(week);
            var breakDownKey = $"{teamCode}-{PositionAbbr}-{week.Week}";

            foreach (var p in playerList)
            {
                if (PositionDelegate(p))
                {
                    var plyrPts = scorer.RatePlayer(p, week);
                    if (plyrPts != 0)
                    {
                        PlayerBreakdowns.AddLine(
                            breakDownKey,
                            line: $"{p.PlayerName,-20} {plyrPts.ToString(),5}");
                    }
                    pts += plyrPts;
                }
            }
            PlayerBreakdowns.Dump(
                breakDownKey,
                $"{RootFolder}\\breakdowns\\{breakDownKey}.htm");
            return(pts);
        }
Beispiel #2
0
 private void AnnounceTotal(NFLPlayer plyr, NFLWeek week)
 {
     Utility.Announce(
         string.Format("{0,-20} has {1:00.0} total pts in week {2}:{3}",
                       plyr.PlayerName, plyr.Points, week.Season, week.Week));
     Announce("--------------------------------------------------");
 }
        public string RenderData(ArrayList unitList, string sHead, NFLWeek week)
        {
            //  Output the list
            var tu1 = (TeamUnit)unitList[0];
            var r   = new SimpleTableReport {
                ReportHeader = sHead, ReportFooter = "", DoRowNumbers = true
            };
            var ds = LoadData(unitList, week);

            r.AddColumn(new ReportColumn("Name", "TEAM", "{0,-15}"));
            r.AddColumn(new ReportColumn("Rating", "RATING", "{0,-1}"));
            r.AddColumn(new ReportColumn("Total", "tot", "{0,5}"));

            const int startAt = Constants.K_WEEKS_IN_A_SEASON;

            var currentWeek = new NFLWeek(Int32.Parse(Utility.CurrentSeason()), Int32.Parse(Utility.CurrentWeek()), false);

            for (var w = startAt; w > 0; w--)
            {
                var header    = string.Format("Week {0}", currentWeek.Week);
                var fieldName = string.Format(FieldFormat, currentWeek.WeekNo);

                r.AddColumn(new ReportColumn(header, fieldName, "{0,5}", tu1.BGPicker));
                currentWeek = currentWeek.PreviousWeek(currentWeek, true, false);
            }

            var dt = ds.Tables[0];

            dt.DefaultView.Sort = "tot " + tu1.SortDirection();
            r.LoadBody(dt);
            FileOut = string.Format("{0}Units\\{1}.htm", Utility.OutputDirectory(), sHead);
            r.RenderAsHtml(FileOut, true);
            return(FileOut);
        }
Beispiel #4
0
        public NFLWeek PreviousWeek(
            NFLWeek theWeek,
            bool loadgames,
            bool regularSeasonGamesOnly)
        {
            var previousWeekNo   = theWeek.WeekNo - 1;
            var previousSeasonNo = theWeek.SeasonNo;

            if (previousWeekNo < 1)
            {
                previousWeekNo = Constants.K_WEEKS_IN_A_SEASON;
                previousSeasonNo--;
            }
            if (regularSeasonGamesOnly)
            {
                while (previousWeekNo > Constants.K_WEEKS_IN_REGULAR_SEASON)
                {
                    previousWeekNo--;
                }
            }

            var previousWeek = new NFLWeek(previousSeasonNo, previousWeekNo, loadgames);

#if DEBUG
            //if ( regularSeasonGamesOnly )
            //   Utility.Announce( string.Format( "Previous Regular Week to {1} was {0}",
            //      previousWeek.WeekKey(":"), theWeek.WeekKey( ":" ) ) );
            //else
            //   Utility.Announce( string.Format( "Previous Week to {1} was {0}",
            //      previousWeek.WeekKey(":"), theWeek.WeekKey(":") ) );
#endif
            return(previousWeek);
        }
Beispiel #5
0
        private void PutWeek(NFLWeek w)
        {
            var weekKey = string.Format("{0}:{1:0#}", w.Season, w.WeekNo);

            TheHt.Add(weekKey, w);
            IsDirty = true;
        }
        public void Render(string catCode, string sPos, string leagueId, bool startersOnly )
        {
            var currentWeek = new NFLWeek( seasonIn:Int32.Parse( Season ), weekIn:17, loadGames:false );
            if ( currentWeek.WeekNo > 0 )
            {
                var gs = leagueId.Equals( Constants.K_LEAGUE_Yahoo )
                                  	? (IRatePlayers) new YahooScorer( currentWeek )
                                  	: new GS4Scorer( currentWeek ) {ScoresOnly = true};

                if ( Scorer.Master == null )
                    Scorer.Master = new YahooMaster( "Yahoo", "YahooOutput.xml" );

                PlayerLister.SetScorer( Scorer );
                PlayerLister.SetFormat( "weekly" );
                PlayerLister.AllWeeks = false; //  dont go back into last year anymore
                PlayerLister.StartersOnly = startersOnly;
            PlayerLister.Clear();
                PlayerLister.Collect( catCode, sPos, leagueId );

                var targetFile = string.Format( leagueId.Equals( Constants.K_LEAGUE_Yahoo )
                    ? "ESPN {1} Performance {0}" : "GS {1} Performance {0}", currentWeek.Season, sPos );

                var destinationFile = string.Format( "{3}{2}//Performance//{0}-{1:0#}.htm",
                    targetFile, WeekNo, Season, Utility.OutputDirectory() );

                FileOut = PlayerLister.Render( destinationFile );
            }
            else
                Utility.Announce( "Season has not started yet" );
        }
        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);
        }
        private void CheckScoresForWeek(int week)
        {
            NflWeek = new NFLWeek(Season, week);
            var scoreFactory = new ScoreFactory();

            var ds = Utility.TflWs.ScoresDs(Season, String.Format("{0:0#}", week));
            var dt = ds.Tables["score"];

            foreach (DataRow dr in dt.Rows)
            {
                ScoresChecked++;
                var score = scoreFactory.CreateScore(dr["SCORE"].ToString());
                if (score != null)
                {
                    score.Load(dr);
#if DEBUG
                    score.Dump();
#endif
                    if (score.IsValid())
                    {
                    }
                    else
                    {
                        Error(score);
                    }
                }
            }
        }
        private void CheckStatsForWeek(int week)
        {
            NflWeek = new NFLWeek(Season, week);
            var statFactory = new StatFactory();

            var ds = Utility.TflWs.PlayerStatsDs(Season, String.Format("{0:0#}", week));
            var dt = ds.Tables["stat"];

            foreach (DataRow dr in dt.Rows)
            {
                StatsChecked++;
                var stat = statFactory.CreateStat(dr["STAT"].ToString());
                if (stat != null)
                {
                    stat.Load(dr);
#if DEBUG
                    stat.Dump();
#endif
                    if (stat.IsValid())
                    {
                        if (!stat.IsReasonable())
                        {
                            Warn(string.Format("{0} {1} not valid", stat.Name, stat.Quantity), stat);
                        }
                    }
                    else
                    {
                        Error(stat);
                    }
                }
            }
        }
 public void TestCurrentWeekSeed()
 {
     var week = new NFLWeek("2015", "01");
      var sut = new GamebookGetter(new Downloader());
      var result = sut.Seed(week);
      Assert.AreEqual(result, "56503");
 }
        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 GameRatings(NFLWeek week, string fTeamOwner)
        {
            var when = string.Format("Week{0}-{1:0#}", week.Season, Int32.Parse(week.Week));

#if DEBUG
            Utility.Announce(string.Format("   GameRatings for {0} owner {1}", when, fTeamOwner));
#endif
            var str = new SimpleTableReport(string.Format("Game Ratings {1}: {0:0#}", when, Name))
            {
                ColumnHeadings = true, DoRowNumbers = true
            };
            str.AddColumn(new ReportColumn("Rating", "RATING", "{0}", typeof(Int32), true));
            str.AddColumn(new ReportColumn("Day", "DAY", "{0}", typeof(String)));
            str.AddColumn(new ReportColumn("Time", "HOUR", "{0}", typeof(String)));
            str.AddColumn(new ReportColumn("AT", "AT", "{0}", typeof(String)));
            str.AddColumn(new ReportColumn("HT", "HT", "{0}", typeof(String)));
            str.AddColumn(new ReportColumn("TV", "TV", "{0}", typeof(String)));
            str.AddColumn(new ReportColumn("Fav", "FAV", "{0}", typeof(String)));
            str.AddColumn(new ReportColumn("Spr", "SPREAD", "{0}", typeof(String)));
            str.AddColumn(new ReportColumn("myTip", "TIP", "{0}", typeof(String)));

            BuildRatingsTable(str, fTeamOwner, week);

            str.RenderAsHtml(string.Format("{0}Ratings{2}{1}.htm", Utility.OutputDirectory(), when, CompCode), true);
        }
Beispiel #13
0
        public void CheckScores()
        {
            if (string.IsNullOrEmpty(Season))
            {
                RosterLib.Utility.Announce("Please specify the Season and Week");
            }
            else
            {
                NflWeek = new NFLWeek(Season, Week);
                var scoreFactory = new ScoreFactory();

                var ds = Utility.TflWs.ScoresDs(Season, String.Format("{0:0#}", Week));
                var dt = ds.Tables["score"];
                foreach (DataRow dr in dt.Rows)
                {
                    ScoresChecked++;
                    var score = scoreFactory.CreateScore(dr["SCORE"].ToString());
                    if (score != null)
                    {
                        score.Load(dr);
#if DEBUG
                        //score.Dump();
#endif
                        if (score.IsValid())
                        {
                        }
                        else
                        {
                            Error(score);
                        }
                    }
                }
            }
            ReportResults(ScoresChecked, "Scores");
        }
        public string ProjectYahooPerformance( string catCode, int weekNo, 
			[System.Runtime.InteropServices.Optional] string sPos )
        {
            if ( String.IsNullOrEmpty( sPos ) || sPos.Equals( "PK" ) )
                sPos = "*";

            var nextWeek = new NFLWeek( Int32.Parse( Utility.CurrentSeason() ), weekNo, false );
            var gs = new StatProjector( nextWeek );

            Lister.SetScorer( gs );
            Lister.StartersOnly = true;
            Lister.SetFormat( "weekly" );
            Lister.Week = nextWeek.WeekNo;
            Lister.AllWeeks = false; //  just the regular saeason
            Lister.Season = nextWeek.Season;
            Lister.Collect( catCode, sPos, Constants.K_LEAGUE_Yahoo );

            if ( String.IsNullOrEmpty( sPos ) || sPos.Equals("*") ) sPos = "All";

            FileOut = String.Format( "{0}\\Yahoo\\{1}\\{1} Projection W{2:00}", Lister.Season, sPos, Lister.Week );
             var weekMaster = new WeekMaster();
            FileOut = Lister.RenderProjection( FileOut, weekMaster );
            FileOut = Lister.FileOut;
            return Lister.FileOut;
        }
        public string ProjectYahooPerformance(string catCode, int weekNo,
                                              [System.Runtime.InteropServices.Optional] string sPos)
        {
            if (String.IsNullOrEmpty(sPos) || sPos.Equals("PK"))
            {
                sPos = "*";
            }

            var nextWeek = new NFLWeek(Int32.Parse(Utility.CurrentSeason()), weekNo, false);
            var gs       = new StatProjector(nextWeek);

            Lister.SetScorer(gs);
            Lister.StartersOnly = true;
            Lister.SetFormat("weekly");
            Lister.Week     = nextWeek.WeekNo;
            Lister.AllWeeks = false;             //  just the regular saeason
            Lister.Season   = nextWeek.Season;
            Lister.Collect(catCode, sPos, Constants.K_LEAGUE_Yahoo);

            if (String.IsNullOrEmpty(sPos) || sPos.Equals("*"))
            {
                sPos = "All";
            }

            FileOut = String.Format("{0}\\Yahoo\\{1}\\{1} Projection W{2:00}", Lister.Season, sPos, Lister.Week);
            FileOut = Lister.RenderProjection(FileOut);
            FileOut = Lister.FileOut;
            return(Lister.FileOut);
        }
        public void RenderTeamToDefendAgainst(NFLWeek week)
        {
            //  Team to beat report showing a jucy opponent for a particular defence
            var offset = -4;

            if (week.WeekNo < 2)
            {
                //  do the whole of last season
#if DEBUG
                Utility.Announce("Looking back at the whole of last season");
#endif
                offset = -Constants.K_WEEKS_IN_REGULAR_SEASON;
            }
            else
            {
#if DEBUG
                Utility.Announce("Going back 4 games");
#endif
            }

            var ttb = new TeamLister
            {
                Heading    = string.Format("{0}\\defense\\Team To beat-{1:0#}", week.Season, week.WeekNo),
                SubHeading = string.Format("last {0} weeks", offset)
            };
            ICalculate ttbCalculator =
                new DefensiveScoringCalculator(new NFLWeek(week.SeasonNo, week.WeekNo), offset);
            FileOut = ttb.RenderTeamToBeat(ttbCalculator);
        }
        public void PredictWeek(NFLWeek week)
        {
            var suWins    = 0;
            var suLosses  = 0;
            var atsWins   = 0;
            var atsLosses = 0;
            var atsTies   = 0;

            foreach (NFLGame game in week.GameList())
            {
                var result = PredictGame(game, PredictionStorer, game.GameDate);

                Utility.Announce(result.LogResult());

                if (game.Played())
                {
                    suWins = AnnounceResult(game, result, suWins, ref suLosses, ref atsWins, ref atsTies, ref atsLosses);
                }
                Utility.Announce("------------------------------");
            }
            if (suWins + suLosses > 0)
            {
                AnnounceTotals(suWins, suLosses, atsWins, atsLosses, atsTies);
            }
        }
Beispiel #18
0
        public SuggestedLineup(string leagueId, string ownerCode, string teamCode, string season, int week)
        {
#if DEBUG
            Utility.Announce(string.Format("Suggesting a lineup for {0} in league {1} team {2} - {3}:{4}",
                                           ownerCode, leagueId, teamCode, season, week));
#endif
            LeagueId  = leagueId;
            League    = new FantasyLeague(leagueId);
            TeamCode  = teamCode;
            OwnerCode = ownerCode;
            Season    = season;
            Week      = week;
            NflWeek   = new NFLWeek(Season, Week.ToString());
            if (LeagueId.Equals(Constants.K_LEAGUE_Yahoo) || LeagueId.Equals(Constants.K_LEAGUE_PerfectChallenge))
            {
                Scorer = new EspnScorer(NflWeek);
            }
            else
            {
                Scorer = new GS4Scorer(NflWeek);
            }

            _usedPlayers      = new List <NFLPlayer>();
            RankMaster        = new Hashtable();
            IncludeFreeAgents = false;
        }
Beispiel #19
0
 public YahooScorer( NFLWeek week )
 {
     Name = "Yahoo Scorer";
      Week = week;
      PgmDao = new DbfPlayerGameMetricsDao();
      Logger = NLog.LogManager.GetCurrentClassLogger();
 }
        public string RenderData(ArrayList unitList, string sHead, NFLWeek week)
        {
            //  Output the list
            var tu1 = (TeamUnit) unitList[0];
            var r = new SimpleTableReport {ReportHeader = sHead, ReportFooter = "", DoRowNumbers = true};
            var ds = LoadData(unitList, week);
            r.AddColumn(new ReportColumn("Name", "TEAM", "{0,-15}"));
            r.AddColumn(new ReportColumn("Rating", "RATING", "{0,-1}"));
            r.AddColumn(new ReportColumn("Total", "tot", "{0,5}"));

            const int startAt = Constants.K_WEEKS_IN_A_SEASON;

            var currentWeek = new NFLWeek(Int32.Parse(Utility.CurrentSeason()), Int32.Parse(Utility.CurrentWeek()), false);

            for (var w = startAt; w > 0; w--)
            {
                var header = string.Format("Week {0}", currentWeek.Week);
                var fieldName = string.Format(FieldFormat, currentWeek.WeekNo);

                r.AddColumn(new ReportColumn(header, fieldName, "{0,5}", tu1.BGPicker));
                currentWeek = currentWeek.PreviousWeek(currentWeek, true, false );
            }

            var dt = ds.Tables[0];

            dt.DefaultView.Sort = "tot " + tu1.SortDirection();
            r.LoadBody(dt);
            FileOut = string.Format( "{0}Units\\{1}.htm", Utility.OutputDirectory(), sHead );
            r.RenderAsHtml( FileOut, true);
            return FileOut;
        }
        public DataSet LoadData(ArrayList unitList, NFLWeek startWeek)
        {
            //  set up data columns
            var ds   = new DataSet();
            var dt   = new DataTable();
            var cols = dt.Columns;

            cols.Add("Team", typeof(String));
            cols.Add("Rating", typeof(String));
            cols.Add("tot", typeof(Int32));

            var currentWeek = new NFLWeek(Int32.Parse(Utility.CurrentSeason()), Int32.Parse(Utility.CurrentWeek()),
                                          loadGames: true);

            //  Add a column for each week under review
            for (var w = Constants.K_WEEKS_IN_A_SEASON; w > 0; w--)
            {
                currentWeek = currentWeek.PreviousWeek(currentWeek, true, false);

                var fieldName = string.Format(FieldFormat, currentWeek.WeekNo);
                cols.Add(fieldName, typeof(Int32));
            }

            //  generate the data for each unit
            foreach (TeamUnit tu in unitList)
            {
                var nTot = 0.0M;
                var dr   = dt.NewRow();
                dr["Team"]   = tu.Team.NameOut();
                dr["Rating"] = tu.Rating();

                //  variable number of weeks
                var weekCounter = Constants.K_WEEKS_IN_A_SEASON;
                var scoreWeek   = startWeek;
                do
                {
                    decimal nScore = tu.GetStat(scoreWeek);
                    if (nScore > -1)
                    {
                        nTot += nScore;
                    }

                    dr[string.Format(FieldFormat, scoreWeek.WeekNo)] = nScore;

                    scoreWeek = scoreWeek.PreviousWeek(scoreWeek, true, false);

                    if (scoreWeek.Season != Utility.CurrentSeason())                     //  only shows current season
                    {
                        weekCounter = 0;
                    }

                    weekCounter--;
                } while (weekCounter > 0);

                dr["tot"] = nTot;
                dt.Rows.Add(dr);
            }
            ds.Tables.Add(dt);
            return(ds);
        }
Beispiel #22
0
        private void CheckGamesForWeek(int week)
        {
            NflWeek = new NFLWeek(
                Season,
                week,
                loadGames: true);

            foreach (var game in NflWeek.GamesList())
            {
                if (!game.Played())
                {
                    continue;
                }

                var ds = Utility.TflWs.GetGameStats(
                    gameCode: game.GameCode,
                    season: Season,
                    week: $"{week:0#}");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    GameError("No Stats");
                }
                GamesChecked++;
            }
            ReportResults(GamesChecked, "Games");
        }
 public void Calculate( string season, string week )
 {
     var theWeek = new NFLWeek( season, week );
     theWeek.LoadGameList();
     foreach ( var nflStat in theWeek.GameList().Cast<NFLGame>()
         .Select( game => game.GenerateGridStatsOutput() ).SelectMany( statList => statList ) )
         PutStat( nflStat );
 }
 public DefensiveScoringCalculator( NFLWeek startWeek, int offset )
 {
     StartWeek = startWeek;
     if (startWeek.WeekNo < 2 )
         StartWeek = startWeek.PreviousWeek(startWeek, loadgames: false, regularSeasonGamesOnly: true);
     Offset = offset;
     Team = new NflTeam("SF");
 }
 public void AllProjections(NFLWeek week)
 {
     ProjectYahooPerformance(Constants.K_QUARTERBACK_CAT, week.WeekNo, "QB");
     ProjectYahooPerformance(Constants.K_RECEIVER_CAT, week.WeekNo, "WR");
     ProjectYahooPerformance(Constants.K_RECEIVER_CAT, week.WeekNo, "TE");
     ProjectYahooPerformance(Constants.K_RUNNINGBACK_CAT, week.WeekNo, "RB");
     ProjectYahooPerformance(Constants.K_KICKER_CAT, week.WeekNo, "PK");
 }
Beispiel #26
0
        public decimal RatePlayer(NFLPlayer plyr, NFLWeek week)
        {
            Week = week;

            plyr.Points = StarsFor(plyr);

            return(plyr.Points);
        }
Beispiel #27
0
        public decimal RatePlayer( NFLPlayer plyr, NFLWeek week )
        {
            Week = week;

            plyr.Points = StarsFor( plyr );

            return plyr.Points;
        }
 public void TestOutputDirectory()
 {
     var week = new NFLWeek("2015", "03");
      var sut = new GamebookGetter(new Downloader("g:\\tfl\\nfl\\gamebooks\\week 03\\"));
      var result = sut.Downloader.OutputFolder;
      Assert.AreEqual(result, "g:\\tfl\\nfl\\gamebooks\\week 03\\" );
      Assert.IsTrue(System.IO.Directory.Exists(result));
 }
 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 );
 }
 public void TestDefensiveScoringReport()
 {
     //  Lists the best Fantasy defence in the last season
      var week = new NFLWeek( "2015", "01" );
      var ds = new DefensiveScorer();
      ds.RenderDefensiveScoringReport( week );
      Assert.IsTrue( File.Exists( ds.FileOut ), string.Format( "Cannot find {0}", ds.FileOut ) );
 }
 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);
 }
 public void AllProjections( NFLWeek week )
 {
     ProjectYahooPerformance( Constants.K_QUARTERBACK_CAT, week.WeekNo, "QB" );
     ProjectYahooPerformance( Constants.K_RECEIVER_CAT, week.WeekNo, "WR" );
     ProjectYahooPerformance( Constants.K_RECEIVER_CAT, week.WeekNo, "TE" );
     ProjectYahooPerformance( Constants.K_RUNNINGBACK_CAT, week.WeekNo, "RB" );
     ProjectYahooPerformance( Constants.K_KICKER_CAT, week.WeekNo, "PK" );
 }
 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 string RenderData(ArrayList playerList, string sHead, NFLWeek week)
        {
            //  Output the list
            var r = new SimpleTableReport {
                ReportHeader = sHead, ReportFooter = "", DoRowNumbers = true
            };

            var ds = LoadData(playerList, week);

            r.AddColumn(new ReportColumn("Name", "NAME", "{0,-15}"));
            r.AddColumn(new ReportColumn("Team", "CURRTEAM", "{0,2}"));
            r.AddColumn(new ReportColumn("Role", "ROLE", "{0,1}"));
            r.AddColumn(new ReportColumn("Owner", "FT", "{0,2}"));
            r.AddColumn(new ReportColumn("Total", "tot", "{0,5}"));

            var startAt = FullStart ? Constants.K_WEEKS_IN_A_SEASON : Constants.K_WEEKS_IN_REGULAR_SEASON;

//			var currentWeek = new NFLWeek( Int32.Parse( Utility.CurrentSeason()), Int32.Parse( Utility.CurrentWeek() ), false );

            for (var w = startAt; w > 0; w--)
            {
                var header    = string.Format("Week {0}", w);
                var fieldName = string.Format(FieldFormat, w);

                if (IsGridStatsQBReport(sHead))
                {
                    r.AddColumn(new ReportColumn(header, fieldName, "{0,5}", QbBgPicker));
                }
                if (IsYahooQbReport(sHead))
                {
                    r.AddColumn(new ReportColumn(header, fieldName, "{0,5}", EspnQbBgPicker));
                }
                if (IsYahooRbReport(sHead))
                {
                    r.AddColumn(new ReportColumn(header, fieldName, "{0,5}", EspnRbBgPicker));
                }
                if (IsYahooWrReport(sHead))
                {
                    r.AddColumn(new ReportColumn(header, fieldName, "{0,5}", EspnWrBgPicker));
                }
                if (IsYahooTeReport(sHead))
                {
                    r.AddColumn(new ReportColumn(header, fieldName, "{0,5}", EspnTeBgPicker));
                }
                if (IsYahooPkReport(sHead))
                {
                    r.AddColumn(new ReportColumn(header, fieldName, "{0,5}", EspnPkBgPicker));
                }
            }

            var dt = ds.Tables[0];

            dt.DefaultView.Sort = "tot DESC";
            r.LoadBody(dt);
            FileOut = sHead;
            r.RenderAsHtml(FileOut, true);
            return(FileOut);
        }
Beispiel #35
0
 public YahooScorer(NFLWeek week)
 {
     Name             = "Yahoo Scorer";
     Week             = week;
     PgmDao           = new DbfPlayerGameMetricsDao();    //   should be injected
     YahooStatService = new YahooStatService();
     Logger           = LogManager.GetCurrentClassLogger();
     UseProjections   = true;
 }
Beispiel #36
0
 public void LoadRegularWeeks()
 {
     RegularWeeks = new List <NFLWeek>();
     for (var i = 1; i <= WeeksIntheRegularSeason; i++)
     {
         var week = new NFLWeek(Year, i);
         RegularWeeks.Add(week);
     }
 }
 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 );
 }
Beispiel #38
0
        public void Calculate( string season, string week )
        {
            var theWeek = new NFLWeek( season, week );
             if (!theWeek.HasPassed()) return;

            theWeek.LoadGameList();
            foreach ( var nflStat in theWeek.GameList().Cast<NFLGame>()
                .Select( game => game.GenerateStats() ).SelectMany( statList => statList ) )
                PutStat( nflStat );
        }
 public void TestPatriotsDefenseCalcs()
 {
     var week = new NFLWeek( 2010, 17 );
      ICalculate myCalculator = new DefensiveScoringCalculator( week, -1 );
      var team = new NflTeam( "NE" );
      team.CalculateDefensiveScoring( myCalculator, doOpponent: false );
      Assert.AreEqual( 17, myCalculator.Team.FantasyPoints );
      Assert.AreEqual( 1, myCalculator.Team.TotInterceptions );
      Assert.AreEqual( 5, myCalculator.Team.TotSacks );
 }
        public void TestGetGamebooksForCurrentWeek()
        {
            const string weekToDownload = "14";  //now put into Debug mode

             var week = new NFLWeek("2016", weekToDownload );
             var sut = new GamebookGetter( new Downloader(
            string.Format( "g:\\tfl\\nfl\\gamebooks\\week {0}\\", weekToDownload ) ) );
             var result = sut.DownloadWeek(week);
             Assert.IsTrue(result > 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));
        }
Beispiel #42
0
 public void Calculate( string season, string week )
 {
     var theWeek = new NFLWeek( season, week );
     theWeek.LoadGameList();
      Announce( string.Format("{0} Games loaded for {1}:{2}",
     theWeek._gameList.Count, season, week ) );
     foreach ( var nflStat in theWeek.GameList().Cast<NFLGame>()
         .Select( game => game.GenerateYahooOutput() ).SelectMany( statList => statList ) )
         PutStat( nflStat );
 }
 public DefensiveScoringCalculator(NFLWeek startWeek, int offset)
 {
     StartWeek = startWeek;
     if (startWeek.WeekNo < 2)
     {
         StartWeek = startWeek.PreviousWeek(startWeek, false, true);
     }
     Offset = offset;
     Team   = new NflTeam("SF");
 }
 public DefensiveScoringCalculator(NFLWeek startWeek, int offset)
 {
     StartWeek = startWeek;
     if (startWeek.WeekNo < 2)
     {
         StartWeek = startWeek.PreviousWeek(startWeek, loadgames: false, regularSeasonGamesOnly: true);
     }
     Offset = offset;
     Team   = new NflTeam("SF");
 }
        public DataSet LoadData(ArrayList unitList, NFLWeek startWeek)
        {
            //  set up data columns
            var ds = new DataSet();
            var dt = new DataTable();
            var cols = dt.Columns;
            cols.Add("Team", typeof (String));
            cols.Add("Rating", typeof (String));
            cols.Add("tot", typeof (Int32));

            var currentWeek = new NFLWeek(Int32.Parse(Utility.CurrentSeason()), Int32.Parse(Utility.CurrentWeek()),
                                              loadGames: true);

            //  Add a column for each week under review
            for (var w = Constants.K_WEEKS_IN_A_SEASON; w > 0; w--)
            {
                currentWeek = currentWeek.PreviousWeek(currentWeek, true, false);

                var fieldName = string.Format(FieldFormat, currentWeek.WeekNo);
                cols.Add(fieldName, typeof (Int32));
            }

            //  generate the data for each unit
            foreach (TeamUnit tu in unitList)
            {
                var nTot = 0.0M;
                var dr = dt.NewRow();
                dr["Team"] = tu.Team.NameOut();
                dr["Rating"] = tu.Rating();

                //  variable number of weeks
                var weekCounter = Constants.K_WEEKS_IN_A_SEASON;
                var scoreWeek = startWeek;
                do
                {
                    decimal nScore = tu.GetStat(scoreWeek);
                    if (nScore > -1)
                        nTot += nScore;

                    dr[string.Format(FieldFormat, scoreWeek.WeekNo)] = nScore;

                    scoreWeek = scoreWeek.PreviousWeek(scoreWeek, true, false);

                    if (scoreWeek.Season != Utility.CurrentSeason()) //  only shows current season
                        weekCounter = 0;

                    weekCounter--;
                } while (weekCounter > 0);

                dr["tot"] = nTot;
                dt.Rows.Add(dr);
            }
            ds.Tables.Add(dt);
            return ds;
        }
        public string Seed(NFLWeek week)
        {
            var gameSeed = "";

            foreach (NFLGame game in week.GameList())
            {
                gameSeed = game.Id;
                break;
            }
            return(gameSeed);
        }
        public void TestDownloadSinglePdf()
        {
            const string weekToDownload = "08";  //now put into Debug mode

             var week = new NFLWeek( "2016", weekToDownload );
             var sut = new Downloader(
            string.Format( "g:\\tfl\\nfl\\gamebooks\\week {0}\\", weekToDownload ) );
             var uri = new Uri("http://www.nfl.com/liveupdate/gamecenter/57010/ATL_Gamebook.pdf");
             var result = sut.Download( uri );
             Assert.IsTrue( result );
        }
 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 );
 }
 public void TestYahooScorerOnBeckham()
 {
     var w = new NFLWeek(2015, 9);
      var scorer = new YahooScorer(w);
      var plyr = new NFLPlayer("BECKOD01");
      var score = scorer.RatePlayer(plyr, w);
      Assert.IsTrue(score > 0.0M);
      var gameKey = w.GameCodeFor(plyr.TeamCode);
      var msg = plyr.MetricsOut(gameKey);
      Console.WriteLine(msg);
 }
Beispiel #50
0
        public void Calculate(string season, string week)
        {
            var theWeek = new NFLWeek(season, week);

            theWeek.LoadGameList();
            foreach (var nflStat in theWeek.GameList().Cast <NFLGame>()
                     .Select(game => game.GenerateYahooOutput()).SelectMany(statList => statList))
            {
                PutStat(nflStat);
            }
        }
Beispiel #51
0
        public NFLWeek NextWeek(NFLWeek theWeek, bool loadgames = false)
        {
            var nextWeekNo   = theWeek.WeekNo + 1;
            var nextSeasonNo = theWeek.SeasonNo;

            if (nextWeekNo > Constants.K_WEEKS_IN_A_SEASON)
            {
                nextWeekNo = 1;
                nextSeasonNo++;
            }
            return(new NFLWeek(nextSeasonNo, nextWeekNo, loadgames));
        }
Beispiel #52
0
        private void CalculateFpts(NflTeam team)
        {
            // Process Stats and Scores for the week
            // save the calculations
            var ds = Utility.TflWs.GameForTeam(Season, Week, team.TeamCode);

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

            DataRow teamRow = Data.NewRow();

            teamRow["TEAM"]  = team.NameOut();
            teamRow["TOTAL"] = 0;
            teamRow["SCORE"] = 0;
            var game = new NFLGame(ds.Tables[0].Rows[0]);

            teamRow["RESULT"] = game.ResultFor(team.TeamCode, abbreviate: true, barIt: false);
            teamRow["SCORE"]  = game.ScoreFor(team);

            List <NFLPlayer> playerList = new List <NFLPlayer>();

            if (game.IsAway(team.TeamCode))
            {
                playerList = game.LoadAllFantasyAwayPlayers();
            }
            else
            {
                playerList = game.LoadAllFantasyHomePlayers();
            }

            var totPts = 0.0M;
            var qbPts  = 0.0M;
            var rbPts  = 0.0M;
            var wrPts  = 0.0M;
            var tePts  = 0.0M;
            var pkPts  = 0.0M;
            var week   = new NFLWeek(Season, Week);

            TallyPts(playerList, ref totPts, ref qbPts, ref rbPts, ref wrPts, ref tePts, ref pkPts, week);

            teamRow["TOTAL"] = totPts;
            teamRow["QB"]    = qbPts;
            teamRow["RB"]    = rbPts;
            teamRow["WR"]    = wrPts;
            teamRow["TE"]    = tePts;
            teamRow["PK"]    = pkPts;
            teamRow["DEF"]   = game.DefensiveFantasyPtsFor(team.TeamCode);

            Data.Rows.Add(teamRow);
        }
Beispiel #53
0
        public NFLWeek PreviousWeek( NFLWeek theWeek  )
        {
            var previousWeekNo = theWeek.WeekNo - 1;
             var previousSeasonNo = theWeek.SeasonNo;
             if (previousWeekNo < 1)
             {
            previousWeekNo = Constants.K_WEEKS_IN_A_SEASON;
            previousSeasonNo--;
             }

             var previousWeek = GetWeek(previousSeasonNo.ToString(), previousWeekNo );

             return previousWeek;
        }
Beispiel #54
0
        public void Calculate(string season, string week)
        {
            if (week.Equals("01"))
            {
                SetupSeason(season);
                Dump2Xml();
                return;
            }

            var hp = new HillinPredictor();

            var theSeason = new NflSeason(season);

            foreach (var team in theSeason.TeamList)
            {
                //  get teams game for the week
                Utility.Announce(string.Format("  Doing {0}", team.TeamCode));
                var upcomingWeek   = new NFLWeek(season, week);
                var previousWeek   = upcomingWeek.PreviousWeek(upcomingWeek, loadgames: false, regularSeasonGamesOnly: true);
                var prevWeek       = string.Format("{0:0#}", previousWeek.WeekNo);
                var oldPowerRating = team.GetPowerRating(prevWeek);

                if (oldPowerRating == 0)
                {
                    return;
                }
                var newRating = new HillenPowerRating
                {
                    Season   = season,
                    TeamCode = team.TeamCode,
                    Week     = week,
                    Quantity = oldPowerRating
                };

                var game = Utility.GetGameFor(season, prevWeek, team.TeamCode);

                if (game.GameDate != new DateTime(1, 1, 1))
                {
                    var predictedResult        = hp.PredictGame(game, null, game.GameDate);
                    var predictedMarginForTeam = predictedResult.MarginForTeam(team.TeamCode);
                    //Utility.Announce( string.Format( "Predicted Margin for {0} is {1}", TeamCode, predictedMarginForTeam ) );
                    var actualMarginForTeam = game.Result.MarginForTeam(team.TeamCode);
                    //Utility.Announce( string.Format( "   Result of {2} means Actual Margin for {0} is {1}",
                    var newPowerRating = AdjustedPower(oldPowerRating, predictedMarginForTeam, actualMarginForTeam);
                    newRating.Quantity = newPowerRating;
                }
                PutRating(newRating);
            }
            Dump2Xml();
        }
Beispiel #55
0
        public void Calculate( string season, string week )
        {
            if ( week.Equals( "01" ) )
            {
                SetupSeason( season );
                Dump2Xml();
                return;
            }

            var hp = new HillinPredictor();

            var theSeason = new NflSeason( season );

            foreach ( var team in theSeason.TeamList )
            {
                //  get teams game for the week
                Utility.Announce( string.Format( "  Doing {0}", team.TeamCode ) );
                var upcomingWeek = new NFLWeek( season, week );
                var previousWeek = upcomingWeek.PreviousWeek( upcomingWeek, loadgames:false, regularSeasonGamesOnly:true );
                var prevWeek = string.Format( "{0:0#}", previousWeek.WeekNo );
                var oldPowerRating = team.GetPowerRating( prevWeek );

                if ( oldPowerRating == 0 )
                {
                    return;
                }
                var newRating = new HillenPowerRating
                {
                    Season = season,
                    TeamCode = team.TeamCode,
                    Week = week,
                    Quantity = oldPowerRating
                };

                var game = Utility.GetGameFor( season, prevWeek, team.TeamCode );

                if ( game.GameDate != new DateTime( 1, 1, 1 ) )
                {
                    var predictedResult = hp.PredictGame( game, null, game.GameDate );
                    var predictedMarginForTeam = predictedResult.MarginForTeam( team.TeamCode );
                    //Utility.Announce( string.Format( "Predicted Margin for {0} is {1}", TeamCode, predictedMarginForTeam ) );
                    var actualMarginForTeam = game.Result.MarginForTeam( team.TeamCode );
                    //Utility.Announce( string.Format( "   Result of {2} means Actual Margin for {0} is {1}",
                    var newPowerRating = AdjustedPower( oldPowerRating, predictedMarginForTeam, actualMarginForTeam );
                    newRating.Quantity = newPowerRating;
                }
                PutRating( newRating );
            }
            Dump2Xml();
        }
        public string Seed(NFLWeek week)
        {
            var gameSeed = "";

            foreach (NFLGame game in week.GameList())
            {
                gameSeed = game.Id;
                if (!string.IsNullOrEmpty(gameSeed))
                {
                    break;
                }
            }
            LogIt($"Game Seed: {gameSeed}");
            return(gameSeed);
        }
Beispiel #57
0
        public NFLWeek PreviousWeek(NFLWeek theWeek)
        {
            var previousWeekNo   = theWeek.WeekNo - 1;
            var previousSeasonNo = theWeek.SeasonNo;

            if (previousWeekNo < 1)
            {
                previousWeekNo = Constants.K_WEEKS_IN_A_SEASON;
                previousSeasonNo--;
            }

            var previousWeek = GetWeek(previousSeasonNo.ToString(), previousWeekNo);

            return(previousWeek);
        }
        public void TestAllPositionsCurrentWeekYahoo()
        {
            var sut = new PerformanceReportGenerator(new TimeKeeper(null) );
             var master = new YahooMaster( "Yahoo", "YahooOutput.xml" );
             var theSeason = Int32.Parse( Utility.CurrentSeason() );
             var weekIn = Utility.PreviousWeek();
             var theWeek =
            new NFLWeek( theSeason, weekIn: weekIn, loadGames: false );
             var gs = new EspnScorer( theWeek ) {Master = master, AnnounceIt = true};
             //var rpt = new PerformanceReportConfig {
             //   Category = Constants.K_QUARTERBACK_CAT, Position = "QB", Scorer = gs, Week = theWeek };

             foreach ( var rpt in sut.Configs )
             {
            sut.GenerateReport( rpt, Constants.K_LEAGUE_Yahoo );
             }
        }
        public SuggestedLineup()
        {
            Name = "Suggested Lineups";
             NflWeek = new NFLWeek(Utility.CurrentSeason(), Utility.CurrentWeek());

             Configs = new List<SuggestedLineupConfig>();
             //  Gs1 suggested for upcoming week
             //Configs.Add(new SuggestedLineupConfig
             //{
             //   Scorer = new GS4Scorer(NflWeek),
             //   Season = Utility.CurrentSeason(),
             //   Week = Int32.Parse(Utility.CurrentWeek()),
             //   League = Constants.K_LEAGUE_Gridstats_NFL1,
             //   OwnerCode = Constants.KOwnerSteveColonna,
             //   TeamCode = "CC",
             //   IncludeSpread = false,
             //   IncludeRatingModifier = false
             //});
             //  Yahoo
             Configs.Add(new SuggestedLineupConfig
             {
            Scorer = new YahooScorer( NflWeek ),
            Season = Utility.CurrentSeason(),
            Week = Int32.Parse( Utility.CurrentWeek() ),
            League = Constants.K_LEAGUE_Yahoo,
            OwnerCode = Constants.KOwnerSteveColonna,
            TeamCode = "77",
            IncludeSpread = true,
            IncludeRatingModifier = true,
            IncludeFreeAgents = true
             });
             // NFL.Com
             //Configs.Add(new SuggestedLineupConfig
             //{
             //   Scorer = new YahooScorer(NflWeek),
             //   Season = Utility.CurrentSeason(),
             //   Week = Int32.Parse(Utility.CurrentWeek()),
             //   League = Constants.K_LEAGUE_Rants_n_Raves,
             //   OwnerCode = Constants.KOwnerSteveColonna,
             //   TeamCode = "BZ",
             //   IncludeSpread = true,
             //   IncludeRatingModifier = true,
             //   IncludeFreeAgents = true
             //});
        }
Beispiel #60
0
        public NFLWeek GetWeek(string season, int week)
        {
            NFLWeek w;
             var weekKey = string.Format("{0}:{1:0#}", season, week);

             if (TheHt.ContainsKey(weekKey))
             {
            w = (NFLWeek)TheHt[weekKey];
            CacheHits++;
             }
             else
             {
            w = new NFLWeek( int.Parse(season), week, loadGames: true);
            PutWeek(w);
            CacheMisses++;
             }
             return w;
        }