From 7c22b9856d783d5e79e631131284ac1416864792 Mon Sep 17 00:00:00 2001 From: Trey Brittain Date: Wed, 17 May 2023 09:55:26 -0500 Subject: [PATCH 01/12] Update SeasonStatsPitching to include retired players (with caveat of some data loss in far past seasons) --- .../Resources/Sql/SeasonStatsPitching.sql | 99 ++++++++++++------- 1 file changed, 64 insertions(+), 35 deletions(-) diff --git a/SMB3Explorer/Resources/Sql/SeasonStatsPitching.sql b/SMB3Explorer/Resources/Sql/SeasonStatsPitching.sql index 5173d8a..57e56c6 100644 --- a/SMB3Explorer/Resources/Sql/SeasonStatsPitching.sql +++ b/SMB3Explorer/Resources/Sql/SeasonStatsPitching.sql @@ -8,46 +8,75 @@ JOIN t_leagues ON t_seasons.historicalLeagueGUID = t_leagues.GUID JOIN t_franchise tf ON t_leagues.GUID = tf.leagueGUID WHERE t_leagues.GUID = CAST(@leagueId AS BLOB)) -SELECT baseballPlayerGUID, - tsea.completionDate, - tsea.ID AS seasonId, +SELECT ts.aggregatorID AS aggregatorID, + ts.statsPlayerID AS statsPlayerID, + tbpli.GUID AS baseballPlayerGUIDIfKnown, + s.seasonID, s.seasonNum, + currentTeam.teamName AS teamName, + mostRecentTeam.teamName AS mostRecentlyPlayedTeamName, + previouslyRecentPlayedTeam.teamName AS previousRecentlyPlayedTeamName, CASE - WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[firstName] - ELSE vbpi.[firstName] END AS firstName, + WHEN tsplayers.baseballPlayerLocalID IS NULL THEN tsplayers.firstName + ELSE vbpi.firstName END AS firstName, CASE - WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[lastName] - ELSE vbpi.[lastName] END AS lastName, + WHEN tsplayers.[baseballPlayerLocalID] IS NULL THEN tsplayers.lastName + ELSE vbpi.lastName END AS lastName, CASE - WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[primaryPos] - ELSE vbpi.[primaryPosition] END AS primaryPosition, + WHEN tsplayers.baseballPlayerLocalID IS NULL THEN tsplayers.primaryPos + ELSE vbpi.primaryPosition END AS primaryPosition, CASE - WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[pitcherRole] - ELSE vbpi.[pitcherRole] END AS pitcherRole, - tspitch.*, - currentTeam.teamName AS currentTeam, - previousTeam.teamName AS previousTeam, - tbp.age - (MAX(seasonNum) OVER (PARTITION BY baseballPlayerGUID) - seasonNum) AS age -FROM [v_baseball_player_info] vbpi - LEFT JOIN t_baseball_player_local_ids tbpli ON vbpi.baseballPlayerGUID = tbpli.GUID - LEFT JOIN t_stats_players tsp ON tbpli.localID = tsp.baseballPlayerLocalID - LEFT JOIN t_stats ts ON tsp.statsPlayerID = ts.statsPlayerID - JOIN t_stats_pitching tspitch ON ts.aggregatorID = tspitch.aggregatorID - - LEFT JOIN t_baseball_players tbp ON tbpli.GUID = tbp.GUID - - LEFT JOIN t_season_stats tss ON ts.aggregatorID = tss.aggregatorID + WHEN tsplayers.baseballPlayerLocalID IS NULL THEN tsplayers.pitcherRole + ELSE vbpi.pitcherRole END AS pitcherRole, + CASE + WHEN tbp.GUID IS NOT NULL THEN + tbp.age - (MAX(seasonNum) OVER (PARTITION BY baseballPlayerGUID) - seasonNum) + ELSE tsplayers.age - (tsplayers.retirementSeason - s.seasonNum) + END AS age, + wins, + losses, + games, + gamesStarted, + completeGames, + totalPitches, + shutouts, + saves, + outsPitched, + hits, + earnedRuns, + homeRuns, + baseOnBalls, + strikeOuts, + battersHitByPitch, + battersFaced, + gamesFinished, + runsAllowed, + wildPitches +FROM t_stats_pitching tsp + JOIN t_stats ts ON tsp.aggregatorID = ts.aggregatorID + JOIN t_stats_players tsplayers USING (statsPlayerID) + JOIN t_season_stats tss USING (aggregatorID) + JOIN seasons s USING (seasonID) - JOIN t_seasons tsea ON tss.seasonID = tsea.ID - JOIN seasons s ON tsea.ID = s.seasonID - JOIN t_league_local_ids tlli ON tsp.leagueLocalID = tlli.localID - JOIN t_leagues tl ON tlli.GUID = tl.GUID + LEFT JOIN t_team_local_ids currentTeamLocal ON ts.currentTeamLocalID = currentTeamLocal.localID + LEFT JOIN t_team_local_ids mostRecentTeamLocal + ON ts.mostRecentlyPlayedTeamLocalID = mostRecentTeamLocal.localID + LEFT JOIN t_team_local_ids previouslyRecentPlayedTeamLocal + ON ts.previousRecentlyPlayedTeamLocalID = previouslyRecentPlayedTeamLocal.localID - LEFT JOIN [t_team_local_ids] tt1 ON ts.[currentTeamLocalID] = tt1.[localID] - LEFT JOIN [t_team_local_ids] tt2 - ON ts.[previousRecentlyPlayedTeamLocalID] = tt2.[localID] - LEFT JOIN teams currentTeam ON tt1.GUID = currentTeam.teamGUID - LEFT JOIN teams previousTeam ON tt2.GUID = previousTeam.teamGUID + LEFT JOIN teams currentTeam ON currentTeamLocal.GUID = currentTeam.teamGUID + LEFT JOIN teams mostRecentTeam ON mostRecentTeamLocal.GUID = mostRecentTeam.teamGUID + LEFT JOIN teams previouslyRecentPlayedTeam + ON previouslyRecentPlayedTeamLocal.GUID = previouslyRecentPlayedTeam.teamGUID -WHERE tl.GUID = CAST(@leagueId AS BLOB) -ORDER BY baseballPlayerGUID \ No newline at end of file + LEFT JOIN t_baseball_player_local_ids tbpli + ON tsplayers.baseballPlayerLocalID = tbpli.localID + LEFT JOIN t_baseball_players tbp on tbpli.GUID = tbp.GUID + LEFT JOIN v_baseball_player_info vbpi + ON tbpli.GUID = vbpi.baseballPlayerGUID +WHERE 1 = CASE + WHEN :seasonId IS NOT NULL THEN CASE + WHEN s.seasonID = :seasonId THEN 1 + ELSE 0 END + ELSE 1 END +ORDER BY s.seasonNum, ts.aggregatorID; From 0b5c4aee9abcc83ae27bc6f818a275e45d1e64a1 Mon Sep 17 00:00:00 2001 From: Trey Brittain Date: Wed, 17 May 2023 10:59:12 -0500 Subject: [PATCH 02/12] Modified sort order on season/playoff pitching stats scripts --- .../Resources/Sql/PlayoffStatsPitching.sql | 97 ++++++++++++------- .../Resources/Sql/SeasonStatsPitching.sql | 2 +- 2 files changed, 65 insertions(+), 34 deletions(-) diff --git a/SMB3Explorer/Resources/Sql/PlayoffStatsPitching.sql b/SMB3Explorer/Resources/Sql/PlayoffStatsPitching.sql index 5ef07e0..b18d3df 100644 --- a/SMB3Explorer/Resources/Sql/PlayoffStatsPitching.sql +++ b/SMB3Explorer/Resources/Sql/PlayoffStatsPitching.sql @@ -8,44 +8,75 @@ JOIN t_leagues ON t_seasons.historicalLeagueGUID = t_leagues.GUID JOIN t_franchise tf ON t_leagues.GUID = tf.leagueGUID WHERE t_leagues.GUID = CAST(@leagueId AS BLOB)) -SELECT baseballPlayerGUID, - tsea.completionDate, - tsea.ID AS seasonId, +SELECT ts.aggregatorID AS aggregatorID, + ts.statsPlayerID AS statsPlayerID, + tbpli.GUID AS baseballPlayerGUIDIfKnown, + s.seasonID, s.seasonNum, + currentTeam.teamName AS teamName, + mostRecentTeam.teamName AS mostRecentlyPlayedTeamName, + previouslyRecentPlayedTeam.teamName AS previousRecentlyPlayedTeamName, CASE - WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[firstName] - ELSE vbpi.[firstName] END AS firstName, + WHEN tsplayers.baseballPlayerLocalID IS NULL THEN tsplayers.firstName + ELSE vbpi.firstName END AS firstName, CASE - WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[lastName] - ELSE vbpi.[lastName] END AS lastName, + WHEN tsplayers.[baseballPlayerLocalID] IS NULL THEN tsplayers.lastName + ELSE vbpi.lastName END AS lastName, CASE - WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[primaryPos] - ELSE vbpi.[primaryPosition] END AS primaryPosition, + WHEN tsplayers.baseballPlayerLocalID IS NULL THEN tsplayers.primaryPos + ELSE vbpi.primaryPosition END AS primaryPosition, CASE - WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[pitcherRole] - ELSE vbpi.[pitcherRole] END AS pitcherRole, - tspitch.*, - currentTeam.teamName AS currentTeam, - tbp.age - (MAX(seasonNum) OVER (PARTITION BY baseballPlayerGUID) - seasonNum) AS age -FROM [v_baseball_player_info] vbpi - LEFT JOIN t_baseball_player_local_ids tbpli ON vbpi.baseballPlayerGUID = tbpli.GUID - LEFT JOIN t_stats_players tsp ON tbpli.localID = tsp.baseballPlayerLocalID - LEFT JOIN t_stats ts ON tsp.statsPlayerID = ts.statsPlayerID - JOIN t_stats_pitching tspitch ON ts.aggregatorID = tspitch.aggregatorID - - LEFT JOIN t_baseball_players tbp ON tbpli.GUID = tbp.GUID - - LEFT JOIN t_playoff_stats tps ON ts.aggregatorID = tps.aggregatorID + WHEN tsplayers.baseballPlayerLocalID IS NULL THEN tsplayers.pitcherRole + ELSE vbpi.pitcherRole END AS pitcherRole, + CASE + WHEN tbp.GUID IS NOT NULL THEN + tbp.age - (MAX(seasonNum) OVER (PARTITION BY baseballPlayerGUID) - seasonNum) + ELSE tsplayers.age - (tsplayers.retirementSeason - s.seasonNum) + END AS age, + wins, + losses, + games, + gamesStarted, + completeGames, + totalPitches, + shutouts, + saves, + outsPitched, + hits, + earnedRuns, + homeRuns, + baseOnBalls, + strikeOuts, + battersHitByPitch, + battersFaced, + gamesFinished, + runsAllowed, + wildPitches +FROM t_stats_pitching tsp + JOIN t_stats ts ON tsp.aggregatorID = ts.aggregatorID + JOIN t_stats_players tsplayers USING (statsPlayerID) + JOIN t_playoff_stats tps USING (aggregatorID) + JOIN seasons s USING (seasonID) - JOIN t_seasons tsea ON tps.seasonID = tsea.ID - JOIN seasons s ON tsea.ID = s.seasonID - JOIN t_league_local_ids tlli ON tsp.leagueLocalID = tlli.localID - JOIN t_leagues tl ON tlli.GUID = tl.GUID + LEFT JOIN t_team_local_ids currentTeamLocal ON ts.currentTeamLocalID = currentTeamLocal.localID + LEFT JOIN t_team_local_ids mostRecentTeamLocal + ON ts.mostRecentlyPlayedTeamLocalID = mostRecentTeamLocal.localID + LEFT JOIN t_team_local_ids previouslyRecentPlayedTeamLocal + ON ts.previousRecentlyPlayedTeamLocalID = previouslyRecentPlayedTeamLocal.localID - LEFT JOIN [t_team_local_ids] tt1 ON ts.[currentTeamLocalID] = tt1.[localID] - LEFT JOIN [t_team_local_ids] tt2 - ON ts.[previousRecentlyPlayedTeamLocalID] = tt2.[localID] - LEFT JOIN teams currentTeam ON tt1.GUID = currentTeam.teamGUID + LEFT JOIN teams currentTeam ON currentTeamLocal.GUID = currentTeam.teamGUID + LEFT JOIN teams mostRecentTeam ON mostRecentTeamLocal.GUID = mostRecentTeam.teamGUID + LEFT JOIN teams previouslyRecentPlayedTeam + ON previouslyRecentPlayedTeamLocal.GUID = previouslyRecentPlayedTeam.teamGUID -WHERE tl.GUID = CAST(@leagueId AS BLOB) -ORDER BY baseballPlayerGUID \ No newline at end of file + LEFT JOIN t_baseball_player_local_ids tbpli + ON tsplayers.baseballPlayerLocalID = tbpli.localID + LEFT JOIN t_baseball_players tbp on tbpli.GUID = tbp.GUID + LEFT JOIN v_baseball_player_info vbpi + ON tbpli.GUID = vbpi.baseballPlayerGUID +WHERE 1 = CASE + WHEN :seasonId IS NOT NULL THEN CASE + WHEN s.seasonID = :seasonId THEN 1 + ELSE 0 END + ELSE 1 END +ORDER BY s.seasonNum, ts.statsPlayerID; diff --git a/SMB3Explorer/Resources/Sql/SeasonStatsPitching.sql b/SMB3Explorer/Resources/Sql/SeasonStatsPitching.sql index 57e56c6..a994ea3 100644 --- a/SMB3Explorer/Resources/Sql/SeasonStatsPitching.sql +++ b/SMB3Explorer/Resources/Sql/SeasonStatsPitching.sql @@ -79,4 +79,4 @@ WHERE 1 = CASE WHEN s.seasonID = :seasonId THEN 1 ELSE 0 END ELSE 1 END -ORDER BY s.seasonNum, ts.aggregatorID; +ORDER BY s.seasonNum, ts.statsPlayerID; From e561f8d68eebe252a1f187ea408ebec1de7f4c65 Mon Sep 17 00:00:00 2001 From: Trey Brittain Date: Wed, 17 May 2023 11:10:38 -0500 Subject: [PATCH 03/12] Update season/playoff batting stats with same changes for pitching --- .../Resources/Sql/PlayoffStatsBatting.sql | 90 ++++++++++-------- .../Resources/Sql/SeasonStatsBatting.sql | 92 +++++++++++-------- 2 files changed, 104 insertions(+), 78 deletions(-) diff --git a/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql b/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql index 7789114..95a325b 100644 --- a/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql +++ b/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql @@ -8,48 +8,62 @@ JOIN t_leagues ON t_seasons.historicalLeagueGUID = t_leagues.GUID JOIN t_franchise tf ON t_leagues.GUID = tf.leagueGUID WHERE t_leagues.GUID = CAST(@leagueId AS BLOB)) -SELECT baseballPlayerGUID, - tsea.completionDate, - tsea.ID AS seasonId, +SELECT ts.aggregatorID AS aggregatorID, + ts.statsPlayerID AS statsPlayerID, + tbpli.GUID AS baseballPlayerGUIDIfKnown, + s.seasonID, s.seasonNum, + currentTeamLocal.GUID AS teamGUID, + mostRecentTeamLocal.GUID AS mostRecentlyPlayedTeamGUID, + previouslyRecentTeam.GUID AS previousRecentlyPlayedTeamGUID, CASE - WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[firstName] - ELSE vbpi.[firstName] END AS firstName, + WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.firstName + ELSE vbpi.firstName END AS firstName, CASE - WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[lastName] - ELSE vbpi.[lastName] END AS lastName, + WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.lastName + ELSE vbpi.lastName END AS lastName, CASE - WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[primaryPos] - ELSE vbpi.[primaryPosition] END AS primaryPosition, + WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.primaryPos + ELSE vbpi.primaryPosition END AS primaryPosition, CASE - WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[pitcherRole] - ELSE vbpi.[pitcherRole] END AS pitcherRole, - CAST(secondaryPosition.optionValue AS INTEGER) AS secondaryPosition, - tsb.*, - currentTeam.teamName AS currentTeam, - tbp.age - (MAX(seasonNum) OVER (PARTITION BY baseballPlayerGUID) - seasonNum) AS age -FROM [v_baseball_player_info] vbpi - LEFT JOIN t_baseball_player_local_ids tbpli ON vbpi.baseballPlayerGUID = tbpli.GUID - LEFT JOIN t_stats_players tsp ON tbpli.localID = tsp.baseballPlayerLocalID - LEFT JOIN t_stats ts ON tsp.statsPlayerID = ts.statsPlayerID - LEFT JOIN t_stats_batting tsb ON ts.aggregatorID = tsb.aggregatorID + WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.pitcherRole + ELSE vbpi.pitcherRole END AS pitcherRole, + gamesBatting, + atBats, + runs, + hits, + doubles, + triples, + homeruns, + rbi, + stolenBases, + caughtStealing, + baseOnBalls, + strikeOuts, + hitByPitch, + sacrificeHits, + sacrificeFlies, + errors, + passedBalls +FROM t_stats_batting tsb + JOIN t_stats ts ON tsb.aggregatorID = ts.aggregatorID + JOIN t_stats_players tsp USING (statsPlayerID) + JOIN t_playoff_stats tps USING (aggregatorID) + JOIN seasons s USING (seasonID) - LEFT JOIN t_baseball_players tbp ON tbpli.GUID = tbp.GUID + LEFT JOIN t_team_local_ids currentTeamLocal ON ts.currentTeamLocalID = currentTeamLocal.localID + LEFT JOIN t_team_local_ids mostRecentTeamLocal + ON ts.mostRecentlyPlayedTeamLocalID = mostRecentTeamLocal.localID + LEFT JOIN t_team_local_ids previouslyRecentTeam + ON ts.previousRecentlyPlayedTeamLocalID = previouslyRecentTeam.localID - LEFT JOIN t_playoff_stats tps ON ts.aggregatorID = tps.aggregatorID - - JOIN t_seasons tsea ON tps.seasonID = tsea.ID - JOIN seasons s ON tsea.ID = s.seasonID - JOIN t_league_local_ids tlli ON tsp.leagueLocalID = tlli.localID - JOIN t_leagues tl ON tlli.GUID = tl.GUID - - LEFT JOIN t_baseball_player_options secondaryPosition - ON tbpli.localID = secondaryPosition.baseballPlayerLocalID AND secondaryPosition.optionKey = 55 - - LEFT JOIN [t_team_local_ids] tt1 ON ts.[currentTeamLocalID] = tt1.[localID] - LEFT JOIN [t_team_local_ids] tt2 - ON ts.[previousRecentlyPlayedTeamLocalID] = tt2.[localID] - LEFT JOIN teams currentTeam ON tt1.GUID = currentTeam.teamGUID - -WHERE tl.GUID = CAST(@leagueId AS BLOB) -ORDER BY baseballPlayerGUID \ No newline at end of file + LEFT JOIN t_baseball_player_local_ids tbpli + ON tsp.baseballPlayerLocalID = tbpli.localID + LEFT JOIN v_baseball_player_info vbpi ON tbpli.GUID = + vbpi.baseballPlayerGUID +WHERE 1 = CASE + WHEN :seasonId IS NOT NULL THEN CASE + WHEN s.seasonID = :seasonId THEN 1 + ELSE 0 END + ELSE 1 END +ORDER BY s.seasonNum, ts.statsPlayerID; diff --git a/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql b/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql index 053cf83..52f8f7e 100644 --- a/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql +++ b/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql @@ -8,50 +8,62 @@ JOIN t_leagues ON t_seasons.historicalLeagueGUID = t_leagues.GUID JOIN t_franchise tf ON t_leagues.GUID = tf.leagueGUID WHERE t_leagues.GUID = CAST(@leagueId AS BLOB)) -SELECT baseballPlayerGUID, - tsea.completionDate, - tsea.ID AS seasonId, +SELECT ts.aggregatorID AS aggregatorID, + ts.statsPlayerID AS statsPlayerID, + tbpli.GUID AS baseballPlayerGUIDIfKnown, + s.seasonID, s.seasonNum, + currentTeamLocal.GUID AS teamGUID, + mostRecentTeamLocal.GUID AS mostRecentlyPlayedTeamGUID, + previouslyRecentTeam.GUID AS previousRecentlyPlayedTeamGUID, CASE - WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[firstName] - ELSE vbpi.[firstName] END AS firstName, + WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.firstName + ELSE vbpi.firstName END AS firstName, CASE - WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[lastName] - ELSE vbpi.[lastName] END AS lastName, + WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.lastName + ELSE vbpi.lastName END AS lastName, CASE - WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[primaryPos] - ELSE vbpi.[primaryPosition] END AS primaryPosition, + WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.primaryPos + ELSE vbpi.primaryPosition END AS primaryPosition, CASE - WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[pitcherRole] - ELSE vbpi.[pitcherRole] END AS pitcherRole, - CAST(secondaryPosition.optionValue AS INTEGER) AS secondaryPosition, - tsb.*, - currentTeam.teamName AS currentTeam, - previousTeam.teamName AS previousTeam, - tbp.age - (MAX(seasonNum) OVER (PARTITION BY baseballPlayerGUID) - seasonNum) AS age -FROM [v_baseball_player_info] vbpi - LEFT JOIN t_baseball_player_local_ids tbpli ON vbpi.baseballPlayerGUID = tbpli.GUID - LEFT JOIN t_stats_players tsp ON tbpli.localID = tsp.baseballPlayerLocalID - LEFT JOIN t_stats ts ON tsp.statsPlayerID = ts.statsPlayerID - LEFT JOIN t_stats_batting tsb ON ts.aggregatorID = tsb.aggregatorID + WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.pitcherRole + ELSE vbpi.pitcherRole END AS pitcherRole, + gamesBatting, + atBats, + runs, + hits, + doubles, + triples, + homeruns, + rbi, + stolenBases, + caughtStealing, + baseOnBalls, + strikeOuts, + hitByPitch, + sacrificeHits, + sacrificeFlies, + errors, + passedBalls +FROM t_stats_batting tsb + JOIN t_stats ts ON tsb.aggregatorID = ts.aggregatorID + JOIN t_stats_players tsp USING (statsPlayerID) + JOIN t_season_stats tss USING (aggregatorID) + JOIN seasons s USING (seasonID) - LEFT JOIN t_baseball_players tbp ON tbpli.GUID = tbp.GUID + LEFT JOIN t_team_local_ids currentTeamLocal ON ts.currentTeamLocalID = currentTeamLocal.localID + LEFT JOIN t_team_local_ids mostRecentTeamLocal + ON ts.mostRecentlyPlayedTeamLocalID = mostRecentTeamLocal.localID + LEFT JOIN t_team_local_ids previouslyRecentTeam + ON ts.previousRecentlyPlayedTeamLocalID = previouslyRecentTeam.localID - LEFT JOIN t_season_stats tss ON ts.aggregatorID = tss.aggregatorID - - JOIN t_seasons tsea ON tss.seasonID = tsea.ID - JOIN seasons s ON tsea.ID = s.seasonID - JOIN t_league_local_ids tlli ON tsp.leagueLocalID = tlli.localID - JOIN t_leagues tl ON tlli.GUID = tl.GUID - - LEFT JOIN t_baseball_player_options secondaryPosition - ON tbpli.localID = secondaryPosition.baseballPlayerLocalID AND secondaryPosition.optionKey = 55 - - LEFT JOIN [t_team_local_ids] tt1 ON ts.[currentTeamLocalID] = tt1.[localID] - LEFT JOIN [t_team_local_ids] tt2 - ON ts.[previousRecentlyPlayedTeamLocalID] = tt2.[localID] - LEFT JOIN teams currentTeam ON tt1.GUID = currentTeam.teamGUID - LEFT JOIN teams previousTeam ON tt2.GUID = previousTeam.teamGUID - -WHERE tl.GUID = CAST(@leagueId AS BLOB) -ORDER BY baseballPlayerGUID, seasonNum \ No newline at end of file + LEFT JOIN t_baseball_player_local_ids tbpli + ON tsp.baseballPlayerLocalID = tbpli.localID + LEFT JOIN v_baseball_player_info vbpi ON tbpli.GUID = + vbpi.baseballPlayerGUID +WHERE 1 = CASE + WHEN :seasonId IS NOT NULL THEN CASE + WHEN s.seasonID = :seasonId THEN 1 + ELSE 0 END + ELSE 1 END +ORDER BY s.seasonNum, ts.statsPlayerID; From 71507b08e79069dbaeb0914be139e3038e34cd95 Mon Sep 17 00:00:00 2001 From: Trey Brittain Date: Wed, 17 May 2023 12:12:57 -0500 Subject: [PATCH 04/12] Display team names in season batting stats as well --- .../Resources/Sql/PlayoffStatsBatting.sql | 29 +++++++++++-------- .../Resources/Sql/SeasonStatsBatting.sql | 29 +++++++++++-------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql b/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql index 95a325b..c76e7c4 100644 --- a/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql +++ b/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql @@ -8,26 +8,26 @@ JOIN t_leagues ON t_seasons.historicalLeagueGUID = t_leagues.GUID JOIN t_franchise tf ON t_leagues.GUID = tf.leagueGUID WHERE t_leagues.GUID = CAST(@leagueId AS BLOB)) -SELECT ts.aggregatorID AS aggregatorID, - ts.statsPlayerID AS statsPlayerID, - tbpli.GUID AS baseballPlayerGUIDIfKnown, +SELECT ts.aggregatorID AS aggregatorID, + ts.statsPlayerID AS statsPlayerID, + tbpli.GUID AS baseballPlayerGUIDIfKnown, s.seasonID, s.seasonNum, - currentTeamLocal.GUID AS teamGUID, - mostRecentTeamLocal.GUID AS mostRecentlyPlayedTeamGUID, - previouslyRecentTeam.GUID AS previousRecentlyPlayedTeamGUID, + currentTeam.teamName AS teamName, + mostRecentTeam.teamName AS mostRecentlyPlayedTeamName, + previouslyRecentPlayedTeam.teamName AS previousRecentlyPlayedTeamName, CASE WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.firstName - ELSE vbpi.firstName END AS firstName, + ELSE vbpi.firstName END AS firstName, CASE WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.lastName - ELSE vbpi.lastName END AS lastName, + ELSE vbpi.lastName END AS lastName, CASE WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.primaryPos - ELSE vbpi.primaryPosition END AS primaryPosition, + ELSE vbpi.primaryPosition END AS primaryPosition, CASE WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.pitcherRole - ELSE vbpi.pitcherRole END AS pitcherRole, + ELSE vbpi.pitcherRole END AS pitcherRole, gamesBatting, atBats, runs, @@ -54,8 +54,13 @@ FROM t_stats_batting tsb LEFT JOIN t_team_local_ids currentTeamLocal ON ts.currentTeamLocalID = currentTeamLocal.localID LEFT JOIN t_team_local_ids mostRecentTeamLocal ON ts.mostRecentlyPlayedTeamLocalID = mostRecentTeamLocal.localID - LEFT JOIN t_team_local_ids previouslyRecentTeam - ON ts.previousRecentlyPlayedTeamLocalID = previouslyRecentTeam.localID + LEFT JOIN t_team_local_ids previouslyRecentPlayedTeamLocal + ON ts.previousRecentlyPlayedTeamLocalID = previouslyRecentPlayedTeamLocal.localID + + LEFT JOIN teams currentTeam ON currentTeamLocal.GUID = currentTeam.teamGUID + LEFT JOIN teams mostRecentTeam ON mostRecentTeamLocal.GUID = mostRecentTeam.teamGUID + LEFT JOIN teams previouslyRecentPlayedTeam + ON previouslyRecentPlayedTeamLocal.GUID = previouslyRecentPlayedTeam.teamGUID LEFT JOIN t_baseball_player_local_ids tbpli ON tsp.baseballPlayerLocalID = tbpli.localID diff --git a/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql b/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql index 52f8f7e..0946875 100644 --- a/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql +++ b/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql @@ -8,26 +8,26 @@ JOIN t_leagues ON t_seasons.historicalLeagueGUID = t_leagues.GUID JOIN t_franchise tf ON t_leagues.GUID = tf.leagueGUID WHERE t_leagues.GUID = CAST(@leagueId AS BLOB)) -SELECT ts.aggregatorID AS aggregatorID, - ts.statsPlayerID AS statsPlayerID, - tbpli.GUID AS baseballPlayerGUIDIfKnown, +SELECT ts.aggregatorID AS aggregatorID, + ts.statsPlayerID AS statsPlayerID, + tbpli.GUID AS baseballPlayerGUIDIfKnown, s.seasonID, s.seasonNum, - currentTeamLocal.GUID AS teamGUID, - mostRecentTeamLocal.GUID AS mostRecentlyPlayedTeamGUID, - previouslyRecentTeam.GUID AS previousRecentlyPlayedTeamGUID, + currentTeam.teamName AS teamName, + mostRecentTeam.teamName AS mostRecentlyPlayedTeamName, + previouslyRecentPlayedTeam.teamName AS previousRecentlyPlayedTeamName, CASE WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.firstName - ELSE vbpi.firstName END AS firstName, + ELSE vbpi.firstName END AS firstName, CASE WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.lastName - ELSE vbpi.lastName END AS lastName, + ELSE vbpi.lastName END AS lastName, CASE WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.primaryPos - ELSE vbpi.primaryPosition END AS primaryPosition, + ELSE vbpi.primaryPosition END AS primaryPosition, CASE WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.pitcherRole - ELSE vbpi.pitcherRole END AS pitcherRole, + ELSE vbpi.pitcherRole END AS pitcherRole, gamesBatting, atBats, runs, @@ -54,8 +54,13 @@ FROM t_stats_batting tsb LEFT JOIN t_team_local_ids currentTeamLocal ON ts.currentTeamLocalID = currentTeamLocal.localID LEFT JOIN t_team_local_ids mostRecentTeamLocal ON ts.mostRecentlyPlayedTeamLocalID = mostRecentTeamLocal.localID - LEFT JOIN t_team_local_ids previouslyRecentTeam - ON ts.previousRecentlyPlayedTeamLocalID = previouslyRecentTeam.localID + LEFT JOIN t_team_local_ids previouslyRecentPlayedTeamLocal + ON ts.previousRecentlyPlayedTeamLocalID = previouslyRecentPlayedTeamLocal.localID + + LEFT JOIN teams currentTeam ON currentTeamLocal.GUID = currentTeam.teamGUID + LEFT JOIN teams mostRecentTeam ON mostRecentTeamLocal.GUID = mostRecentTeam.teamGUID + LEFT JOIN teams previouslyRecentPlayedTeam + ON previouslyRecentPlayedTeamLocal.GUID = previouslyRecentPlayedTeam.teamGUID LEFT JOIN t_baseball_player_local_ids tbpli ON tsp.baseballPlayerLocalID = tbpli.localID From 0bead2b010c1303815cc82f440ae9a7200a3e20b Mon Sep 17 00:00:00 2001 From: Trey Brittain Date: Wed, 17 May 2023 21:19:25 -0500 Subject: [PATCH 05/12] Add secondary position to player season exports --- .../Resources/Sql/PlayoffStatsBatting.sql | 5 +++++ .../Resources/Sql/SeasonStatsBatting.sql | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql b/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql index c76e7c4..7e42b63 100644 --- a/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql +++ b/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql @@ -25,6 +25,9 @@ SELECT ts.aggregatorID AS aggregatorID, CASE WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.primaryPos ELSE vbpi.primaryPosition END AS primaryPosition, + CASE + WHEN tsp.baseballPlayerLocalID IS NOT NULL THEN CAST(secondaryPosition.optionValue AS INTEGER) + ELSE tsp.secondaryPos END AS secondaryPosition, CASE WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.pitcherRole ELSE vbpi.pitcherRole END AS pitcherRole, @@ -64,6 +67,8 @@ FROM t_stats_batting tsb LEFT JOIN t_baseball_player_local_ids tbpli ON tsp.baseballPlayerLocalID = tbpli.localID + LEFT JOIN t_baseball_player_options secondaryPosition + ON tbpli.localID = secondaryPosition.baseballPlayerLocalID AND secondaryPosition.optionKey = 55 LEFT JOIN v_baseball_player_info vbpi ON tbpli.GUID = vbpi.baseballPlayerGUID WHERE 1 = CASE diff --git a/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql b/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql index 0946875..55519e2 100644 --- a/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql +++ b/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql @@ -8,9 +8,9 @@ JOIN t_leagues ON t_seasons.historicalLeagueGUID = t_leagues.GUID JOIN t_franchise tf ON t_leagues.GUID = tf.leagueGUID WHERE t_leagues.GUID = CAST(@leagueId AS BLOB)) -SELECT ts.aggregatorID AS aggregatorID, - ts.statsPlayerID AS statsPlayerID, - tbpli.GUID AS baseballPlayerGUIDIfKnown, +SELECT ts.aggregatorID AS aggregatorID, + ts.statsPlayerID AS statsPlayerID, + tbpli.GUID AS baseballPlayerGUIDIfKnown, s.seasonID, s.seasonNum, currentTeam.teamName AS teamName, @@ -18,16 +18,19 @@ SELECT ts.aggregatorID AS aggregatorID, previouslyRecentPlayedTeam.teamName AS previousRecentlyPlayedTeamName, CASE WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.firstName - ELSE vbpi.firstName END AS firstName, + ELSE vbpi.firstName END AS firstName, CASE WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.lastName - ELSE vbpi.lastName END AS lastName, + ELSE vbpi.lastName END AS lastName, CASE WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.primaryPos - ELSE vbpi.primaryPosition END AS primaryPosition, + ELSE vbpi.primaryPosition END AS primaryPosition, + CASE + WHEN tsp.baseballPlayerLocalID IS NOT NULL THEN CAST(secondaryPosition.optionValue AS INTEGER) + ELSE tsp.secondaryPos END AS secondaryPosition, CASE WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.pitcherRole - ELSE vbpi.pitcherRole END AS pitcherRole, + ELSE vbpi.pitcherRole END AS pitcherRole, gamesBatting, atBats, runs, @@ -64,6 +67,8 @@ FROM t_stats_batting tsb LEFT JOIN t_baseball_player_local_ids tbpli ON tsp.baseballPlayerLocalID = tbpli.localID + LEFT JOIN t_baseball_player_options secondaryPosition + ON tbpli.localID = secondaryPosition.baseballPlayerLocalID AND secondaryPosition.optionKey = 55 LEFT JOIN v_baseball_player_info vbpi ON tbpli.GUID = vbpi.baseballPlayerGUID WHERE 1 = CASE From 90b0af24c44ad13ec3a7dfdc47bcab4a5e3140d2 Mon Sep 17 00:00:00 2001 From: Trey Brittain Date: Wed, 17 May 2023 21:50:28 -0500 Subject: [PATCH 06/12] Add age to batting season exports --- .../Resources/Sql/PlayoffStatsBatting.sql | 23 ++++++++++++------- .../Resources/Sql/SeasonStatsBatting.sql | 23 ++++++++++++------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql b/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql index 7e42b63..7e9de1e 100644 --- a/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql +++ b/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql @@ -17,21 +17,27 @@ SELECT ts.aggregatorID AS aggregatorID, mostRecentTeam.teamName AS mostRecentlyPlayedTeamName, previouslyRecentPlayedTeam.teamName AS previousRecentlyPlayedTeamName, CASE - WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.firstName + WHEN tsplayers.baseballPlayerLocalID IS NULL THEN tsplayers.firstName ELSE vbpi.firstName END AS firstName, CASE - WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.lastName + WHEN tsplayers.baseballPlayerLocalID IS NULL THEN tsplayers.lastName ELSE vbpi.lastName END AS lastName, CASE - WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.primaryPos + WHEN tsplayers.baseballPlayerLocalID IS NULL THEN tsplayers.primaryPos ELSE vbpi.primaryPosition END AS primaryPosition, CASE - WHEN tsp.baseballPlayerLocalID IS NOT NULL THEN CAST(secondaryPosition.optionValue AS INTEGER) - ELSE tsp.secondaryPos END AS secondaryPosition, + WHEN tsplayers.baseballPlayerLocalID IS NOT NULL THEN CAST(secondaryPosition.optionValue AS INTEGER) + ELSE tsplayers.secondaryPos END AS secondaryPosition, CASE - WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.pitcherRole + WHEN tsplayers.baseballPlayerLocalID IS NULL THEN tsplayers.pitcherRole ELSE vbpi.pitcherRole END AS pitcherRole, + CASE + WHEN tbp.GUID IS NOT NULL THEN + tbp.age - (MAX(seasonNum) OVER (PARTITION BY baseballPlayerGUID) - seasonNum) + ELSE tsplayers.age - (tsplayers.retirementSeason - s.seasonNum) + END AS age, gamesBatting, + gamesPlayed, atBats, runs, hits, @@ -50,7 +56,7 @@ SELECT ts.aggregatorID AS aggregatorID, passedBalls FROM t_stats_batting tsb JOIN t_stats ts ON tsb.aggregatorID = ts.aggregatorID - JOIN t_stats_players tsp USING (statsPlayerID) + JOIN t_stats_players tsplayers USING (statsPlayerID) JOIN t_playoff_stats tps USING (aggregatorID) JOIN seasons s USING (seasonID) @@ -66,9 +72,10 @@ FROM t_stats_batting tsb ON previouslyRecentPlayedTeamLocal.GUID = previouslyRecentPlayedTeam.teamGUID LEFT JOIN t_baseball_player_local_ids tbpli - ON tsp.baseballPlayerLocalID = tbpli.localID + ON tsplayers.baseballPlayerLocalID = tbpli.localID LEFT JOIN t_baseball_player_options secondaryPosition ON tbpli.localID = secondaryPosition.baseballPlayerLocalID AND secondaryPosition.optionKey = 55 + LEFT JOIN t_baseball_players tbp on tbpli.GUID = tbp.GUID LEFT JOIN v_baseball_player_info vbpi ON tbpli.GUID = vbpi.baseballPlayerGUID WHERE 1 = CASE diff --git a/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql b/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql index 55519e2..3aad8c6 100644 --- a/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql +++ b/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql @@ -17,21 +17,27 @@ SELECT ts.aggregatorID AS aggregatorID, mostRecentTeam.teamName AS mostRecentlyPlayedTeamName, previouslyRecentPlayedTeam.teamName AS previousRecentlyPlayedTeamName, CASE - WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.firstName + WHEN tsplayers.baseballPlayerLocalID IS NULL THEN tsplayers.firstName ELSE vbpi.firstName END AS firstName, CASE - WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.lastName + WHEN tsplayers.baseballPlayerLocalID IS NULL THEN tsplayers.lastName ELSE vbpi.lastName END AS lastName, CASE - WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.primaryPos + WHEN tsplayers.baseballPlayerLocalID IS NULL THEN tsplayers.primaryPos ELSE vbpi.primaryPosition END AS primaryPosition, CASE - WHEN tsp.baseballPlayerLocalID IS NOT NULL THEN CAST(secondaryPosition.optionValue AS INTEGER) - ELSE tsp.secondaryPos END AS secondaryPosition, + WHEN tsplayers.baseballPlayerLocalID IS NOT NULL THEN CAST(secondaryPosition.optionValue AS INTEGER) + ELSE tsplayers.secondaryPos END AS secondaryPosition, CASE - WHEN tsp.baseballPlayerLocalID IS NULL THEN tsp.pitcherRole + WHEN tsplayers.baseballPlayerLocalID IS NULL THEN tsplayers.pitcherRole ELSE vbpi.pitcherRole END AS pitcherRole, + CASE + WHEN tbp.GUID IS NOT NULL THEN + tbp.age - (MAX(seasonNum) OVER (PARTITION BY baseballPlayerGUID) - seasonNum) + ELSE tsplayers.age - (tsplayers.retirementSeason - s.seasonNum) + END AS age, gamesBatting, + gamesPlayed, atBats, runs, hits, @@ -50,7 +56,7 @@ SELECT ts.aggregatorID AS aggregatorID, passedBalls FROM t_stats_batting tsb JOIN t_stats ts ON tsb.aggregatorID = ts.aggregatorID - JOIN t_stats_players tsp USING (statsPlayerID) + JOIN t_stats_players tsplayers USING (statsPlayerID) JOIN t_season_stats tss USING (aggregatorID) JOIN seasons s USING (seasonID) @@ -66,9 +72,10 @@ FROM t_stats_batting tsb ON previouslyRecentPlayedTeamLocal.GUID = previouslyRecentPlayedTeam.teamGUID LEFT JOIN t_baseball_player_local_ids tbpli - ON tsp.baseballPlayerLocalID = tbpli.localID + ON tsplayers.baseballPlayerLocalID = tbpli.localID LEFT JOIN t_baseball_player_options secondaryPosition ON tbpli.localID = secondaryPosition.baseballPlayerLocalID AND secondaryPosition.optionKey = 55 + LEFT JOIN t_baseball_players tbp on tbpli.GUID = tbp.GUID LEFT JOIN v_baseball_player_info vbpi ON tbpli.GUID = vbpi.baseballPlayerGUID WHERE 1 = CASE From dc09a90e08dca3d338b2278e7218e83ec6d0785f Mon Sep 17 00:00:00 2001 From: Trey Brittain Date: Wed, 17 May 2023 21:53:00 -0500 Subject: [PATCH 07/12] Update BattingSeasonStatistic with new field order and headings --- .../Models/Exports/BattingSeasonStatistic.cs | 162 +++++++++--------- 1 file changed, 84 insertions(+), 78 deletions(-) diff --git a/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs b/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs index 7cb6f08..10d0a2f 100644 --- a/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs @@ -11,153 +11,159 @@ namespace SMB3Explorer.Models.Exports; public class BattingSeasonStatistic { - [Name("player_id"), Index(0)] + public int AggregatorId { get; set; } + + public int StatsPlayerId { get; set; } + public Guid? PlayerId { get; set; } - [Name("first_name"), Index(1)] + public int SeasonId { get; set; } + + [Name("Season"), Index(0)] + public int SeasonNum { get; set; } + + [Name("First Name"), Index(1)] public string FirstName { get; set; } = string.Empty; - [Name("last_name"), Index(2)] + [Name("Last Name"), Index(2)] public string LastName { get; set; } = string.Empty; - - [Name("current_team_name"), Index(3)] - public string? CurrentTeam { get; set; } - - [Name("previous_team_name"), Index(4)] + + [Name("Team"), Index(3)] + public string? TeamName { get; set; } + + [Name("Most Recent Team"), Index(4)] + public string? MostRecentTeamName { get; set; } + + [Name("Second Most Recent Team"), Index(5)] public string? PreviousTeam { get; set; } - [Name("primary_position"), Index(5)] public int PositionNumber { get; set; } - [Name("primary_position_name"), Index(6)] + [Name("Position"), Index(6)] // ReSharper disable once UnusedMember.Global public string Position => ((BaseballPlayerPosition) PositionNumber).GetEnumDescription(); - - [Name("secondary_position"), Index(7)] + public int? SecondaryPositionNumber { get; set; } - [Name("secondary_position_name"), Index(8)] + [Name("Secondary Position"), Index(7)] // ReSharper disable once UnusedMember.Global public string? SecondaryPosition => SecondaryPositionNumber.HasValue ? ((BaseballPlayerPosition) SecondaryPositionNumber).GetEnumDescription() : null; - [Name("games_batting"), Index(9)] + public int PitcherRole { get; set; } + + [Name("Pitcher Role"), Index(8)] + // ReSharper disable once UnusedMember.Global + public string PitcherRoleDescription => ((PitcherRole) PitcherRole).GetEnumDescription(); + + [Name("Age"), Index(9)] + public int Age { get; set; } + + [Name("Games Batting"), Index(10)] public int GamesBatting { get; set; } - [Name("games_played"), Index(10)] + [Name("Games Played"), Index(11)] public int GamesPlayed { get; set; } - [Name("at_bats"), Index(11)] + [Name("AB"), Index(12)] public int AtBats { get; set; } - [Name("plate_appearances"), Index(12)] + [Name("PA"), Index(13)] public int PlateAppearances => AtBats + Walks + SacrificeHits + SacrificeFlies + HitByPitch; - [Name("runs"), Index(13)] + [Name("R"), Index(14)] public int Runs { get; set; } - [Name("hits"), Index(14)] + [Name("H"), Index(15)] public int Hits { get; set; } - [Name("singles"), Index(15)] + [Name("BA"), Index(36)] + public double BattingAverage => Hits / (double) AtBats; + + [Name("1B"), Index(17)] public int Singles => Hits - Doubles - Triples - HomeRuns; - [Name("doubles"), Index(16)] + [Name("2B"), Index(18)] public int Doubles { get; set; } - [Name("triples"), Index(17)] + [Name("3B"), Index(19)] public int Triples { get; set; } - [Name("home_runs"), Index(18)] + [Name("HR"), Index(20)] public int HomeRuns { get; set; } - [Name("rbi"), Index(19)] + [Name("RBI"), Index(21)] public int RunsBattedIn { get; set; } - [Name("extra_base_hits"), Index(20)] + [Name("XBH"), Index(22)] public int ExtraBaseHits => Doubles + Triples + HomeRuns; - [Name("total_bases"), Index(21)] + [Name("TB"), Index(23)] public int TotalBases => Singles + (2 * Doubles) + (3 * Triples) + (4 * HomeRuns); - [Name("stolen_bases"), Index(22)] + [Name("SB"), Index(24)] public int StolenBases { get; set; } - [Name("caught_stealing"), Index(23)] + [Name("CS"), Index(25)] public int CaughtStealing { get; set; } - [Name("walks"), Index(24)] + [Name("BB"), Index(26)] public int Walks { get; set; } - [Name("strikeouts"), Index(25)] + [Name("K"), Index(27)] public int Strikeouts { get; set; } - [Name("hit_by_pitch"), Index(26)] + [Name("HBP"), Index(28)] public int HitByPitch { get; set; } + + [Name("OBP"), Index(29)] + public double OnBasePercentage => (Hits + Walks + HitByPitch) / + (double) (AtBats + Walks + HitByPitch + SacrificeFlies); + + [Name("SLG"), Index(30)] + public double SluggingPercentage => (Singles + (2 * Doubles) + (3 * Triples) + + (4 * HomeRuns)) / (double) AtBats; + + [Name("OPS"), Index(31)] + public double OnBasePlusSlugging => OnBasePercentage + SluggingPercentage; + + // Caveat with this, the denominator should be subtracting intentional walks, but that data is not available + [Name("wOBA"), Index(32)] + public double WeightedOnBaseAverage => ((0.69 * Walks) + (0.72 * HitByPitch) + (0.89 * Singles) + (1.27 * Doubles) + + (1.62 * Triples) + (2.10 * HomeRuns)) / (AtBats + Walks + SacrificeFlies + HitByPitch); - [Name("sacrifice_hits"), Index(27)] + [Name("ISO"), Index(33)] + public double IsolatedPower => SluggingPercentage - BattingAverage; + + [Name("BABIP"), Index(34)] + public double BattingAverageOnBallsInPlay => + (Hits - HomeRuns) / (double) (AtBats - Strikeouts - HomeRuns + SacrificeFlies); + + [Name("Sac Hits"), Index(35)] public int SacrificeHits { get; set; } - [Name("sacrifice_flies"), Index(28)] + [Name("Sac Flies"), Index(36)] public int SacrificeFlies { get; set; } - [Name("errors"), Index(29)] + [Name("Errors"), Index(37)] public int Errors { get; set; } - [Name("passed_balls"), Index(30)] + [Name("Passed Balls"), Index(38)] public int PassedBalls { get; set; } - [Name("plate_appearances_per_game"), Index(31)] + [Name("PA/Game"), Index(39)] public double PlateAppearancesPerGame => PlateAppearances / (double) GamesPlayed; - [Name("on_base_percentage"), Index(32)] - public double OnBasePercentage => (Hits + Walks + HitByPitch) / - (double) (AtBats + Walks + HitByPitch + SacrificeFlies); - - [Name("slugging_percentage"), Index(33)] - public double SluggingPercentage => (Singles + (2 * Doubles) + (3 * Triples) + - (4 * HomeRuns)) / (double) AtBats; - - [Name("on_base_plus_slugging"), Index(34)] - public double OnBasePlusSlugging => OnBasePercentage + SluggingPercentage; - - [Name("batting_average"), Index(35)] - public double BattingAverage => Hits / (double) AtBats; - - [Name("babip"), Index(36)] - public double BattingAverageOnBallsInPlay => - (Hits - HomeRuns) / (double) (AtBats - Strikeouts - HomeRuns + SacrificeFlies); - - [Name("at_bats_per_home_run"), Index(37)] + [Name("AB/HR"), Index(40)] public double AtBatsPerHomeRun => AtBats / (double) HomeRuns; - [Name("strikeout_percentage"), Index(38)] + [Name("K%"), Index(41)] public double StrikeoutPercentage => Strikeouts / (double) AtBats; - [Name("walk_percentage"), Index(39)] + [Name("BB%"), Index(42)] public double WalkPercentage => Walks / (double) PlateAppearances; - [Name("extra_base_hit_percentage"), Index(40)] + [Name("XBH%"), Index(43)] public double ExtraBaseHitPercentage => ExtraBaseHits / (double) Hits; - - // Caveat with this, the denominator should be subtracting intentional walks, but that data is not available - [Name("wOBA"), Index(41)] - public double WeightedOnBaseAverage => ((0.69 * Walks) + (0.72 * HitByPitch) + (0.89 * Singles) + (1.27 * Doubles) + - (1.62 * Triples) + (2.10 * HomeRuns)) / (AtBats + Walks + SacrificeFlies + HitByPitch); - - [Name("ISO"), Index(42)] - public double IsolatedPower => SluggingPercentage - BattingAverage; - - [Name("season_completion_date"), Index(43)] - public DateTime? CompletionDate { get; set; } - - [Name("season_id"), Index(44)] - public int SeasonId { get; set; } - - [Name("season_num"), Index(45)] - public int SeasonNum { get; set; } - - [Name("age"), Index(46)] - public int Age { get; set; } } \ No newline at end of file From 05e104b61300df8e1ad10e868b4dc5d4efe55660 Mon Sep 17 00:00:00 2001 From: Trey Brittain Date: Wed, 17 May 2023 22:56:41 -0500 Subject: [PATCH 08/12] Update PitchingSeasonStatistic with new field order and headings --- .../Models/Exports/BattingSeasonStatistic.cs | 6 +- .../Models/Exports/PitchingSeasonStatistic.cs | 139 +++++++++--------- 2 files changed, 70 insertions(+), 75 deletions(-) diff --git a/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs b/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs index 10d0a2f..b54feba 100644 --- a/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs @@ -31,10 +31,10 @@ public class BattingSeasonStatistic [Name("Team"), Index(3)] public string? TeamName { get; set; } - [Name("Most Recent Team"), Index(4)] + [Name("Prev Team"), Index(4)] public string? MostRecentTeamName { get; set; } - [Name("Second Most Recent Team"), Index(5)] + [Name("2nd Prev Team"), Index(5)] public string? PreviousTeam { get; set; } public int PositionNumber { get; set; } @@ -166,4 +166,4 @@ public class BattingSeasonStatistic [Name("XBH%"), Index(43)] public double ExtraBaseHitPercentage => ExtraBaseHits / (double) Hits; -} \ No newline at end of file +} diff --git a/SMB3Explorer/Models/Exports/PitchingSeasonStatistic.cs b/SMB3Explorer/Models/Exports/PitchingSeasonStatistic.cs index 0686988..e5bc642 100644 --- a/SMB3Explorer/Models/Exports/PitchingSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/PitchingSeasonStatistic.cs @@ -11,145 +11,140 @@ namespace SMB3Explorer.Models.Exports; public class PitchingSeasonStatistic { - [Name("player_id"), Index(0)] + public int AggregatorId { get; set; } + + public int StatsPlayerId { get; set; } + public Guid? PlayerId { get; set; } + + public int SeasonId { get; set; } + + [Name("Season"), Index(0)] + public int SeasonNum { get; set; } - [Name("first_name"), Index(1)] + [Name("First Name"), Index(1)] public string FirstName { get; set; } = string.Empty; - [Name("last_name"), Index(2)] + [Name("Last Name"), Index(2)] public string LastName { get; set; } = string.Empty; - [Name("current_team_name"), Index(3)] - public string? CurrentTeam { get; set; } - - [Name("previous_team_name"), Index(4)] + [Name("Team"), Index(3)] + public string? TeamName { get; set; } + + [Name("Prev Team"), Index(4)] + public string? MostRecentTeamName { get; set; } + + [Name("2nd Prev Team"), Index(5)] public string? PreviousTeam { get; set; } - [Name("primary_position"), Index(5)] public int PositionNumber { get; set; } - - [Name("primary_position_name"), Index(6)] - // ReSharper disable once UnusedMember.Global - public string Position => ((BaseballPlayerPosition) PositionNumber).GetEnumDescription(); - [Name("pitcher_role"), Index(7)] public int PitcherRole { get; set; } - [Name("pitcher_role_name"), Index(8)] + [Name("Pitcher Role"), Index(6)] // ReSharper disable once UnusedMember.Global public string PitcherRoleDescription => ((PitcherRole) PitcherRole).GetEnumDescription(); + + [Name("Age"), Index(7)] + public int Age { get; set; } - [Name("games_played"), Index(9)] - public int GamesPlayed { get; set; } - - [Name("games_started"), Index(10)] - public int GamesStarted { get; set; } - - [Name("wins"), Index(11)] + [Name("W"), Index(8)] public int Wins { get; set; } - [Name("losses"), Index(12)] + [Name("L"), Index(9)] public int Losses { get; set; } - [Name("complete_games"), Index(13)] + [Name("CG"), Index(10)] public int CompleteGames { get; set; } - [Name("shutouts"), Index(14)] + [Name("CGSO"), Index(11)] public int Shutouts { get; set; } - [Name("total_pitches"), Index(15)] - public int TotalPitches { get; set; } - - [Name("saves"), Index(16)] - public int Saves { get; set; } - - [Name("outs_pitched"), Index(17)] public int OutsPitched { get; set; } - [Name("hits_allowed"), Index(18)] + [Name("H"), Index(12)] public int HitsAllowed { get; set; } - [Name("earned_runs"), Index(19)] + [Name("ER"), Index(13)] public int EarnedRuns { get; set; } - [Name("home_runs_allowed"), Index(20)] + [Name("HR"), Index(14)] public int HomeRunsAllowed { get; set; } - [Name("walks_allowed"), Index(21)] + [Name("BB"), Index(15)] public int WalksAllowed { get; set; } - [Name("strikeouts"), Index(22)] + [Name("K"), Index(16)] public int Strikeouts { get; set; } + + [Name("IP"), Index(17)] + public double InningsPitched => OutsPitched / 3.0; + + [Name("ERA"), Index(18)] + public double EarnedRunAverage => EarnedRuns / InningsPitched; + + [Name("TP"), Index(19)] + public int TotalPitches { get; set; } - [Name("hit_by_pitch"), Index(23)] + [Name("S"), Index(20)] + public int Saves { get; set; } + + [Name("HBP"), Index(21)] public int HitByPitch { get; set; } - [Name("batters_faced"), Index(24)] + [Name("Batters Faced"), Index(22)] public int BattersFaced { get; set; } + + [Name("Games Played"), Index(23)] + public int GamesPlayed { get; set; } + + [Name("Games Started"), Index(24)] + public int GamesStarted { get; set; } - [Name("games_finished"), Index(25)] + [Name("Games Finished"), Index(25)] public int GamesFinished { get; set; } - [Name("runs_allowed"), Index(26)] + [Name("Runs Allowed"), Index(26)] public int RunsAllowed { get; set; } - [Name("wild_pitches"), Index(27)] + [Name("WP"), Index(27)] public int WildPitches { get; set; } - [Name("innings_pitched"), Index(30)] - public double InningsPitched => OutsPitched / 3.0; - - [Name("era"), Index(31)] - public double EarnedRunAverage => EarnedRuns / InningsPitched; - - [Name("batting_average_against"), Index(32)] + [Name("BAA"), Index(28)] public double BattingAverageAgainst => HitsAllowed / (double) BattersFaced; - [Name("fip"), Index(33)] + [Name("FIP"), Index(29)] public double FieldingIndependentPitching => (((13 * HomeRunsAllowed) + (3 * (WalksAllowed + HitByPitch)) - (2 * Strikeouts)) / (double) OutsPitched) + 3.10; - [Name("whip"), Index(34)] + [Name("WHIP"), Index(30)] public double WalksAndHitsPerInning => (WalksAllowed + HitsAllowed) / InningsPitched; - [Name("win_percentage"), Index(35)] + [Name("WPCT"), Index(31)] public double WinPercentage => Wins / (double) (Wins + Losses); - [Name("opponent_on_base_percentage"), Index(36)] + [Name("Opp OBP"), Index(32)] public double OpponentOnBasePercentage => (HitsAllowed + WalksAllowed + HitByPitch) / (double) BattersFaced; - [Name("strikeout_to_walk_ratio"), Index(37)] + [Name("K/BB"), Index(33)] public double StrikeoutToWalkRatio => Strikeouts / (double) WalksAllowed; - [Name("strikeouts_per_nine_innings"), Index(38)] + [Name("K/9"), Index(34)] public double StrikeoutsPerNineInnings => Strikeouts / (InningsPitched / 9.0); - [Name("walks_per_nine_innings"), Index(39)] + [Name("BB/9"), Index(35)] public double WalksPerNineInnings => WalksAllowed / (InningsPitched / 9.0); - [Name("hits_per_nine_innings"), Index(40)] + [Name("H/9"), Index(36)] public double HitsPerNineInnings => HitsAllowed / (InningsPitched / 9.0); - [Name("home_runs_per_nine_innings"), Index(41)] + [Name("HR/9"), Index(37)] public double HomeRunsPerNineInnings => HomeRunsAllowed / (InningsPitched / 9.0); - [Name("pitches_per_inning"), Index(42)] + [Name("Pitches Per Inning"), Index(38)] public double PitchesPerInning => TotalPitches / InningsPitched; - [Name("pitches_per_game"), Index(43)] + [Name("Pitcher Per Game"), Index(39)] public double PitchesPerGame => TotalPitches / (double) GamesPlayed; - - [Name("season_completion_date"), Index(44)] - public DateTime? CompletionDate { get; set; } - - [Name("season_id"), Index(45)] - public int SeasonId { get; set; } - - [Name("season_num"), Index(46)] - public int SeasonNum { get; set; } - - [Name("age"), Index(47)] - public int Age { get; set; } -} \ No newline at end of file +} From 30a5863d03fb9e0ec62b0be55736cd491400333b Mon Sep 17 00:00:00 2001 From: Trey Brittain Date: Thu, 18 May 2023 13:06:51 -0500 Subject: [PATCH 09/12] Fix mapping from database records for GetPitchingSeasonStatistic and GetPositionPlayerSeasonStatistic to new format --- .../BattingMostRecentSeasonStatistic.cs | 2 +- .../DataServiceFranchiseSeasons.cs | 64 ++++++++++--------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs b/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs index 7ef063d..b9e857c 100644 --- a/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs @@ -2,7 +2,7 @@ namespace SMB3Explorer.Models.Exports; -public class BattingMostRecentSeasonStatistic : BattingSeasonStatistic +public class BattingMostRecentSeasonStatistic { public BattingMostRecentSeasonStatistic(BattingSeasonStatistic battingSeasonStatistic) { diff --git a/SMB3Explorer/Services/DataService/DataServiceFranchiseSeasons.cs b/SMB3Explorer/Services/DataService/DataServiceFranchiseSeasons.cs index ede8d37..f5a081d 100644 --- a/SMB3Explorer/Services/DataService/DataServiceFranchiseSeasons.cs +++ b/SMB3Explorer/Services/DataService/DataServiceFranchiseSeasons.cs @@ -95,13 +95,28 @@ private static PitchingSeasonStatistic GetPitchingSeasonStatistic(bool isRegular { var pitcherStatistic = new PitchingSeasonStatistic(); + pitcherStatistic.AggregatorId = int.Parse(reader["aggregatorID"].ToString()!); + pitcherStatistic.StatsPlayerId = int.Parse(reader["statsPlayerID"].ToString()!); pitcherStatistic.PlayerId = reader["baseballPlayerGUID"] is not byte[] bytes ? null : bytes.ToGuid(); + + pitcherStatistic.SeasonId = int.Parse(reader["seasonId"].ToString()!); + pitcherStatistic.SeasonNum = int.Parse(reader["seasonNum"].ToString()!); + pitcherStatistic.Age = int.Parse(reader["age"].ToString()!); + pitcherStatistic.FirstName = reader["firstName"].ToString()!; pitcherStatistic.LastName = reader["lastName"].ToString()!; pitcherStatistic.PositionNumber = int.Parse(reader["primaryPosition"].ToString()!); - pitcherStatistic.CurrentTeam = string.IsNullOrEmpty(reader["currentTeam"].ToString()!) + + pitcherStatistic.TeamName = string.IsNullOrEmpty(reader["teamName"].ToString()!) + ? null + : reader["teamName"].ToString()!; + pitcherStatistic.MostRecentTeamName = string.IsNullOrEmpty(reader["mostRecentlyPlayedTeamName"].ToString()!) ? null - : reader["currentTeam"].ToString()!; + : reader["mostRecentlyPlayedTeamName"].ToString()!; + pitcherStatistic.PreviousTeam = string.IsNullOrEmpty(reader["previousRecentlyPlayedTeamName"].ToString()!) + ? null + : reader["previousRecentlyPlayedTeamName"].ToString()!; + pitcherStatistic.PitcherRole = int.Parse(reader["pitcherRole"].ToString()!); pitcherStatistic.GamesPlayed = int.Parse(reader["games"].ToString()!); pitcherStatistic.GamesStarted = int.Parse(reader["gamesStarted"].ToString()!); @@ -122,19 +137,6 @@ private static PitchingSeasonStatistic GetPitchingSeasonStatistic(bool isRegular pitcherStatistic.GamesFinished = int.Parse(reader["gamesFinished"].ToString()!); pitcherStatistic.RunsAllowed = int.Parse(reader["runsAllowed"].ToString()!); pitcherStatistic.WildPitches = int.Parse(reader["wildPitches"].ToString()!); - pitcherStatistic.CompletionDate = string.IsNullOrEmpty(reader["completionDate"].ToString()!) - ? null - : DateTime.Parse(reader["completionDate"].ToString()!); - pitcherStatistic.SeasonId = int.Parse(reader["seasonId"].ToString()!); - pitcherStatistic.SeasonNum = int.Parse(reader["seasonNum"].ToString()!); - pitcherStatistic.Age = int.Parse(reader["age"].ToString()!); - - if (isRegularSeason) - { - pitcherStatistic.PreviousTeam = string.IsNullOrEmpty(reader["previousTeam"].ToString()!) - ? null - : reader["previousTeam"].ToString()!; - } return pitcherStatistic; } @@ -142,6 +144,14 @@ private static PitchingSeasonStatistic GetPitchingSeasonStatistic(bool isRegular private static BattingSeasonStatistic GetPositionPlayerSeasonStatistic(bool isRegularSeason, IDataRecord reader) { var positionPlayerStatistic = new BattingSeasonStatistic(); + + positionPlayerStatistic.AggregatorId = int.Parse(reader["aggregatorID"].ToString()!); + positionPlayerStatistic.StatsPlayerId = int.Parse(reader["statsPlayerID"].ToString()!); + positionPlayerStatistic.PlayerId = reader["baseballPlayerGUID"] is not byte[] bytes ? null : bytes.ToGuid(); + + positionPlayerStatistic.SeasonId = int.Parse(reader["seasonId"].ToString()!); + positionPlayerStatistic.SeasonNum = int.Parse(reader["seasonNum"].ToString()!); + positionPlayerStatistic.Age = int.Parse(reader["age"].ToString()!); positionPlayerStatistic.FirstName = reader["firstName"].ToString()!; positionPlayerStatistic.LastName = reader["lastName"].ToString()!; @@ -153,9 +163,15 @@ private static BattingSeasonStatistic GetPositionPlayerSeasonStatistic(bool isRe string.IsNullOrEmpty(reader["secondaryPosition"].ToString()!) ? null : int.Parse(reader["secondaryPosition"].ToString()!); - positionPlayerStatistic.CurrentTeam = string.IsNullOrEmpty(reader["currentTeam"].ToString()!) + positionPlayerStatistic.TeamName = string.IsNullOrEmpty(reader["teamName"].ToString()!) + ? null + : reader["teamName"].ToString()!; + positionPlayerStatistic.MostRecentTeamName = string.IsNullOrEmpty(reader["mostRecentlyPlayedTeamName"].ToString()!) ? null - : reader["currentTeam"].ToString()!; + : reader["mostRecentlyPlayedTeamName"].ToString()!; + positionPlayerStatistic.PreviousTeam = string.IsNullOrEmpty(reader["previousRecentlyPlayedTeamName"].ToString()!) + ? null + : reader["previousRecentlyPlayedTeamName"].ToString()!; positionPlayerStatistic.GamesPlayed = int.Parse(reader["gamesPlayed"].ToString()!); positionPlayerStatistic.GamesBatting = int.Parse(reader["gamesBatting"].ToString()!); positionPlayerStatistic.AtBats = int.Parse(reader["atBats"].ToString()!); @@ -174,20 +190,6 @@ private static BattingSeasonStatistic GetPositionPlayerSeasonStatistic(bool isRe positionPlayerStatistic.SacrificeFlies = int.Parse(reader["sacrificeFlies"].ToString()!); positionPlayerStatistic.Errors = int.Parse(reader["errors"].ToString()!); positionPlayerStatistic.PassedBalls = int.Parse(reader["passedBalls"].ToString()!); - positionPlayerStatistic.CompletionDate = string.IsNullOrEmpty(reader["completionDate"].ToString()!) - ? null - : DateTime.Parse(reader["completionDate"].ToString()!); - positionPlayerStatistic.SeasonId = int.Parse(reader["seasonId"].ToString()!); - positionPlayerStatistic.SeasonNum = int.Parse(reader["seasonNum"].ToString()!); - positionPlayerStatistic.Age = int.Parse(reader["age"].ToString()!); - positionPlayerStatistic.PlayerId = reader["baseballPlayerGUID"] is not byte[] bytes ? null : bytes.ToGuid(); - - if (isRegularSeason) - { - positionPlayerStatistic.PreviousTeam = string.IsNullOrEmpty(reader["previousTeam"].ToString()!) - ? null - : reader["previousTeam"].ToString()!; - } return positionPlayerStatistic; } From f8c6594a3ff90cd2d15dbe08f5cfb1dcf2f2804f Mon Sep 17 00:00:00 2001 From: Trey Brittain Date: Thu, 18 May 2023 19:23:07 -0500 Subject: [PATCH 10/12] Update most recent season top performers exports to be consistent with changes from season stats exports --- .../BattingMostRecentSeasonStatistic.cs | 39 +---- .../Models/Exports/BattingSeasonStatistic.cs | 154 +---------------- .../Models/Exports/BattingStatistic.cs | 161 ++++++++++++++++++ .../PitchingMostRecentSeasonStatistic.cs | 45 +---- .../Models/Exports/PitchingSeasonStatistic.cs | 135 +-------------- .../Models/Exports/PitchingStatistic.cs | 142 +++++++++++++++ .../Resources/Sql/TopPerformersBatting.sql | 16 +- .../Resources/Sql/TopPerformersPitching.sql | 26 +-- .../Sql/TopPerformersRookiesBatting.sql | 16 +- .../Sql/TopPerformersRookiesPitching.sql | 26 +-- .../DataServiceFranchiseSeasons.cs | 4 +- .../DataServiceMostRecentSeason.cs | 87 +++++++--- 12 files changed, 420 insertions(+), 431 deletions(-) create mode 100644 SMB3Explorer/Models/Exports/BattingStatistic.cs create mode 100644 SMB3Explorer/Models/Exports/PitchingStatistic.cs diff --git a/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs b/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs index b9e857c..4364ea3 100644 --- a/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs @@ -1,41 +1,12 @@ -using CsvHelper.Configuration.Attributes; +using System; +using CsvHelper.Configuration.Attributes; namespace SMB3Explorer.Models.Exports; -public class BattingMostRecentSeasonStatistic +public class BattingMostRecentSeasonStatistic : BattingStatistic { - public BattingMostRecentSeasonStatistic(BattingSeasonStatistic battingSeasonStatistic) - { - PlayerId = battingSeasonStatistic.PlayerId; - FirstName = battingSeasonStatistic.FirstName; - LastName = battingSeasonStatistic.LastName; - CurrentTeam = battingSeasonStatistic.CurrentTeam; - PreviousTeam = battingSeasonStatistic.PreviousTeam; - PositionNumber = battingSeasonStatistic.PositionNumber; - SecondaryPositionNumber = battingSeasonStatistic.SecondaryPositionNumber; - GamesBatting = battingSeasonStatistic.GamesBatting; - GamesPlayed = battingSeasonStatistic.GamesPlayed; - AtBats = battingSeasonStatistic.AtBats; - Runs = battingSeasonStatistic.Runs; - Hits = battingSeasonStatistic.Hits; - Doubles = battingSeasonStatistic.Doubles; - Triples = battingSeasonStatistic.Triples; - HomeRuns = battingSeasonStatistic.HomeRuns; - RunsBattedIn = battingSeasonStatistic.RunsBattedIn; - StolenBases = battingSeasonStatistic.StolenBases; - CaughtStealing = battingSeasonStatistic.CaughtStealing; - Walks = battingSeasonStatistic.Walks; - Strikeouts = battingSeasonStatistic.Strikeouts; - HitByPitch = battingSeasonStatistic.HitByPitch; - SacrificeHits = battingSeasonStatistic.SacrificeHits; - SacrificeFlies = battingSeasonStatistic.SacrificeFlies; - PassedBalls = battingSeasonStatistic.PassedBalls; - CompletionDate = battingSeasonStatistic.CompletionDate; - SeasonId = battingSeasonStatistic.SeasonId; - SeasonNum = battingSeasonStatistic.SeasonNum; - Age = battingSeasonStatistic.Age; - } + public new Guid PlayerId { get; set; } - [Name("OPS+"), Index(47)] + [Name("OPS+"), Index(44)] public double OnBasePercentagePlus { get; set; } } \ No newline at end of file diff --git a/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs b/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs index b54feba..d6fa096 100644 --- a/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs @@ -9,161 +9,9 @@ namespace SMB3Explorer.Models.Exports; -public class BattingSeasonStatistic +public class BattingSeasonStatistic : BattingStatistic { public int AggregatorId { get; set; } public int StatsPlayerId { get; set; } - - public Guid? PlayerId { get; set; } - - public int SeasonId { get; set; } - - [Name("Season"), Index(0)] - public int SeasonNum { get; set; } - - [Name("First Name"), Index(1)] - public string FirstName { get; set; } = string.Empty; - - [Name("Last Name"), Index(2)] - public string LastName { get; set; } = string.Empty; - - [Name("Team"), Index(3)] - public string? TeamName { get; set; } - - [Name("Prev Team"), Index(4)] - public string? MostRecentTeamName { get; set; } - - [Name("2nd Prev Team"), Index(5)] - public string? PreviousTeam { get; set; } - - public int PositionNumber { get; set; } - - [Name("Position"), Index(6)] - // ReSharper disable once UnusedMember.Global - public string Position => ((BaseballPlayerPosition) PositionNumber).GetEnumDescription(); - - public int? SecondaryPositionNumber { get; set; } - - [Name("Secondary Position"), Index(7)] - // ReSharper disable once UnusedMember.Global - public string? SecondaryPosition => SecondaryPositionNumber.HasValue - ? ((BaseballPlayerPosition) SecondaryPositionNumber).GetEnumDescription() - : null; - - public int PitcherRole { get; set; } - - [Name("Pitcher Role"), Index(8)] - // ReSharper disable once UnusedMember.Global - public string PitcherRoleDescription => ((PitcherRole) PitcherRole).GetEnumDescription(); - - [Name("Age"), Index(9)] - public int Age { get; set; } - - [Name("Games Batting"), Index(10)] - public int GamesBatting { get; set; } - - [Name("Games Played"), Index(11)] - public int GamesPlayed { get; set; } - - [Name("AB"), Index(12)] - public int AtBats { get; set; } - - [Name("PA"), Index(13)] - public int PlateAppearances => AtBats + Walks + SacrificeHits + SacrificeFlies + HitByPitch; - - [Name("R"), Index(14)] - public int Runs { get; set; } - - [Name("H"), Index(15)] - public int Hits { get; set; } - - [Name("BA"), Index(36)] - public double BattingAverage => Hits / (double) AtBats; - - [Name("1B"), Index(17)] - public int Singles => Hits - Doubles - Triples - HomeRuns; - - [Name("2B"), Index(18)] - public int Doubles { get; set; } - - [Name("3B"), Index(19)] - public int Triples { get; set; } - - [Name("HR"), Index(20)] - public int HomeRuns { get; set; } - - [Name("RBI"), Index(21)] - public int RunsBattedIn { get; set; } - - [Name("XBH"), Index(22)] - public int ExtraBaseHits => Doubles + Triples + HomeRuns; - - [Name("TB"), Index(23)] - public int TotalBases => Singles + (2 * Doubles) + (3 * Triples) + (4 * HomeRuns); - - [Name("SB"), Index(24)] - public int StolenBases { get; set; } - - [Name("CS"), Index(25)] - public int CaughtStealing { get; set; } - - [Name("BB"), Index(26)] - public int Walks { get; set; } - - [Name("K"), Index(27)] - public int Strikeouts { get; set; } - - [Name("HBP"), Index(28)] - public int HitByPitch { get; set; } - - [Name("OBP"), Index(29)] - public double OnBasePercentage => (Hits + Walks + HitByPitch) / - (double) (AtBats + Walks + HitByPitch + SacrificeFlies); - - [Name("SLG"), Index(30)] - public double SluggingPercentage => (Singles + (2 * Doubles) + (3 * Triples) + - (4 * HomeRuns)) / (double) AtBats; - - [Name("OPS"), Index(31)] - public double OnBasePlusSlugging => OnBasePercentage + SluggingPercentage; - - // Caveat with this, the denominator should be subtracting intentional walks, but that data is not available - [Name("wOBA"), Index(32)] - public double WeightedOnBaseAverage => ((0.69 * Walks) + (0.72 * HitByPitch) + (0.89 * Singles) + (1.27 * Doubles) + - (1.62 * Triples) + (2.10 * HomeRuns)) / (AtBats + Walks + SacrificeFlies + HitByPitch); - - [Name("ISO"), Index(33)] - public double IsolatedPower => SluggingPercentage - BattingAverage; - - [Name("BABIP"), Index(34)] - public double BattingAverageOnBallsInPlay => - (Hits - HomeRuns) / (double) (AtBats - Strikeouts - HomeRuns + SacrificeFlies); - - [Name("Sac Hits"), Index(35)] - public int SacrificeHits { get; set; } - - [Name("Sac Flies"), Index(36)] - public int SacrificeFlies { get; set; } - - [Name("Errors"), Index(37)] - public int Errors { get; set; } - - [Name("Passed Balls"), Index(38)] - public int PassedBalls { get; set; } - - [Name("PA/Game"), Index(39)] - public double PlateAppearancesPerGame => PlateAppearances / (double) GamesPlayed; - - [Name("AB/HR"), Index(40)] - public double AtBatsPerHomeRun => AtBats / (double) HomeRuns; - - [Name("K%"), Index(41)] - public double StrikeoutPercentage => Strikeouts / (double) AtBats; - - [Name("BB%"), Index(42)] - public double WalkPercentage => Walks / (double) PlateAppearances; - - [Name("XBH%"), Index(43)] - public double ExtraBaseHitPercentage => ExtraBaseHits / (double) Hits; } diff --git a/SMB3Explorer/Models/Exports/BattingStatistic.cs b/SMB3Explorer/Models/Exports/BattingStatistic.cs new file mode 100644 index 0000000..a851cd0 --- /dev/null +++ b/SMB3Explorer/Models/Exports/BattingStatistic.cs @@ -0,0 +1,161 @@ +using System; +using CsvHelper.Configuration.Attributes; +using SMB3Explorer.Enums; +using SMB3Explorer.Utils; + +namespace SMB3Explorer.Models.Exports; + +public abstract class BattingStatistic +{ + public Guid? PlayerId { get; set; } + + public int SeasonId { get; set; } + + [Name("Season"), Index(0)] + public int SeasonNum { get; set; } + + [Name("First Name"), Index(1)] + public string FirstName { get; set; } = string.Empty; + + [Name("Last Name"), Index(2)] + public string LastName { get; set; } = string.Empty; + + [Name("Team"), Index(3)] + public string? TeamName { get; set; } + + [Name("Prev Team"), Index(4)] + public string? MostRecentTeamName { get; set; } + + [Name("2nd Prev Team"), Index(5)] + public string? PreviousTeamName { get; set; } + + public int PositionNumber { get; set; } + + [Name("Position"), Index(6)] + // ReSharper disable once UnusedMember.Global + public string Position => ((BaseballPlayerPosition) PositionNumber).GetEnumDescription(); + + public int? SecondaryPositionNumber { get; set; } + + [Name("Secondary Position"), Index(7)] + // ReSharper disable once UnusedMember.Global + public string? SecondaryPosition => SecondaryPositionNumber.HasValue + ? ((BaseballPlayerPosition) SecondaryPositionNumber).GetEnumDescription() + : null; + + public int PitcherRole { get; set; } + + [Name("Pitcher Role"), Index(8)] + // ReSharper disable once UnusedMember.Global + public string PitcherRoleDescription => ((PitcherRole) PitcherRole).GetEnumDescription(); + + [Name("Age"), Index(9)] + public int Age { get; set; } + + [Name("Games Batting"), Index(10)] + public int GamesBatting { get; set; } + + [Name("Games Played"), Index(11)] + public int GamesPlayed { get; set; } + + [Name("AB"), Index(12)] + public int AtBats { get; set; } + + [Name("PA"), Index(13)] + public int PlateAppearances => AtBats + Walks + SacrificeHits + SacrificeFlies + HitByPitch; + + [Name("R"), Index(14)] + public int Runs { get; set; } + + [Name("H"), Index(15)] + public int Hits { get; set; } + + [Name("BA"), Index(36)] + public double BattingAverage => Hits / (double) AtBats; + + [Name("1B"), Index(17)] + public int Singles => Hits - Doubles - Triples - HomeRuns; + + [Name("2B"), Index(18)] + public int Doubles { get; set; } + + [Name("3B"), Index(19)] + public int Triples { get; set; } + + [Name("HR"), Index(20)] + public int HomeRuns { get; set; } + + [Name("RBI"), Index(21)] + public int RunsBattedIn { get; set; } + + [Name("XBH"), Index(22)] + public int ExtraBaseHits => Doubles + Triples + HomeRuns; + + [Name("TB"), Index(23)] + public int TotalBases => Singles + (2 * Doubles) + (3 * Triples) + (4 * HomeRuns); + + [Name("SB"), Index(24)] + public int StolenBases { get; set; } + + [Name("CS"), Index(25)] + public int CaughtStealing { get; set; } + + [Name("BB"), Index(26)] + public int Walks { get; set; } + + [Name("K"), Index(27)] + public int Strikeouts { get; set; } + + [Name("HBP"), Index(28)] + public int HitByPitch { get; set; } + + [Name("OBP"), Index(29)] + public double OnBasePercentage => (Hits + Walks + HitByPitch) / + (double) (AtBats + Walks + HitByPitch + SacrificeFlies); + + [Name("SLG"), Index(30)] + public double SluggingPercentage => (Singles + (2 * Doubles) + (3 * Triples) + + (4 * HomeRuns)) / (double) AtBats; + + [Name("OPS"), Index(31)] + public double OnBasePlusSlugging => OnBasePercentage + SluggingPercentage; + + // Caveat with this, the denominator should be subtracting intentional walks, but that data is not available + [Name("wOBA"), Index(32)] + public double WeightedOnBaseAverage => ((0.69 * Walks) + (0.72 * HitByPitch) + (0.89 * Singles) + (1.27 * Doubles) + + (1.62 * Triples) + (2.10 * HomeRuns)) / (AtBats + Walks + SacrificeFlies + HitByPitch); + + [Name("ISO"), Index(33)] + public double IsolatedPower => SluggingPercentage - BattingAverage; + + [Name("BABIP"), Index(34)] + public double BattingAverageOnBallsInPlay => + (Hits - HomeRuns) / (double) (AtBats - Strikeouts - HomeRuns + SacrificeFlies); + + [Name("Sac Hits"), Index(35)] + public int SacrificeHits { get; set; } + + [Name("Sac Flies"), Index(36)] + public int SacrificeFlies { get; set; } + + [Name("Errors"), Index(37)] + public int Errors { get; set; } + + [Name("Passed Balls"), Index(38)] + public int PassedBalls { get; set; } + + [Name("PA/Game"), Index(39)] + public double PlateAppearancesPerGame => PlateAppearances / (double) GamesPlayed; + + [Name("AB/HR"), Index(40)] + public double AtBatsPerHomeRun => AtBats / (double) HomeRuns; + + [Name("K%"), Index(41)] + public double StrikeoutPercentage => Strikeouts / (double) AtBats; + + [Name("BB%"), Index(42)] + public double WalkPercentage => Walks / (double) PlateAppearances; + + [Name("XBH%"), Index(43)] + public double ExtraBaseHitPercentage => ExtraBaseHits / (double) Hits; +} \ No newline at end of file diff --git a/SMB3Explorer/Models/Exports/PitchingMostRecentSeasonStatistic.cs b/SMB3Explorer/Models/Exports/PitchingMostRecentSeasonStatistic.cs index e180dcb..ed3ee49 100644 --- a/SMB3Explorer/Models/Exports/PitchingMostRecentSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/PitchingMostRecentSeasonStatistic.cs @@ -1,46 +1,17 @@ -using CsvHelper.Configuration.Attributes; +using System; +using CsvHelper.Configuration.Attributes; +using SMB3Explorer.Enums; +using SMB3Explorer.Utils; namespace SMB3Explorer.Models.Exports; -public class PitchingMostRecentSeasonStatistic : PitchingSeasonStatistic +public class PitchingMostRecentSeasonStatistic : PitchingStatistic { - public PitchingMostRecentSeasonStatistic(PitchingSeasonStatistic pitchingSeasonStatistic) - { - PlayerId = pitchingSeasonStatistic.PlayerId; - FirstName = pitchingSeasonStatistic.FirstName; - LastName = pitchingSeasonStatistic.LastName; - CurrentTeam = pitchingSeasonStatistic.CurrentTeam; - PreviousTeam = pitchingSeasonStatistic.PreviousTeam; - PositionNumber = pitchingSeasonStatistic.PositionNumber; - PitcherRole = pitchingSeasonStatistic.PitcherRole; - GamesPlayed = pitchingSeasonStatistic.GamesPlayed; - GamesStarted = pitchingSeasonStatistic.GamesStarted; - Wins = pitchingSeasonStatistic.Wins; - Losses = pitchingSeasonStatistic.Losses; - CompleteGames = pitchingSeasonStatistic.CompleteGames; - Shutouts = pitchingSeasonStatistic.Shutouts; - TotalPitches = pitchingSeasonStatistic.TotalPitches; - Saves = pitchingSeasonStatistic.Saves; - OutsPitched = pitchingSeasonStatistic.OutsPitched; - HitsAllowed = pitchingSeasonStatistic.HitsAllowed; - EarnedRuns = pitchingSeasonStatistic.EarnedRuns; - HomeRunsAllowed = pitchingSeasonStatistic.HomeRunsAllowed; - WalksAllowed = pitchingSeasonStatistic.WalksAllowed; - Strikeouts = pitchingSeasonStatistic.Strikeouts; - HitByPitch = pitchingSeasonStatistic.HitByPitch; - BattersFaced = pitchingSeasonStatistic.BattersFaced; - GamesFinished = pitchingSeasonStatistic.GamesFinished; - RunsAllowed = pitchingSeasonStatistic.RunsAllowed; - WildPitches = pitchingSeasonStatistic.WildPitches; - CompletionDate = pitchingSeasonStatistic.CompletionDate; - SeasonId = pitchingSeasonStatistic.SeasonId; - SeasonNum = pitchingSeasonStatistic.SeasonNum; - Age = pitchingSeasonStatistic.Age; - } + public new Guid PlayerId { get; set; } - [Name("ERA-"), Index(48)] + [Name("ERA-"), Index(40)] public double EarnedRunsAllowedMinus { get; set; } - [Name("FIP-"), Index(49)] + [Name("FIP-"), Index(41)] public double FieldingIndependentPitchingMinus { get; set; } } \ No newline at end of file diff --git a/SMB3Explorer/Models/Exports/PitchingSeasonStatistic.cs b/SMB3Explorer/Models/Exports/PitchingSeasonStatistic.cs index e5bc642..c609534 100644 --- a/SMB3Explorer/Models/Exports/PitchingSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/PitchingSeasonStatistic.cs @@ -9,142 +9,9 @@ namespace SMB3Explorer.Models.Exports; -public class PitchingSeasonStatistic +public class PitchingSeasonStatistic : PitchingStatistic { public int AggregatorId { get; set; } public int StatsPlayerId { get; set; } - - public Guid? PlayerId { get; set; } - - public int SeasonId { get; set; } - - [Name("Season"), Index(0)] - public int SeasonNum { get; set; } - - [Name("First Name"), Index(1)] - public string FirstName { get; set; } = string.Empty; - - [Name("Last Name"), Index(2)] - public string LastName { get; set; } = string.Empty; - - [Name("Team"), Index(3)] - public string? TeamName { get; set; } - - [Name("Prev Team"), Index(4)] - public string? MostRecentTeamName { get; set; } - - [Name("2nd Prev Team"), Index(5)] - public string? PreviousTeam { get; set; } - - public int PositionNumber { get; set; } - - public int PitcherRole { get; set; } - - [Name("Pitcher Role"), Index(6)] - // ReSharper disable once UnusedMember.Global - public string PitcherRoleDescription => ((PitcherRole) PitcherRole).GetEnumDescription(); - - [Name("Age"), Index(7)] - public int Age { get; set; } - - [Name("W"), Index(8)] - public int Wins { get; set; } - - [Name("L"), Index(9)] - public int Losses { get; set; } - - [Name("CG"), Index(10)] - public int CompleteGames { get; set; } - - [Name("CGSO"), Index(11)] - public int Shutouts { get; set; } - - public int OutsPitched { get; set; } - - [Name("H"), Index(12)] - public int HitsAllowed { get; set; } - - [Name("ER"), Index(13)] - public int EarnedRuns { get; set; } - - [Name("HR"), Index(14)] - public int HomeRunsAllowed { get; set; } - - [Name("BB"), Index(15)] - public int WalksAllowed { get; set; } - - [Name("K"), Index(16)] - public int Strikeouts { get; set; } - - [Name("IP"), Index(17)] - public double InningsPitched => OutsPitched / 3.0; - - [Name("ERA"), Index(18)] - public double EarnedRunAverage => EarnedRuns / InningsPitched; - - [Name("TP"), Index(19)] - public int TotalPitches { get; set; } - - [Name("S"), Index(20)] - public int Saves { get; set; } - - [Name("HBP"), Index(21)] - public int HitByPitch { get; set; } - - [Name("Batters Faced"), Index(22)] - public int BattersFaced { get; set; } - - [Name("Games Played"), Index(23)] - public int GamesPlayed { get; set; } - - [Name("Games Started"), Index(24)] - public int GamesStarted { get; set; } - - [Name("Games Finished"), Index(25)] - public int GamesFinished { get; set; } - - [Name("Runs Allowed"), Index(26)] - public int RunsAllowed { get; set; } - - [Name("WP"), Index(27)] - public int WildPitches { get; set; } - - [Name("BAA"), Index(28)] - public double BattingAverageAgainst => HitsAllowed / (double) BattersFaced; - - [Name("FIP"), Index(29)] - public double FieldingIndependentPitching => - (((13 * HomeRunsAllowed) + (3 * (WalksAllowed + HitByPitch)) - - (2 * Strikeouts)) / (double) OutsPitched) + 3.10; - - [Name("WHIP"), Index(30)] - public double WalksAndHitsPerInning => (WalksAllowed + HitsAllowed) / InningsPitched; - - [Name("WPCT"), Index(31)] - public double WinPercentage => Wins / (double) (Wins + Losses); - - [Name("Opp OBP"), Index(32)] - public double OpponentOnBasePercentage => (HitsAllowed + WalksAllowed + HitByPitch) / (double) BattersFaced; - - [Name("K/BB"), Index(33)] - public double StrikeoutToWalkRatio => Strikeouts / (double) WalksAllowed; - - [Name("K/9"), Index(34)] - public double StrikeoutsPerNineInnings => Strikeouts / (InningsPitched / 9.0); - - [Name("BB/9"), Index(35)] - public double WalksPerNineInnings => WalksAllowed / (InningsPitched / 9.0); - - [Name("H/9"), Index(36)] - public double HitsPerNineInnings => HitsAllowed / (InningsPitched / 9.0); - - [Name("HR/9"), Index(37)] - public double HomeRunsPerNineInnings => HomeRunsAllowed / (InningsPitched / 9.0); - - [Name("Pitches Per Inning"), Index(38)] - public double PitchesPerInning => TotalPitches / InningsPitched; - - [Name("Pitcher Per Game"), Index(39)] - public double PitchesPerGame => TotalPitches / (double) GamesPlayed; } diff --git a/SMB3Explorer/Models/Exports/PitchingStatistic.cs b/SMB3Explorer/Models/Exports/PitchingStatistic.cs new file mode 100644 index 0000000..63516b4 --- /dev/null +++ b/SMB3Explorer/Models/Exports/PitchingStatistic.cs @@ -0,0 +1,142 @@ +using System; +using CsvHelper.Configuration.Attributes; +using SMB3Explorer.Enums; +using SMB3Explorer.Utils; + +namespace SMB3Explorer.Models.Exports; + +public abstract class PitchingStatistic +{ + public Guid? PlayerId { get; set; } + + public int SeasonId { get; set; } + + [Name("Season"), Index(0)] + public int SeasonNum { get; set; } + + [Name("First Name"), Index(1)] + public string FirstName { get; set; } = string.Empty; + + [Name("Last Name"), Index(2)] + public string LastName { get; set; } = string.Empty; + + [Name("Team"), Index(3)] + public string? TeamName { get; set; } + + [Name("Prev Team"), Index(4)] + public string? MostRecentTeamName { get; set; } + + [Name("2nd Prev Team"), Index(5)] + public string? PreviousTeamName { get; set; } + + public int PositionNumber { get; set; } + + public int PitcherRole { get; set; } + + [Name("Pitcher Role"), Index(6)] + // ReSharper disable once UnusedMember.Global + public string PitcherRoleDescription => ((PitcherRole) PitcherRole).GetEnumDescription(); + + [Name("Age"), Index(7)] + public int Age { get; set; } + + [Name("W"), Index(8)] + public int Wins { get; set; } + + [Name("L"), Index(9)] + public int Losses { get; set; } + + [Name("CG"), Index(10)] + public int CompleteGames { get; set; } + + [Name("CGSO"), Index(11)] + public int Shutouts { get; set; } + + public int OutsPitched { get; set; } + + [Name("H"), Index(12)] + public int HitsAllowed { get; set; } + + [Name("ER"), Index(13)] + public int EarnedRuns { get; set; } + + [Name("HR"), Index(14)] + public int HomeRunsAllowed { get; set; } + + [Name("BB"), Index(15)] + public int WalksAllowed { get; set; } + + [Name("K"), Index(16)] + public int Strikeouts { get; set; } + + [Name("IP"), Index(17)] + public double InningsPitched => OutsPitched / 3.0; + + [Name("ERA"), Index(18)] + public double EarnedRunAverage => EarnedRuns / InningsPitched; + + [Name("TP"), Index(19)] + public int TotalPitches { get; set; } + + [Name("S"), Index(20)] + public int Saves { get; set; } + + [Name("HBP"), Index(21)] + public int HitByPitch { get; set; } + + [Name("Batters Faced"), Index(22)] + public int BattersFaced { get; set; } + + [Name("Games Played"), Index(23)] + public int GamesPlayed { get; set; } + + [Name("Games Started"), Index(24)] + public int GamesStarted { get; set; } + + [Name("Games Finished"), Index(25)] + public int GamesFinished { get; set; } + + [Name("Runs Allowed"), Index(26)] + public int RunsAllowed { get; set; } + + [Name("WP"), Index(27)] + public int WildPitches { get; set; } + + [Name("BAA"), Index(28)] + public double BattingAverageAgainst => HitsAllowed / (double) BattersFaced; + + [Name("FIP"), Index(29)] + public double FieldingIndependentPitching => + (((13 * HomeRunsAllowed) + (3 * (WalksAllowed + HitByPitch)) - + (2 * Strikeouts)) / (double) OutsPitched) + 3.10; + + [Name("WHIP"), Index(30)] + public double WalksAndHitsPerInning => (WalksAllowed + HitsAllowed) / InningsPitched; + + [Name("WPCT"), Index(31)] + public double WinPercentage => Wins / (double) (Wins + Losses); + + [Name("Opp OBP"), Index(32)] + public double OpponentOnBasePercentage => (HitsAllowed + WalksAllowed + HitByPitch) / (double) BattersFaced; + + [Name("K/BB"), Index(33)] + public double StrikeoutToWalkRatio => Strikeouts / (double) WalksAllowed; + + [Name("K/9"), Index(34)] + public double StrikeoutsPerNineInnings => Strikeouts / (InningsPitched / 9.0); + + [Name("BB/9"), Index(35)] + public double WalksPerNineInnings => WalksAllowed / (InningsPitched / 9.0); + + [Name("H/9"), Index(36)] + public double HitsPerNineInnings => HitsAllowed / (InningsPitched / 9.0); + + [Name("HR/9"), Index(37)] + public double HomeRunsPerNineInnings => HomeRunsAllowed / (InningsPitched / 9.0); + + [Name("Pitches Per Inning"), Index(38)] + public double PitchesPerInning => TotalPitches / InningsPitched; + + [Name("Pitcher Per Game"), Index(39)] + public double PitchesPerGame => TotalPitches / (double) GamesPlayed; +} \ No newline at end of file diff --git a/SMB3Explorer/Resources/Sql/TopPerformersBatting.sql b/SMB3Explorer/Resources/Sql/TopPerformersBatting.sql index 1f0b6fe..44e16f0 100644 --- a/SMB3Explorer/Resources/Sql/TopPerformersBatting.sql +++ b/SMB3Explorer/Resources/Sql/TopPerformersBatting.sql @@ -11,7 +11,6 @@ ORDER BY ID DESC LIMIT 1) SELECT baseballPlayerGUID, - tsea.completionDate, tsea.ID AS seasonId, s.seasonNum, CASE @@ -41,8 +40,9 @@ SELECT baseballPlayerGUID, (([hits] - [doubles] - [triples] - [homeruns]) + 2 * [doubles] + 3 * [triples] + 4 * [homeruns]) / CAST(NULLIF([atBats], 0) AS [REAL]) ) / @leagueOps) AS sortOrder, - currentTeam.teamName AS currentTeam, - previousTeam.teamName AS previousTeam, + currentTeam.teamName AS teamName, + mostRecentTeam.teamName AS mostRecentlyPlayedTeamName, + previouslyRecentPlayedTeam.teamName AS previousRecentlyPlayedTeamName, tbp.age AS age FROM [v_baseball_player_info] vbpi LEFT JOIN t_baseball_player_local_ids tbpli ON vbpi.baseballPlayerGUID = tbpli.GUID @@ -62,11 +62,11 @@ FROM [v_baseball_player_info] vbpi LEFT JOIN t_baseball_player_options secondaryPosition ON tbpli.localID = secondaryPosition.baseballPlayerLocalID AND secondaryPosition.optionKey = 55 - LEFT JOIN [t_team_local_ids] tt1 ON ts.[currentTeamLocalID] = tt1.[localID] - LEFT JOIN [t_team_local_ids] tt2 - ON ts.[previousRecentlyPlayedTeamLocalID] = tt2.[localID] + LEFT JOIN t_team_local_ids tt1 ON ts.currentTeamLocalID = tt1.localID + LEFT JOIN t_team_local_ids tt2 ON ts.mostRecentlyPlayedTeamLocalID = tt2.localID + LEFT JOIN t_team_local_ids tt3 ON ts.previousRecentlyPlayedTeamLocalID = tt3.localID LEFT JOIN teams currentTeam ON tt1.GUID = currentTeam.teamGUID - LEFT JOIN teams previousTeam ON tt2.GUID = previousTeam.teamGUID - + LEFT JOIN teams mostRecentTeam ON tt2.GUID = mostRecentTeam.teamGUID + LEFT JOIN teams previouslyRecentPlayedTeam ON tt3.GUID = previouslyRecentPlayedTeam.teamGUID WHERE tl.GUID = CAST(@leagueId AS BLOB) ORDER BY sortOrder DESC \ No newline at end of file diff --git a/SMB3Explorer/Resources/Sql/TopPerformersPitching.sql b/SMB3Explorer/Resources/Sql/TopPerformersPitching.sql index a39a48f..8e9a561 100644 --- a/SMB3Explorer/Resources/Sql/TopPerformersPitching.sql +++ b/SMB3Explorer/Resources/Sql/TopPerformersPitching.sql @@ -12,7 +12,6 @@ ORDER BY ID DESC LIMIT 1) SELECT baseballPlayerGUID, - tsea.completionDate, tsea.ID AS seasonId, s.seasonNum, CASE @@ -53,8 +52,9 @@ SELECT baseballPlayerGUID, @leagueEra / ((tspitch.earnedRuns * 9) / (tspitch.outsPitched / 3.0)) ) END AS sortOrder, - currentTeam.teamName AS currentTeam, - previousTeam.teamName AS previousTeam, + currentTeam.teamName AS teamName, + mostRecentTeam.teamName AS mostRecentlyPlayedTeamName, + previouslyRecentPlayedTeam.teamName AS previousRecentlyPlayedTeamName, tbp.age AS age FROM [v_baseball_player_info] vbpi LEFT JOIN t_baseball_player_local_ids tbpli ON vbpi.baseballPlayerGUID = tbpli.GUID @@ -71,21 +71,11 @@ FROM [v_baseball_player_info] vbpi JOIN t_league_local_ids tlli ON tsp.leagueLocalID = tlli.localID JOIN t_leagues tl ON tlli.GUID = tl.GUID - LEFT JOIN [t_team_local_ids] tt1 ON ts.[currentTeamLocalID] = tt1.[localID] - LEFT JOIN [t_team_local_ids] tt2 - ON ts.[previousRecentlyPlayedTeamLocalID] = tt2.[localID] + LEFT JOIN t_team_local_ids tt1 ON ts.currentTeamLocalID = tt1.localID + LEFT JOIN t_team_local_ids tt2 ON ts.mostRecentlyPlayedTeamLocalID = tt2.localID + LEFT JOIN t_team_local_ids tt3 ON ts.previousRecentlyPlayedTeamLocalID = tt3.localID LEFT JOIN teams currentTeam ON tt1.GUID = currentTeam.teamGUID - LEFT JOIN teams previousTeam ON tt2.GUID = previousTeam.teamGUID + LEFT JOIN teams mostRecentTeam ON tt2.GUID = mostRecentTeam.teamGUID + LEFT JOIN teams previouslyRecentPlayedTeam ON tt3.GUID = previouslyRecentPlayedTeam.teamGUID WHERE tl.GUID = CAST(@leagueId AS BLOB) - AND outsPitched > (SELECT AVG(tspitch.outsPitched) - FROM [v_baseball_player_info] vbpi - LEFT JOIN t_baseball_player_local_ids tbpli ON vbpi.baseballPlayerGUID = tbpli.GUID - LEFT JOIN t_stats_players tsp ON tbpli.localID = tsp.baseballPlayerLocalID - LEFT JOIN t_stats ts ON tsp.statsPlayerID = ts.statsPlayerID - JOIN t_stats_pitching tspitch ON ts.aggregatorID = tspitch.aggregatorID - - LEFT JOIN t_season_stats tss ON ts.aggregatorID = tss.aggregatorID - - JOIN t_seasons tsea ON tss.seasonID = tsea.ID - JOIN mostRecentSeason s ON tsea.ID = s.seasonID) ORDER BY sortOrder DESC \ No newline at end of file diff --git a/SMB3Explorer/Resources/Sql/TopPerformersRookiesBatting.sql b/SMB3Explorer/Resources/Sql/TopPerformersRookiesBatting.sql index f6cccb2..4777c2b 100644 --- a/SMB3Explorer/Resources/Sql/TopPerformersRookiesBatting.sql +++ b/SMB3Explorer/Resources/Sql/TopPerformersRookiesBatting.sql @@ -20,7 +20,6 @@ GROUP BY baseballPlayerGUID HAVING numSeasons = 1) SELECT vbpi.baseballPlayerGUID, - tsea.completionDate, tsea.ID AS seasonId, s.seasonNum, CASE @@ -50,8 +49,9 @@ SELECT vbpi.baseballPlayerGUID, (([hits] - [doubles] - [triples] - [homeruns]) + 2 * [doubles] + 3 * [triples] + 4 * [homeruns]) / CAST(NULLIF([atBats], 0) AS [REAL]) ) / @leagueOps) AS sortOrder, - currentTeam.teamName AS currentTeam, - previousTeam.teamName AS previousTeam, + currentTeam.teamName AS teamName, + mostRecentTeam.teamName AS mostRecentlyPlayedTeamName, + previouslyRecentPlayedTeam.teamName AS previousRecentlyPlayedTeamName, tbp.age AS age FROM [v_baseball_player_info] vbpi LEFT JOIN t_baseball_player_local_ids tbpli ON vbpi.baseballPlayerGUID = tbpli.GUID @@ -73,11 +73,11 @@ FROM [v_baseball_player_info] vbpi LEFT JOIN t_baseball_player_options secondaryPosition ON tbpli.localID = secondaryPosition.baseballPlayerLocalID AND secondaryPosition.optionKey = 55 - LEFT JOIN [t_team_local_ids] tt1 ON ts.[currentTeamLocalID] = tt1.[localID] - LEFT JOIN [t_team_local_ids] tt2 - ON ts.[previousRecentlyPlayedTeamLocalID] = tt2.[localID] + LEFT JOIN t_team_local_ids tt1 ON ts.currentTeamLocalID = tt1.localID + LEFT JOIN t_team_local_ids tt2 ON ts.mostRecentlyPlayedTeamLocalID = tt2.localID + LEFT JOIN t_team_local_ids tt3 ON ts.previousRecentlyPlayedTeamLocalID = tt3.localID LEFT JOIN teams currentTeam ON tt1.GUID = currentTeam.teamGUID - LEFT JOIN teams previousTeam ON tt2.GUID = previousTeam.teamGUID - + LEFT JOIN teams mostRecentTeam ON tt2.GUID = mostRecentTeam.teamGUID + LEFT JOIN teams previouslyRecentPlayedTeam ON tt3.GUID = previouslyRecentPlayedTeam.teamGUID WHERE tl.GUID = CAST(@leagueId AS BLOB) ORDER BY sortOrder DESC \ No newline at end of file diff --git a/SMB3Explorer/Resources/Sql/TopPerformersRookiesPitching.sql b/SMB3Explorer/Resources/Sql/TopPerformersRookiesPitching.sql index 940fd67..2fddc8b 100644 --- a/SMB3Explorer/Resources/Sql/TopPerformersRookiesPitching.sql +++ b/SMB3Explorer/Resources/Sql/TopPerformersRookiesPitching.sql @@ -21,7 +21,6 @@ GROUP BY baseballPlayerGUID HAVING numSeasons = 1) SELECT vbpi.baseballPlayerGUID, - tsea.completionDate, tsea.ID AS seasonId, s.seasonNum, CASE @@ -62,8 +61,9 @@ SELECT vbpi.baseballPlayerGUID, @leagueEra / ((tspitch.earnedRuns * 9) / (tspitch.outsPitched / 3.0)) ) END AS sortOrder, - currentTeam.teamName AS currentTeam, - previousTeam.teamName AS previousTeam, + currentTeam.teamName AS teamName, + mostRecentTeam.teamName AS mostRecentlyPlayedTeamName, + previouslyRecentPlayedTeam.teamName AS previousRecentlyPlayedTeamName, tbp.age AS age FROM [v_baseball_player_info] vbpi LEFT JOIN t_baseball_player_local_ids tbpli ON vbpi.baseballPlayerGUID = tbpli.GUID @@ -82,21 +82,11 @@ FROM [v_baseball_player_info] vbpi JOIN t_league_local_ids tlli ON tsp.leagueLocalID = tlli.localID JOIN t_leagues tl ON tlli.GUID = tl.GUID - LEFT JOIN [t_team_local_ids] tt1 ON ts.[currentTeamLocalID] = tt1.[localID] - LEFT JOIN [t_team_local_ids] tt2 - ON ts.[previousRecentlyPlayedTeamLocalID] = tt2.[localID] + LEFT JOIN t_team_local_ids tt1 ON ts.currentTeamLocalID = tt1.localID + LEFT JOIN t_team_local_ids tt2 ON ts.mostRecentlyPlayedTeamLocalID = tt2.localID + LEFT JOIN t_team_local_ids tt3 ON ts.previousRecentlyPlayedTeamLocalID = tt3.localID LEFT JOIN teams currentTeam ON tt1.GUID = currentTeam.teamGUID - LEFT JOIN teams previousTeam ON tt2.GUID = previousTeam.teamGUID + LEFT JOIN teams mostRecentTeam ON tt2.GUID = mostRecentTeam.teamGUID + LEFT JOIN teams previouslyRecentPlayedTeam ON tt3.GUID = previouslyRecentPlayedTeam.teamGUID WHERE tl.GUID = CAST(@leagueId AS BLOB) - AND outsPitched > (SELECT AVG(tspitch.outsPitched) - FROM [v_baseball_player_info] vbpi - LEFT JOIN t_baseball_player_local_ids tbpli ON vbpi.baseballPlayerGUID = tbpli.GUID - LEFT JOIN t_stats_players tsp ON tbpli.localID = tsp.baseballPlayerLocalID - LEFT JOIN t_stats ts ON tsp.statsPlayerID = ts.statsPlayerID - JOIN t_stats_pitching tspitch ON ts.aggregatorID = tspitch.aggregatorID - - LEFT JOIN t_season_stats tss ON ts.aggregatorID = tss.aggregatorID - - JOIN t_seasons tsea ON tss.seasonID = tsea.ID - JOIN mostRecentSeason s ON tsea.ID = s.seasonID) ORDER BY sortOrder DESC \ No newline at end of file diff --git a/SMB3Explorer/Services/DataService/DataServiceFranchiseSeasons.cs b/SMB3Explorer/Services/DataService/DataServiceFranchiseSeasons.cs index f5a081d..5085132 100644 --- a/SMB3Explorer/Services/DataService/DataServiceFranchiseSeasons.cs +++ b/SMB3Explorer/Services/DataService/DataServiceFranchiseSeasons.cs @@ -113,7 +113,7 @@ private static PitchingSeasonStatistic GetPitchingSeasonStatistic(bool isRegular pitcherStatistic.MostRecentTeamName = string.IsNullOrEmpty(reader["mostRecentlyPlayedTeamName"].ToString()!) ? null : reader["mostRecentlyPlayedTeamName"].ToString()!; - pitcherStatistic.PreviousTeam = string.IsNullOrEmpty(reader["previousRecentlyPlayedTeamName"].ToString()!) + pitcherStatistic.PreviousTeamName = string.IsNullOrEmpty(reader["previousRecentlyPlayedTeamName"].ToString()!) ? null : reader["previousRecentlyPlayedTeamName"].ToString()!; @@ -169,7 +169,7 @@ private static BattingSeasonStatistic GetPositionPlayerSeasonStatistic(bool isRe positionPlayerStatistic.MostRecentTeamName = string.IsNullOrEmpty(reader["mostRecentlyPlayedTeamName"].ToString()!) ? null : reader["mostRecentlyPlayedTeamName"].ToString()!; - positionPlayerStatistic.PreviousTeam = string.IsNullOrEmpty(reader["previousRecentlyPlayedTeamName"].ToString()!) + positionPlayerStatistic.PreviousTeamName = string.IsNullOrEmpty(reader["previousRecentlyPlayedTeamName"].ToString()!) ? null : reader["previousRecentlyPlayedTeamName"].ToString()!; positionPlayerStatistic.GamesPlayed = int.Parse(reader["gamesPlayed"].ToString()!); diff --git a/SMB3Explorer/Services/DataService/DataServiceMostRecentSeason.cs b/SMB3Explorer/Services/DataService/DataServiceMostRecentSeason.cs index b687192..25ddfe0 100644 --- a/SMB3Explorer/Services/DataService/DataServiceMostRecentSeason.cs +++ b/SMB3Explorer/Services/DataService/DataServiceMostRecentSeason.cs @@ -38,14 +38,41 @@ public async IAsyncEnumerable GetMostRecentSea while (reader.Read()) { - var positionPlayerStatistic = GetPositionPlayerSeasonStatistic(true, reader); - - var mostRecentSeasonStatistic = new BattingMostRecentSeasonStatistic(positionPlayerStatistic); - - var opsPlus = reader["opsPlus"].ToString()!; - mostRecentSeasonStatistic.OnBasePercentagePlus = string.IsNullOrEmpty(opsPlus) ? 0 : double.Parse(opsPlus); - - yield return mostRecentSeasonStatistic; + var positionPlayerStatistic = new BattingMostRecentSeasonStatistic(); + + positionPlayerStatistic.PlayerId = reader.GetGuid(0); + positionPlayerStatistic.SeasonId = reader.GetInt32(1); + positionPlayerStatistic.SeasonNum = reader.GetInt32(2); + positionPlayerStatistic.FirstName = reader.GetString(3); + positionPlayerStatistic.LastName = reader.GetString(4); + positionPlayerStatistic.PositionNumber = reader.GetInt32(5); + positionPlayerStatistic.PitcherRole = reader.GetInt32(6); + positionPlayerStatistic.SecondaryPositionNumber = reader.IsDBNull(7) ? null : reader.GetInt32(7); + positionPlayerStatistic.GamesBatting = reader.GetInt32(9); + positionPlayerStatistic.GamesPlayed = reader.GetInt32(10); + positionPlayerStatistic.AtBats = reader.GetInt32(11); + positionPlayerStatistic.Runs = reader.GetInt32(12); + positionPlayerStatistic.Hits = reader.GetInt32(13); + positionPlayerStatistic.Doubles = reader.GetInt32(14); + positionPlayerStatistic.Triples = reader.GetInt32(15); + positionPlayerStatistic.HomeRuns = reader.GetInt32(16); + positionPlayerStatistic.RunsBattedIn = reader.GetInt32(17); + positionPlayerStatistic.StolenBases = reader.GetInt32(18); + positionPlayerStatistic.CaughtStealing = reader.GetInt32(19); + positionPlayerStatistic.Walks = reader.GetInt32(20); + positionPlayerStatistic.Strikeouts = reader.GetInt32(21); + positionPlayerStatistic.HitByPitch = reader.GetInt32(22); + positionPlayerStatistic.SacrificeHits = reader.GetInt32(23); + positionPlayerStatistic.SacrificeFlies = reader.GetInt32(24); + positionPlayerStatistic.Errors = reader.GetInt32(25); + positionPlayerStatistic.PassedBalls = reader.GetInt32(26); + positionPlayerStatistic.OnBasePercentagePlus = reader.GetDouble(27); + positionPlayerStatistic.TeamName = reader.GetString(28); + positionPlayerStatistic.MostRecentTeamName = reader.IsDBNull(29) ? null : reader.GetString(29); + positionPlayerStatistic.PreviousTeamName = reader.IsDBNull(30) ? null : reader.GetString(30); + positionPlayerStatistic.Age = reader.GetInt32(31); + + yield return positionPlayerStatistic; } } @@ -80,17 +107,39 @@ public async IAsyncEnumerable GetMostRecentSe while (reader.Read()) { - var pitcherStatistic = GetPitchingSeasonStatistic(true, reader); - - var mostRecentSeasonStatistic = new PitchingMostRecentSeasonStatistic(pitcherStatistic); - - var eraMinus = reader["eraMinus"].ToString()!; - mostRecentSeasonStatistic.EarnedRunsAllowedMinus = - string.IsNullOrEmpty(eraMinus) ? 0 : double.Parse(eraMinus); - - var fipMinus = reader["fipMinus"].ToString()!; - mostRecentSeasonStatistic.FieldingIndependentPitchingMinus = - string.IsNullOrEmpty(fipMinus) ? 0 : double.Parse(fipMinus); + var mostRecentSeasonStatistic = new PitchingMostRecentSeasonStatistic(); + + mostRecentSeasonStatistic.PlayerId = reader.GetGuid(0); + mostRecentSeasonStatistic.SeasonId = reader.GetInt32(1); + mostRecentSeasonStatistic.SeasonNum = reader.GetInt32(2); + mostRecentSeasonStatistic.FirstName = reader.GetString(3); + mostRecentSeasonStatistic.LastName = reader.GetString(4); + mostRecentSeasonStatistic.PositionNumber = reader.GetInt32(5); + mostRecentSeasonStatistic.PitcherRole = reader.GetInt32(6); + mostRecentSeasonStatistic.Wins = reader.GetInt32(8); + mostRecentSeasonStatistic.Losses = reader.GetInt32(9); + mostRecentSeasonStatistic.GamesStarted = reader.GetInt32(11); + mostRecentSeasonStatistic.CompleteGames = reader.GetInt32(12); + mostRecentSeasonStatistic.TotalPitches = reader.GetInt32(13); + mostRecentSeasonStatistic.GamesPlayed = reader.GetInt32(14); + mostRecentSeasonStatistic.Shutouts = reader.GetInt32(15); + mostRecentSeasonStatistic.Saves = reader.GetInt32(16); + mostRecentSeasonStatistic.OutsPitched = reader.GetInt32(17); + mostRecentSeasonStatistic.HitsAllowed = reader.GetInt32(18); + mostRecentSeasonStatistic.EarnedRuns = reader.GetInt32(19); + mostRecentSeasonStatistic.HomeRunsAllowed = reader.GetInt32(20); + mostRecentSeasonStatistic.WalksAllowed = reader.GetInt32(21); + mostRecentSeasonStatistic.Strikeouts = reader.GetInt32(22); + mostRecentSeasonStatistic.HitByPitch = reader.GetInt32(23); + mostRecentSeasonStatistic.BattersFaced = reader.GetInt32(24); + mostRecentSeasonStatistic.RunsAllowed = reader.GetInt32(25); + mostRecentSeasonStatistic.WildPitches = reader.GetInt32(26); + mostRecentSeasonStatistic.EarnedRunsAllowedMinus = reader.GetDouble(27); + mostRecentSeasonStatistic.FieldingIndependentPitchingMinus = reader.GetDouble(28); + mostRecentSeasonStatistic.TeamName = reader.GetString(30); + mostRecentSeasonStatistic.MostRecentTeamName = reader.IsDBNull(31) ? null : reader.GetString(31); + mostRecentSeasonStatistic.PreviousTeamName = reader.IsDBNull(32) ? null : reader.GetString(32); + mostRecentSeasonStatistic.Age = reader.GetInt32(33); yield return mostRecentSeasonStatistic; } From 7ce3f1c38d59050f3c49a0bf37c287389ac3bc50 Mon Sep 17 00:00:00 2001 From: Trey Brittain Date: Thu, 18 May 2023 20:07:25 -0500 Subject: [PATCH 11/12] Fix issues with season exports --- .../Exports/BattingMostRecentSeasonStatistic.cs | 1 + .../Models/Exports/BattingSeasonStatistic.cs | 2 ++ SMB3Explorer/Models/Exports/BattingStatistic.cs | 14 +++++++++----- .../Exports/PitchingMostRecentSeasonStatistic.cs | 1 + .../Models/Exports/PitchingSeasonStatistic.cs | 2 ++ SMB3Explorer/Models/Exports/PitchingStatistic.cs | 7 ++++++- SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql | 5 ----- .../Resources/Sql/PlayoffStatsPitching.sql | 5 ----- SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql | 7 +------ SMB3Explorer/Resources/Sql/SeasonStatsPitching.sql | 5 ----- .../DataService/DataServiceFranchiseSeasons.cs | 11 ++++++++--- .../DataService/DataServiceMostRecentSeason.cs | 3 ++- 12 files changed, 32 insertions(+), 31 deletions(-) diff --git a/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs b/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs index 4364ea3..c4c87ff 100644 --- a/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs @@ -5,6 +5,7 @@ namespace SMB3Explorer.Models.Exports; public class BattingMostRecentSeasonStatistic : BattingStatistic { + [Ignore] public new Guid PlayerId { get; set; } [Name("OPS+"), Index(44)] diff --git a/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs b/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs index d6fa096..bdc16d4 100644 --- a/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs @@ -11,7 +11,9 @@ namespace SMB3Explorer.Models.Exports; public class BattingSeasonStatistic : BattingStatistic { + [Ignore] public int AggregatorId { get; set; } + [Ignore] public int StatsPlayerId { get; set; } } diff --git a/SMB3Explorer/Models/Exports/BattingStatistic.cs b/SMB3Explorer/Models/Exports/BattingStatistic.cs index a851cd0..e4e83f2 100644 --- a/SMB3Explorer/Models/Exports/BattingStatistic.cs +++ b/SMB3Explorer/Models/Exports/BattingStatistic.cs @@ -7,9 +7,9 @@ namespace SMB3Explorer.Models.Exports; public abstract class BattingStatistic { - public Guid? PlayerId { get; set; } + public Guid? PlayerId { private get; set; } - public int SeasonId { get; set; } + public int SeasonId { private get; set; } [Name("Season"), Index(0)] public int SeasonNum { get; set; } @@ -29,12 +29,14 @@ public abstract class BattingStatistic [Name("2nd Prev Team"), Index(5)] public string? PreviousTeamName { get; set; } + [Ignore] public int PositionNumber { get; set; } [Name("Position"), Index(6)] // ReSharper disable once UnusedMember.Global public string Position => ((BaseballPlayerPosition) PositionNumber).GetEnumDescription(); + [Ignore] public int? SecondaryPositionNumber { get; set; } [Name("Secondary Position"), Index(7)] @@ -43,12 +45,14 @@ public abstract class BattingStatistic ? ((BaseballPlayerPosition) SecondaryPositionNumber).GetEnumDescription() : null; - public int PitcherRole { get; set; } + [Ignore] + public int? PitcherRole { get; set; } [Name("Pitcher Role"), Index(8)] // ReSharper disable once UnusedMember.Global - public string PitcherRoleDescription => ((PitcherRole) PitcherRole).GetEnumDescription(); - + public string? PitcherRoleDescription => + !PitcherRole.HasValue ? null : ((PitcherRole) PitcherRole).GetEnumDescription(); + [Name("Age"), Index(9)] public int Age { get; set; } diff --git a/SMB3Explorer/Models/Exports/PitchingMostRecentSeasonStatistic.cs b/SMB3Explorer/Models/Exports/PitchingMostRecentSeasonStatistic.cs index ed3ee49..b7e3ec8 100644 --- a/SMB3Explorer/Models/Exports/PitchingMostRecentSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/PitchingMostRecentSeasonStatistic.cs @@ -7,6 +7,7 @@ namespace SMB3Explorer.Models.Exports; public class PitchingMostRecentSeasonStatistic : PitchingStatistic { + [Ignore] public new Guid PlayerId { get; set; } [Name("ERA-"), Index(40)] diff --git a/SMB3Explorer/Models/Exports/PitchingSeasonStatistic.cs b/SMB3Explorer/Models/Exports/PitchingSeasonStatistic.cs index c609534..9a3a8ec 100644 --- a/SMB3Explorer/Models/Exports/PitchingSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/PitchingSeasonStatistic.cs @@ -11,7 +11,9 @@ namespace SMB3Explorer.Models.Exports; public class PitchingSeasonStatistic : PitchingStatistic { + [Ignore] public int AggregatorId { get; set; } + [Ignore] public int StatsPlayerId { get; set; } } diff --git a/SMB3Explorer/Models/Exports/PitchingStatistic.cs b/SMB3Explorer/Models/Exports/PitchingStatistic.cs index 63516b4..6674b38 100644 --- a/SMB3Explorer/Models/Exports/PitchingStatistic.cs +++ b/SMB3Explorer/Models/Exports/PitchingStatistic.cs @@ -7,8 +7,10 @@ namespace SMB3Explorer.Models.Exports; public abstract class PitchingStatistic { + [Ignore] public Guid? PlayerId { get; set; } + [Ignore] public int SeasonId { get; set; } [Name("Season"), Index(0)] @@ -29,8 +31,10 @@ public abstract class PitchingStatistic [Name("2nd Prev Team"), Index(5)] public string? PreviousTeamName { get; set; } + [Ignore] public int PositionNumber { get; set; } + [Ignore] public int PitcherRole { get; set; } [Name("Pitcher Role"), Index(6)] @@ -52,6 +56,7 @@ public abstract class PitchingStatistic [Name("CGSO"), Index(11)] public int Shutouts { get; set; } + [Ignore] public int OutsPitched { get; set; } [Name("H"), Index(12)] @@ -73,7 +78,7 @@ public abstract class PitchingStatistic public double InningsPitched => OutsPitched / 3.0; [Name("ERA"), Index(18)] - public double EarnedRunAverage => EarnedRuns / InningsPitched; + public double EarnedRunAverage => EarnedRuns / (InningsPitched / 9.0); [Name("TP"), Index(19)] public int TotalPitches { get; set; } diff --git a/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql b/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql index 7e9de1e..695b566 100644 --- a/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql +++ b/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql @@ -78,9 +78,4 @@ FROM t_stats_batting tsb LEFT JOIN t_baseball_players tbp on tbpli.GUID = tbp.GUID LEFT JOIN v_baseball_player_info vbpi ON tbpli.GUID = vbpi.baseballPlayerGUID -WHERE 1 = CASE - WHEN :seasonId IS NOT NULL THEN CASE - WHEN s.seasonID = :seasonId THEN 1 - ELSE 0 END - ELSE 1 END ORDER BY s.seasonNum, ts.statsPlayerID; diff --git a/SMB3Explorer/Resources/Sql/PlayoffStatsPitching.sql b/SMB3Explorer/Resources/Sql/PlayoffStatsPitching.sql index b18d3df..2d7c27d 100644 --- a/SMB3Explorer/Resources/Sql/PlayoffStatsPitching.sql +++ b/SMB3Explorer/Resources/Sql/PlayoffStatsPitching.sql @@ -74,9 +74,4 @@ FROM t_stats_pitching tsp LEFT JOIN t_baseball_players tbp on tbpli.GUID = tbp.GUID LEFT JOIN v_baseball_player_info vbpi ON tbpli.GUID = vbpi.baseballPlayerGUID -WHERE 1 = CASE - WHEN :seasonId IS NOT NULL THEN CASE - WHEN s.seasonID = :seasonId THEN 1 - ELSE 0 END - ELSE 1 END ORDER BY s.seasonNum, ts.statsPlayerID; diff --git a/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql b/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql index 3aad8c6..1a3b30f 100644 --- a/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql +++ b/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql @@ -7,7 +7,7 @@ FROM t_seasons JOIN t_leagues ON t_seasons.historicalLeagueGUID = t_leagues.GUID JOIN t_franchise tf ON t_leagues.GUID = tf.leagueGUID - WHERE t_leagues.GUID = CAST(@leagueId AS BLOB)) + WHERE t_leagues.name = 'Baseball United v2') SELECT ts.aggregatorID AS aggregatorID, ts.statsPlayerID AS statsPlayerID, tbpli.GUID AS baseballPlayerGUIDIfKnown, @@ -78,9 +78,4 @@ FROM t_stats_batting tsb LEFT JOIN t_baseball_players tbp on tbpli.GUID = tbp.GUID LEFT JOIN v_baseball_player_info vbpi ON tbpli.GUID = vbpi.baseballPlayerGUID -WHERE 1 = CASE - WHEN :seasonId IS NOT NULL THEN CASE - WHEN s.seasonID = :seasonId THEN 1 - ELSE 0 END - ELSE 1 END ORDER BY s.seasonNum, ts.statsPlayerID; diff --git a/SMB3Explorer/Resources/Sql/SeasonStatsPitching.sql b/SMB3Explorer/Resources/Sql/SeasonStatsPitching.sql index a994ea3..4d43e80 100644 --- a/SMB3Explorer/Resources/Sql/SeasonStatsPitching.sql +++ b/SMB3Explorer/Resources/Sql/SeasonStatsPitching.sql @@ -74,9 +74,4 @@ FROM t_stats_pitching tsp LEFT JOIN t_baseball_players tbp on tbpli.GUID = tbp.GUID LEFT JOIN v_baseball_player_info vbpi ON tbpli.GUID = vbpi.baseballPlayerGUID -WHERE 1 = CASE - WHEN :seasonId IS NOT NULL THEN CASE - WHEN s.seasonID = :seasonId THEN 1 - ELSE 0 END - ELSE 1 END ORDER BY s.seasonNum, ts.statsPlayerID; diff --git a/SMB3Explorer/Services/DataService/DataServiceFranchiseSeasons.cs b/SMB3Explorer/Services/DataService/DataServiceFranchiseSeasons.cs index 5085132..e76f290 100644 --- a/SMB3Explorer/Services/DataService/DataServiceFranchiseSeasons.cs +++ b/SMB3Explorer/Services/DataService/DataServiceFranchiseSeasons.cs @@ -97,7 +97,7 @@ private static PitchingSeasonStatistic GetPitchingSeasonStatistic(bool isRegular pitcherStatistic.AggregatorId = int.Parse(reader["aggregatorID"].ToString()!); pitcherStatistic.StatsPlayerId = int.Parse(reader["statsPlayerID"].ToString()!); - pitcherStatistic.PlayerId = reader["baseballPlayerGUID"] is not byte[] bytes ? null : bytes.ToGuid(); + pitcherStatistic.PlayerId = reader["baseballPlayerGUIDIfKnown"] is not byte[] bytes ? null : bytes.ToGuid(); pitcherStatistic.SeasonId = int.Parse(reader["seasonId"].ToString()!); pitcherStatistic.SeasonNum = int.Parse(reader["seasonNum"].ToString()!); @@ -117,7 +117,8 @@ private static PitchingSeasonStatistic GetPitchingSeasonStatistic(bool isRegular ? null : reader["previousRecentlyPlayedTeamName"].ToString()!; - pitcherStatistic.PitcherRole = int.Parse(reader["pitcherRole"].ToString()!); + pitcherStatistic.PitcherRole = + int.Parse(reader["pitcherRole"].ToString()!); pitcherStatistic.GamesPlayed = int.Parse(reader["games"].ToString()!); pitcherStatistic.GamesStarted = int.Parse(reader["gamesStarted"].ToString()!); pitcherStatistic.Wins = int.Parse(reader["wins"].ToString()!); @@ -147,7 +148,7 @@ private static BattingSeasonStatistic GetPositionPlayerSeasonStatistic(bool isRe positionPlayerStatistic.AggregatorId = int.Parse(reader["aggregatorID"].ToString()!); positionPlayerStatistic.StatsPlayerId = int.Parse(reader["statsPlayerID"].ToString()!); - positionPlayerStatistic.PlayerId = reader["baseballPlayerGUID"] is not byte[] bytes ? null : bytes.ToGuid(); + positionPlayerStatistic.PlayerId = reader["baseballPlayerGUIDIfKnown"] is not byte[] bytes ? null : bytes.ToGuid(); positionPlayerStatistic.SeasonId = int.Parse(reader["seasonId"].ToString()!); positionPlayerStatistic.SeasonNum = int.Parse(reader["seasonNum"].ToString()!); @@ -163,6 +164,10 @@ private static BattingSeasonStatistic GetPositionPlayerSeasonStatistic(bool isRe string.IsNullOrEmpty(reader["secondaryPosition"].ToString()!) ? null : int.Parse(reader["secondaryPosition"].ToString()!); + positionPlayerStatistic.PitcherRole = + string.IsNullOrEmpty(reader["pitcherRole"].ToString()!) + ? null + : int.Parse(reader["pitcherRole"].ToString()!); positionPlayerStatistic.TeamName = string.IsNullOrEmpty(reader["teamName"].ToString()!) ? null : reader["teamName"].ToString()!; diff --git a/SMB3Explorer/Services/DataService/DataServiceMostRecentSeason.cs b/SMB3Explorer/Services/DataService/DataServiceMostRecentSeason.cs index 25ddfe0..6fdbdbd 100644 --- a/SMB3Explorer/Services/DataService/DataServiceMostRecentSeason.cs +++ b/SMB3Explorer/Services/DataService/DataServiceMostRecentSeason.cs @@ -46,7 +46,7 @@ public async IAsyncEnumerable GetMostRecentSea positionPlayerStatistic.FirstName = reader.GetString(3); positionPlayerStatistic.LastName = reader.GetString(4); positionPlayerStatistic.PositionNumber = reader.GetInt32(5); - positionPlayerStatistic.PitcherRole = reader.GetInt32(6); + positionPlayerStatistic.PitcherRole = reader.IsDBNull(6) ? null : reader.GetInt32(6); positionPlayerStatistic.SecondaryPositionNumber = reader.IsDBNull(7) ? null : reader.GetInt32(7); positionPlayerStatistic.GamesBatting = reader.GetInt32(9); positionPlayerStatistic.GamesPlayed = reader.GetInt32(10); @@ -139,6 +139,7 @@ public async IAsyncEnumerable GetMostRecentSe mostRecentSeasonStatistic.TeamName = reader.GetString(30); mostRecentSeasonStatistic.MostRecentTeamName = reader.IsDBNull(31) ? null : reader.GetString(31); mostRecentSeasonStatistic.PreviousTeamName = reader.IsDBNull(32) ? null : reader.GetString(32); + // TODO: mostRecentSeasonStatistic.Age = reader.GetInt32(33); yield return mostRecentSeasonStatistic; From 698d1f58545080eaa8a9fd4e0503ba6d1fe595c3 Mon Sep 17 00:00:00 2001 From: Trey Brittain Date: Thu, 18 May 2023 20:51:56 -0500 Subject: [PATCH 12/12] Fix current season exports --- .../BattingMostRecentSeasonStatistic.cs | 2 +- .../Resources/Sql/TopPerformersPitching.sql | 1 + .../Sql/TopPerformersRookiesPitching.sql | 1 + .../DataServiceMostRecentSeason.cs | 27 +++++++++---------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs b/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs index c4c87ff..d21852d 100644 --- a/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs @@ -9,5 +9,5 @@ public class BattingMostRecentSeasonStatistic : BattingStatistic public new Guid PlayerId { get; set; } [Name("OPS+"), Index(44)] - public double OnBasePercentagePlus { get; set; } + public double? OnBasePercentagePlus { get; set; } } \ No newline at end of file diff --git a/SMB3Explorer/Resources/Sql/TopPerformersPitching.sql b/SMB3Explorer/Resources/Sql/TopPerformersPitching.sql index 8e9a561..2c40515 100644 --- a/SMB3Explorer/Resources/Sql/TopPerformersPitching.sql +++ b/SMB3Explorer/Resources/Sql/TopPerformersPitching.sql @@ -78,4 +78,5 @@ FROM [v_baseball_player_info] vbpi LEFT JOIN teams mostRecentTeam ON tt2.GUID = mostRecentTeam.teamGUID LEFT JOIN teams previouslyRecentPlayedTeam ON tt3.GUID = previouslyRecentPlayedTeam.teamGUID WHERE tl.GUID = CAST(@leagueId AS BLOB) + AND outsPitched > 0 ORDER BY sortOrder DESC \ No newline at end of file diff --git a/SMB3Explorer/Resources/Sql/TopPerformersRookiesPitching.sql b/SMB3Explorer/Resources/Sql/TopPerformersRookiesPitching.sql index 2fddc8b..26ab291 100644 --- a/SMB3Explorer/Resources/Sql/TopPerformersRookiesPitching.sql +++ b/SMB3Explorer/Resources/Sql/TopPerformersRookiesPitching.sql @@ -89,4 +89,5 @@ FROM [v_baseball_player_info] vbpi LEFT JOIN teams mostRecentTeam ON tt2.GUID = mostRecentTeam.teamGUID LEFT JOIN teams previouslyRecentPlayedTeam ON tt3.GUID = previouslyRecentPlayedTeam.teamGUID WHERE tl.GUID = CAST(@leagueId AS BLOB) + AND outsPitched > 0 ORDER BY sortOrder DESC \ No newline at end of file diff --git a/SMB3Explorer/Services/DataService/DataServiceMostRecentSeason.cs b/SMB3Explorer/Services/DataService/DataServiceMostRecentSeason.cs index 6fdbdbd..6fc1369 100644 --- a/SMB3Explorer/Services/DataService/DataServiceMostRecentSeason.cs +++ b/SMB3Explorer/Services/DataService/DataServiceMostRecentSeason.cs @@ -66,11 +66,11 @@ public async IAsyncEnumerable GetMostRecentSea positionPlayerStatistic.SacrificeFlies = reader.GetInt32(24); positionPlayerStatistic.Errors = reader.GetInt32(25); positionPlayerStatistic.PassedBalls = reader.GetInt32(26); - positionPlayerStatistic.OnBasePercentagePlus = reader.GetDouble(27); - positionPlayerStatistic.TeamName = reader.GetString(28); - positionPlayerStatistic.MostRecentTeamName = reader.IsDBNull(29) ? null : reader.GetString(29); - positionPlayerStatistic.PreviousTeamName = reader.IsDBNull(30) ? null : reader.GetString(30); - positionPlayerStatistic.Age = reader.GetInt32(31); + positionPlayerStatistic.OnBasePercentagePlus = reader.IsDBNull(27) ? null : reader.GetDouble(27); + positionPlayerStatistic.TeamName = reader.IsDBNull(29) ? null : reader.GetString(29); + positionPlayerStatistic.MostRecentTeamName = reader.IsDBNull(30) ? null : reader.GetString(30); + positionPlayerStatistic.PreviousTeamName = reader.IsDBNull(31) ? null : reader.GetString(31); + positionPlayerStatistic.Age = reader.GetInt32(32); yield return positionPlayerStatistic; } @@ -133,15 +133,14 @@ public async IAsyncEnumerable GetMostRecentSe mostRecentSeasonStatistic.HitByPitch = reader.GetInt32(23); mostRecentSeasonStatistic.BattersFaced = reader.GetInt32(24); mostRecentSeasonStatistic.RunsAllowed = reader.GetInt32(25); - mostRecentSeasonStatistic.WildPitches = reader.GetInt32(26); - mostRecentSeasonStatistic.EarnedRunsAllowedMinus = reader.GetDouble(27); - mostRecentSeasonStatistic.FieldingIndependentPitchingMinus = reader.GetDouble(28); - mostRecentSeasonStatistic.TeamName = reader.GetString(30); - mostRecentSeasonStatistic.MostRecentTeamName = reader.IsDBNull(31) ? null : reader.GetString(31); - mostRecentSeasonStatistic.PreviousTeamName = reader.IsDBNull(32) ? null : reader.GetString(32); - // TODO: - mostRecentSeasonStatistic.Age = reader.GetInt32(33); - + mostRecentSeasonStatistic.WildPitches = reader.GetInt32(27); + mostRecentSeasonStatistic.EarnedRunsAllowedMinus = reader.GetDouble(28); + mostRecentSeasonStatistic.FieldingIndependentPitchingMinus = reader.GetDouble(29); + mostRecentSeasonStatistic.TeamName = reader.IsDBNull(31) ? null : reader.GetString(31); + mostRecentSeasonStatistic.MostRecentTeamName = reader.IsDBNull(32) ? null : reader.GetString(32); + mostRecentSeasonStatistic.PreviousTeamName = reader.IsDBNull(33) ? null : reader.GetString(33); + mostRecentSeasonStatistic.Age = reader.GetInt32(34); + yield return mostRecentSeasonStatistic; } }