Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 7 additions & 35 deletions SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
156 changes: 6 additions & 150 deletions SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
[Ignore]
public int StatsPlayerId { get; set; }
}
165 changes: 165 additions & 0 deletions SMB3Explorer/Models/Exports/BattingStatistic.cs
Original file line number Diff line number Diff line change
@@ -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;
}
Loading