Esempio n. 1
0
 public void TestPostSeason()
 {
     var sut = new TimeKeeper( new FakeClock( new DateTime( 2016, 01, 16, 12, 0, 0 ) ) );  // set clock to January
      Assert.IsFalse( sut.IsItPreseason() );
      Assert.IsFalse( sut.IsItRegularSeason() );
      Assert.IsTrue( sut.IsItPostSeason() );
 }
 public void TestHowStengthOfScheduleDterminesCurrentSeason()
 {
     var sut = new TimeKeeper(null);
      var result = sut.CurrentSeason( new DateTime( 2016, 7, 24 ) );
      Assert.AreEqual( "2016", result );
      Console.WriteLine( "Season>{0}", result );
 }
Esempio n. 3
0
 public void TestPreseasonLastSeason()
 {
     var sut = new TimeKeeper(new FakeClock(new DateTime(2014, 03, 16 )));  // set clock to March
      Assert.IsTrue(sut.IsItPreseason());
      Assert.IsFalse(sut.IsItRegularSeason());
      Assert.IsFalse(sut.IsItPostSeason());
 }
Esempio n. 4
0
 public Job()
 {
     MyHoldList = new HoldList();
     MyHoldList.LoadFromXml(".//xml//hold-jobs.xml");
      TimeKeeper = new TimeKeeper(null);
      Logger = NLog.LogManager.GetCurrentClassLogger();
 }
Esempio n. 5
0
        public void RankTeams(DateTime when)
        {
            if (ForceReRank)
            {
                Logger.Trace("  Ranking forced");
            }
            else
            {
                if (HaveAlreadyRated(when))
                {
                    Logger.Trace($"  Have already got Ratings for {when:d}");
                    LoadRatings(when);
                    return;
                }
                else
                {
                    Logger.Trace("  Generating ratings for {0:d}", when);
                }
            }
#if DEBUG
            var stopwatch = new Stopwatch();
            stopwatch.Start();
#endif
            //  what season are we in
            var season = TimeKeeper.CurrentSeason(when);
            //  Get the teams for that season
            var teamList = new List <NflTeam>();
            LoadTeams(teamList, season, when);

            var metricTable = LoadMetrix(teamList, when);
            Rank(metricTable, "YDr DESC", UnitRatings.UnitRating.Ro);
#if !DEBUG2
            Rank(metricTable, "YDp DESC", UnitRatings.UnitRating.Po);
            Rank(metricTable, "SAKa ASC", UnitRatings.UnitRating.Pp);
            Rank(metricTable, "SAK DESC", UnitRatings.UnitRating.Pr);
            Rank(metricTable, "YDra ASC", UnitRatings.UnitRating.Rd);
            Rank(metricTable, "IntRatio DESC", UnitRatings.UnitRating.Pd);
#endif
            LastDateRanked = when;
            DumpRatingsHt(when);
            UpdateMetricsWithRatings(metricTable);
            DumpMetricTable(metricTable, when);
            WriteRatings(metricTable, when);
            UpdateRatings(metricTable, season);
#if DEBUG
            Utility.StopTheWatch(stopwatch, string.Format("Ranking teams : {0:d}", when));
#endif
        }
        public override void RenderAsHtml()
        {
            NflSeason = new NflSeason(
                TimeKeeper.CurrentSeason(),
                loadGames: true,
                loadDivisions: false);
            foreach (var game in NflSeason.GameList)
            {
                game.WriteProjection();
#if DEBUG
                if (game.WeekNo > 1)
                {
                    break;
                }
#endif
            }
        }
Esempio n. 7
0
        private void WriteRatings(DataTable dt, DateTime when)
        {
            foreach (DataRow dr in dt.Rows)
            {
                var po       = dr["RYDp"].ToString();
                var ro       = dr["RYDr"].ToString();
                var pp       = dr["RSAKa"].ToString();
                var pr       = dr["RSAK"].ToString();
                var rd       = dr["RYDra"].ToString();
                var pd       = dr["RIntRatio"].ToString();
                var ratings  = string.Format("{0}{1}{2}{3}{4}{5}", po, ro, pp, pr, rd, pd);
                var teamCode = dr["TEAM"].ToString();

                var theSunday = TimeKeeper.GetSundayFor(when);
                Logger.Trace("  Saving URATINGS for Sunday {0:d}", theSunday);
                Utility.TflWs.SaveUnitRatings(ratings, theSunday, teamCode);
            }
        }
 public override void RenderAsHtml()
 {
     if (FullSeason)
     {
         YahooMaster.Calculate(TimeKeeper.Season);
         Logger.Info("  Generating Yahoo xml for full Season}");
     }
     else
     {
         Logger.Info(
             "  Generating Yahoo xml for Season {0} Week {1}",
             TimeKeeper.Season, TimeKeeper.Week);
         YahooMaster.Calculate(
             TimeKeeper.Season,
             TimeKeeper.PreviousWeek());
     }
     YahooMaster.Dump2Xml(Logger);
 }
        public override void RenderAsHtml()
        {
            LeagueInFocus = Constants.K_LEAGUE_Yahoo;
            if (TimeKeeper.CurrentWeek(DateTime.Now) > 16)
            {
                LeagueInFocus = Constants.K_LEAGUE_Gridstats_NFL1;
            }

            var totalPlayers = 0;
            var season       = new NflSeason(Season, teamsOnly: true);

            foreach (var team in season.TeamList)
            {
                TeamCode = team.TeamCode;
                Execute();
                totalPlayers += PlayerCount;
#if DEBUG2
                break;
#endif
            }
            DumpErrors();
            TraceIt($"   {TeamCode} Player Count : {totalPlayers}");
        }
Esempio n. 10
0
 public void TestWeekCutsOverOnMonday()
 {
     int lastWeek = 0;
      for ( int d = 0; d < 7; d++ )
      {
     var day = d + 1;
     var testDate = new DateTime( 2016, 12, day );
     var sut = new TimeKeeper( new FakeClock( testDate ) );
     Console.WriteLine( "{0,10:dddd} {0,10:d} {1} {2}", testDate, sut.Season, sut.Week );
     if ( testDate.ToString( "dddd" ).Equals( "Monday" ) )
        Assert.IsTrue( Int32.Parse( sut.Week ) > lastWeek );
     lastWeek = Int32.Parse(sut.Week);
      }
 }
Esempio n. 11
0
 public void TestTimekeeperKnowslastweek()
 {
     var sut = new TimeKeeper(new FakeClock(new DateTime(2015, 11, 17, 12, 0, 0)));
     Console.WriteLine( "This week is {0}:{1}", sut.CurrentSeason(), sut.CurrentWeek());
     Console.WriteLine("Last week is {0}:{1}", sut.CurrentSeason(), sut.PreviousWeek());
     Assert.IsTrue(sut.PreviousWeek().Equals("10"));
 }
Esempio n. 12
0
        private void LoadDataTable()
        {
#if DEBUG2
            var tCount = 0;
#endif
            var asOfWeek = int.Parse(Week);
            foreach (KeyValuePair <string, NflTeam> teamPair in TeamList)
            {
                var team = teamPair.Value;

                FptsAllowed fptsAllowed = new FptsAllowed(
                    team.TeamCode);
                FptsAllowed totalFptsAllowed = new FptsAllowed(
                    team.TeamCode);
                for (var w = TimeKeeper.CurrentWeek(
                         DateTime.Now) - 1; w > 0; w--)
                {
                    if (w > asOfWeek)
                    {
                        continue;
                    }
                    if (w < asOfWeek - 5)
                    {
                        continue;
                    }

                    string theWeek = $"{w:0#}";

                    var ds = Utility.TflWs.GameForTeam(
                        Season,
                        theWeek,
                        team.TeamCode);
                    if (ds.Tables[0].Rows.Count != 1)
                    {
                        continue;
                    }

                    fptsAllowed = CalculateFptsAllowed(
                        team,
                        theWeek,
                        ds);

                    totalFptsAllowed.Add(
                        fptsAllowed);
                    AccumulateFptsAllowed(
                        fptsAllowed);
                }

                DumpBreakdowns(
                    team.TeamCode);

#if DEBUG2
                tCount++;
                if (tCount > 0)
                {
                    break;
                }
#endif
            }

            RankTotalPoints();
            RankPointsToQbs();
            RankPointsToRbs();
            RankPointsToWrs();
            RankPointsToTes();
            RankPointsToPks();

            //  Build the output table
            foreach (FptsAllowed item in TotalFpAllowedList)
            {
                DataRow teamRow = Data.NewRow();
                teamRow["TEAM"] = item.TeamCode;
                teamRow["OPP"]  = Opponent(
                    item.TeamCode);
                teamRow["TOTAL"] = 0;
                teamRow["QB"]    = LinkFor(item.TeamCode, "QB", item.ToQbs, item.ToQbsRank);
                teamRow["RB"]    = LinkFor(item.TeamCode, "RB", item.ToRbs, item.ToRbsRank);
                teamRow["WR"]    = LinkFor(item.TeamCode, "WR", item.ToWrs, item.ToWrsRank);
                teamRow["TE"]    = LinkFor(item.TeamCode, "TE", item.ToTes, item.ToTesRank);
                teamRow["PK"]    = LinkFor(item.TeamCode, "PK", item.ToPks, item.ToPksRank);

                teamRow["TOTAL"] = item.TotPtsAllowed();
                Data.Rows.Add(teamRow);
            }
        }
Esempio n. 13
0
 public void TestPeakTimeWhen6to1()
 {
     var testDateTime = new DateTime( 2014, 09, 04, 13, 42, 0 );
      var sut = new TimeKeeper( null );
      Assert.IsTrue( sut.IsItPeakTime( testDateTime ) );
 }
Esempio n. 14
0
 public void TestPeakTime()
 {
     var testDateTime = new DateTime( 2014, 09, 04, 3, 42, 0 );
      var sut = new TimeKeeper(null);
      Assert.IsFalse( sut.IsItPeakTime( testDateTime ) );
 }
Esempio n. 15
0
 public void TestCurrentWeek()
 {
     var sut = new TimeKeeper( new FakeClock( new DateTime( 2015, 03, 16 ) ) );  // set clock to March
      Assert.AreEqual( sut.CurrentWeek(), 0 );
 }
Esempio n. 16
0
 public void TestCurrentSeasonPost()
 {
     var sut = new TimeKeeper( new FakeClock( new DateTime( 2016, 02, 15 ) ) );  // set clock to Feb-2016
      Assert.AreEqual( sut.CurrentSeason(), "2015" );
 }
Esempio n. 17
0
 public void TestCurrentSeason2016()
 {
     var sut = new TimeKeeper(new FakeClock(new DateTime(2016, 04, 25)));  // set clock to Apr-2016
      Assert.AreEqual(sut.CurrentSeason(), "2016");
 }