Skip to content

Commit f91f488

Browse files
authored
Season stats for retired players (#102)
2 parents 5aa0a80 + 698d1f5 commit f91f488

16 files changed

Lines changed: 723 additions & 609 deletions
Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,13 @@
1-
using CsvHelper.Configuration.Attributes;
1+
using System;
2+
using CsvHelper.Configuration.Attributes;
23

34
namespace SMB3Explorer.Models.Exports;
45

5-
public class BattingMostRecentSeasonStatistic : BattingSeasonStatistic
6+
public class BattingMostRecentSeasonStatistic : BattingStatistic
67
{
7-
public BattingMostRecentSeasonStatistic(BattingSeasonStatistic battingSeasonStatistic)
8-
{
9-
PlayerId = battingSeasonStatistic.PlayerId;
10-
FirstName = battingSeasonStatistic.FirstName;
11-
LastName = battingSeasonStatistic.LastName;
12-
CurrentTeam = battingSeasonStatistic.CurrentTeam;
13-
PreviousTeam = battingSeasonStatistic.PreviousTeam;
14-
PositionNumber = battingSeasonStatistic.PositionNumber;
15-
SecondaryPositionNumber = battingSeasonStatistic.SecondaryPositionNumber;
16-
GamesBatting = battingSeasonStatistic.GamesBatting;
17-
GamesPlayed = battingSeasonStatistic.GamesPlayed;
18-
AtBats = battingSeasonStatistic.AtBats;
19-
Runs = battingSeasonStatistic.Runs;
20-
Hits = battingSeasonStatistic.Hits;
21-
Doubles = battingSeasonStatistic.Doubles;
22-
Triples = battingSeasonStatistic.Triples;
23-
HomeRuns = battingSeasonStatistic.HomeRuns;
24-
RunsBattedIn = battingSeasonStatistic.RunsBattedIn;
25-
StolenBases = battingSeasonStatistic.StolenBases;
26-
CaughtStealing = battingSeasonStatistic.CaughtStealing;
27-
Walks = battingSeasonStatistic.Walks;
28-
Strikeouts = battingSeasonStatistic.Strikeouts;
29-
HitByPitch = battingSeasonStatistic.HitByPitch;
30-
SacrificeHits = battingSeasonStatistic.SacrificeHits;
31-
SacrificeFlies = battingSeasonStatistic.SacrificeFlies;
32-
PassedBalls = battingSeasonStatistic.PassedBalls;
33-
CompletionDate = battingSeasonStatistic.CompletionDate;
34-
SeasonId = battingSeasonStatistic.SeasonId;
35-
SeasonNum = battingSeasonStatistic.SeasonNum;
36-
Age = battingSeasonStatistic.Age;
37-
}
8+
[Ignore]
9+
public new Guid PlayerId { get; set; }
3810

39-
[Name("OPS+"), Index(47)]
40-
public double OnBasePercentagePlus { get; set; }
11+
[Name("OPS+"), Index(44)]
12+
public double? OnBasePercentagePlus { get; set; }
4113
}

SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs

Lines changed: 6 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -9,155 +9,11 @@
99

1010
namespace SMB3Explorer.Models.Exports;
1111

12-
public class BattingSeasonStatistic
12+
public class BattingSeasonStatistic : BattingStatistic
1313
{
14-
[Name("player_id"), Index(0)]
15-
public Guid? PlayerId { get; set; }
14+
[Ignore]
15+
public int AggregatorId { get; set; }
1616

17-
[Name("first_name"), Index(1)]
18-
public string FirstName { get; set; } = string.Empty;
19-
20-
[Name("last_name"), Index(2)]
21-
public string LastName { get; set; } = string.Empty;
22-
23-
[Name("current_team_name"), Index(3)]
24-
public string? CurrentTeam { get; set; }
25-
26-
[Name("previous_team_name"), Index(4)]
27-
public string? PreviousTeam { get; set; }
28-
29-
[Name("primary_position"), Index(5)]
30-
public int PositionNumber { get; set; }
31-
32-
[Name("primary_position_name"), Index(6)]
33-
// ReSharper disable once UnusedMember.Global
34-
public string Position => ((BaseballPlayerPosition) PositionNumber).GetEnumDescription();
35-
36-
[Name("secondary_position"), Index(7)]
37-
public int? SecondaryPositionNumber { get; set; }
38-
39-
[Name("secondary_position_name"), Index(8)]
40-
// ReSharper disable once UnusedMember.Global
41-
public string? SecondaryPosition => SecondaryPositionNumber.HasValue
42-
? ((BaseballPlayerPosition) SecondaryPositionNumber).GetEnumDescription()
43-
: null;
44-
45-
[Name("games_batting"), Index(9)]
46-
public int GamesBatting { get; set; }
47-
48-
[Name("games_played"), Index(10)]
49-
public int GamesPlayed { get; set; }
50-
51-
[Name("at_bats"), Index(11)]
52-
public int AtBats { get; set; }
53-
54-
[Name("plate_appearances"), Index(12)]
55-
public int PlateAppearances => AtBats + Walks + SacrificeHits + SacrificeFlies + HitByPitch;
56-
57-
[Name("runs"), Index(13)]
58-
public int Runs { get; set; }
59-
60-
[Name("hits"), Index(14)]
61-
public int Hits { get; set; }
62-
63-
[Name("singles"), Index(15)]
64-
public int Singles => Hits - Doubles - Triples - HomeRuns;
65-
66-
[Name("doubles"), Index(16)]
67-
public int Doubles { get; set; }
68-
69-
[Name("triples"), Index(17)]
70-
public int Triples { get; set; }
71-
72-
[Name("home_runs"), Index(18)]
73-
public int HomeRuns { get; set; }
74-
75-
[Name("rbi"), Index(19)]
76-
public int RunsBattedIn { get; set; }
77-
78-
[Name("extra_base_hits"), Index(20)]
79-
public int ExtraBaseHits => Doubles + Triples + HomeRuns;
80-
81-
[Name("total_bases"), Index(21)]
82-
public int TotalBases => Singles + (2 * Doubles) + (3 * Triples) + (4 * HomeRuns);
83-
84-
[Name("stolen_bases"), Index(22)]
85-
public int StolenBases { get; set; }
86-
87-
[Name("caught_stealing"), Index(23)]
88-
public int CaughtStealing { get; set; }
89-
90-
[Name("walks"), Index(24)]
91-
public int Walks { get; set; }
92-
93-
[Name("strikeouts"), Index(25)]
94-
public int Strikeouts { get; set; }
95-
96-
[Name("hit_by_pitch"), Index(26)]
97-
public int HitByPitch { get; set; }
98-
99-
[Name("sacrifice_hits"), Index(27)]
100-
public int SacrificeHits { get; set; }
101-
102-
[Name("sacrifice_flies"), Index(28)]
103-
public int SacrificeFlies { get; set; }
104-
105-
[Name("errors"), Index(29)]
106-
public int Errors { get; set; }
107-
108-
[Name("passed_balls"), Index(30)]
109-
public int PassedBalls { get; set; }
110-
111-
[Name("plate_appearances_per_game"), Index(31)]
112-
public double PlateAppearancesPerGame => PlateAppearances / (double) GamesPlayed;
113-
114-
[Name("on_base_percentage"), Index(32)]
115-
public double OnBasePercentage => (Hits + Walks + HitByPitch) /
116-
(double) (AtBats + Walks + HitByPitch + SacrificeFlies);
117-
118-
[Name("slugging_percentage"), Index(33)]
119-
public double SluggingPercentage => (Singles + (2 * Doubles) + (3 * Triples) +
120-
(4 * HomeRuns)) / (double) AtBats;
121-
122-
[Name("on_base_plus_slugging"), Index(34)]
123-
public double OnBasePlusSlugging => OnBasePercentage + SluggingPercentage;
124-
125-
[Name("batting_average"), Index(35)]
126-
public double BattingAverage => Hits / (double) AtBats;
127-
128-
[Name("babip"), Index(36)]
129-
public double BattingAverageOnBallsInPlay =>
130-
(Hits - HomeRuns) / (double) (AtBats - Strikeouts - HomeRuns + SacrificeFlies);
131-
132-
[Name("at_bats_per_home_run"), Index(37)]
133-
public double AtBatsPerHomeRun => AtBats / (double) HomeRuns;
134-
135-
[Name("strikeout_percentage"), Index(38)]
136-
public double StrikeoutPercentage => Strikeouts / (double) AtBats;
137-
138-
[Name("walk_percentage"), Index(39)]
139-
public double WalkPercentage => Walks / (double) PlateAppearances;
140-
141-
[Name("extra_base_hit_percentage"), Index(40)]
142-
public double ExtraBaseHitPercentage => ExtraBaseHits / (double) Hits;
143-
144-
// Caveat with this, the denominator should be subtracting intentional walks, but that data is not available
145-
[Name("wOBA"), Index(41)]
146-
public double WeightedOnBaseAverage => ((0.69 * Walks) + (0.72 * HitByPitch) + (0.89 * Singles) + (1.27 * Doubles) +
147-
(1.62 * Triples) + (2.10 * HomeRuns)) / (AtBats + Walks + SacrificeFlies + HitByPitch);
148-
149-
[Name("ISO"), Index(42)]
150-
public double IsolatedPower => SluggingPercentage - BattingAverage;
151-
152-
[Name("season_completion_date"), Index(43)]
153-
public DateTime? CompletionDate { get; set; }
154-
155-
[Name("season_id"), Index(44)]
156-
public int SeasonId { get; set; }
157-
158-
[Name("season_num"), Index(45)]
159-
public int SeasonNum { get; set; }
160-
161-
[Name("age"), Index(46)]
162-
public int Age { get; set; }
163-
}
17+
[Ignore]
18+
public int StatsPlayerId { get; set; }
19+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
using System;
2+
using CsvHelper.Configuration.Attributes;
3+
using SMB3Explorer.Enums;
4+
using SMB3Explorer.Utils;
5+
6+
namespace SMB3Explorer.Models.Exports;
7+
8+
public abstract class BattingStatistic
9+
{
10+
public Guid? PlayerId { private get; set; }
11+
12+
public int SeasonId { private get; set; }
13+
14+
[Name("Season"), Index(0)]
15+
public int SeasonNum { get; set; }
16+
17+
[Name("First Name"), Index(1)]
18+
public string FirstName { get; set; } = string.Empty;
19+
20+
[Name("Last Name"), Index(2)]
21+
public string LastName { get; set; } = string.Empty;
22+
23+
[Name("Team"), Index(3)]
24+
public string? TeamName { get; set; }
25+
26+
[Name("Prev Team"), Index(4)]
27+
public string? MostRecentTeamName { get; set; }
28+
29+
[Name("2nd Prev Team"), Index(5)]
30+
public string? PreviousTeamName { get; set; }
31+
32+
[Ignore]
33+
public int PositionNumber { get; set; }
34+
35+
[Name("Position"), Index(6)]
36+
// ReSharper disable once UnusedMember.Global
37+
public string Position => ((BaseballPlayerPosition) PositionNumber).GetEnumDescription();
38+
39+
[Ignore]
40+
public int? SecondaryPositionNumber { get; set; }
41+
42+
[Name("Secondary Position"), Index(7)]
43+
// ReSharper disable once UnusedMember.Global
44+
public string? SecondaryPosition => SecondaryPositionNumber.HasValue
45+
? ((BaseballPlayerPosition) SecondaryPositionNumber).GetEnumDescription()
46+
: null;
47+
48+
[Ignore]
49+
public int? PitcherRole { get; set; }
50+
51+
[Name("Pitcher Role"), Index(8)]
52+
// ReSharper disable once UnusedMember.Global
53+
public string? PitcherRoleDescription =>
54+
!PitcherRole.HasValue ? null : ((PitcherRole) PitcherRole).GetEnumDescription();
55+
56+
[Name("Age"), Index(9)]
57+
public int Age { get; set; }
58+
59+
[Name("Games Batting"), Index(10)]
60+
public int GamesBatting { get; set; }
61+
62+
[Name("Games Played"), Index(11)]
63+
public int GamesPlayed { get; set; }
64+
65+
[Name("AB"), Index(12)]
66+
public int AtBats { get; set; }
67+
68+
[Name("PA"), Index(13)]
69+
public int PlateAppearances => AtBats + Walks + SacrificeHits + SacrificeFlies + HitByPitch;
70+
71+
[Name("R"), Index(14)]
72+
public int Runs { get; set; }
73+
74+
[Name("H"), Index(15)]
75+
public int Hits { get; set; }
76+
77+
[Name("BA"), Index(36)]
78+
public double BattingAverage => Hits / (double) AtBats;
79+
80+
[Name("1B"), Index(17)]
81+
public int Singles => Hits - Doubles - Triples - HomeRuns;
82+
83+
[Name("2B"), Index(18)]
84+
public int Doubles { get; set; }
85+
86+
[Name("3B"), Index(19)]
87+
public int Triples { get; set; }
88+
89+
[Name("HR"), Index(20)]
90+
public int HomeRuns { get; set; }
91+
92+
[Name("RBI"), Index(21)]
93+
public int RunsBattedIn { get; set; }
94+
95+
[Name("XBH"), Index(22)]
96+
public int ExtraBaseHits => Doubles + Triples + HomeRuns;
97+
98+
[Name("TB"), Index(23)]
99+
public int TotalBases => Singles + (2 * Doubles) + (3 * Triples) + (4 * HomeRuns);
100+
101+
[Name("SB"), Index(24)]
102+
public int StolenBases { get; set; }
103+
104+
[Name("CS"), Index(25)]
105+
public int CaughtStealing { get; set; }
106+
107+
[Name("BB"), Index(26)]
108+
public int Walks { get; set; }
109+
110+
[Name("K"), Index(27)]
111+
public int Strikeouts { get; set; }
112+
113+
[Name("HBP"), Index(28)]
114+
public int HitByPitch { get; set; }
115+
116+
[Name("OBP"), Index(29)]
117+
public double OnBasePercentage => (Hits + Walks + HitByPitch) /
118+
(double) (AtBats + Walks + HitByPitch + SacrificeFlies);
119+
120+
[Name("SLG"), Index(30)]
121+
public double SluggingPercentage => (Singles + (2 * Doubles) + (3 * Triples) +
122+
(4 * HomeRuns)) / (double) AtBats;
123+
124+
[Name("OPS"), Index(31)]
125+
public double OnBasePlusSlugging => OnBasePercentage + SluggingPercentage;
126+
127+
// Caveat with this, the denominator should be subtracting intentional walks, but that data is not available
128+
[Name("wOBA"), Index(32)]
129+
public double WeightedOnBaseAverage => ((0.69 * Walks) + (0.72 * HitByPitch) + (0.89 * Singles) + (1.27 * Doubles) +
130+
(1.62 * Triples) + (2.10 * HomeRuns)) / (AtBats + Walks + SacrificeFlies + HitByPitch);
131+
132+
[Name("ISO"), Index(33)]
133+
public double IsolatedPower => SluggingPercentage - BattingAverage;
134+
135+
[Name("BABIP"), Index(34)]
136+
public double BattingAverageOnBallsInPlay =>
137+
(Hits - HomeRuns) / (double) (AtBats - Strikeouts - HomeRuns + SacrificeFlies);
138+
139+
[Name("Sac Hits"), Index(35)]
140+
public int SacrificeHits { get; set; }
141+
142+
[Name("Sac Flies"), Index(36)]
143+
public int SacrificeFlies { get; set; }
144+
145+
[Name("Errors"), Index(37)]
146+
public int Errors { get; set; }
147+
148+
[Name("Passed Balls"), Index(38)]
149+
public int PassedBalls { get; set; }
150+
151+
[Name("PA/Game"), Index(39)]
152+
public double PlateAppearancesPerGame => PlateAppearances / (double) GamesPlayed;
153+
154+
[Name("AB/HR"), Index(40)]
155+
public double AtBatsPerHomeRun => AtBats / (double) HomeRuns;
156+
157+
[Name("K%"), Index(41)]
158+
public double StrikeoutPercentage => Strikeouts / (double) AtBats;
159+
160+
[Name("BB%"), Index(42)]
161+
public double WalkPercentage => Walks / (double) PlateAppearances;
162+
163+
[Name("XBH%"), Index(43)]
164+
public double ExtraBaseHitPercentage => ExtraBaseHits / (double) Hits;
165+
}

0 commit comments

Comments
 (0)