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
41 changes: 41 additions & 0 deletions SMB3Explorer/Models/Exports/BattingMostRecentSeasonStatistic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using CsvHelper.Configuration.Attributes;

namespace SMB3Explorer.Models.Exports;

public class BattingMostRecentSeasonStatistic : BattingSeasonStatistic
{
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;
}

[Name("OPS+"), Index(47)]
public double OnBasePercentagePlus { get; set; }
}
16 changes: 12 additions & 4 deletions SMB3Explorer/Models/Exports/BattingSeasonStatistic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,23 @@ public class BattingSeasonStatistic
[Name("extra_base_hit_percentage"), Index(40)]
public double ExtraBaseHitPercentage => ExtraBaseHits / (double) Hits;

[Name("season_completion_date"), Index(41)]
// 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(42)]
[Name("season_id"), Index(44)]
public int SeasonId { get; set; }

[Name("season_num"), Index(43)]
[Name("season_num"), Index(45)]
public int SeasonNum { get; set; }

[Name("age"), Index(44)]
[Name("age"), Index(46)]
public int Age { get; set; }
}
44 changes: 44 additions & 0 deletions SMB3Explorer/Models/Exports/PitchingMostRecentSeasonStatistic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using CsvHelper.Configuration.Attributes;

namespace SMB3Explorer.Models.Exports;

public class PitchingMostRecentSeasonStatistic : PitchingSeasonStatistic
{
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;
}


[Name("ERA-"), Index(47)]
public double EarnedRunsAllowedMinus { get; set; }
}
24 changes: 24 additions & 0 deletions SMB3Explorer/Resources/Sql/SeasonAverageBatterStats.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
WITH mostRecentSeason AS (SELECT id AS seasonID,
RANK() OVER (ORDER BY id) AS seasonNum
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)
ORDER BY ID DESC
LIMIT 1)
SELECT AVG(
([hits] + [baseOnBalls] + [hitByPitch]) /
CAST(NULLIF([atBats] + [baseOnBalls] + [hitByPitch] + [sacrificeFlies], 0) AS [REAL]) +
(([hits] - [doubles] - [triples] - [homeruns]) + 2 * [doubles] + 3 * [triples] +
4 * [homeruns]) / CAST(NULLIF([atBats], 0) AS [REAL])
)
AS ops
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
LEFT JOIN t_season_stats tss ON ts.aggregatorID = tss.aggregatorID
JOIN t_seasons tsea ON tss.seasonID = tsea.ID
JOIN mostRecentSeason ON mostRecentSeason.seasonID = tsea.ID
22 changes: 22 additions & 0 deletions SMB3Explorer/Resources/Sql/SeasonAveragePitcherStats.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
WITH mostRecentSeason AS (SELECT id AS seasonID,
RANK() OVER (ORDER BY id) AS seasonNum
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)
ORDER BY ID DESC
LIMIT 1)
SELECT AVG(
CASE
WHEN tspitch.outsPitched = 0 THEN NULL
ELSE (tspitch.earnedRuns * 9) / (tspitch.outsPitched / 3.0)
END) AS era
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
JOIN t_seasons tsea ON tss.seasonID = tsea.ID
JOIN mostRecentSeason ON mostRecentSeason.seasonID = tsea.ID
16 changes: 14 additions & 2 deletions SMB3Explorer/Resources/Sql/TopPerformersBatting.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ SELECT baseballPlayerGUID,
ELSE vbpi.[pitcherRole] END AS pitcherRole,
CAST(secondaryPosition.optionValue AS INTEGER) AS secondaryPosition,
tsb.*,
100 * ((
([hits] + [baseOnBalls] + [hitByPitch]) /
CAST(NULLIF([atBats] + [baseOnBalls] + [hitByPitch] + [sacrificeFlies], 0) AS [REAL]) +
(([hits] - [doubles] - [triples] - [homeruns]) + 2 * [doubles] + 3 * [triples] +
4 * [homeruns]) / CAST(NULLIF([atBats], 0) AS [REAL])
) / @leagueOps) AS opsPlus,
-- sortOrder is a weighted OPS+ based on number of at bats
atBats * 100 * ((
([hits] + [baseOnBalls] + [hitByPitch]) /
CAST(NULLIF([atBats] + [baseOnBalls] + [hitByPitch] + [sacrificeFlies], 0) AS [REAL]) +
(([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,
tbp.age AS age
Expand Down Expand Up @@ -56,5 +69,4 @@ FROM [v_baseball_player_info] vbpi
LEFT JOIN teams previousTeam ON tt2.GUID = previousTeam.teamGUID

WHERE tl.GUID = CAST(@leagueId AS BLOB)
ORDER BY homeruns DESC
LIMIT 25
ORDER BY sortOrder DESC
15 changes: 13 additions & 2 deletions SMB3Explorer/Resources/Sql/TopPerformersPitching.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ SELECT baseballPlayerGUID,
WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[pitcherRole]
ELSE vbpi.[pitcherRole] END AS pitcherRole,
tspitch.*,
CASE
WHEN tspitch.outsPitched = 0 THEN 0
ELSE 100 * (
@leagueEra /
((tspitch.earnedRuns * 9) / (tspitch.outsPitched / 3.0))
)
END AS eraMinus,
-- sortOrder is a weighted eraMinus based on innings pitched
tspitch.outsPitched * 100 * (
@leagueEra /
((tspitch.earnedRuns * 9) / (tspitch.outsPitched / 3.0))
) AS sortOrder,
currentTeam.teamName AS currentTeam,
previousTeam.teamName AS previousTeam,
tbp.age AS age
Expand Down Expand Up @@ -63,5 +75,4 @@ WHERE tl.GUID = CAST(@leagueId AS BLOB)

JOIN t_seasons tsea ON tss.seasonID = tsea.ID
JOIN mostRecentSeason s ON tsea.ID = s.seasonID)
ORDER BY strikeOuts DESC
LIMIT 25
ORDER BY sortOrder DESC
16 changes: 14 additions & 2 deletions SMB3Explorer/Resources/Sql/TopPerformersRookiesBatting.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ SELECT vbpi.baseballPlayerGUID,
ELSE vbpi.[pitcherRole] END AS pitcherRole,
CAST(secondaryPosition.optionValue AS INTEGER) AS secondaryPosition,
tsb.*,
100 * ((
([hits] + [baseOnBalls] + [hitByPitch]) /
CAST(NULLIF([atBats] + [baseOnBalls] + [hitByPitch] + [sacrificeFlies], 0) AS [REAL]) +
(([hits] - [doubles] - [triples] - [homeruns]) + 2 * [doubles] + 3 * [triples] +
4 * [homeruns]) / CAST(NULLIF([atBats], 0) AS [REAL])
) / @leagueOps) AS opsPlus,
-- sortOrder is a weighted OPS+ based on number of at bats
atBats * 100 * ((
([hits] + [baseOnBalls] + [hitByPitch]) /
CAST(NULLIF([atBats] + [baseOnBalls] + [hitByPitch] + [sacrificeFlies], 0) AS [REAL]) +
(([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,
tbp.age AS age
Expand Down Expand Up @@ -67,5 +80,4 @@ FROM [v_baseball_player_info] vbpi
LEFT JOIN teams previousTeam ON tt2.GUID = previousTeam.teamGUID

WHERE tl.GUID = CAST(@leagueId AS BLOB)
ORDER BY homeruns DESC
LIMIT 25
ORDER BY sortOrder DESC
15 changes: 13 additions & 2 deletions SMB3Explorer/Resources/Sql/TopPerformersRookiesPitching.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ SELECT vbpi.baseballPlayerGUID,
WHEN tsp.[baseballPlayerLocalID] IS NULL THEN tsp.[pitcherRole]
ELSE vbpi.[pitcherRole] END AS pitcherRole,
tspitch.*,
CASE
WHEN tspitch.outsPitched = 0 THEN 0
ELSE 100 * (
@leagueEra /
((tspitch.earnedRuns * 9) / (tspitch.outsPitched / 3.0))
)
END AS eraMinus,
-- sortOrder is a weighted eraMinus based on innings pitched
tspitch.outsPitched * 100 * (
@leagueEra /
((tspitch.earnedRuns * 9) / (tspitch.outsPitched / 3.0))
) AS sortOrder,
currentTeam.teamName AS currentTeam,
previousTeam.teamName AS previousTeam,
tbp.age AS age
Expand Down Expand Up @@ -74,5 +86,4 @@ WHERE tl.GUID = CAST(@leagueId AS BLOB)

JOIN t_seasons tsea ON tss.seasonID = tsea.ID
JOIN mostRecentSeason s ON tsea.ID = s.seasonID)
ORDER BY strikeOuts DESC
LIMIT 25
ORDER BY sortOrder DESC
4 changes: 4 additions & 0 deletions SMB3Explorer/SMB3Explorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
<EmbeddedResource Include="Resources\Sql\MostRecentSeasonPlayers.sql" />
<None Remove="Resources\Sql\MostRecentSeasonTeams.sql" />
<EmbeddedResource Include="Resources\Sql\MostRecentSeasonTeams.sql" />
<None Remove="Resources\Sql\SeasonAverageBatterStats.sql" />
<EmbeddedResource Include="Resources\Sql\SeasonAverageBatterStats.sql" />
<None Remove="Resources\Sql\SeasonAveragePitcherStats.sql" />
<EmbeddedResource Include="Resources\Sql\SeasonAveragePitcherStats.sql" />
</ItemGroup>

</Project>
Loading