private async void window_Loaded(object sender, RoutedEventArgs e) { if (MainWindow.Tf.IsBetween) { MainWindow.Tf = new Timeframe(MainWindow.Tf.SeasonNum); IsEnabled = false; await MainWindow.UpdateAllData(true); } _pst = MainWindow.PST; prepareWindow(curMode); MainWindow.TempBSE_BS = new TeamBoxScore(); if (curMode == Mode.Update) { curTeamBoxScore = new TeamBoxScore(); FillTeamBoxScore(curTeamBoxScore); txtMINS1.Text = MainWindow.GameLength.ToString(); } try { ProgressWindow.PwInstance.CanClose = true; ProgressWindow.PwInstance.Close(); } catch { Console.WriteLine("ProgressWindow couldn't be closed; maybe it wasn't open."); } if (_bseToLoad != null) { loadBoxScore(_bseToLoad); } else if (_idToLoad != -1) { loadBoxScore(_idToLoad); } dgvPlayersAway.PreviewKeyDown += GenericEventHandlers.WPFDataGrid_PreviewKeyDown_GoToNextColumnOnEnter; dgvPlayersHome.PreviewKeyDown += GenericEventHandlers.WPFDataGrid_PreviewKeyDown_GoToNextColumnOnEnter; IsEnabled = true; }
public void AddInfoFromTeamBoxScore(TeamBoxScore bs, Dictionary<int, TeamStats> tst) { bs.PrepareForDisplay(tst, TeamID); Result = bs.DisplayResult; TeamPTS = TeamID == bs.Team1ID ? bs.PTS1 : bs.PTS2; OppTeamID = TeamID == bs.Team1ID ? bs.Team2ID : bs.Team1ID; OppTeamPTS = TeamID == bs.Team1ID ? bs.PTS2 : bs.PTS1; Date = bs.GameDate.ToString().Split(' ')[0]; RealDate = bs.GameDate; DisplayTeam = tst[TeamID].DisplayName; DisplayOppTeam = tst[OppTeamID].DisplayName; }
/// <summary> /// Finds the requested box score and loads it. /// </summary> /// <param name="id">The ID of the box score.</param> private void loadBoxScore(int id) { int bsHistID = -1; for (int i = 0; i < MainWindow.BSHist.Count; i++) { if (MainWindow.BSHist[i].BS.ID == id) { bsHistID = i; break; } } BoxScoreEntry bse = MainWindow.BSHist[bsHistID]; _curTeamBoxScore = MainWindow.BSHist[bsHistID].BS; _curTeamBoxScore.BSHistID = bsHistID; loadBoxScore(bse); }
private void FillTeamBoxScore(TeamBoxScore bs) { txtPTS1.Text = bs.PTS1.ToString(); txtREB1.Text = bs.REB1.ToString(); txtAST1.Text = bs.AST1.ToString(); txtSTL1.Text = bs.STL1.ToString(); txtBLK1.Text = bs.BLK1.ToString(); txtTO1.Text = bs.TOS1.ToString(); txtFGM1.Text = bs.FGM1.ToString(); txtFGA1.Text = bs.FGA1.ToString(); txt3PM1.Text = bs.TPM1.ToString(); txt3PA1.Text = bs.TPA1.ToString(); txtFTM1.Text = bs.FTM1.ToString(); txtFTA1.Text = bs.FTA1.ToString(); txtOREB1.Text = bs.OREB1.ToString(); txtFOUL1.Text = bs.FOUL1.ToString(); txtMINS1.Text = bs.MINS1.ToString(); txtPTS2.Text = bs.PTS2.ToString(); txtREB2.Text = bs.REB2.ToString(); txtAST2.Text = bs.AST2.ToString(); txtSTL2.Text = bs.STL2.ToString(); txtBLK2.Text = bs.BLK2.ToString(); txtTO2.Text = bs.TOS2.ToString(); txtFGM2.Text = bs.FGM2.ToString(); txtFGA2.Text = bs.FGA2.ToString(); txt3PM2.Text = bs.TPM2.ToString(); txt3PA2.Text = bs.TPA2.ToString(); txtFTM2.Text = bs.FTM2.ToString(); txtFTA2.Text = bs.FTA2.ToString(); txtOREB2.Text = bs.OREB2.ToString(); txtFOUL2.Text = bs.FOUL2.ToString(); txtMINS2.Text = bs.MINS2.ToString(); }
/// <summary> /// Initializes a new instance of the <see cref="BoxScoreEntry" /> class. /// </summary> /// <param name="bs">The TeamBoxScore to initialize with.</param> /// <param name="pbsList">The PlayerBoxScore list.</param> /// <param name="pbpeList"></param> public BoxScoreEntry(TeamBoxScore bs, List<PlayerBoxScore> pbsList, List<PlayByPlayEntry> pbpeList) : this(bs) { PBSList = pbsList; PBPEList = pbpeList; }
/// <summary>Adds the team stats from a box score.</summary> /// <param name="bsToAdd">The box score to add.</param> /// <param name="tst">The team stats dictionary.</param> /// <param name="tstOpp">The opposing team stats dictionary.</param> public static void AddTeamStatsFromBoxScore( TeamBoxScore bsToAdd, ref Dictionary<int, TeamStats> tst, ref Dictionary<int, TeamStats> tstOpp) { AddTeamStatsFromBoxScore(bsToAdd, ref tst, ref tstOpp, bsToAdd.Team1ID, bsToAdd.Team2ID); }
/// <summary> /// Initializes a new instance of the <see cref="MainWindow" /> class. Creates the program's documents directories if needed, /// initializes structures, and loads the settings from registry. /// </summary> public MainWindow() { InitializeComponent(); MWInstance = this; TempBSE_BS = new TeamBoxScore(); Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("en-US"); setDefaultCulture(CultureInfo.CreateSpecificCulture("en-US")); //btnInject.Visibility = Visibility.Hidden; #if DEBUG btnTest.Visibility = Visibility.Visible; #else btnTest.Visibility = Visibility.Hidden; #endif if (Directory.Exists(PSFiltersPath) == false) { Directory.CreateDirectory(PSFiltersPath); } if (Directory.Exists(ASCFiltersPath) == false) { Directory.CreateDirectory(ASCFiltersPath); } var appTempPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\NBA Stats Tracker\" + @"Temp\"; if (Directory.Exists(appTempPath) == false) { Directory.CreateDirectory(appTempPath); } TST[0] = new TeamStats(-1, "$$NewDB"); TSTOpp[0] = new TeamStats(-1, "$$NewDB"); for (var i = 0; i < 30; i++) { RealTST[i] = new TeamStats(); } RegistryKey rk = null; try { rk = Registry.CurrentUser; } catch (Exception ex) { App.ForceCriticalError(ex, "Registry.CurrentUser"); } Debug.Assert(rk != null, "rk != null"); rk = rk.OpenSubKey(@"SOFTWARE\2K Sports\NBA 2K12"); if (rk == null) { SavesPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\2K Sports\NBA 2K12\Saves\"; } else { try { SavesPath = rk.GetValue("Saves").ToString(); } catch (Exception) { SavesPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\2K Sports\NBA 2K12\Saves\"; } } CSV.ReplaceREDitorSortingChars = true; if (App.RealNBAOnly) { mnuFileGetRealStats_Click(null, null); MessageBox.Show("Nothing but net! Thanks for using NBA Stats Tracker!"); Environment.Exit(-1); } else { var exportTeamsOnly = Tools.GetRegistrySetting("ExportTeamsOnly", 1); mnuOptionsExportTeamsOnly.IsChecked = exportTeamsOnly == 1; var compatibilityCheck = Tools.GetRegistrySetting("CompatibilityCheck", 1); mnuOptionsCompatibilityCheck.IsChecked = compatibilityCheck == 1; IsImperial = Tools.GetRegistrySetting("IsImperial", 1) == 1; mnuOptionsIsImperial.IsChecked = IsImperial; // Displays a message to urge the user to donate at the 50th start of the program. var timesStarted = Tools.GetRegistrySetting("TimesStarted", -1); if (timesStarted == -1) { Tools.SetRegistrySetting("TimesStarted", 1); } else if (timesStarted <= 50) { if (timesStarted == 50) { var r = MessageBox.Show( "Hey there! This is a friendly reminder from the creator of NBA Stats Tracker.\n\n" + "You seem to like using NBA Stats Tracker a lot, and I'm sure you enjoy the fact that it's free. " + "However, if you believe that I deserve your support and you want to help me to continue my studies, " + "as well as continue developing and supporting NBA Stats Tracker, you can always donate!\n\n" + "Even a small amount can help a lot!\n\n" + "Would you like to find out how you can donate?\n\n" + "Clicking Cancel will make sure this message never shows up again.", "NBA Stats Tracker - A friendly reminder", MessageBoxButton.YesNoCancel, MessageBoxImage.Information); if (r == MessageBoxResult.Yes) { mnuHelpDonate_Click(null, null); } else if (r == MessageBoxResult.No) { timesStarted = -1; } } Tools.SetRegistrySetting("TimesStarted", timesStarted + 1); } } UIScheduler = TaskScheduler.FromCurrentSynchronizationContext(); SearchCache = new List<SearchItem>(); #region Keyboard Shortcuts CmndImport.InputGestures.Add(new KeyGesture(Key.I, ModifierKeys.Control)); CommandBindings.Add(new CommandBinding(CmndImport, btnImport2K12_Click)); CmndExport.InputGestures.Add(new KeyGesture(Key.E, ModifierKeys.Control)); CommandBindings.Add(new CommandBinding(CmndExport, btnExport2K12_Click)); CmndOpen.InputGestures.Add(new KeyGesture(Key.O, ModifierKeys.Control)); CommandBindings.Add(new CommandBinding(CmndOpen, btnOpen_Click)); CmndSave.InputGestures.Add(new KeyGesture(Key.S, ModifierKeys.Control)); CommandBindings.Add(new CommandBinding(CmndSave, btnSaveCurrentSeason_Click)); CmndFind.InputGestures.Add(new KeyGesture(Key.F, ModifierKeys.Control)); CommandBindings.Add(new CommandBinding(CmndFind, QuickFind)); #endregion //prepareImageCache(); }
/// <summary> /// Creates a team box score and all the required player box score instances using data from the downloaded DataSet. /// </summary> /// <param name="ds">The DataSet.</param> /// <param name="parts">The parts of the split date string.</param> /// <param name="bse">The resulting BoxScoreEntry.</param> /// <returns>0 if every required player was found in the database; otherwise, -1.</returns> private static int boxScoreFromDataSet(DataSet ds, string[] parts, out BoxScoreEntry bse) { DataTable awayDT = ds.Tables[0]; DataTable homeDT = ds.Tables[1]; var bs = new TeamBoxScore(ds, parts); bse = new BoxScoreEntry(bs) {Date = bs.GameDate, PBSList = new List<PlayerBoxScore>()}; int result = 0; for (int i = 0; i < awayDT.Rows.Count - 1; i++) { if (i == 5) { continue; } var pbs = new PlayerBoxScore(awayDT.Rows[i], bs.Team1ID, bs.ID, (i < 5), MainWindow.PST); if (pbs.PlayerID == -1) { result = -1; continue; } bse.PBSList.Add(pbs); } for (int i = 0; i < homeDT.Rows.Count - 1; i++) { if (i == 5) { continue; } var pbs = new PlayerBoxScore(homeDT.Rows[i], bs.Team2ID, bs.ID, (i < 5), MainWindow.PST); if (pbs.PlayerID == -1) { result = -1; continue; } bse.PBSList.Add(pbs); } return result; }
/// <summary> /// Initializes a new instance of the <see cref="BoxScoreEntry" /> class. /// </summary> /// <param name="bs">The TeamBoxScore to initialize with.</param> /// <param name="date">The date of the game.</param> /// <param name="pbsList">The PlayerBoxScore list.</param> public BoxScoreEntry(TeamBoxScore bs, DateTime date, List<PlayerBoxScore> pbsList) { BS = bs; Date = date; PBSList = pbsList; }
/// <summary> /// Calculates the box score by comparing the participating team's current and previous team and player stats. /// </summary> /// <param name="tst">The team stats dictionary.</param> /// <param name="oldTST">The old team stats dictionary.</param> /// <param name="pst">The player stats dictionary.</param> /// <param name="oldPST">The old player stats dictionary.</param> /// <param name="t1">The away team ID.</param> /// <param name="t2">The home team ID.</param> /// <returns></returns> private static BoxScoreEntry prepareBoxScore(Dictionary<int, TeamStats> tst, Dictionary<int, TeamStats> oldTST, Dictionary<int, PlayerStats> pst, Dictionary<int, PlayerStats> oldPST, int t1, int t2) { bool isPlayoff = (tst[t1].GetPlayoffGames() > 0); var bs = new TeamBoxScore { IsPlayoff = isPlayoff, Team1ID = t1, MINS1 = getDiff(tst, oldTST, t1, TAbbr.MINS, isPlayoff), Team2ID = t2, MINS2 = getDiff(tst, oldTST, t2, TAbbr.MINS, isPlayoff) }; var bse = new BoxScoreEntry(bs) {PBSList = new List<PlayerBoxScore>()}; /* var team1Players = pst.Where(pair => pair.Value.TeamF == bs.Team1); var team2Players = pst.Where(pair => pair.Value.TeamF == bs.Team2); */ IEnumerable<KeyValuePair<int, PlayerStats>> bothTeamsPlayers = pst.Where(pair => pair.Value.TeamF == bs.Team1ID || pair.Value.TeamF == bs.Team2ID); foreach (var playerKVP in bothTeamsPlayers) { KeyValuePair<int, PlayerStats> oldplayerKVP = oldPST.Single(pair => pair.Value.ID == playerKVP.Value.ID); PlayerStats newPlayer = playerKVP.Value; PlayerStats oldPlayer = oldplayerKVP.Value; PlayerBoxScore pbs; if (getDiff(newPlayer, oldPlayer, PAbbr.GP) == 1) { pbs = new PlayerBoxScore { PlayerID = newPlayer.ID, TeamID = newPlayer.TeamF, IsStarter = (getDiff(newPlayer, oldPlayer, PAbbr.GS) == 1), PlayedInjured = newPlayer.Injury.IsInjured, MINS = getDiff(newPlayer, oldPlayer, PAbbr.MINS), PTS = getDiff(newPlayer, oldPlayer, PAbbr.PTS), OREB = getDiff(newPlayer, oldPlayer, PAbbr.OREB), DREB = getDiff(newPlayer, oldPlayer, PAbbr.DREB), AST = getDiff(newPlayer, oldPlayer, PAbbr.AST), STL = getDiff(newPlayer, oldPlayer, PAbbr.STL), BLK = getDiff(newPlayer, oldPlayer, PAbbr.BLK), TOS = getDiff(newPlayer, oldPlayer, PAbbr.TOS), FGM = getDiff(newPlayer, oldPlayer, PAbbr.FGM), FGA = getDiff(newPlayer, oldPlayer, PAbbr.FGA), TPM = getDiff(newPlayer, oldPlayer, PAbbr.TPM), TPA = getDiff(newPlayer, oldPlayer, PAbbr.TPA), FTM = getDiff(newPlayer, oldPlayer, PAbbr.FTM), FTA = getDiff(newPlayer, oldPlayer, PAbbr.FTA), FOUL = getDiff(newPlayer, oldPlayer, PAbbr.FOUL) }; pbs.REB = (ushort) (pbs.OREB + pbs.DREB); pbs.FGp = (float) pbs.FGM/pbs.FGA; pbs.TPp = (float) pbs.TPM/pbs.TPA; pbs.FTp = (float) pbs.FTM/pbs.FTA; } else { pbs = new PlayerBoxScore {PlayerID = newPlayer.ID, TeamID = newPlayer.TeamF, IsOut = true}; } bse.PBSList.Add(pbs); } bse.Date = DateTime.Today; bse.BS.GameDate = bse.Date; bse.BS.SeasonNum = MainWindow.CurSeason; return bse; }
/// <summary> /// Initializes a new instance of the <see cref="BoxScoreEntry" /> class. /// </summary> /// <param name="bs">The TeamBoxScore to initialize with.</param> public BoxScoreEntry(TeamBoxScore bs) { BS = bs; Date = DateTime.Now; }
/// <summary> /// OBSOLETE: /// Handles the Click event of the mnuHistoryBoxScores control. /// Used to open the Box Score window in View mode so that the user can view and edit any box score. /// Superseded by the Box Scores tab in the League Overview window. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e"> /// The <see cref="RoutedEventArgs" /> instance containing the event data. /// </param> private void mnuHistoryBoxScores_Click(object sender, RoutedEventArgs e) { if (SQLiteIO.IsTSTEmpty()) { return; } bs = new TeamBoxScore(); var bsw = new BoxScoreWindow(BoxScoreWindow.Mode.View); bsw.ShowDialog(); UpdateBoxScore(); }
/// <summary> /// Initializes a new instance of the <see cref="MainWindow" /> class. /// Creates the program's documents directories if needed, initializes structures, and loads the settings from registry. /// </summary> public MainWindow() { InitializeComponent(); MWInstance = this; bs = new TeamBoxScore(); Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); //btnInject.Visibility = Visibility.Hidden; #if DEBUG btnTest.Visibility = Visibility.Visible; #else btnTest.Visibility = Visibility.Hidden; #endif if (Directory.Exists(PSFiltersPath) == false) { Directory.CreateDirectory(PSFiltersPath); } if (Directory.Exists(ASCFiltersPath) == false) { Directory.CreateDirectory(ASCFiltersPath); } if (Directory.Exists(AppTempPath) == false) { Directory.CreateDirectory(AppTempPath); } TST[0] = new TeamStats(-1, "$$NewDB"); TSTOpp[0] = new TeamStats(-1, "$$NewDB"); for (int i = 0; i < 30; i++) { RealTST[i] = new TeamStats(); } RegistryKey rk = null; try { rk = Registry.CurrentUser; } catch (Exception ex) { App.ErrorReport(ex, "Registry.CurrentUser"); } Debug.Assert(rk != null, "rk != null"); rk = rk.OpenSubKey(@"SOFTWARE\2K Sports\NBA 2K12"); if (rk == null) { SavesPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\2K Sports\NBA 2K12\Saves\"; } else { try { SavesPath = rk.GetValue("Saves").ToString(); } catch (Exception) { SavesPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\2K Sports\NBA 2K12\Saves\"; } } // TODO: Re-enable downloading NBA stats when possible mnuFileGetRealStats.IsEnabled = false; btnDownloadBoxScore.IsEnabled = false; btnGrabNBAStats.IsEnabled = false; // if (App.RealNBAOnly) { // TODO: Re-enable downloading NBA stats when possible /* mnuFileGetRealStats_Click(null, null); MessageBox.Show("Nothing but net! Thanks for using NBA Stats Tracker!"); Environment.Exit(-1); */ // MessageBox.Show("This feature is temporarily disabled. Sorry for the inconvenience.", "NBA Stats Tracker", MessageBoxButton.OK, MessageBoxImage.Information); Environment.Exit(-1); } else { int importSetting = Misc.GetRegistrySetting("NBA2K12ImportMethod", 0); if (importSetting == 0) { mnuOptionsImportREDitor.IsChecked = true; } else { Misc.SetRegistrySetting("NBA2K12ImportMethod", 0); mnuOptionsImportREDitor.IsChecked = true; } int exportTeamsOnly = Misc.GetRegistrySetting("ExportTeamsOnly", 1); mnuOptionsExportTeamsOnly.IsChecked = exportTeamsOnly == 1; int compatibilityCheck = Misc.GetRegistrySetting("CompatibilityCheck", 1); mnuOptionsCompatibilityCheck.IsChecked = compatibilityCheck == 1; IsImperial = Misc.GetRegistrySetting("IsImperial", 1) == 1; mnuOptionsIsImperial.IsChecked = IsImperial; // Displays a message to urge the user to donate at the 50th start of the program. int timesStarted = Misc.GetRegistrySetting("TimesStarted", -1); if (timesStarted == -1) { Misc.SetRegistrySetting("TimesStarted", 1); } else if (timesStarted <= 50) { if (timesStarted == 50) { MessageBoxResult r = MessageBox.Show( "Hey there! This is a friendly reminder from the creator of NBA Stats Tracker.\n\n" + "You seem to like using NBA Stats Tracker a lot, and I'm sure you enjoy the fact that it's free. " + "However, if you believe that I deserve your support and you want to help me to continue my studies, " + "as well as continue developing and supporting NBA Stats Tracker, you can always donate!\n\n" + "Even a small amount can help a lot!\n\n" + "Would you like to find out how you can donate?\n\n" + "Clicking Cancel will make sure this message never shows up again.", "NBA Stats Tracker - A friendly reminder", MessageBoxButton.YesNoCancel, MessageBoxImage.Information); if (r == MessageBoxResult.Yes) { mnuHelpDonate_Click(null, null); } else if (r == MessageBoxResult.No) { timesStarted = -1; } } Misc.SetRegistrySetting("TimesStarted", timesStarted + 1); } } UIScheduler = TaskScheduler.FromCurrentSynchronizationContext(); List<string> metricsNames = PAbbr.MetricsNames; for (int i = 0; i < metricsNames.Count; i++) { string name = metricsNames[i]; PAbbr.MetricsDict.Add(name, double.NaN); } #region Keyboard Shortcuts CmndImport.InputGestures.Add(new KeyGesture(Key.I, ModifierKeys.Control)); CommandBindings.Add(new CommandBinding(CmndImport, btnImport2K12_Click)); CmndExport.InputGestures.Add(new KeyGesture(Key.E, ModifierKeys.Control)); CommandBindings.Add(new CommandBinding(CmndExport, btnExport2K12_Click)); CmndOpen.InputGestures.Add(new KeyGesture(Key.O, ModifierKeys.Control)); CommandBindings.Add(new CommandBinding(CmndOpen, FileOpen)); CmndSave.InputGestures.Add(new KeyGesture(Key.S, ModifierKeys.Control)); CommandBindings.Add(new CommandBinding(CmndSave, btnSaveCurrentSeason_Click)); #endregion //prepareImageCache(); }
/// <summary>Calculates the metrics of a player's performance.</summary> /// <param name="r"> /// The SQLite DataRow containing the player's box score. Should be the result of an INNER JOIN'ed query between /// PlayerResults and GameResults. /// </param> public void CalcMetrics(DataRow r) { var bs = new TeamBoxScore(r, null); var ts = new TeamStats(TeamID); var tsopp = new TeamStats(OppTeamID); var team1ID = ParseCell.GetInt32(r, "Team1ID"); var team2ID = ParseCell.GetInt32(r, "Team2ID"); if (TeamID == team1ID) { TeamStats.AddTeamStatsFromBoxScore(bs, ref ts, ref tsopp); } else { TeamStats.AddTeamStatsFromBoxScore(bs, ref tsopp, ref ts); } var ps = new PlayerStats { ID = PlayerID }; ps.AddBoxScore(this, bs.IsPlayoff); ps.CalcMetrics(ts, tsopp, new TeamStats(-1), GmScOnly: true); GmSc = ps.Metrics["GmSc"]; GmScE = ps.Metrics["GmScE"]; }
/// <summary> /// Handles the Click event of the btnLoadUpdate control. Opens the Box Score window to allow the user to update the team stats /// by entering a box score. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e"> /// The <see cref="RoutedEventArgs" /> instance containing the event data. /// </param> private async void btnLoadUpdate_Click(object sender, RoutedEventArgs e) { if (SQLiteIO.IsTSTEmpty()) { UpdateStatus("No file is loaded or the file currently loaded is empty"); return; } TempBSE_BS = new TeamBoxScore(); var bsW = new BoxScoreWindow(); bsW.ShowDialog(); await parseBoxScoreResult(); }
/// <summary>Calculates the metrics of a player's performance.</summary> /// <param name="bs">The game's box score from which to calculate the metrics.</param> public void CalcMetrics(TeamBoxScore bs) { var ts = new TeamStats(TeamID); var tsopp = new TeamStats(OppTeamID); var team1ID = bs.Team1ID; if (TeamID == team1ID) { TeamStats.AddTeamStatsFromBoxScore(bs, ref ts, ref tsopp); } else { TeamStats.AddTeamStatsFromBoxScore(bs, ref tsopp, ref ts); } var ps = new PlayerStats { ID = PlayerID }; ps.AddBoxScore(this, bs.IsPlayoff); ps.CalcMetrics(ts, tsopp, new TeamStats(-1), GmScOnly: true); GmSc = ps.Metrics["GmSc"]; GmScE = ps.Metrics["GmScE"]; }
/// <summary> /// Handles the Click event of the btnCalculateTeams control. Calculates the stats for each team from the totals of the /// corresponding player stats. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e"> /// The <see cref="RoutedEventArgs" /> instance containing the event data. /// </param> private void btnCalculateTeams_Click(object sender, RoutedEventArgs e) { var bs = new TeamBoxScore(); CalculateTeamsFromPlayers(ref bs, pbsAwayList, pbsHomeList); txtREB1.Text = bs.REB1.ToString(); txtAST1.Text = bs.AST1.ToString(); txtSTL1.Text = bs.STL1.ToString(); txtBLK1.Text = bs.BLK1.ToString(); txtTO1.Text = bs.TOS1.ToString(); txtFGM1.Text = bs.FGM1.ToString(); txtFGA1.Text = bs.FGA1.ToString(); txt3PM1.Text = bs.TPM1.ToString(); txt3PA1.Text = bs.TPA1.ToString(); txtFTM1.Text = bs.FTM1.ToString(); txtFTA1.Text = bs.FTA1.ToString(); txtOREB1.Text = bs.OREB1.ToString(); txtFOUL1.Text = bs.FOUL1.ToString(); txtREB2.Text = bs.REB2.ToString(); txtAST2.Text = bs.AST2.ToString(); txtSTL2.Text = bs.STL2.ToString(); txtBLK2.Text = bs.BLK2.ToString(); txtTO2.Text = bs.TOS2.ToString(); txtFGM2.Text = bs.FGM2.ToString(); txtFGA2.Text = bs.FGA2.ToString(); txt3PM2.Text = bs.TPM2.ToString(); txt3PA2.Text = bs.TPA2.ToString(); txtFTM2.Text = bs.FTM2.ToString(); txtFTA2.Text = bs.FTA2.ToString(); txtOREB2.Text = bs.OREB2.ToString(); txtFOUL2.Text = bs.FOUL2.ToString(); calculateScoreAway(); calculateScoreHome(); }
/// <summary> /// Initializes a new instance of the <see cref="BoxScoreEntry" /> class. /// </summary> /// <param name="bs">The TeamBoxScore to initialize with.</param> public BoxScoreEntry(TeamBoxScore bs) : this() { BS = bs; }
public static void CalculateTeamsFromPlayers( ref TeamBoxScore bs, IEnumerable<PlayerBoxScore> awayPBS, IEnumerable<PlayerBoxScore> homePBS) { ushort reb = 0, ast = 0, stl = 0, tos = 0, blk = 0, fgm = 0, fga = 0, tpm = 0, tpa = 0, ftm = 0, fta = 0, oreb = 0, foul = 0; foreach (var pbs in awayPBS) { reb += pbs.REB; ast += pbs.AST; stl += pbs.STL; tos += pbs.TOS; blk += pbs.BLK; fgm += pbs.FGM; fga += pbs.FGA; tpm += pbs.TPM; tpa += pbs.TPA; ftm += pbs.FTM; fta += pbs.FTA; oreb += pbs.OREB; foul += pbs.FOUL; } bs.REB1 = reb; bs.AST1 = ast; bs.STL1 = stl; bs.BLK1 = blk; bs.TOS1 = tos; bs.FGM1 = fgm; bs.FGA1 = fga; bs.TPM1 = tpm; bs.TPA1 = tpa; bs.FTM1 = ftm; bs.FTA1 = fta; bs.OREB1 = oreb; bs.FOUL1 = foul; bs.PTS1 = (ushort) (bs.FGM1 * 2 + bs.TPM1 + bs.FTM1); reb = 0; ast = 0; stl = 0; tos = 0; blk = 0; fgm = 0; fga = 0; tpm = 0; tpa = 0; ftm = 0; fta = 0; oreb = 0; foul = 0; foreach (var pbs in homePBS) { reb += pbs.REB; ast += pbs.AST; stl += pbs.STL; tos += pbs.TOS; blk += pbs.BLK; fgm += pbs.FGM; fga += pbs.FGA; tpm += pbs.TPM; tpa += pbs.TPA; ftm += pbs.FTM; fta += pbs.FTA; oreb += pbs.OREB; foul += pbs.FOUL; } bs.REB2 = reb; bs.AST2 = ast; bs.STL2 = stl; bs.BLK2 = blk; bs.TOS2 = tos; bs.FGM2 = fgm; bs.FGA2 = fga; bs.TPM2 = tpm; bs.TPA2 = tpa; bs.FTM2 = ftm; bs.FTA2 = fta; bs.OREB2 = oreb; bs.FOUL2 = foul; bs.PTS2 = (ushort) (bs.FGM2 * 2 + bs.TPM2 + bs.FTM2); }
/// <summary>Adds the team stats from a box score.</summary> /// <param name="bsToAdd">The box score to add.</param> /// <param name="ts1">The first team's team stats.</param> /// <param name="ts2">The second team's team stats.</param> /// <param name="ignorePlayoffFlag">Whether to ignore the playoff flag in the box score and add the stats to the season totals.</param> public static void AddTeamStatsFromBoxScore( TeamBoxScore bsToAdd, ref TeamStats ts1, ref TeamStats ts2, bool ignorePlayoffFlag = false) { var tst = new Dictionary<int, TeamStats> { { 1, ts1 }, { 2, ts2 } }; var tstOpp = new Dictionary<int, TeamStats> { { 1, new TeamStats() }, { 2, new TeamStats() } }; AddTeamStatsFromBoxScore(bsToAdd, ref tst, ref tstOpp, 1, 2, ignorePlayoffFlag); ts1 = tst[1]; ts2 = tst[2]; }
/// <summary>Finds the requested box score and loads it.</summary> /// <param name="id">The ID of the box score.</param> private void loadBoxScore(int id) { var bse = MainWindow.BSHist.Single(entry => entry.BS.ID == id); curTeamBoxScore = bse.BS; loadBoxScore(bse); }
/// <summary>Adds the team stats from a box score.</summary> /// <param name="bsToAdd">The box score to add.</param> /// <param name="tst">The team stats dictionary.</param> /// <param name="tstOpp">The opposing team stats dictionary.</param> /// <param name="id1">The away team's ID.</param> /// <param name="id2">The home team's ID.</param> public static void AddTeamStatsFromBoxScore( TeamBoxScore bsToAdd, ref Dictionary<int, TeamStats> tst, ref Dictionary<int, TeamStats> tstOpp, int id1, int id2, bool ignorePlayoffFlag = false) { var ts1 = tst[id1]; var ts2 = tst[id2]; var tsopp1 = tstOpp[id1]; var tsopp2 = tstOpp[id2]; if (!bsToAdd.IsPlayoff || ignorePlayoffFlag) { // Add win & loss if (bsToAdd.PTS1 > bsToAdd.PTS2) { ts1.Record[0]++; ts2.Record[1]++; } else { ts1.Record[1]++; ts2.Record[0]++; } // Add minutes played ts1.Totals[TAbbrT.MINS] += bsToAdd.MINS1; ts2.Totals[TAbbrT.MINS] += bsToAdd.MINS2; // Add Points For ts1.Totals[TAbbrT.PF] += bsToAdd.PTS1; ts2.Totals[TAbbrT.PF] += bsToAdd.PTS2; // Add Points Against ts1.Totals[TAbbrT.PA] += bsToAdd.PTS2; ts2.Totals[TAbbrT.PA] += bsToAdd.PTS1; // ts1.Totals[TAbbrT.FGM] += bsToAdd.FGM1; ts2.Totals[TAbbrT.FGM] += bsToAdd.FGM2; ts1.Totals[TAbbrT.FGA] += bsToAdd.FGA1; ts2.Totals[TAbbrT.FGA] += bsToAdd.FGA2; // ts1.Totals[TAbbrT.TPM] += bsToAdd.TPM1; ts2.Totals[TAbbrT.TPM] += bsToAdd.TPM2; // ts1.Totals[TAbbrT.TPA] += bsToAdd.TPA1; ts2.Totals[TAbbrT.TPA] += bsToAdd.TPA2; // ts1.Totals[TAbbrT.FTM] += bsToAdd.FTM1; ts2.Totals[TAbbrT.FTM] += bsToAdd.FTM2; // ts1.Totals[TAbbrT.FTA] += bsToAdd.FTA1; ts2.Totals[TAbbrT.FTA] += bsToAdd.FTA2; // ts1.Totals[TAbbrT.OREB] += bsToAdd.OREB1; ts2.Totals[TAbbrT.OREB] += bsToAdd.OREB2; // ts1.Totals[TAbbrT.DREB] += Convert.ToUInt16(bsToAdd.REB1 - bsToAdd.OREB1); ts2.Totals[TAbbrT.DREB] += Convert.ToUInt16(bsToAdd.REB2 - bsToAdd.OREB2); // ts1.Totals[TAbbrT.STL] += bsToAdd.STL1; ts2.Totals[TAbbrT.STL] += bsToAdd.STL2; // ts1.Totals[TAbbrT.TOS] += bsToAdd.TOS1; ts2.Totals[TAbbrT.TOS] += bsToAdd.TOS2; // ts1.Totals[TAbbrT.BLK] += bsToAdd.BLK1; ts2.Totals[TAbbrT.BLK] += bsToAdd.BLK2; // ts1.Totals[TAbbrT.AST] += bsToAdd.AST1; ts2.Totals[TAbbrT.AST] += bsToAdd.AST2; // ts1.Totals[TAbbrT.FOUL] += bsToAdd.FOUL1; ts2.Totals[TAbbrT.FOUL] += bsToAdd.FOUL2; // Opponents Team Stats // Add win & loss if (bsToAdd.PTS1 > bsToAdd.PTS2) { tsopp2.Record[0]++; tsopp1.Record[1]++; } else { tsopp2.Record[1]++; tsopp1.Record[0]++; } // Add minutes played tsopp2.Totals[TAbbrT.MINS] += bsToAdd.MINS1; tsopp1.Totals[TAbbrT.MINS] += bsToAdd.MINS2; // Add Points For tsopp2.Totals[TAbbrT.PF] += bsToAdd.PTS1; tsopp1.Totals[TAbbrT.PF] += bsToAdd.PTS2; // Add Points Against tsopp2.Totals[TAbbrT.PA] += bsToAdd.PTS2; tsopp1.Totals[TAbbrT.PA] += bsToAdd.PTS1; // tsopp2.Totals[TAbbrT.FGM] += bsToAdd.FGM1; tsopp1.Totals[TAbbrT.FGM] += bsToAdd.FGM2; tsopp2.Totals[TAbbrT.FGA] += bsToAdd.FGA1; tsopp1.Totals[TAbbrT.FGA] += bsToAdd.FGA2; // tsopp2.Totals[TAbbrT.TPM] += bsToAdd.TPM1; tsopp1.Totals[TAbbrT.TPM] += bsToAdd.TPM2; // tsopp2.Totals[TAbbrT.TPA] += bsToAdd.TPA1; tsopp1.Totals[TAbbrT.TPA] += bsToAdd.TPA2; // tsopp2.Totals[TAbbrT.FTM] += bsToAdd.FTM1; tsopp1.Totals[TAbbrT.FTM] += bsToAdd.FTM2; // tsopp2.Totals[TAbbrT.FTA] += bsToAdd.FTA1; tsopp1.Totals[TAbbrT.FTA] += bsToAdd.FTA2; // tsopp2.Totals[TAbbrT.OREB] += bsToAdd.OREB1; tsopp1.Totals[TAbbrT.OREB] += bsToAdd.OREB2; // tsopp2.Totals[TAbbrT.DREB] += Convert.ToUInt16(bsToAdd.REB1 - bsToAdd.OREB1); tsopp1.Totals[TAbbrT.DREB] += Convert.ToUInt16(bsToAdd.REB2 - bsToAdd.OREB2); // tsopp2.Totals[TAbbrT.STL] += bsToAdd.STL1; tsopp1.Totals[TAbbrT.STL] += bsToAdd.STL2; // tsopp2.Totals[TAbbrT.TOS] += bsToAdd.TOS1; tsopp1.Totals[TAbbrT.TOS] += bsToAdd.TOS2; // tsopp2.Totals[TAbbrT.BLK] += bsToAdd.BLK1; tsopp1.Totals[TAbbrT.BLK] += bsToAdd.BLK2; // tsopp2.Totals[TAbbrT.AST] += bsToAdd.AST1; tsopp1.Totals[TAbbrT.AST] += bsToAdd.AST2; // tsopp2.Totals[TAbbrT.FOUL] += bsToAdd.FOUL1; tsopp1.Totals[TAbbrT.FOUL] += bsToAdd.FOUL2; } else { // Add win & loss if (bsToAdd.PTS1 > bsToAdd.PTS2) { ts1.PlRecord[0]++; ts2.PlRecord[1]++; } else { ts1.PlRecord[1]++; ts2.PlRecord[0]++; } // Add minutes played ts1.PlTotals[TAbbrT.MINS] += bsToAdd.MINS1; ts2.PlTotals[TAbbrT.MINS] += bsToAdd.MINS2; // Add Points For ts1.PlTotals[TAbbrT.PF] += bsToAdd.PTS1; ts2.PlTotals[TAbbrT.PF] += bsToAdd.PTS2; // Add Points Against ts1.PlTotals[TAbbrT.PA] += bsToAdd.PTS2; ts2.PlTotals[TAbbrT.PA] += bsToAdd.PTS1; // ts1.PlTotals[TAbbrT.FGM] += bsToAdd.FGM1; ts2.PlTotals[TAbbrT.FGM] += bsToAdd.FGM2; ts1.PlTotals[TAbbrT.FGA] += bsToAdd.FGA1; ts2.PlTotals[TAbbrT.FGA] += bsToAdd.FGA2; // ts1.PlTotals[TAbbrT.TPM] += bsToAdd.TPM1; ts2.PlTotals[TAbbrT.TPM] += bsToAdd.TPM2; // ts1.PlTotals[TAbbrT.TPA] += bsToAdd.TPA1; ts2.PlTotals[TAbbrT.TPA] += bsToAdd.TPA2; // ts1.PlTotals[TAbbrT.FTM] += bsToAdd.FTM1; ts2.PlTotals[TAbbrT.FTM] += bsToAdd.FTM2; // ts1.PlTotals[TAbbrT.FTA] += bsToAdd.FTA1; ts2.PlTotals[TAbbrT.FTA] += bsToAdd.FTA2; // ts1.PlTotals[TAbbrT.OREB] += bsToAdd.OREB1; ts2.PlTotals[TAbbrT.OREB] += bsToAdd.OREB2; // ts1.PlTotals[TAbbrT.DREB] += Convert.ToUInt16(bsToAdd.REB1 - bsToAdd.OREB1); ts2.PlTotals[TAbbrT.DREB] += Convert.ToUInt16(bsToAdd.REB2 - bsToAdd.OREB2); // ts1.PlTotals[TAbbrT.STL] += bsToAdd.STL1; ts2.PlTotals[TAbbrT.STL] += bsToAdd.STL2; // ts1.PlTotals[TAbbrT.TOS] += bsToAdd.TOS1; ts2.PlTotals[TAbbrT.TOS] += bsToAdd.TOS2; // ts1.PlTotals[TAbbrT.BLK] += bsToAdd.BLK1; ts2.PlTotals[TAbbrT.BLK] += bsToAdd.BLK2; // ts1.PlTotals[TAbbrT.AST] += bsToAdd.AST1; ts2.PlTotals[TAbbrT.AST] += bsToAdd.AST2; // ts1.PlTotals[TAbbrT.FOUL] += bsToAdd.FOUL1; ts2.PlTotals[TAbbrT.FOUL] += bsToAdd.FOUL2; // Opponents Team Stats // Add win & loss if (bsToAdd.PTS1 > bsToAdd.PTS2) { tsopp2.PlRecord[0]++; tsopp1.PlRecord[1]++; } else { tsopp2.PlRecord[1]++; tsopp1.PlRecord[0]++; } // Add minutes played tsopp2.PlTotals[TAbbrT.MINS] += bsToAdd.MINS1; tsopp1.PlTotals[TAbbrT.MINS] += bsToAdd.MINS2; // Add Points For tsopp2.PlTotals[TAbbrT.PF] += bsToAdd.PTS1; tsopp1.PlTotals[TAbbrT.PF] += bsToAdd.PTS2; // Add Points Against tsopp2.PlTotals[TAbbrT.PA] += bsToAdd.PTS2; tsopp1.PlTotals[TAbbrT.PA] += bsToAdd.PTS1; // tsopp2.PlTotals[TAbbrT.FGM] += bsToAdd.FGM1; tsopp1.PlTotals[TAbbrT.FGM] += bsToAdd.FGM2; tsopp2.PlTotals[TAbbrT.FGA] += bsToAdd.FGA1; tsopp1.PlTotals[TAbbrT.FGA] += bsToAdd.FGA2; // tsopp2.PlTotals[TAbbrT.TPM] += bsToAdd.TPM1; tsopp1.PlTotals[TAbbrT.TPM] += bsToAdd.TPM2; // tsopp2.PlTotals[TAbbrT.TPA] += bsToAdd.TPA1; tsopp1.PlTotals[TAbbrT.TPA] += bsToAdd.TPA2; // tsopp2.PlTotals[TAbbrT.FTM] += bsToAdd.FTM1; tsopp1.PlTotals[TAbbrT.FTM] += bsToAdd.FTM2; // tsopp2.PlTotals[TAbbrT.FTA] += bsToAdd.FTA1; tsopp1.PlTotals[TAbbrT.FTA] += bsToAdd.FTA2; // tsopp2.PlTotals[TAbbrT.OREB] += bsToAdd.OREB1; tsopp1.PlTotals[TAbbrT.OREB] += bsToAdd.OREB2; // tsopp2.PlTotals[TAbbrT.DREB] += Convert.ToUInt16(bsToAdd.REB1 - bsToAdd.OREB1); tsopp1.PlTotals[TAbbrT.DREB] += Convert.ToUInt16(bsToAdd.REB2 - bsToAdd.OREB2); // tsopp2.PlTotals[TAbbrT.STL] += bsToAdd.STL1; tsopp1.PlTotals[TAbbrT.STL] += bsToAdd.STL2; // tsopp2.PlTotals[TAbbrT.TOS] += bsToAdd.TOS1; tsopp1.PlTotals[TAbbrT.TOS] += bsToAdd.TOS2; // tsopp2.PlTotals[TAbbrT.BLK] += bsToAdd.BLK1; tsopp1.PlTotals[TAbbrT.BLK] += bsToAdd.BLK2; // tsopp2.PlTotals[TAbbrT.AST] += bsToAdd.AST1; tsopp1.PlTotals[TAbbrT.AST] += bsToAdd.AST2; // tsopp2.PlTotals[TAbbrT.FOUL] += bsToAdd.FOUL1; tsopp1.PlTotals[TAbbrT.FOUL] += bsToAdd.FOUL2; } ts1.CalcAvg(); ts2.CalcAvg(); tsopp1.CalcAvg(); tsopp2.CalcAvg(); tst[id1] = ts1; tst[id2] = ts2; tstOpp[id1] = tsopp1; tstOpp[id2] = tsopp2; }
private void finishInitialization(Mode curMode) { _pst = MainWindow.PST; _curMode = curMode; prepareWindow(curMode); MainWindow.bs = new TeamBoxScore(); if (curMode == Mode.Update) { _curTeamBoxScore = new TeamBoxScore(); } try { ProgressWindow.PwInstance.CanClose = true; ProgressWindow.PwInstance.Close(); } catch { Console.WriteLine("ProgressWindow couldn't be closed; maybe it wasn't open."); } IsEnabled = true; }