public void AddPoMetric(GameStats game, bool bHome) { var metric = (bHome) ? Decimal.Parse(game.HomeTDpasses.ToString()): Decimal.Parse(game.AwayTDpasses.ToString()); PoExp[game.Week - 1, KCol1Metric] += metric; PoExp[KRowTotal, KCol1Metric] += metric; // Also count Tdp and Fg if (bHome) { TotTDp += Int32.Parse(game.HomeTDpasses.ToString()); TotYDp += Decimal.Parse(game.HomePassingYds.ToString()); TotYDr += Decimal.Parse(game.HomeRushingYds.ToString()); TotFGs += Int32.Parse(game.HomeFGs.ToString()); } else { TotTDp += Int32.Parse(game.AwayTDpasses.ToString()); TotYDp += Decimal.Parse(game.AwayPassingYds.ToString()); TotYDr += Decimal.Parse(game.AwayRushingYds.ToString()); TotFGs += Int32.Parse(game.AwayFGs.ToString()); } }
public void AddPrBonus(decimal points, GameStats game) { PrExp[game.Week - 1, KCol0ExperiencePts] += points; PrExp[KRowTotal, KCol0ExperiencePts] += points; }
public void AddPrPoints(decimal points, decimal multiplier, GameStats game) { PrExp[game.Week - 1, KCol0ExperiencePts] += (points * multiplier); PrExp[KRowTotal, KCol0ExperiencePts] += (points * multiplier); PrExp[game.Week - 1, KCol2Multiplier] += multiplier; }
/// <summary> /// Crunches a game then increments the exp PTS for /// the 6 units on each team. /// </summary> /// <param name="homeMatrix">The home Matrix.</param> /// <param name="awayMatrix">The away Matrix.</param> /// <param name="game">The game.</param> private void IncrementExpPts( UnitMatrix homeMatrix, UnitMatrix awayMatrix, GameStats game ) { //RosterLib.Utility.Announce( string.Format( "Evaluating game {0} {1}@{2}", // game.Code, game.AwayTeam, game.HomeTeam ) ); #if DEBUG homeMatrix.DumpToLog(); awayMatrix.DumpToLog(); #endif EvaluatePo( game, homeMatrix, awayMatrix, true ); EvaluatePo( game, awayMatrix, homeMatrix, false ); EvaluateRo( game, homeMatrix, awayMatrix, true ); EvaluateRo( game, awayMatrix, homeMatrix, false ); EvaluatePp( game, homeMatrix, awayMatrix, true ); EvaluatePp( game, awayMatrix, homeMatrix, false ); }
private void LoadSeason( string seasonIn, string startWeekIn, string endWeekIn ) { #if DEBUG Utility.Announce( "WizSeason.LoadSeason " + seasonIn + " from " + startWeekIn + " to " + endWeekIn ); #endif // for each game in the season var ds = Utility.TflWs.GetSeason( seasonIn, startWeekIn, endWeekIn ); // calculate gamestat totals for the season var dt = ds.Tables[ "sched" ]; foreach ( DataRow dr in dt.Rows ) { if ( dr[ "HOMESCORE" ].ToString() != "0" || dr[ "AWAYSCORE" ].ToString() != "0" ) { _nGames++; var game = new GameStats( string.Format("{0}:{1}:{2}", dr["SEASON"], dr["WEEK"], dr["GAMENO"]), dr["HOMETEAM"].ToString(), dr["AWAYTEAM"].ToString(), Int32.Parse(dr["WEEK"].ToString())) { HomePassingYds = Utility.TflWs.TeamStats("S", _season, dr["WEEK"].ToString(), dr["GAMENO"].ToString(), dr["HOMETEAM"].ToString()), AwayPassingYds = Utility.TflWs.TeamStats("S", _season, dr["WEEK"].ToString(), dr["GAMENO"].ToString(), dr["AWAYTEAM"].ToString()) }; #region Passing Yards // Increment totals _total.HomePassingYds += game.HomePassingYds; _total.AwayPassingYds += game.AwayPassingYds; #endregion #region SacksAllowed game.HomeSacksAllowed = Utility.TflWs.TeamStats( "Q", _season, dr[ "WEEK" ].ToString(), dr[ "GAMENO" ].ToString(), dr[ "AWAYTEAM" ].ToString() ); game.AwaySacksAllowed = Utility.TflWs.TeamStats( "Q", _season, dr[ "WEEK" ].ToString(), dr[ "GAMENO" ].ToString(), dr[ "HOMETEAM" ].ToString() ); game.HomeSacks = game.AwaySacksAllowed; game.AwaySacks = game.HomeSacksAllowed; // Increment totals _total.HomeSacksAllowed += game.HomeSacksAllowed; _total.AwaySacksAllowed += game.AwaySacksAllowed; _total.HomeSacks += game.HomeSacks; _total.AwaySacks += game.AwaySacks; #endregion #region TD passes game.HomeTDpasses = Utility.TflWs.TeamScores( "P", _season, dr[ "WEEK" ].ToString(), dr[ "GAMENO" ].ToString(), dr[ "HOMETEAM" ].ToString() ); IsTopEffort( "TD passes", game.HomeTDpasses, dr[ "HOMETEAM" ].ToString(), dr[ "WEEK" ].ToString() ); game.AwayTDpasses = Utility.TflWs.TeamScores( "P", _season, dr[ "WEEK" ].ToString(), dr[ "GAMENO" ].ToString(), dr[ "AWAYTEAM" ].ToString() ); IsTopEffort("TD passes", game.AwayTDpasses, dr["AWAYTEAM"].ToString(), dr["WEEK"].ToString()); // Increment totals _total.HomeTDpasses += game.HomeTDpasses; _total.AwayTDpasses += game.AwayTDpasses; #endregion #region TD runs game.HomeTDruns = Utility.TflWs.TeamScores( "R", _season, dr[ "WEEK" ].ToString(), dr[ "GAMENO" ].ToString(), dr[ "HOMETEAM" ].ToString() ); IsTopEffort("TD runs", game.HomeTDruns, dr["HOMETEAM"].ToString(), dr["WEEK"].ToString()); game.AwayTDruns = Utility.TflWs.TeamScores( "R", _season, dr[ "WEEK" ].ToString(), dr[ "GAMENO" ].ToString(), dr[ "AWAYTEAM" ].ToString() ); IsTopEffort("TD runs", game.AwayTDruns, dr["AWAYTEAM"].ToString(), dr["WEEK"].ToString()); // Increment totals _total.HomeTDruns += game.HomeTDruns; _total.AwayTDruns += game.AwayTDruns; #endregion #region FGs game.HomeFGs = Utility.TflWs.TeamScores( "3", _season, dr[ "WEEK" ].ToString(), dr[ "GAMENO" ].ToString(), dr[ "HOMETEAM" ].ToString() ); game.AwayFGs = Utility.TflWs.TeamScores( "3", _season, dr[ "WEEK" ].ToString(), dr[ "GAMENO" ].ToString(), dr[ "AWAYTEAM" ].ToString() ); // Increment totals _total.HomeFGs += game.HomeFGs; _total.AwayFGs += game.AwayFGs; #endregion #region Rushing Yards game.HomeRushingYds = Utility.TflWs.TeamStats( "Y", _season, dr[ "WEEK" ].ToString(), dr[ "GAMENO" ].ToString(), dr[ "HOMETEAM" ].ToString() ); game.AwayRushingYds = Utility.TflWs.TeamStats( "Y", _season, dr[ "WEEK" ].ToString(), dr[ "GAMENO" ].ToString(), dr[ "AWAYTEAM" ].ToString() ); // Increment totals _total.HomeRushingYds += game.HomeRushingYds; _total.AwayRushingYds += game.AwayRushingYds; #endregion #region Matrix Loading // Wack the results into the team Matrix var homeMatrix = GetMatrix( game.HomeTeam ); var awayMatrix = GetMatrix( game.AwayTeam ); homeMatrix.SetOpponent( game.Week, "v" + awayMatrix.TeamCode ); awayMatrix.SetOpponent( game.Week, "@" + homeMatrix.TeamCode ); if ( game.Played() ) { homeMatrix.AddMetrics( game, true ); awayMatrix.AddMetrics( game, false ); GamesPlayed++; } #endregion _gameList.Add( game ); } } }
public WizSeason( string seasonIn, string startWeekIn, string endWeekIn ) { // The constructor will read all the results and crunch the // experience points for each unit. _season = seasonIn; _startWeek = startWeekIn; _endWeek = endWeekIn; _gameList = new ArrayList(); // stats for all the games _matrixList = new ArrayList(); // Ratings Matrix for all the teams if ( bOutputPlayerEP ) PlayerHt = new Hashtable(); // table of EP _total = new GameStats( seasonIn, "tot", "tot", 0 ); // League Totals InitialiseMatrix(); LoadSeason( _season, _startWeek, _endWeek ); // loads game stats for a season used for averages Utility.Announce( string.Format( "WizSeason:Loaded and tallied {0} games", _gameList.Count ) ); if ( seasonIn != Utility.CurrentSeason() ) { if ( Int32.Parse( Utility.CurrentWeek() ) > 0 ) { // This adds current season games giving a cumulative affect Utility.Announce( "Adding ratings for up to " + Utility.CurrentWeek() ); LoadSeason( Utility.CurrentSeason(), "01", Utility.CurrentWeek() ); } } AnnounceTotals(); DetermineExperience(); OutputPhase( seasonIn ); }
private void EvaluateRo( GameStats game, UnitMatrix offMatrix, UnitMatrix defMatrix, bool bHome ) { decimal avgMetric = AverageMetric( ( Total.AwayTDruns + Total.HomeTDruns )/2 ); // RosterLib.Utility.Announce( string.Format( "League Average Tdr is {0:###.#} (tot={1:###.#})", // avgMetric, Total.AwayTDruns + Total.HomeTDruns ) ); decimal gp = offMatrix.GamesPlayed; decimal tdr = offMatrix.RoMetrics; decimal offMult = Multiplier( tdr/gp, avgMetric ); decimal defMult = Multiplier( avgMetric, defMatrix.RdMetrics/defMatrix.GamesPlayed ); // RosterLib.Utility.Announce( string.Format( "Offense {1} averages {0:###.#} Tdr/game", // offMatrix.ROMetrics / offMatrix.GamesPlayed, offMatrix.TeamCode ) ); // RosterLib.Utility.Announce( string.Format( "Defence {1} averages {0:###.#} Tdr allowed/game", // defMatrix.RDMetrics / defMatrix.GamesPlayed, defMatrix.TeamCode ) ); decimal metric = ( bHome ) ? game.HomeTDruns : game.AwayTDruns; //string result = ResultOf( metric, 100.0M, 125.0M ); string result = ResultOf( metric, 0.0M, 1.0M ); // RosterLib.Utility.Announce( "Result=" + result ); decimal offPoints; decimal defPoints; switch ( result ) { case "L": offPoints = KPointsLoss; defPoints = KPointsWin; break; case "D": offPoints = KPointsDraw; defPoints = KPointsDraw; break; default: offPoints = KPointsWin; defPoints = KPointsLoss; break; } offMatrix.AddRoPoints( offPoints, defMult, game ); defMatrix.AddRdPoints( defPoints, offMult, game ); DistributeEp( "RO", offPoints, defMult, game, bHome ); DistributeEp( "RD", defPoints, offMult, game, bHome ); Explain( offMatrix, defMatrix, "Rush Offence", offPoints, defPoints, "RO", "RD", offMult, defMult, result, ( offMatrix.RoPoints - offPoints ), ( defMatrix.RdPoints - defPoints ), metric, bHome ); }
private void EvaluatePp( GameStats game, UnitMatrix offMatrix, UnitMatrix defMatrix, bool bHome ) { decimal avgMetric = AverageMetric( ( Total.AwaySacksAllowed + Total.HomeSacksAllowed )/2 ); #if DEBUG Utility.Announce( string.Format( "League Average Sacks Allowed is {0:###.#} (tot={1:###.#})", avgMetric, Total.AwaySacksAllowed + Total.HomeSacksAllowed ) ); #endif // Multipliers var sakAllowed = offMatrix.PpMetrics; var saks = defMatrix.PrMetrics; var offMult = Multiplier( avgMetric, DivByZeroCheck( sakAllowed, offMatrix.GamesPlayed ) ); #if DEBUG Utility.Announce( string.Format( "Defence {1} averages {0:###.#} Sacks/game", DivByZeroCheck( defMatrix.PrMetrics, defMatrix.GamesPlayed ), defMatrix.TeamCode ) ); Utility.Announce( string.Format( "Offense {1} averages {0:###.#} Sacks allowed/game", DivByZeroCheck( sakAllowed, offMatrix.GamesPlayed ), offMatrix.TeamCode ) ); #endif var defMult = Multiplier( DivByZeroCheck( saks, defMatrix.GamesPlayed ), avgMetric ); if ( offMult == 0.0M ) offMult = 1.0M; if ( defMult == 0.0M ) defMult = 1.0M; #if DEBUG Utility.Announce( string.Format( "Offensive multiplier is {0:##.##}", offMult ) ); Utility.Announce( string.Format( "Defensive multiplier is {0:##.##}", defMult ) ); #endif var metric = ( bHome ) ? game.HomeSacksAllowed : game.AwaySacksAllowed; decimal offPoints; decimal defPoints; var result = ResultOf( metric, 2.0M, 4.0M ); //RosterLib.Utility.Announce( "Result=" + result ); switch ( result ) { case "W": offPoints = KPointsLoss; defPoints = KPointsWin; break; case "D": offPoints = KPointsDraw; defPoints = KPointsDraw; break; default: offPoints = KPointsWin; defPoints = KPointsLoss; break; } offMatrix.AddPpPoints( offPoints, defMult, game ); defMatrix.AddPrPoints( defPoints, offMult, game ); DistributeEp( "PP", offPoints, defMult, game, bHome ); DistributeEp( "PR", defPoints, offMult, game, bHome ); #if DEBUG Explain( offMatrix, defMatrix, "Pass Protection", offPoints, defPoints, "PP", "PR", offMult, defMult, result, ( offMatrix.PpPoints - offPoints ), ( defMatrix.PrPoints - defPoints ), metric, bHome ); #endif }
/// <summary> /// Evaluates the Passing Offense and Defence, based on passing yards. /// </summary> /// <param name="game">The game.</param> /// <param name="offMatrix">The off Matrix.</param> /// <param name="defMatrix">The def Matrix.</param> /// <param name="bHome">if set to <c>true</c> [b home].</param> private void EvaluatePo( GameStats game, UnitMatrix offMatrix, UnitMatrix defMatrix, bool bHome ) { // What is the league average for Tdp var avgMetric = AverageMetric( ( Total.AwayTDpasses + Total.HomeTDpasses )/2 ); // How does the offence compare against the League var offMult = Multiplier( offMatrix.PoMetrics/offMatrix.GamesPlayed, avgMetric ); #if DEBUG Utility.Announce( string.Format( "League Average Tdp is {0:###.#} (tot={1:###.#})", avgMetric, Total.AwayTDpasses + Total.HomeTDpasses ) ); Utility.Announce( string.Format( "Defence {1} gives up an average of {0:###.#} Tdp/game", defMatrix.PpMetrics/defMatrix.GamesPlayed, defMatrix.TeamCode ) ); Utility.Announce( string.Format( "Offense {1} averages {0:###.#} Tdp/game", offMatrix.PoMetrics/offMatrix.GamesPlayed, offMatrix.TeamCode ) ); #endif var defMult = Multiplier( avgMetric, defMatrix.PdMetrics/defMatrix.GamesPlayed ); // Avg Def = 1.0 var metric = ( bHome ) ? game.HomeTDpasses : game.AwayTDpasses; decimal offPoints; decimal defPoints; var result = ResultOf( metric, 0.0M, 1.0M ); //Utility.Announce( string.Format( " WizSeason.EvaluatePO Result for {1} = {0}", result, offMatrix.Team.Name ) ); #region tally switch ( result ) { case "L": offPoints = KPointsLoss; defPoints = KPointsWin; break; case "D": offPoints = KPointsDraw; defPoints = KPointsDraw; break; default: offPoints = KPointsWin; defPoints = KPointsLoss; break; } offMatrix.AddPoPoints( offPoints, defMult, game ); defMatrix.AddPdPoints( defPoints, offMult, game ); // Give each member of the passing unit the experience too DistributeEp( "PO", offPoints, defMult, game, bHome ); DistributeEp( "PD", defPoints, offMult, game, bHome ); #endregion Explain( offMatrix, defMatrix, "Pass Offence", offPoints, defPoints, "PO", "PD", offMult, defMult, result, ( offMatrix.PoPoints - ( offPoints*defMult ) ), ( defMatrix.PdPoints - ( defPoints*offMult ) ), metric, bHome ); }
private void DistributeEp( string unitCode, decimal points, decimal multiplier, GameStats game, bool bHome ) { if ( bOutputPlayerEP ) { var teamCode = ( bHome ) ? game.HomeTeam : game.AwayTeam; var ep = points*multiplier; #if DEBUG Utility.Announce( string.Format( "Distributing {0:##.##} points to the {1} unit from game {2}", ep, unitCode, game.Code ) ); #endif var ds = Utility.TflWs.GetLineup( teamCode, game.Season, game.Week ); // For each player in the game in the particular unit tally points if ( ds.Tables[ 0 ].Rows.Count > 0 ) { var dt = ds.Tables[ "lineup" ]; foreach ( DataRow dr in dt.Rows ) { var playerId = dr[ "PLAYERID" ].ToString(); var startVal = dr[ "START" ].ToString(); var starter = ( startVal == "True" ) ? true : false; var p = new NFLPlayer( playerId ); if ( p.IsInUnit( unitCode ) ) TallyEp( playerId, ep, starter ); } } } }