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 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 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 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 DefensiveScoringCalculator(NFLWeek startWeek, int offset) { StartWeek = startWeek; if (startWeek.WeekNo < 2) { StartWeek = startWeek.PreviousWeek(startWeek, false, 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 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 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 Decimal RatePlayer(NFLPlayer plyr, NFLWeek week) { // Points for Scores and points for stats if (week.WeekNo.Equals(0)) return 0; // Only starter or backup will score if ( ! ( plyr.PlayerRole.Equals( Constants.K_ROLE_STARTER ) || plyr.PlayerRole.Equals( Constants.K_ROLE_STARTER ) ) ) 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 var currentWeek = Int32.Parse(Utility.CurrentWeek()); #region Passing // determine receiving stats decimal YD1p = 0; var nGames = 0; // yards receiving will be the average of the last x games // Last week var lastWeek = week.PreviousWeek(week, false, true); var ds = plyr.LastStats( Constants.K_STATCODE_PASSING_YARDS, lastWeek.WeekNo, lastWeek.WeekNo, lastWeek.Season ); foreach (DataRow dr in ds.Tables[0].Rows) { YD1p += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards receiving in week {2}", plyr.PlayerName, YD1p, lastWeek.WeekKey() ) ); // two weeks ago var twoWeeksAgo = lastWeek.PreviousWeek(lastWeek, false, true); decimal YD2p = 0; ds = plyr.LastStats( Constants.K_STATCODE_PASSING_YARDS, twoWeeksAgo.WeekNo, twoWeeksAgo.WeekNo, twoWeeksAgo.Season ); foreach (DataRow dr in ds.Tables[0].Rows) { YD2p += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards passing in week {2}", plyr.PlayerName, YD2p, twoWeeksAgo.WeekKey() ) ); // Three weeks ago var threeWeeksAgo = lastWeek.PreviousWeek( twoWeeksAgo, false, true ); decimal YD3p = 0; ds = plyr.LastStats( Constants.K_STATCODE_PASSING_YARDS, threeWeeksAgo.WeekNo, threeWeeksAgo.WeekNo, threeWeeksAgo.Season ); foreach (DataRow dr in ds.Tables[0].Rows) { YD3p += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards passing in week {2}", plyr.PlayerName, YD3p, threeWeeksAgo.WeekKey() ) ); if (nGames > 0) plyr.TotStats.YDp = (int) (YD1p + YD2p + YD3p)/nGames; Utility.Announce(string.Format(" {0,-15} has averaged {1,4:##0} Yards passing in last 3 weeks", plyr.PlayerName, plyr.TotStats.YDp)); if (plyr.TotStats.YDp > 0) { // adjust for role if (plyr.PlayerRole.Equals( Constants.K_ROLE_BACKUP)) { plyr.TotStats.YDp = (plyr.TotStats.YDp/2); Utility.Announce(string.Format(" {0,-15} average halved to {1,4:##0} due to being a backup", plyr.PlayerName, plyr.TotStats.YDp)); } } ///////////////////////// // home bonus if (plyr.TotStats.YDp != 0) { if (plyr.IsAtHome(Week)) plyr.TotStats.YDp = (int) (plyr.TotStats.YDp*1.1); else plyr.TotStats.YDp = (int) (plyr.TotStats.YDp*.9); Utility.Announce(string.Format(" {0,-15} average adjusted to {1,4:##0} home v away", plyr.PlayerName, plyr.TotStats.YDp)); } /////////////////// // opponent factor if (plyr.TotStats.YDp != 0) { var opponent = plyr.CurrTeam.OpponentFor(Week.Season, Week.WeekNo); if (opponent != null) { var oppRating = plyr.OpponentRating(opponent.Ratings); var ratingModifier = QbRatingModifier(plyr.OpponentRating(opponent.Ratings)); plyr.TotStats.YDp = (int) (plyr.TotStats.YDp*ratingModifier); Utility.Announce( string.Format(" {0} output modified by {1} to {4} due to opponent ({3}) rating modifier of {2}", plyr.PlayerName, ratingModifier, oppRating, opponent.TeamCode, plyr.TotStats.YDp)); plyr.OppRate = oppRating; } } /////////////// // line factor if (plyr.TotStats.YDp != 0) { var game = plyr.CurrTeam.GameFor(Week.Season, Week.WeekNo); if (game != null) { if (game.SpreadFavourite().Equals(plyr.TeamCode)) { if (Math.Abs(game.Spread) > 6.5M) plyr.TotStats.YDp = (int) (plyr.TotStats.YDp*1.1); else plyr.TotStats.YDp = (int) (plyr.TotStats.YDp*1.05); plyr.PlayerSpread = string.Format("+{0:#.#}", Math.Abs(game.Spread)); } else { if (Math.Abs(game.Spread) > 6.5M) plyr.TotStats.YDp = (int) (plyr.TotStats.YDp*0.95); else plyr.TotStats.YDp = (int) (plyr.TotStats.YDp*0.9); plyr.PlayerSpread = string.Format("-{0:#.#}", Math.Abs(game.Spread)); } Utility.Announce(string.Format(" {0} output modified to {1} due to the spread ({2})", plyr.PlayerName, plyr.TotStats.YDp, plyr.PlayerSpread)); plyr.Opponent = game.OpponentOut(plyr.CurrTeam.TeamCode); } } Utility.Announce(string.Format(" {0} is projected for {1} Yards receiving in week {2}", plyr.PlayerName, plyr.TotStats.YDp, Week.WeekNo)); // 1 pt / 25 yds var ptsForYDs = (int) (plyr.TotStats.YDp/25.0M); plyr.Points += ptsForYDs; if (plyr.TotStats.YDp > 0) { // one TD for each 100 yds passing plyr.TotStats.Tdp = (plyr.TotStats.YDp/100); plyr.Points += plyr.TotStats.Tdp*4; } Utility.Announce( string.Format( " {0} has {1} points for YDc", plyr.PlayerName, ptsForYDs ) ); #endregion #region Catching // determine receiving stats decimal YD1c = 0; nGames = 0; // yards receiving will be the average of the last x games ds = plyr.LastStats( Constants.K_STATCODE_RECEPTION_YARDS, lastWeek.WeekNo, lastWeek.WeekNo, lastWeek.Season ); foreach (DataRow dr in ds.Tables[0].Rows) { YD1c += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards receiving in week {2}", plyr.PlayerName, YD1c, lastWeek.WeekKey())); decimal YD2c = 0; ds = plyr.LastStats( Constants.K_STATCODE_RECEPTION_YARDS, twoWeeksAgo.WeekNo, twoWeeksAgo.WeekNo, twoWeeksAgo.Season ); foreach (DataRow dr in ds.Tables[0].Rows) { YD2c += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards receiving in week {2}", plyr.PlayerName, YD2c, twoWeeksAgo.WeekKey() ) ); decimal YD3c = 0; ds = plyr.LastStats( Constants.K_STATCODE_RECEPTION_YARDS, threeWeeksAgo.WeekNo, threeWeeksAgo.WeekNo, threeWeeksAgo.Season ); foreach (DataRow dr in ds.Tables[0].Rows) { YD3c += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards receiving in week {2}", plyr.PlayerName, YD3c, threeWeeksAgo.WeekKey() ) ); if (nGames > 0) plyr.TotStats.YDc = (int) (YD1c + YD2c + YD3c)/nGames; Utility.Announce(string.Format(" {0,-15} has averaged {1,4:##0} Yards receiving in last 3 weeks", plyr.PlayerName, plyr.TotStats.YDc ) ); if (plyr.TotStats.YDc > 0) { // adjust for role if (plyr.PlayerRole.Equals( Constants.K_ROLE_BACKUP ) ) { plyr.TotStats.YDc = (plyr.TotStats.YDc/2); Utility.Announce(string.Format(" {0,-15} average halved to {1,4:##0} due to being a backup", plyr.PlayerName, plyr.TotStats.YDc)); } } ///////////////////////// // returner bonus 25 yds if (plyr.IsReturner()) { plyr.TotStats.YDc += 25; Utility.Announce(string.Format(" {0,-15} returner bonus to {1,4:##0}", plyr.PlayerName, plyr.TotStats.YDc)); } ///////////////////////// // home bonus if (plyr.TotStats.YDc != 0) { if (plyr.IsAtHome(Week)) plyr.TotStats.YDc = (int) (plyr.TotStats.YDc*1.2); else plyr.TotStats.YDc = (int) (plyr.TotStats.YDc*.8); Utility.Announce(string.Format(" {0,-15} average adjusted to {1,4:##0} home v away", plyr.PlayerName, plyr.TotStats.YDc)); } /////////////////// // opponent factor if (plyr.TotStats.YDc != 0) { var opponent = plyr.CurrTeam.OpponentFor(Week.Season, Week.WeekNo); if (opponent != null) { var oppRating = plyr.OpponentRating(opponent.Ratings); var ratingModifier = RatingModifier(plyr.OpponentRating(opponent.Ratings)); plyr.TotStats.YDc = (int) (plyr.TotStats.YDc*ratingModifier); Utility.Announce(string.Format(" {0} output modified by {1} due to opponent ({3}) rating of {2}", plyr.PlayerName, ratingModifier, oppRating, opponent.TeamCode)); plyr.OppRate = oppRating; } } /////////////// // line factor if (plyr.TotStats.YDc != 0) { var game = plyr.CurrTeam.GameFor(Week.Season, Week.WeekNo); if (game != null) { if (game.SpreadFavourite().Equals(plyr.TeamCode)) { if (Math.Abs(game.Spread) > 6.5M) plyr.TotStats.YDc = (int) (plyr.TotStats.YDc*1.2); else plyr.TotStats.YDc = (int) (plyr.TotStats.YDc*1.1); plyr.PlayerSpread = string.Format("+{0:#.#}", Math.Abs(game.Spread)); } else { if (Math.Abs(game.Spread) > 6.5M) plyr.TotStats.YDc = (int) (plyr.TotStats.YDc*0.8); else plyr.TotStats.YDc = (int) (plyr.TotStats.YDc*0.9); plyr.PlayerSpread = string.Format("-{0:#.#}", Math.Abs(game.Spread)); } Utility.Announce(string.Format(" {0} output modified to {1} due to the spread ({2})", plyr.PlayerName, plyr.TotStats.YDc, plyr.PlayerSpread)); plyr.Opponent = game.OpponentOut(plyr.CurrTeam.TeamCode); } } Utility.Announce(string.Format(" {0} is projected for {1} Yards receiving in week {2}", plyr.PlayerName, plyr.TotStats.YDc, Week.WeekNo)); // 1 pt / 10 yds ptsForYDs = (int) (plyr.TotStats.YDc/10.0M); plyr.Points += ptsForYDs; Utility.Announce( string.Format( " {0} has {1} points for YDc", plyr.PlayerName, ptsForYDs ) ); if (plyr.TotStats.YDc > 0) { // one TD for each 75 yds caught plyr.TotStats.Tdc = (plyr.TotStats.YDc/75); plyr.Points += plyr.TotStats.Tdc*6; } #endregion #region Running decimal YD1r = 0; nGames = 0; // yards running will be the average of the last x games ds = plyr.LastStats( Constants.K_STATCODE_RUSHING_YARDS, lastWeek.WeekNo, lastWeek.WeekNo, lastWeek.Season ); foreach (DataRow dr in ds.Tables[0].Rows) { YD1r += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards receiving in week {2}", plyr.PlayerName, YD1r, lastWeek.WeekKey() ) ); decimal YD2r = 0; ds = plyr.LastStats( Constants.K_STATCODE_RUSHING_YARDS, twoWeeksAgo.WeekNo, twoWeeksAgo.WeekNo, twoWeeksAgo.Season ); foreach (DataRow dr in ds.Tables[0].Rows) { YD2r += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards receiving in week {2}", plyr.PlayerName, YD2r, twoWeeksAgo.WeekKey() ) ); decimal YD3r = 0; ds = plyr.LastStats( Constants.K_STATCODE_RUSHING_YARDS, threeWeeksAgo.WeekNo, threeWeeksAgo.WeekNo, threeWeeksAgo.Season ); foreach (DataRow dr in ds.Tables[0].Rows) { YD3r += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards receiving in week {2}", plyr.PlayerName, YD3r, threeWeeksAgo.WeekKey()) ); if (nGames > 0) plyr.TotStats.YDr = (int) (YD1r + YD2r + YD3r)/nGames; Utility.Announce(string.Format(" {0,-15} has averaged {1,4:##0} Yards rushing in last 3 weeks", plyr.PlayerName, plyr.TotStats.YDr)); if (plyr.TotStats.YDr > 0) { // adjust for role if (plyr.PlayerRole.Equals(Constants.K_ROLE_BACKUP)) { plyr.TotStats.YDr = (plyr.TotStats.YDr/2); Utility.Announce(string.Format(" {0,-15} average halved to {1,4:##0} due to being a backup", plyr.PlayerName, plyr.TotStats.YDr ) ); } } ///////////////////////// // returner bonus 25 yds if (plyr.IsReturner()) { plyr.TotStats.YDr += 25; Utility.Announce(string.Format(" {0,-15} returner bonus to {1,4:##0}", plyr.PlayerName, plyr.TotStats.YDr)); } ///////////////////////// // home bonus if (plyr.TotStats.YDr != 0) { if (plyr.IsAtHome(Week)) plyr.TotStats.YDr = (int) (plyr.TotStats.YDr*1.2); else plyr.TotStats.YDr = (int) (plyr.TotStats.YDr*.8); Utility.Announce(string.Format(" {0,-15} average adjusted to {1,4:##0} home v away", plyr.PlayerName, plyr.TotStats.YDr)); } /////////////////// // opponent factor if (plyr.TotStats.YDr != 0) { var opponent = plyr.CurrTeam.OpponentFor(Week.Season, Week.WeekNo); if (opponent != null) { var oppRating = plyr.OpponentRating(opponent.Ratings); var ratingModifier = RatingModifier(plyr.OpponentRating(opponent.Ratings)); plyr.TotStats.YDr = (int) (plyr.TotStats.YDr*ratingModifier); Utility.Announce(string.Format(" {0} output modified by {1} due to opponent ({3}) rating of {2}", plyr.PlayerName, ratingModifier, oppRating, opponent.TeamCode)); plyr.OppRate = oppRating; } } /////////////// // line factor if (plyr.TotStats.YDr != 0) { var game = plyr.CurrTeam.GameFor(Week.Season, Week.WeekNo); if (game != null) { if (game.SpreadFavourite().Equals(plyr.TeamCode)) { if (Math.Abs(game.Spread) > 6.5M) plyr.TotStats.YDr = (int) (plyr.TotStats.YDr*1.2); else plyr.TotStats.YDr = (int) (plyr.TotStats.YDr*1.1); plyr.PlayerSpread = string.Format("+{0:#.#}", Math.Abs(game.Spread)); } else { if (Math.Abs(game.Spread) > 6.5M) plyr.TotStats.YDr = (int) (plyr.TotStats.YDr*0.8); else plyr.TotStats.YDr = (int) (plyr.TotStats.YDr*0.9); plyr.PlayerSpread = string.Format("-{0:#.#}", Math.Abs(game.Spread)); } Utility.Announce(string.Format(" {0} output modified to {1} due to the spread ({2})", plyr.PlayerName, plyr.TotStats.YDr, plyr.PlayerSpread)); plyr.Opponent = game.OpponentOut(plyr.CurrTeam.TeamCode); } } Utility.Announce(string.Format(" {0} is projected for {1} Yards rushing in week {2}", plyr.PlayerName, plyr.TotStats.YDr, Week.WeekNo)); // 1 pt / 10 yds ptsForYDs = (int) (plyr.TotStats.YDr/10.0M); plyr.Points += ptsForYDs; Utility.Announce( string.Format( " {0} has {1} points for YDr", plyr.PlayerName, ptsForYDs ) ); if (plyr.TotStats.YDr > 0) { // one TD for each 75 yds caught plyr.TotStats.Tdr = (plyr.TotStats.YDr/75); plyr.Points += plyr.TotStats.Tdr*6; } #endregion if (plyr.PlayerCat.Equals(Constants.K_KICKER_CAT)) { #region Kicking // determine FG decimal fg = 0; // FGs will be the average of the last x games ds = plyr.LastScores( Constants.K_SCORE_FIELD_GOAL, threeWeeksAgo.WeekNo, lastWeek.WeekNo, lastWeek.Season, "1" ); foreach (DataRow dr in ds.Tables[0].Rows) fg++; Utility.Announce(string.Format(" {0,-15} has {1,4:##0} FG in last 3 weeks", plyr.PlayerName, fg ) ); if (fg > 0) plyr.TotStats.Fg = (int) (fg/3); if (plyr.TotStats.Fg > 0) { // adjust for role if (plyr.PlayerRole.Equals(Constants.K_ROLE_BACKUP)) { plyr.TotStats.YDr = (plyr.TotStats.Fg/2); Utility.Announce(string.Format(" {0,-15} average halved to {1,4:##0} due to being a backup", plyr.PlayerName, plyr.TotStats.Fg)); } } ///////////////////////// // home bonus if (plyr.TotStats.Fg != 0) { if (plyr.IsAtHome(Week)) plyr.TotStats.Fg++; else plyr.TotStats.Fg--; Utility.Announce(string.Format(" {0,-15} fg adjusted to {1,4:##0} home v away", plyr.PlayerName, plyr.TotStats.Fg)); } /////////////// // line factor if (plyr.TotStats.Fg != 0) { var game = plyr.CurrTeam.GameFor(Week.Season, Week.WeekNo); if (game != null) { if (game.SpreadFavourite().Equals(plyr.TeamCode)) { if (Math.Abs(game.Spread) > 6.5M) plyr.TotStats.Fg += 2; else plyr.TotStats.Fg ++; plyr.PlayerSpread = string.Format("+{0:#.#}", Math.Abs(game.Spread)); } else { if (Math.Abs(game.Spread) > 6.5M) plyr.TotStats.Fg -= 2; else plyr.TotStats.Fg--; plyr.PlayerSpread = string.Format("-{0:#.#}", Math.Abs(game.Spread)); } Utility.Announce(string.Format(" {0} output modified to {1} due to the spread ({2})", plyr.PlayerName, plyr.TotStats.Fg, plyr.PlayerSpread)); plyr.Opponent = game.OpponentOut(plyr.CurrTeam.TeamCode); } } if (plyr.TotStats.Fg < 0) plyr.TotStats.Fg = 0; Utility.Announce(string.Format(" {0} is projected for {1} FGs in week {2}", plyr.PlayerName, plyr.TotStats.Fg, Week.WeekNo)); // 1 pt / 10 yds decimal ptsForFgs = (int) (plyr.TotStats.Fg*3.0M); plyr.Points += ptsForFgs; // determine PAT decimal pat = 0; // yards running will be the average of the last x games ds = plyr.LastScores(RosterLib.Constants.K_SCORE_PAT, currentWeek - 3, currentWeek - 1, Week.Season, "1"); foreach (DataRow dr in ds.Tables[0].Rows) pat++; Utility.Announce(string.Format(" {0,-15} has {1,4:##0} PATs in last 3 weeks", plyr.PlayerName, pat)); plyr.TotStats.Pat = (int) pat; if (plyr.TotStats.Pat > 0) // adjust for role if (plyr.PlayerRole.Equals(Constants.K_ROLE_BACKUP)) plyr.TotStats.YDr = (plyr.TotStats.YDr/2); ///////////////////////// // home bonus if (plyr.TotStats.Pat != 0) { if (plyr.IsAtHome(Week)) plyr.TotStats.Pat++; else plyr.TotStats.Pat--; Utility.Announce(string.Format(" {0,-15} pat adjusted to {1,4:##0} home v away", plyr.PlayerName, plyr.TotStats.Pat ) ); } /////////////// // line factor if (plyr.TotStats.Pat != 0) { var game = plyr.CurrTeam.GameFor(Week.Season, Week.WeekNo); if (game != null) { if (game.SpreadFavourite().Equals(plyr.TeamCode)) { if (Math.Abs(game.Spread) > 6.5M) plyr.TotStats.Pat += 2; else plyr.TotStats.Pat++; plyr.PlayerSpread = string.Format("+{0:#.#}", Math.Abs(game.Spread)); } else { if (Math.Abs(game.Spread) > 6.5M) plyr.TotStats.Pat -= 2; else plyr.TotStats.Pat--; plyr.PlayerSpread = string.Format("-{0:#.#}", Math.Abs(game.Spread)); } Utility.Announce(string.Format(" {0} output modified to {1} due to the spread ({2})", plyr.PlayerName, plyr.TotStats.Pat, plyr.PlayerSpread)); plyr.Opponent = game.OpponentOut(plyr.CurrTeam.TeamCode); } } if (plyr.TotStats.Pat < 0) plyr.TotStats.Pat = 0; Utility.Announce(string.Format(" {0} is projected for {1} PATs in week {2}", plyr.PlayerName, plyr.TotStats.Pat, Week.WeekNo)); // 1 pt / 10 yds decimal ptsForPats = (int) (plyr.TotStats.Pat*1.0M); plyr.Points += ptsForPats; #endregion } Utility.Announce( string.Format( "{0} has {1} in week {2}:{3}", plyr.PlayerName, plyr.Points, week.Season, week.Week ) ); return plyr.Points; }
public DataSet LoadData(ArrayList plyrList, NFLWeek startWeek) { var ds = new DataSet(); var dt = new DataTable(); var cols = dt.Columns; cols.Add("Name", typeof(String)); cols.Add("Currteam", typeof(String)); cols.Add("ROLE", typeof(String)); cols.Add("FT", typeof(String)); cols.Add("tot", typeof(Int32)); var currentWeek = new NFLWeek( Int32.Parse(TimeKeeper.Season), Int32.Parse(TimeKeeper.Week), loadGames: false); for (var w = Constants.K_WEEKS_IN_A_SEASON; w > 0; w--) { var fieldName = string.Format( FieldFormat, currentWeek.WeekNo); //Utility.Announce( // string.Format( "Adding field: {0}", fieldName ) ); cols.Add( fieldName, typeof(String)); currentWeek = currentWeek.PreviousWeek( currentWeek, loadgames: false, regularSeasonGamesOnly: false); } foreach (NFLPlayer p in plyrList) { decimal nTot = 0; var dr = dt.NewRow(); dr["Name"] = p.ProjectionLink(TimeKeeper.Season); dr["CurrTeam"] = p.TeamCode; dr["ROLE"] = p.PlayerRole; dr["FT"] = p.Owner; var weekCounter = Constants.K_WEEKS_IN_A_SEASON; var weeksDone = 0; var scoreWeek = WeekMaster != null ? WeekMaster.GetWeek(startWeek.Season, 17) : new NFLWeek( startWeek.Season, Constants.K_WEEKS_IN_REGULAR_SEASON); do { var game = scoreWeek.GameFor(p.TeamCode); var cOp = game == null ? string.Empty : game.OpponentOut(p.TeamCode); var nScore = 0M; if (game != null) { if (game.Played()) { nScore = _scorer.RatePlayer(p, scoreWeek); nTot += nScore; weeksDone++; } } if (game != null && game.Played()) { dr[string.Format(FieldFormat, scoreWeek.WeekNo)] = string.Format("{0:0}:{1}", nScore, cOp) + "<br>" + OpponentDefence(p, game); } else { dr[string.Format(FieldFormat, scoreWeek.WeekNo)] = string.Format("{0:#}:{1}", nScore, cOp) + "<br>" + OpponentDefence(p, game); } scoreWeek = WeekMaster != null?WeekMaster.PreviousWeek(scoreWeek) : scoreWeek.PreviousWeek(scoreWeek, false, false); if (CurrentSeasonOnly) { if (scoreWeek.Season != Utility.CurrentSeason()) { weekCounter = 0; // breaks you out of the loop } } if (weeksDone >= WeeksToGoBack) { break; } weekCounter--; } while (weekCounter > 0); dr["tot"] = nTot; dt.Rows.Add(dr); } ds.Tables.Add(dt); return(ds); }
public Decimal RatePlayer(NFLPlayer plyr, NFLWeek week, bool takeCache = true) { // Points for Scores and points for stats if (week.WeekNo.Equals(0)) { return(0); } // Only starter or backup will score if (!(plyr.PlayerRole.Equals(Constants.K_ROLE_STARTER) || plyr.PlayerRole.Equals(Constants.K_ROLE_STARTER))) { 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 var currentWeek = Int32.Parse(Utility.CurrentWeek()); #region Passing // determine receiving stats decimal YD1p = 0; var nGames = 0; // yards receiving will be the average of the last x games // Last week var lastWeek = week.PreviousWeek(week, false, true); var ds = plyr.LastStats( Constants.K_STATCODE_PASSING_YARDS, lastWeek.WeekNo, lastWeek.WeekNo, lastWeek.Season); foreach (DataRow dr in ds.Tables[0].Rows) { YD1p += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards receiving in week {2}", plyr.PlayerName, YD1p, lastWeek.WeekKey())); // two weeks ago var twoWeeksAgo = lastWeek.PreviousWeek(lastWeek, false, true); decimal YD2p = 0; ds = plyr.LastStats(Constants.K_STATCODE_PASSING_YARDS, twoWeeksAgo.WeekNo, twoWeeksAgo.WeekNo, twoWeeksAgo.Season); foreach (DataRow dr in ds.Tables[0].Rows) { YD2p += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards passing in week {2}", plyr.PlayerName, YD2p, twoWeeksAgo.WeekKey())); // Three weeks ago var threeWeeksAgo = lastWeek.PreviousWeek(twoWeeksAgo, false, true); decimal YD3p = 0; ds = plyr.LastStats(Constants.K_STATCODE_PASSING_YARDS, threeWeeksAgo.WeekNo, threeWeeksAgo.WeekNo, threeWeeksAgo.Season); foreach (DataRow dr in ds.Tables[0].Rows) { YD3p += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards passing in week {2}", plyr.PlayerName, YD3p, threeWeeksAgo.WeekKey())); if (nGames > 0) { plyr.TotStats.YDp = (int)(YD1p + YD2p + YD3p) / nGames; } Utility.Announce(string.Format(" {0,-15} has averaged {1,4:##0} Yards passing in last 3 weeks", plyr.PlayerName, plyr.TotStats.YDp)); if (plyr.TotStats.YDp > 0) { // adjust for role if (plyr.PlayerRole.Equals(Constants.K_ROLE_BACKUP)) { plyr.TotStats.YDp = (plyr.TotStats.YDp / 2); Utility.Announce(string.Format(" {0,-15} average halved to {1,4:##0} due to being a backup", plyr.PlayerName, plyr.TotStats.YDp)); } } ///////////////////////// // home bonus if (plyr.TotStats.YDp != 0) { if (plyr.IsAtHome(Week)) { plyr.TotStats.YDp = (int)(plyr.TotStats.YDp * 1.1); } else { plyr.TotStats.YDp = (int)(plyr.TotStats.YDp * .9); } Utility.Announce(string.Format(" {0,-15} average adjusted to {1,4:##0} home v away", plyr.PlayerName, plyr.TotStats.YDp)); } /////////////////// // opponent factor if (plyr.TotStats.YDp != 0) { var opponent = plyr.CurrTeam.OpponentFor(Week.Season, Week.WeekNo); if (opponent != null) { var oppRating = plyr.OpponentRating(opponent.Ratings); var ratingModifier = QbRatingModifier(plyr.OpponentRating(opponent.Ratings)); plyr.TotStats.YDp = (int)(plyr.TotStats.YDp * ratingModifier); Utility.Announce( string.Format(" {0} output modified by {1} to {4} due to opponent ({3}) rating modifier of {2}", plyr.PlayerName, ratingModifier, oppRating, opponent.TeamCode, plyr.TotStats.YDp)); plyr.OppRate = oppRating; } } /////////////// // line factor if (plyr.TotStats.YDp != 0) { var game = plyr.CurrTeam.GameFor(Week.Season, Week.WeekNo); if (game != null) { if (game.SpreadFavourite().Equals(plyr.TeamCode)) { if (Math.Abs(game.Spread) > 6.5M) { plyr.TotStats.YDp = (int)(plyr.TotStats.YDp * 1.1); } else { plyr.TotStats.YDp = (int)(plyr.TotStats.YDp * 1.05); } plyr.PlayerSpread = string.Format("+{0:#.#}", Math.Abs(game.Spread)); } else { if (Math.Abs(game.Spread) > 6.5M) { plyr.TotStats.YDp = (int)(plyr.TotStats.YDp * 0.95); } else { plyr.TotStats.YDp = (int)(plyr.TotStats.YDp * 0.9); } plyr.PlayerSpread = string.Format("-{0:#.#}", Math.Abs(game.Spread)); } Utility.Announce(string.Format(" {0} output modified to {1} due to the spread ({2})", plyr.PlayerName, plyr.TotStats.YDp, plyr.PlayerSpread)); plyr.Opponent = game.OpponentOut(plyr.CurrTeam.TeamCode); } } Utility.Announce(string.Format(" {0} is projected for {1} Yards receiving in week {2}", plyr.PlayerName, plyr.TotStats.YDp, Week.WeekNo)); // 1 pt / 25 yds var ptsForYDs = (int)(plyr.TotStats.YDp / 25.0M); plyr.Points += ptsForYDs; if (plyr.TotStats.YDp > 0) { // one TD for each 100 yds passing plyr.TotStats.Tdp = (plyr.TotStats.YDp / 100); plyr.Points += plyr.TotStats.Tdp * 4; } Utility.Announce(string.Format(" {0} has {1} points for YDc", plyr.PlayerName, ptsForYDs)); #endregion #region Catching // determine receiving stats decimal YD1c = 0; nGames = 0; // yards receiving will be the average of the last x games ds = plyr.LastStats(Constants.K_STATCODE_RECEPTION_YARDS, lastWeek.WeekNo, lastWeek.WeekNo, lastWeek.Season); foreach (DataRow dr in ds.Tables[0].Rows) { YD1c += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards receiving in week {2}", plyr.PlayerName, YD1c, lastWeek.WeekKey())); decimal YD2c = 0; ds = plyr.LastStats(Constants.K_STATCODE_RECEPTION_YARDS, twoWeeksAgo.WeekNo, twoWeeksAgo.WeekNo, twoWeeksAgo.Season); foreach (DataRow dr in ds.Tables[0].Rows) { YD2c += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards receiving in week {2}", plyr.PlayerName, YD2c, twoWeeksAgo.WeekKey())); decimal YD3c = 0; ds = plyr.LastStats(Constants.K_STATCODE_RECEPTION_YARDS, threeWeeksAgo.WeekNo, threeWeeksAgo.WeekNo, threeWeeksAgo.Season); foreach (DataRow dr in ds.Tables[0].Rows) { YD3c += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards receiving in week {2}", plyr.PlayerName, YD3c, threeWeeksAgo.WeekKey())); if (nGames > 0) { plyr.TotStats.YDc = (int)(YD1c + YD2c + YD3c) / nGames; } Utility.Announce(string.Format(" {0,-15} has averaged {1,4:##0} Yards receiving in last 3 weeks", plyr.PlayerName, plyr.TotStats.YDc)); if (plyr.TotStats.YDc > 0) { // adjust for role if (plyr.PlayerRole.Equals(Constants.K_ROLE_BACKUP)) { plyr.TotStats.YDc = (plyr.TotStats.YDc / 2); Utility.Announce(string.Format(" {0,-15} average halved to {1,4:##0} due to being a backup", plyr.PlayerName, plyr.TotStats.YDc)); } } ///////////////////////// // returner bonus 25 yds if (plyr.IsReturner()) { plyr.TotStats.YDc += 25; Utility.Announce(string.Format(" {0,-15} returner bonus to {1,4:##0}", plyr.PlayerName, plyr.TotStats.YDc)); } ///////////////////////// // home bonus if (plyr.TotStats.YDc != 0) { if (plyr.IsAtHome(Week)) { plyr.TotStats.YDc = (int)(plyr.TotStats.YDc * 1.2); } else { plyr.TotStats.YDc = (int)(plyr.TotStats.YDc * .8); } Utility.Announce(string.Format(" {0,-15} average adjusted to {1,4:##0} home v away", plyr.PlayerName, plyr.TotStats.YDc)); } /////////////////// // opponent factor if (plyr.TotStats.YDc != 0) { var opponent = plyr.CurrTeam.OpponentFor(Week.Season, Week.WeekNo); if (opponent != null) { var oppRating = plyr.OpponentRating(opponent.Ratings); var ratingModifier = RatingModifier(plyr.OpponentRating(opponent.Ratings)); plyr.TotStats.YDc = (int)(plyr.TotStats.YDc * ratingModifier); Utility.Announce(string.Format(" {0} output modified by {1} due to opponent ({3}) rating of {2}", plyr.PlayerName, ratingModifier, oppRating, opponent.TeamCode)); plyr.OppRate = oppRating; } } /////////////// // line factor if (plyr.TotStats.YDc != 0) { var game = plyr.CurrTeam.GameFor(Week.Season, Week.WeekNo); if (game != null) { if (game.SpreadFavourite().Equals(plyr.TeamCode)) { if (Math.Abs(game.Spread) > 6.5M) { plyr.TotStats.YDc = (int)(plyr.TotStats.YDc * 1.2); } else { plyr.TotStats.YDc = (int)(plyr.TotStats.YDc * 1.1); } plyr.PlayerSpread = string.Format("+{0:#.#}", Math.Abs(game.Spread)); } else { if (Math.Abs(game.Spread) > 6.5M) { plyr.TotStats.YDc = (int)(plyr.TotStats.YDc * 0.8); } else { plyr.TotStats.YDc = (int)(plyr.TotStats.YDc * 0.9); } plyr.PlayerSpread = string.Format("-{0:#.#}", Math.Abs(game.Spread)); } Utility.Announce(string.Format(" {0} output modified to {1} due to the spread ({2})", plyr.PlayerName, plyr.TotStats.YDc, plyr.PlayerSpread)); plyr.Opponent = game.OpponentOut(plyr.CurrTeam.TeamCode); } } Utility.Announce(string.Format(" {0} is projected for {1} Yards receiving in week {2}", plyr.PlayerName, plyr.TotStats.YDc, Week.WeekNo)); // 1 pt / 10 yds ptsForYDs = (int)(plyr.TotStats.YDc / 10.0M); plyr.Points += ptsForYDs; Utility.Announce(string.Format(" {0} has {1} points for YDc", plyr.PlayerName, ptsForYDs)); if (plyr.TotStats.YDc > 0) { // one TD for each 75 yds caught plyr.TotStats.Tdc = (plyr.TotStats.YDc / 75); plyr.Points += plyr.TotStats.Tdc * 6; } #endregion #region Running decimal YD1r = 0; nGames = 0; // yards running will be the average of the last x games ds = plyr.LastStats(Constants.K_STATCODE_RUSHING_YARDS, lastWeek.WeekNo, lastWeek.WeekNo, lastWeek.Season); foreach (DataRow dr in ds.Tables[0].Rows) { YD1r += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards receiving in week {2}", plyr.PlayerName, YD1r, lastWeek.WeekKey())); decimal YD2r = 0; ds = plyr.LastStats(Constants.K_STATCODE_RUSHING_YARDS, twoWeeksAgo.WeekNo, twoWeeksAgo.WeekNo, twoWeeksAgo.Season); foreach (DataRow dr in ds.Tables[0].Rows) { YD2r += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards receiving in week {2}", plyr.PlayerName, YD2r, twoWeeksAgo.WeekKey())); decimal YD3r = 0; ds = plyr.LastStats(Constants.K_STATCODE_RUSHING_YARDS, threeWeeksAgo.WeekNo, threeWeeksAgo.WeekNo, threeWeeksAgo.Season); foreach (DataRow dr in ds.Tables[0].Rows) { YD3r += Decimal.Parse(dr["QTY"].ToString()); nGames++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} Yards receiving in week {2}", plyr.PlayerName, YD3r, threeWeeksAgo.WeekKey())); if (nGames > 0) { plyr.TotStats.YDr = (int)(YD1r + YD2r + YD3r) / nGames; } Utility.Announce(string.Format(" {0,-15} has averaged {1,4:##0} Yards rushing in last 3 weeks", plyr.PlayerName, plyr.TotStats.YDr)); if (plyr.TotStats.YDr > 0) { // adjust for role if (plyr.PlayerRole.Equals(Constants.K_ROLE_BACKUP)) { plyr.TotStats.YDr = (plyr.TotStats.YDr / 2); Utility.Announce(string.Format(" {0,-15} average halved to {1,4:##0} due to being a backup", plyr.PlayerName, plyr.TotStats.YDr)); } } ///////////////////////// // returner bonus 25 yds if (plyr.IsReturner()) { plyr.TotStats.YDr += 25; Utility.Announce(string.Format(" {0,-15} returner bonus to {1,4:##0}", plyr.PlayerName, plyr.TotStats.YDr)); } ///////////////////////// // home bonus if (plyr.TotStats.YDr != 0) { if (plyr.IsAtHome(Week)) { plyr.TotStats.YDr = (int)(plyr.TotStats.YDr * 1.2); } else { plyr.TotStats.YDr = (int)(plyr.TotStats.YDr * .8); } Utility.Announce(string.Format(" {0,-15} average adjusted to {1,4:##0} home v away", plyr.PlayerName, plyr.TotStats.YDr)); } /////////////////// // opponent factor if (plyr.TotStats.YDr != 0) { var opponent = plyr.CurrTeam.OpponentFor(Week.Season, Week.WeekNo); if (opponent != null) { var oppRating = plyr.OpponentRating(opponent.Ratings); var ratingModifier = RatingModifier(plyr.OpponentRating(opponent.Ratings)); plyr.TotStats.YDr = (int)(plyr.TotStats.YDr * ratingModifier); Utility.Announce(string.Format(" {0} output modified by {1} due to opponent ({3}) rating of {2}", plyr.PlayerName, ratingModifier, oppRating, opponent.TeamCode)); plyr.OppRate = oppRating; } } /////////////// // line factor if (plyr.TotStats.YDr != 0) { var game = plyr.CurrTeam.GameFor(Week.Season, Week.WeekNo); if (game != null) { if (game.SpreadFavourite().Equals(plyr.TeamCode)) { if (Math.Abs(game.Spread) > 6.5M) { plyr.TotStats.YDr = (int)(plyr.TotStats.YDr * 1.2); } else { plyr.TotStats.YDr = (int)(plyr.TotStats.YDr * 1.1); } plyr.PlayerSpread = string.Format("+{0:#.#}", Math.Abs(game.Spread)); } else { if (Math.Abs(game.Spread) > 6.5M) { plyr.TotStats.YDr = (int)(plyr.TotStats.YDr * 0.8); } else { plyr.TotStats.YDr = (int)(plyr.TotStats.YDr * 0.9); } plyr.PlayerSpread = string.Format("-{0:#.#}", Math.Abs(game.Spread)); } Utility.Announce(string.Format(" {0} output modified to {1} due to the spread ({2})", plyr.PlayerName, plyr.TotStats.YDr, plyr.PlayerSpread)); plyr.Opponent = game.OpponentOut(plyr.CurrTeam.TeamCode); } } Utility.Announce(string.Format(" {0} is projected for {1} Yards rushing in week {2}", plyr.PlayerName, plyr.TotStats.YDr, Week.WeekNo)); // 1 pt / 10 yds ptsForYDs = (int)(plyr.TotStats.YDr / 10.0M); plyr.Points += ptsForYDs; Utility.Announce(string.Format(" {0} has {1} points for YDr", plyr.PlayerName, ptsForYDs)); if (plyr.TotStats.YDr > 0) { // one TD for each 75 yds caught plyr.TotStats.Tdr = (plyr.TotStats.YDr / 75); plyr.Points += plyr.TotStats.Tdr * 6; } #endregion if (plyr.PlayerCat.Equals(Constants.K_KICKER_CAT)) { #region Kicking // determine FG decimal fg = 0; // FGs will be the average of the last x games ds = plyr.LastScores(Constants.K_SCORE_FIELD_GOAL, threeWeeksAgo.WeekNo, lastWeek.WeekNo, lastWeek.Season, "1"); foreach (DataRow dr in ds.Tables[0].Rows) { fg++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} FG in last 3 weeks", plyr.PlayerName, fg)); if (fg > 0) { plyr.TotStats.Fg = (int)(fg / 3); } if (plyr.TotStats.Fg > 0) { // adjust for role if (plyr.PlayerRole.Equals(Constants.K_ROLE_BACKUP)) { plyr.TotStats.YDr = (plyr.TotStats.Fg / 2); Utility.Announce(string.Format(" {0,-15} average halved to {1,4:##0} due to being a backup", plyr.PlayerName, plyr.TotStats.Fg)); } } ///////////////////////// // home bonus if (plyr.TotStats.Fg != 0) { if (plyr.IsAtHome(Week)) { plyr.TotStats.Fg++; } else { plyr.TotStats.Fg--; } Utility.Announce(string.Format(" {0,-15} fg adjusted to {1,4:##0} home v away", plyr.PlayerName, plyr.TotStats.Fg)); } /////////////// // line factor if (plyr.TotStats.Fg != 0) { var game = plyr.CurrTeam.GameFor(Week.Season, Week.WeekNo); if (game != null) { if (game.SpreadFavourite().Equals(plyr.TeamCode)) { if (Math.Abs(game.Spread) > 6.5M) { plyr.TotStats.Fg += 2; } else { plyr.TotStats.Fg++; } plyr.PlayerSpread = string.Format("+{0:#.#}", Math.Abs(game.Spread)); } else { if (Math.Abs(game.Spread) > 6.5M) { plyr.TotStats.Fg -= 2; } else { plyr.TotStats.Fg--; } plyr.PlayerSpread = string.Format("-{0:#.#}", Math.Abs(game.Spread)); } Utility.Announce(string.Format(" {0} output modified to {1} due to the spread ({2})", plyr.PlayerName, plyr.TotStats.Fg, plyr.PlayerSpread)); plyr.Opponent = game.OpponentOut(plyr.CurrTeam.TeamCode); } } if (plyr.TotStats.Fg < 0) { plyr.TotStats.Fg = 0; } Utility.Announce(string.Format(" {0} is projected for {1} FGs in week {2}", plyr.PlayerName, plyr.TotStats.Fg, Week.WeekNo)); // 1 pt / 10 yds decimal ptsForFgs = (int)(plyr.TotStats.Fg * 3.0M); plyr.Points += ptsForFgs; // determine PAT decimal pat = 0; // yards running will be the average of the last x games ds = plyr.LastScores(RosterLib.Constants.K_SCORE_PAT, currentWeek - 3, currentWeek - 1, Week.Season, "1"); foreach (DataRow dr in ds.Tables[0].Rows) { pat++; } Utility.Announce(string.Format(" {0,-15} has {1,4:##0} PATs in last 3 weeks", plyr.PlayerName, pat)); plyr.TotStats.Pat = (int)pat; if (plyr.TotStats.Pat > 0) { // adjust for role if (plyr.PlayerRole.Equals(Constants.K_ROLE_BACKUP)) { plyr.TotStats.YDr = (plyr.TotStats.YDr / 2); } } ///////////////////////// // home bonus if (plyr.TotStats.Pat != 0) { if (plyr.IsAtHome(Week)) { plyr.TotStats.Pat++; } else { plyr.TotStats.Pat--; } Utility.Announce(string.Format(" {0,-15} pat adjusted to {1,4:##0} home v away", plyr.PlayerName, plyr.TotStats.Pat)); } /////////////// // line factor if (plyr.TotStats.Pat != 0) { var game = plyr.CurrTeam.GameFor(Week.Season, Week.WeekNo); if (game != null) { if (game.SpreadFavourite().Equals(plyr.TeamCode)) { if (Math.Abs(game.Spread) > 6.5M) { plyr.TotStats.Pat += 2; } else { plyr.TotStats.Pat++; } plyr.PlayerSpread = string.Format("+{0:#.#}", Math.Abs(game.Spread)); } else { if (Math.Abs(game.Spread) > 6.5M) { plyr.TotStats.Pat -= 2; } else { plyr.TotStats.Pat--; } plyr.PlayerSpread = string.Format("-{0:#.#}", Math.Abs(game.Spread)); } Utility.Announce(string.Format(" {0} output modified to {1} due to the spread ({2})", plyr.PlayerName, plyr.TotStats.Pat, plyr.PlayerSpread)); plyr.Opponent = game.OpponentOut(plyr.CurrTeam.TeamCode); } } if (plyr.TotStats.Pat < 0) { plyr.TotStats.Pat = 0; } Utility.Announce(string.Format(" {0} is projected for {1} PATs in week {2}", plyr.PlayerName, plyr.TotStats.Pat, Week.WeekNo)); // 1 pt / 10 yds decimal ptsForPats = (int)(plyr.TotStats.Pat * 1.0M); plyr.Points += ptsForPats; #endregion } Utility.Announce(string.Format("{0} has {1} in week {2}:{3}", plyr.PlayerName, plyr.Points, week.Season, week.Week)); return(plyr.Points); }
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 plyrList, NFLWeek startWeek) { var ds = new DataSet(); var dt = new DataTable(); var cols = dt.Columns; cols.Add("Name", typeof(String)); cols.Add("Currteam", typeof(String)); cols.Add("ROLE", typeof(String)); cols.Add("FT", typeof(String)); cols.Add("tot", typeof(Int32)); var currentWeek = new NFLWeek(Int32.Parse(Utility.CurrentSeason()), Int32.Parse(Utility.CurrentWeek()), false); for (var w = Constants.K_WEEKS_IN_A_SEASON; w > 0; w--) { var fieldName = string.Format(FieldFormat, currentWeek.WeekNo); cols.Add(fieldName, typeof(String)); currentWeek = currentWeek.PreviousWeek(currentWeek, false, false); } foreach (NFLPlayer p in plyrList) { decimal nTot = 0; var dr = dt.NewRow(); dr["Name"] = p.PlayerName; dr["CurrTeam"] = p.TeamCode; dr["ROLE"] = p.PlayerRole; dr["FT"] = p.Owner; var weekCounter = Constants.K_WEEKS_IN_A_SEASON; // var scoreWeek = startWeek; var scoreWeek = new NFLWeek(startWeek.Season, Constants.K_WEEKS_IN_REGULAR_SEASON); do { var game = scoreWeek.GameFor(p.TeamCode); var cOp = game == null ? string.Empty : game.OpponentOut(p.TeamCode); var nScore = 0M; if (game != null) { if (game.Played()) { nScore = _scorer.RatePlayer(p, scoreWeek); nTot += nScore; } } dr[string.Format(FieldFormat, scoreWeek.WeekNo)] = string.Format("{0:#}:{1}", nScore, cOp); scoreWeek = scoreWeek.PreviousWeek(scoreWeek, false, false); if (CurrentSeasonOnly) { if (scoreWeek.Season != Utility.CurrentSeason()) { weekCounter = 0; } } weekCounter--; } while (weekCounter > 0); dr["tot"] = nTot; dt.Rows.Add(dr); } ds.Tables.Add(dt); return(ds); }
public DataSet LoadData(ArrayList plyrList, NFLWeek startWeek) { var ds = new DataSet(); var dt = new DataTable(); var cols = dt.Columns; cols.Add("Name", typeof (String)); cols.Add("Currteam", typeof (String)); cols.Add("ROLE", typeof (String)); cols.Add("FT", typeof (String)); cols.Add("tot", typeof (Int32)); var currentWeek = new NFLWeek( Int32.Parse(TimeKeeper.Season), Int32.Parse(TimeKeeper.Week), loadGames:false); for (var w = Constants.K_WEEKS_IN_A_SEASON; w > 0; w--) { var fieldName = string.Format(FieldFormat, currentWeek.WeekNo); Utility.Announce( string.Format( "Adding field: {0}", fieldName ) ); cols.Add(fieldName, typeof (String)); currentWeek = currentWeek.PreviousWeek(currentWeek,loadgames:false, regularSeasonGamesOnly: false); } foreach (NFLPlayer p in plyrList) { decimal nTot = 0; var dr = dt.NewRow(); dr["Name"] = p.PlayerName; dr["CurrTeam"] = p.TeamCode; dr["ROLE"] = p.PlayerRole; dr["FT"] = p.Owner; var weekCounter = Constants.K_WEEKS_IN_A_SEASON; var weeksDone = 0; var scoreWeek = WeekMaster != null ? WeekMaster.GetWeek(startWeek.Season, 17) : new NFLWeek( startWeek.Season, Constants.K_WEEKS_IN_REGULAR_SEASON ); do { var game = scoreWeek.GameFor(p.TeamCode); var cOp = game == null ? string.Empty : game.OpponentOut(p.TeamCode); var nScore = 0M; if ( game != null ) { if ( game.Played() ) { nScore = _scorer.RatePlayer( p, scoreWeek ); nTot += nScore; weeksDone++; } } if (game != null && game.Played()) { dr[ string.Format(FieldFormat, scoreWeek.WeekNo) ] = string.Format("{0:0}:{1}", nScore, cOp) + "<br>" + OpponentDefence(p, game); } else { dr[ string.Format( FieldFormat, scoreWeek.WeekNo ) ] = string.Format( "{0:#}:{1}", nScore, cOp ) + "<br>" + OpponentDefence( p, game ); } scoreWeek = WeekMaster != null ? WeekMaster.PreviousWeek(scoreWeek) : scoreWeek.PreviousWeek(scoreWeek,false,false); if (CurrentSeasonOnly) if (scoreWeek.Season != Utility.CurrentSeason()) weekCounter = 0; // breaks you out of the loop if ( weeksDone >= WeeksToGoBack ) break; weekCounter--; } while (weekCounter > 0); dr["tot"] = nTot; dt.Rows.Add(dr); } ds.Tables.Add(dt); return ds; }
public ArrayList LoadGamesFrom(string sStartSeason, string sStartWeek, int offset) { if (GameList == null) GameList = new ArrayList(); GameList.Clear(); var processWeek = new NFLWeek(Int32.Parse(sStartSeason), Int32.Parse(sStartWeek), true); if (offset > 0) { for (var i = 0; i < offset; i++) { foreach (var game in processWeek.GameList()) GameList.Add(game); processWeek = processWeek.NextWeek(processWeek); } } else { // going backwards for (var i = 0; i > offset; i--) { // process week #if DEBUG Utility.Announce(string.Format(" getting {0} game for {1} wk {2} ", Name, processWeek.Season, processWeek.Week)); #endif var dr = Utility.TflWs.GetGame(processWeek.Season, string.Format("{0:00}", Int32.Parse(processWeek.Week)), TeamCode); if (dr != null) { var myGame = new NFLGame(dr); GameList.Add(myGame); } processWeek = processWeek.PreviousWeek(processWeek, false, regularSeasonGamesOnly: true); } } return GameList; }
public DataSet LoadData(ArrayList plyrList, IRatePlayers scorer) { var ds = new DataSet(); var dt = new DataTable(); var cols = dt.Columns; cols.Add("Name", typeof(String)); cols.Add("Pos", typeof(String)); cols.Add("Role", typeof(String)); cols.Add("RookieYr", typeof(String)); cols.Add("Age", typeof(String)); cols.Add("Currteam", typeof(String)); cols.Add("FT", typeof(String)); if (LongStats) { cols.Add("CurScores", typeof(Int32)); cols.Add("Scores", typeof(Int32)); cols.Add("Avg", typeof(Decimal)); cols.Add("Injury", typeof(Int32)); cols.Add("Tdp", typeof(Int32)); cols.Add("YDp", typeof(Int32)); cols.Add("Tdr", typeof(Int32)); cols.Add("TDc", typeof(Int32)); cols.Add("YDr", typeof(Int32)); cols.Add("YDc", typeof(Int32)); cols.Add("Fg", typeof(Int32)); } cols.Add("Points", typeof(Decimal)); if (Season == null) { Season = Utility.CurrentSeason(); } foreach (NFLPlayer p in plyrList) { if (p.TotStats == null) { p.LoadPerformances(false, true, Season); // to get the stats } // rate the last whatevr weeks var theWeek = new NFLWeek(Int32.Parse(Season), Week, false); // start here var totPoints = 0M; for (var w = WeeksToGoBack; w > 0; w--) { if (scorer != null) { scorer.RatePlayer(p, theWeek); } totPoints += p.Points; theWeek = theWeek.PreviousWeek(theWeek, false, false); } if (totPoints > 0 || !SupressZeros) { var dr = dt.NewRow(); if (RenderToCsv) { dr["Name"] = p.PlayerName; } else { dr["Name"] = p.ProjectionLink(Season); } dr["Pos"] = p.PlayerPos; dr["Role"] = p.RoleOut(); dr["RookieYr"] = p.RookieYear; dr["CurrTeam"] = p.TeamCode; dr["FT"] = p.Owner; dr["Age"] = p.PlayerAge(); if (LongStats) { dr["CurSCORES"] = p.CurrScores; dr["SCORES"] = p.Scores; dr["Avg"] = p.ScoresPerYear(); dr["INJURY"] = p.Injuries(); dr["Tdp"] = p.TotStats.Tdp; dr["YDp"] = p.TotStats.YDp; dr["Tdr"] = p.TotStats.Tdr; dr["TDc"] = p.TotStats.Tdc; dr["YDr"] = p.TotStats.YDr; dr["YDc"] = p.TotStats.YDc; dr["Fg"] = p.TotStats.Fg; } dr["Points"] = totPoints; dt.Rows.Add(dr); } } ds.Tables.Add(dt); return(ds); }