diff --git a/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs b/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs index 7ef063d..d21852d 100644 --- a/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs @@ -1,41 +1,13 @@ -using CsvHelper.Configuration.Attributes; +using System; +using CsvHelper.Configuration.Attributes; namespace SMB3Explorer.Models.Exports; -public class BattingMostRecentSeasonStatistic : BattingSeasonStatistic +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; - } + [Ignore] + public new Guid PlayerId { get; set; } - [Name("OPS+"), Index(47)] - public double OnBasePercentagePlus { get; set; } + [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 7cb6f08..bdc16d4 100644 --- a/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs @@ -9,155 +9,11 @@ namespace SMB3Explorer.Models.Exports; -public class BattingSeasonStatistic +public class BattingSeasonStatistic : BattingStatistic { - [Name("player_id"), Index(0)] - public Guid? PlayerId { get; set; } + [Ignore] + public int AggregatorId { 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("current_team_name"), Index(3)] - public string? CurrentTeam { get; set; } - - [Name("previous_team_name"), Index(4)] - 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("secondary_position"), Index(7)] - public int? SecondaryPositionNumber { get; set; } - - [Name("secondary_position_name"), Index(8)] - // ReSharper disable once UnusedMember.Global - public string? SecondaryPosition => SecondaryPositionNumber.HasValue - ? ((BaseballPlayerPosition) SecondaryPositionNumber).GetEnumDescription() - : null; - - [Name("games_batting"), Index(9)] - public int GamesBatting { get; set; } - - [Name("games_played"), Index(10)] - public int GamesPlayed { get; set; } - - [Name("at_bats"), Index(11)] - public int AtBats { get; set; } - - [Name("plate_appearances"), Index(12)] - public int PlateAppearances => AtBats + Walks + SacrificeHits + SacrificeFlies + HitByPitch; - - [Name("runs"), Index(13)] - public int Runs { get; set; } - - [Name("hits"), Index(14)] - public int Hits { get; set; } - - [Name("singles"), Index(15)] - public int Singles => Hits - Doubles - Triples - HomeRuns; - - [Name("doubles"), Index(16)] - public int Doubles { get; set; } - - [Name("triples"), Index(17)] - public int Triples { get; set; } - - [Name("home_runs"), Index(18)] - public int HomeRuns { get; set; } - - [Name("rbi"), Index(19)] - public int RunsBattedIn { get; set; } - - [Name("extra_base_hits"), Index(20)] - public int ExtraBaseHits => Doubles + Triples + HomeRuns; - - [Name("total_bases"), Index(21)] - public int TotalBases => Singles + (2 * Doubles) + (3 * Triples) + (4 * HomeRuns); - - [Name("stolen_bases"), Index(22)] - public int StolenBases { get; set; } - - [Name("caught_stealing"), Index(23)] - public int CaughtStealing { get; set; } - - [Name("walks"), Index(24)] - public int Walks { get; set; } - - [Name("strikeouts"), Index(25)] - public int Strikeouts { get; set; } - - [Name("hit_by_pitch"), Index(26)] - public int HitByPitch { get; set; } - - [Name("sacrifice_hits"), Index(27)] - public int SacrificeHits { get; set; } - - [Name("sacrifice_flies"), Index(28)] - public int SacrificeFlies { get; set; } - - [Name("errors"), Index(29)] - public int Errors { get; set; } - - [Name("passed_balls"), Index(30)] - public int PassedBalls { get; set; } - - [Name("plate_appearances_per_game"), Index(31)] - 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)] - public double AtBatsPerHomeRun => AtBats / (double) HomeRuns; - - [Name("strikeout_percentage"), Index(38)] - public double StrikeoutPercentage => Strikeouts / (double) AtBats; - - [Name("walk_percentage"), Index(39)] - public double WalkPercentage => Walks / (double) PlateAppearances; - - [Name("extra_base_hit_percentage"), Index(40)] - 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 + [Ignore] + public int StatsPlayerId { get; set; } +} diff --git a/SMB3Explorer/Models/Exports/BattingStatistic.cs b/SMB3Explorer/Models/Exports/BattingStatistic.cs new file mode 100644 index 0000000..e4e83f2 --- /dev/null +++ b/SMB3Explorer/Models/Exports/BattingStatistic.cs @@ -0,0 +1,165 @@ +using System; +using CsvHelper.Configuration.Attributes; +using SMB3Explorer.Enums; +using SMB3Explorer.Utils; + +namespace SMB3Explorer.Models.Exports; + +public abstract class BattingStatistic +{ + public Guid? PlayerId { private get; set; } + + public int SeasonId { private 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; } + + [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)] + // ReSharper disable once UnusedMember.Global + public string? SecondaryPosition => SecondaryPositionNumber.HasValue + ? ((BaseballPlayerPosition) SecondaryPositionNumber).GetEnumDescription() + : null; + + [Ignore] + public int? PitcherRole { get; set; } + + [Name("Pitcher Role"), Index(8)] + // ReSharper disable once UnusedMember.Global + public string? PitcherRoleDescription => + !PitcherRole.HasValue ? null : ((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..b7e3ec8 100644 --- a/SMB3Explorer/Models/Exports/PitchingMostRecentSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/PitchingMostRecentSeasonStatistic.cs @@ -1,46 +1,18 @@ -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; - } + [Ignore] + 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 0686988..9a3a8ec 100644 --- a/SMB3Explorer/Models/Exports/PitchingSeasonStatistic.cs +++ b/SMB3Explorer/Models/Exports/PitchingSeasonStatistic.cs @@ -9,147 +9,11 @@ namespace SMB3Explorer.Models.Exports; -public class PitchingSeasonStatistic +public class PitchingSeasonStatistic : PitchingStatistic { - [Name("player_id"), Index(0)] - public Guid? PlayerId { get; set; } + [Ignore] + public int AggregatorId { 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("current_team_name"), Index(3)] - public string? CurrentTeam { get; set; } - - [Name("previous_team_name"), Index(4)] - 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)] - // ReSharper disable once UnusedMember.Global - public string PitcherRoleDescription => ((PitcherRole) PitcherRole).GetEnumDescription(); - - [Name("games_played"), Index(9)] - public int GamesPlayed { get; set; } - - [Name("games_started"), Index(10)] - public int GamesStarted { get; set; } - - [Name("wins"), Index(11)] - public int Wins { get; set; } - - [Name("losses"), Index(12)] - public int Losses { get; set; } - - [Name("complete_games"), Index(13)] - public int CompleteGames { get; set; } - - [Name("shutouts"), Index(14)] - 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)] - public int HitsAllowed { get; set; } - - [Name("earned_runs"), Index(19)] - public int EarnedRuns { get; set; } - - [Name("home_runs_allowed"), Index(20)] - public int HomeRunsAllowed { get; set; } - - [Name("walks_allowed"), Index(21)] - public int WalksAllowed { get; set; } - - [Name("strikeouts"), Index(22)] - public int Strikeouts { get; set; } - - [Name("hit_by_pitch"), Index(23)] - public int HitByPitch { get; set; } - - [Name("batters_faced"), Index(24)] - public int BattersFaced { get; set; } - - [Name("games_finished"), Index(25)] - public int GamesFinished { get; set; } - - [Name("runs_allowed"), Index(26)] - public int RunsAllowed { get; set; } - - [Name("wild_pitches"), 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)] - public double BattingAverageAgainst => HitsAllowed / (double) BattersFaced; - - [Name("fip"), Index(33)] - public double FieldingIndependentPitching => - (((13 * HomeRunsAllowed) + (3 * (WalksAllowed + HitByPitch)) - - (2 * Strikeouts)) / (double) OutsPitched) + 3.10; - - [Name("whip"), Index(34)] - public double WalksAndHitsPerInning => (WalksAllowed + HitsAllowed) / InningsPitched; - - [Name("win_percentage"), Index(35)] - public double WinPercentage => Wins / (double) (Wins + Losses); - - [Name("opponent_on_base_percentage"), Index(36)] - public double OpponentOnBasePercentage => (HitsAllowed + WalksAllowed + HitByPitch) / (double) BattersFaced; - - [Name("strikeout_to_walk_ratio"), Index(37)] - public double StrikeoutToWalkRatio => Strikeouts / (double) WalksAllowed; - - [Name("strikeouts_per_nine_innings"), Index(38)] - public double StrikeoutsPerNineInnings => Strikeouts / (InningsPitched / 9.0); - - [Name("walks_per_nine_innings"), Index(39)] - public double WalksPerNineInnings => WalksAllowed / (InningsPitched / 9.0); - - [Name("hits_per_nine_innings"), Index(40)] - public double HitsPerNineInnings => HitsAllowed / (InningsPitched / 9.0); - - [Name("home_runs_per_nine_innings"), Index(41)] - public double HomeRunsPerNineInnings => HomeRunsAllowed / (InningsPitched / 9.0); - - [Name("pitches_per_inning"), Index(42)] - public double PitchesPerInning => TotalPitches / InningsPitched; - - [Name("pitches_per_game"), Index(43)] - 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 + [Ignore] + public int StatsPlayerId { get; set; } +} diff --git a/SMB3Explorer/Models/Exports/PitchingStatistic.cs b/SMB3Explorer/Models/Exports/PitchingStatistic.cs new file mode 100644 index 0000000..6674b38 --- /dev/null +++ b/SMB3Explorer/Models/Exports/PitchingStatistic.cs @@ -0,0 +1,147 @@ +using System; +using CsvHelper.Configuration.Attributes; +using SMB3Explorer.Enums; +using SMB3Explorer.Utils; + +namespace SMB3Explorer.Models.Exports; + +public abstract class PitchingStatistic +{ + [Ignore] + public Guid? PlayerId { get; set; } + + [Ignore] + 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; } + + [Ignore] + public int PositionNumber { get; set; } + + [Ignore] + 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; } + + [Ignore] + 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 / 9.0); + + [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/PlayoffStatsBatting.sql b/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql index 7789114..695b566 100644 --- a/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql +++ b/SMB3Explorer/Resources/Sql/PlayoffStatsBatting.sql @@ -8,48 +8,74 @@ 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, - 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 - - LEFT JOIN t_baseball_players tbp ON tbpli.GUID = tbp.GUID + WHEN tsplayers.baseballPlayerLocalID IS NOT NULL THEN CAST(secondaryPosition.optionValue AS INTEGER) + ELSE tsplayers.secondaryPos END AS secondaryPosition, + CASE + 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, + 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 tsplayers USING (statsPlayerID) + JOIN t_playoff_stats tps USING (aggregatorID) + JOIN seasons s USING (seasonID) - LEFT JOIN t_playoff_stats tps ON ts.aggregatorID = tps.aggregatorID + 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 - 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 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 tsplayers.baseballPlayerLocalID = tbpli.localID 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_players tbp on tbpli.GUID = tbp.GUID + LEFT JOIN v_baseball_player_info vbpi ON tbpli.GUID = + vbpi.baseballPlayerGUID +ORDER BY s.seasonNum, ts.statsPlayerID; diff --git a/SMB3Explorer/Resources/Sql/PlayoffStatsPitching.sql b/SMB3Explorer/Resources/Sql/PlayoffStatsPitching.sql index 5ef07e0..2d7c27d 100644 --- a/SMB3Explorer/Resources/Sql/PlayoffStatsPitching.sql +++ b/SMB3Explorer/Resources/Sql/PlayoffStatsPitching.sql @@ -8,44 +8,70 @@ 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 +ORDER BY s.seasonNum, ts.statsPlayerID; diff --git a/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql b/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql index 053cf83..1a3b30f 100644 --- a/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql +++ b/SMB3Explorer/Resources/Sql/SeasonStatsBatting.sql @@ -7,51 +7,75 @@ 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)) -SELECT baseballPlayerGUID, - tsea.completionDate, - tsea.ID AS seasonId, + WHERE t_leagues.name = 'Baseball United v2') +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, - 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 - - LEFT JOIN t_baseball_players tbp ON tbpli.GUID = tbp.GUID + WHEN tsplayers.baseballPlayerLocalID IS NOT NULL THEN CAST(secondaryPosition.optionValue AS INTEGER) + ELSE tsplayers.secondaryPos END AS secondaryPosition, + CASE + 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, + 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 tsplayers USING (statsPlayerID) + JOIN t_season_stats tss USING (aggregatorID) + JOIN seasons s USING (seasonID) - LEFT JOIN t_season_stats tss ON ts.aggregatorID = tss.aggregatorID + 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 - 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 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 tsplayers.baseballPlayerLocalID = tbpli.localID 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_players tbp on tbpli.GUID = tbp.GUID + LEFT JOIN v_baseball_player_info vbpi ON tbpli.GUID = + vbpi.baseballPlayerGUID +ORDER BY s.seasonNum, ts.statsPlayerID; diff --git a/SMB3Explorer/Resources/Sql/SeasonStatsPitching.sql b/SMB3Explorer/Resources/Sql/SeasonStatsPitching.sql index 5173d8a..4d43e80 100644 --- a/SMB3Explorer/Resources/Sql/SeasonStatsPitching.sql +++ b/SMB3Explorer/Resources/Sql/SeasonStatsPitching.sql @@ -8,46 +8,70 @@ 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 +ORDER BY s.seasonNum, ts.statsPlayerID; 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..2c40515 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,12 @@ 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) + AND outsPitched > 0 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..26ab291 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,12 @@ 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) + AND outsPitched > 0 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 ede8d37..e76f290 100644 --- a/SMB3Explorer/Services/DataService/DataServiceFranchiseSeasons.cs +++ b/SMB3Explorer/Services/DataService/DataServiceFranchiseSeasons.cs @@ -95,14 +95,30 @@ private static PitchingSeasonStatistic GetPitchingSeasonStatistic(bool isRegular { var pitcherStatistic = new PitchingSeasonStatistic(); - pitcherStatistic.PlayerId = reader["baseballPlayerGUID"] is not byte[] bytes ? null : bytes.ToGuid(); + pitcherStatistic.AggregatorId = int.Parse(reader["aggregatorID"].ToString()!); + pitcherStatistic.StatsPlayerId = int.Parse(reader["statsPlayerID"].ToString()!); + 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()!); + 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()!; - pitcherStatistic.PitcherRole = int.Parse(reader["pitcherRole"].ToString()!); + : reader["mostRecentlyPlayedTeamName"].ToString()!; + pitcherStatistic.PreviousTeamName = 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()!); pitcherStatistic.Wins = int.Parse(reader["wins"].ToString()!); @@ -122,19 +138,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 +145,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["baseballPlayerGUIDIfKnown"] 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 +164,19 @@ 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.PitcherRole = + string.IsNullOrEmpty(reader["pitcherRole"].ToString()!) + ? null + : int.Parse(reader["pitcherRole"].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.PreviousTeamName = 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 +195,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; } diff --git a/SMB3Explorer/Services/DataService/DataServiceMostRecentSeason.cs b/SMB3Explorer/Services/DataService/DataServiceMostRecentSeason.cs index b687192..6fc1369 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.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); + 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.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; } } @@ -80,18 +107,40 @@ public async IAsyncEnumerable GetMostRecentSe while (reader.Read()) { - var pitcherStatistic = GetPitchingSeasonStatistic(true, reader); + 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(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); - 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); - yield return mostRecentSeasonStatistic; } }