public void TallyTeam( ICollection <NflTeam> teamList, string season, DateTime focusDate, string teamCode) { var team = new NflTeam(teamCode); // simple code constructor //if ( teamCode == "IC") // Console.WriteLine("Test Team"); if (thisSeasonOnly) { team.LoadGames(team.TeamCode, season); } else { team.LoadPreviousRegularSeasonGames( team.TeamCode, season, focusDate); } team.TallyStats( breakdowns: null); teamList.Add(team); }
public string GetUnitRatingsFor( NflTeam team, DateTime when) { //if ( IsCurrent( team, when ) ) // return team.Ratings; if (CacheIsDirty(when)) { RankTeams(when); CacheHit = false; } else { CacheHit = true; } var ratings = RatingsFor(team.TeamCode); var strRatings = ratings.ToString(); if (TimeKeeper.IsItPreseason()) { strRatings = team.AdjustedRatings( strRatings); // we dont adjust if season has started - implement check } return(strRatings); }
private static void Injuries(ref string s, NflTeam offensiveTeam, NflTeam defensiveTeam, string offName, string defName) { if ((offensiveTeam == null) || (defensiveTeam == null)) { Utility.Announce("Injuries:one or more teams are null"); } else { s += "<br>\n"; // Table with one row which has 2 columns s += HtmlLib.TableOpen("BORDER='1' BORDERCOLOR='BLUE'"); s += HtmlLib.TableRowOpen(); s += HtmlLib.TableDataAttr("Injuries", "COLSPAN='2'"); s += HtmlLib.TableRowClose(); s += HtmlLib.TableRowOpen(); s += HtmlLib.TableDataAttr("Offence " + offName, "WIDTH='400'"); s += HtmlLib.TableDataAttr("Defence " + defName, "WIDTH='400'"); s += HtmlLib.TableRowClose(); s += HtmlLib.TableRowOpen(); s += HtmlLib.TableDataAttr(offensiveTeam.InjuredList(true), "VALIGN='TOP'"); s += HtmlLib.TableDataAttr(defensiveTeam.InjuredList(false), "VALIGN='TOP'"); s += HtmlLib.TableRowClose() + HtmlLib.TableClose() + "<br>\n"; } }
public NflTeam GetTeam(string season, string teamCode) { #if DEBUG //Utility.Announce( string.Format( "TeamMaster:Getting Team {0} for {1}", teamCode, season ) ); #endif NflTeam team; var key = season + teamCode; if (TheHt.ContainsKey(key)) { team = (NflTeam)TheHt[key]; team.SetRecord(season); CacheHits++; } else { // new it up #if DEBUG //Utility.Announce( string.Format( "TeamMaster:Instantiating Team {0} for {1}", teamCode, season ) ); #endif team = new NflTeam(teamCode, season); PutTeam(team); IsDirty = true; CacheMisses++; } return(team); }
private static void AddRow( DataTable dt, int stat, NflTeam t, string metricName) { var dr = dt.NewRow(); var p = t.GetCurrentStarter(PosInFocus(metricName)); var starterName = String.Empty; var gs11Owner = String.Empty; var gs2Owner = String.Empty; if (p != null) { starterName = p.PlayerName; gs11Owner = Utility.TflWs.GetStatus( p.PlayerCode, "GS", Utility.CurrentSeason()); gs2Owner = Utility.TflWs.GetStatus( p.PlayerCode, "G2", Utility.CurrentSeason()); } dr["TEAM"] = t.Name; dr["TOTAL"] = Normalised(stat, metricName); dr["STARTER"] = metricName.Equals("spread") ? "" : starterName; dr["GS"] = gs11Owner; dr["G2"] = gs2Owner; dt.Rows.Add(dr); }
public void Calculate(NflTeam team, NFLGame game) { Team = team; _game = game; var opponentCode = DetermineOpponent(); Team.FantasyPoints = 0; Team.DefensiveScores = 0; Team.TotInterceptions = 0; Team.TotSacks = 0; Team.PtsAgin = 0; CalculateDefensiveScores(); // will increment _team.FantasyPoints CountStats(); Team.FantasyPoints += (int)Team.TotSacks; Team.FantasyPoints += Team.TotInterceptions * 2; CountYardage(opponentCode); Team.PtsAgin = CountPointsAllowed(); var defFantasyPts = PointsForAllowing(Team.PtsAgin); Team.FantasyPoints += defFantasyPts; #if DEBUG Utility.Announce(string.Format(" Defense gave up {0} real points for {1} FP", Team.PtsAgin, defFantasyPts)); #endif Team.Games++; }
public void PutTeam(NflTeam team) { if (!TheHt.ContainsKey(Key(team))) { TheHt.Add(Key(team), team); } }
public void TestDepthChartExecution() { var teamCode = "MV"; var t = new NflTeam(teamCode); var sut = new DepthChartReport("2013", teamCode); sut.Execute(); var isError = false; if (sut.HasIntegrityError()) { isError = true; sut.DumpErrors(); Utility.Announce(string.Format(" Need to fix Depth Chart {0}", t.Name)); } t.LoadRushUnit(); if (t.RushUnit.HasIntegrityError()) { isError = true; t.RushUnit.DumpUnit(); Utility.Announce(string.Format(" Need to fix Rushing Unit {0}", t.Name)); } t.LoadPassUnit(); if (t.PassUnit.HasIntegrityError()) { isError = true; t.PassUnit.DumpUnit(); Utility.Announce(string.Format(" Need to fix Passing Unit {0}", t.Name)); } Assert.IsFalse(isError); }
public void RenderTeam(NflTeam team) { if (team.MetricsHt == null) { LoadTeam(team, team.TeamCode); } var metricsHt = team.MetricsHt; var str = new SimpleTableReport(string.Format("Metrics-{0}", team.TeamCode)); str.AddStyle("#container { text-align: left; background-color: #ccc; margin: 0 auto; border: 1px solid #545454; width: 761px; padding:10px; font: 13px/19px Trebuchet MS, Georgia, Times New Roman, serif; }"); str.AddStyle("#main { margin-left:1em; }"); str.AddStyle("#dtStamp { font-size:0.8em; }"); str.AddStyle(".end { clear: both; }"); str.AddStyle(".gponame { color:white; background:black }"); str.ColumnHeadings = true; str.DoRowNumbers = true; str.ShowElapsedTime = false; str.IsFooter = false; str.AddColumn(new ReportColumn("Week", "WeekSeed", "{0}", typeof(String), false)); str.AddColumn(new ReportColumn("OffTDp", "OffTDp", "{0}", typeof(Int32), true)); str.AddColumn(new ReportColumn("Mult", "AvgOffTDp", "{0:#.#}", typeof(Decimal), false)); str.AddColumn(new ReportColumn("OffTDr", "OFFTDR", "{0}", typeof(Int32), true)); str.AddColumn(new ReportColumn("Mult", "AvgOffTDr", "{0:#.#}", typeof(Decimal), false)); str.AddColumn(new ReportColumn("OffSAKa", "OFFSAKa", "{0}", typeof(Decimal), true)); str.AddColumn(new ReportColumn("Mult", "AvgOffSaka", "{0:#.#}", typeof(Decimal), false)); str.AddColumn(new ReportColumn("DefTDpa", "DefTDpa", "{0}", typeof(Int32), true)); str.AddColumn(new ReportColumn("Mult", "AvgDefTDp", "{0:#.#}", typeof(Decimal), false)); str.AddColumn(new ReportColumn("DefTDra", "DEFTDRa", "{0}", typeof(Int32), true)); str.AddColumn(new ReportColumn("Mult", "AvgDefTDr", "{0:#.#}", typeof(Decimal), false)); str.AddColumn(new ReportColumn("DefSAK", "DEFSAK", "{0}", typeof(Decimal), true)); str.AddColumn(new ReportColumn("Mult", "AvgDefSak", "{0:#.#}", typeof(Decimal), false)); BuildTable(str, metricsHt, team); str.SetSortOrder("WeekSeed"); str.RenderAsHtml(string.Format("{0}Metrics-{1}.htm", Utility.OutputDirectory(), team.TeamCode), true); }
private string GenerateBody() { var bodyOut = new StringBuilder(); NflTeam = new NflTeam(TeamCode); NflTeam.LoadTeam(); PlayerCount = NflTeam.PlayerList.Count; #if DEBUG Utility.Announce(string.Format(" {0} Roster Count : {1}", TeamCode, PlayerCount)); #endif bodyOut.AppendLine(NflTeam.RatingsOut()); bodyOut.AppendLine(); AppendPlayerLine(bodyOut, "QB"); AppendPlayerLine(bodyOut, "Q2"); AppendPlayerLine(bodyOut, "RB"); AppendPlayerLine(bodyOut, "R2"); AppendPlayerLine(bodyOut, "RR"); AppendPlayerLine(bodyOut, "3D"); AppendPlayerLine(bodyOut, "SH"); AppendPlayerLine(bodyOut, "FB"); AppendPlayerLine(bodyOut, "W1"); AppendPlayerLine(bodyOut, "W2"); AppendPlayerLine(bodyOut, "W3"); AppendPlayerLine(bodyOut, "TE"); AppendPlayerLine(bodyOut, "T2"); AppendPlayerLine(bodyOut, "PR"); AppendPlayerLine(bodyOut, "KR"); AppendPlayerLine(bodyOut, "PK"); AppendPlayerLine(bodyOut, "INJ"); AppendPlayerLine(bodyOut, "SUS"); AppendPlayerLine(bodyOut, "HO"); return(bodyOut.ToString()); }
public void TestDefensivePatsyNextOpponent() { var team = new NflTeam("JJ"); var opp = team.NextOpponent(new System.DateTime(2013, 9, 12)); Assert.AreEqual("@OR", opp); }
public void TallyTeam( ICollection <NflTeam> teamList, string season, DateTime focusDate, string teamCode) { var team = new NflTeam(teamCode); // simple code constructor if (TimeKeeper.IsItRegularSeason()) { team.LoadGames(team.TeamCode, season); GameScope = GameScopeFromGameList( team.GameList); } else { GameScope = $@"Regular season Games { Int32.Parse(season)-1 }" ; team.LoadPreviousRegularSeasonGames( team.TeamCode, season, focusDate); } team.TallyStats(Breakdowns); teamList.Add(team); var breakdownKey = $"{team.TeamCode}-Q"; var breakdownFile = $@"{Utility.OutputDirectory()}\\{ TimeKeeper.CurrentSeason() }\\Metrics\\breakdowns\\{breakdownKey}.htm" ; Breakdowns.Dump( breakdownKey, breakdownFile); }
private string PlusMatchup( NFLPlayer player, NflTeam nextOppTeam, NflTeam pTeam) { if (pTeam.TeamCode == string.Empty) { return(" "); } var matchUp = "-"; var oppRating = nextOppTeam.DefensiveRating( player.PlayerCat); var oppNumber = GetAsciiValue( oppRating); var plrRating = pTeam.OffensiveRating( player.PlayerCat); var plrNumber = GetAsciiValue( plrRating); if (plrNumber <= oppNumber) { matchUp = "+"; if (oppNumber - plrNumber >= 3) { matchUp = "*"; // big mismatch } } return(matchUp); }
private static NFLPlayer GetKicker(string teamCode) { var team = new NflTeam(teamCode); team.SetKicker(); return(team.Kicker); }
public EventReport(string teamCode, string statCode, DataLibrarian tflWS) { Team = new NflTeam(teamCode); Team.LoadGames(teamCode, Utility.LastSeason()); this.tflWS = tflWS; StatCode = statCode; }
// Does NextWeek equate to Current Week public bool IsCurrent(NflTeam team, DateTime when) { var nextGame = team.NextGame(when); var currentWeek = Utility.CurrentNFLWeek(); return(currentWeek.Season.Equals(nextGame.Season) && currentWeek.WeekNo.Equals(nextGame.WeekNo)); }
private static void BuildTable(SimpleTableReport str, Hashtable metricsHt, NflTeam team) { if (metricsHt != null) { var myEnumerator = metricsHt.GetEnumerator(); while (myEnumerator.MoveNext()) { var ep = (EpMetric)myEnumerator.Value; var dr = str.Body.NewRow(); dr["WEEKSEED"] = Utility.SeedOut(ep.WeekSeed); dr["OFFTDP"] = ep.OffTDp; dr["AVGOFFTDP"] = team.PoMultiplierAt(ep.WeekSeed); dr["OFFTDR"] = ep.OffTDr; dr["AVGOFFTDR"] = team.RoMultiplierAt(ep.WeekSeed); dr["OFFSAKA"] = ep.OffSakAllowed; dr["AVGOFFSAKA"] = team.PpMultiplierAt(ep.WeekSeed); dr["DEFTDPA"] = ep.DefTDp; dr["DEFTDRA"] = ep.DefTDr; dr["DEFSAK"] = ep.DefSak; dr["AVGDEFTDP"] = team.PdMultiplierAt(ep.WeekSeed); dr["AVGDEFTDR"] = team.RdMultiplierAt(ep.WeekSeed); dr["AVGDEFSAK"] = team.PrMultiplierAt(ep.WeekSeed); str.Body.Rows.Add(dr); } } return; }
/// <summary> /// Renders the object as a simple HTML report. /// </summary> public override void RenderAsHtml() { Name = "Strength of Schedule"; var ds = Utility.TflWs.TeamsDs(Season); var dt = ds.Tables["Team"]; _teamList = new ArrayList(); foreach (DataRow dr in dt.Rows) { var t = new NflTeam(dr["TEAMID"].ToString(), Season, Int32.Parse(dr["WINS"].ToString()), dr["TEAMNAME"].ToString()); t.StrengthOfSchedule(); _teamList.Add(t); } var str = new SimpleTableReport(Name) { ColumnHeadings = true, DoRowNumbers = true }; str.AddColumn(new ReportColumn("Team", KFieldTeam, "{0,-20}")); str.AddColumn(new ReportColumn("SoS", KFieldSos, "{0}")); str.AddColumn(new ReportColumn("Exp W", KFieldExpWins, "{0}")); str.AddColumn(new ReportColumn("Exp L", KFieldExpLosses, "{0}")); str.AddColumn(new ReportColumn("Prev W", KFieldWins, "{0}")); str.AddColumn(new ReportColumn("Prev L", KFieldLosses, "{0}")); str.AddColumn(new ReportColumn("Var", KFieldVariance, "{0}")); str.LoadBody(BuildTable()); str.RenderAsHtml(OutputFilename(), true); }
public int PredictSteals(NflTeam team, string season, int week) { // Predict the number of Interceptions the team will make int ints = 0; // who are the opponents NflTeam opponent = team.OpponentFor(season, week); if (opponent != null) { // not on a bye int pdInts = ConvertRating(team.PrRating()); int poInts = ConvertRating(opponent.PpRating()); ints += (pdInts - poInts) - 1; // will range from 3 to -5 } // What is the Game NFLGame game = team.GameFor(season, week); if (game != null) { if (game.IsHome(team.TeamCode)) { ints += 1; } } if (ints < 0) { ints = 0; } return(ints); }
public void ProjectNextWeek(NflTeam t) { SimpleDefencePredictor sp = new SimpleDefencePredictor(); t.ProjectedSacks = sp.PredictSacks(t, Utility.CurrentSeason(), Int32.Parse(Utility.CurrentWeek()) + 1); t.ProjectedSteals = sp.PredictSteals(t, Utility.CurrentSeason(), Int32.Parse(Utility.CurrentWeek()) + 1); }
/// <summary> /// Gets the team, if we have it already return it otherwise create it. /// </summary> /// <param name="teamCode">The team code.</param> /// <returns>NFLTeam</returns> public static NflTeam GetTeam(string teamCode) { // if we have it already return it otherwise create it var team = new NflTeam(teamCode); return(team); }
public Int32 PredictYDc(NFLPlayer plyr, string season, int week) { int YDc = 0; // starters only if (plyr.IsStarter() && (plyr.PlayerCat == RosterLib.Constants.K_RECEIVER_CAT)) { int gamesOppPlayed = 0; NflTeam opponent = plyr.CurrTeam.OpponentFor(season, week); if (opponent != null) // not on a bye { // Workout Team YDc average int teamTotYDc = 0; int gamesPlayed = 0; plyr.CurrTeam.LoadGames(plyr.CurrTeam.TeamCode, season); foreach (NFLGame g in plyr.CurrTeam.GameList) { if (g.Played()) { g.TallyMetrics("Y"); teamTotYDc += g.IsHome(plyr.CurrTeam.TeamCode) ? g.HomeYDp : g.AwayYDp; gamesPlayed++; } } // work out the average that the oppenent gives up int teamTotYDcAllowed = 0; opponent.LoadGames(opponent.TeamCode, season); foreach (NFLGame g in opponent.GameList) { if (g.Played()) { g.TallyMetrics("Y"); teamTotYDcAllowed += g.IsHome(plyr.CurrTeam.TeamCode) ? g.AwayYDr : g.HomeYDr; // switch it around gamesOppPlayed++; } } Decimal predictedYDc; if ((gamesPlayed > 0) && (gamesOppPlayed > 0)) { // Average the averages predictedYDc = ((teamTotYDc / gamesPlayed) + (teamTotYDcAllowed / gamesOppPlayed)) / 2; } else { predictedYDc = 0.0M; } // find out how many carries the starter usually has // YDr is the proportion of the whole YDc = plyr.IsTe() ? Convert.ToInt32(predictedYDc * .2M) : Convert.ToInt32(predictedYDc * .4M); } } return(YDc); }
private string ScenarioOut( string teamCode) { var team = new NflTeam(teamCode); var decSpread = Game.ExpMarginFor(team); return(Scenario(decSpread)); }
public void TestRushingUnitContainsGoallineBack() { var sut = new NflTeam("SF"); sut.LoadRushUnit(); Assert.IsNotNull(sut.RushUnit.GoalLineBack); Utility.Announce(string.Format("GoalLine Back is {0}", sut.RushUnit.GoalLineBack.PlayerName)); }
private string SpreadOut( string teamCode) { var team = new NflTeam(teamCode); var decSpread = Game.ExpMarginFor(team); var spread = String.Format("{0,5:##.#}", decSpread); return(spread); }
public void TestDepthChartRatingsOut() { var sut = new NflTeam("SF"); sut.Ratings = "CBEAAB"; var spreadRatings = sut.RatingsOut(); Assert.AreEqual("C B E - A A B : 39", spreadRatings); }
public void TestSpreadOutRatingsError() { var sut = new NflTeam("SF"); sut.Ratings = "ABC"; var spreadRatings = sut.SpreadoutRatings(); Assert.AreEqual("??????", spreadRatings); }
private static void AppendScorer( NflTeam t, string scorer, string htKey) { var oldScorer = t.MetricsHt[htKey]; t.MetricsHt[htKey] = oldScorer + "<br>" + scorer; }
public void TestPoRatings() { var sut = new NflTeam("SF"); sut.Ratings = "ABCDEF"; var rating = sut.PoRating(); Assert.AreEqual("A", rating); }
public void TestGetShortYardageBack() { var sut = new NflTeam("AF"); sut.LoadRushUnit(); var sh = sut.RushUnit.GetShortYardageBack("2013", "12", "AF"); Assert.AreEqual("JACKST02", sh); }
public int RateTeam(NflTeam team) { // Defensive team ratings team.ProjectNextWeek(); // Sacks are worth 3 points each int sackPoints = team.ProjectedSacks * 3; // Interceptions are worth 6 points each int intPoints = team.ProjectedSteals * 6; team.Points = sackPoints + intPoints; return team.Points; }
private string GenerateBody() { var bodyOut = new StringBuilder(); var ds = Utility.TflWs.GetTeams(Utility.CurrentSeason()); var dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) { var theKey = dr["TEAMID"].ToString(); var team = new NflTeam(theKey); var inPlayoffs = false; if (team.WinningRecord()) { bodyOut.AppendLine(string.Format("{0,-25} {1}", team.NameOut(), team.RecordOut())); inPlayoffs = true; } Utility.TflWs.UpdatePlayoff(team.Season, team.TeamCode, inPlayoffs); } return bodyOut.ToString(); }
private string PlayoffFlag( string teamCode ) { var flag = " "; var team = new NflTeam( teamCode ); if ( team.IsPlayoffBound ) flag = "*"; return flag; }