-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathMLBBaseballBatter.cs
144 lines (114 loc) · 4.94 KB
/
MLBBaseballBatter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.ML;
using Microsoft.ML.Data;
namespace BaseballPredictionBlazor.Shared
{
public class MLBBaseballBatter
{
[LoadColumn(0), ColumnName("InductedToHallOfFame")]
public bool InductedToHallOfFame { get; set; }
[LoadColumn(1), ColumnName("OnHallOfFameBallot")]
public bool OnHallOfFameBallot { get; set; }
[LoadColumn(2), ColumnName("FullPlayerName")]
public string FullPlayerName { get; set; }
[LoadColumn(3), ColumnName("YearsPlayed")]
public float YearsPlayed { get; set; }
[LoadColumn(4), ColumnName("AB")]
public float AB { get; set; }
[LoadColumn(5), ColumnName("R")]
public float R { get; set; }
[LoadColumn(6), ColumnName("H")]
public float H { get; set; }
[LoadColumn(7), ColumnName("Doubles")]
public float Doubles { get; set; }
[LoadColumn(8), ColumnName("Triples")]
public float Triples { get; set; }
[LoadColumn(9), ColumnName("HR")]
public float HR { get; set; }
[LoadColumn(10), ColumnName("RBI")]
public float RBI { get; set; }
[LoadColumn(11), ColumnName("SB")]
public float SB { get; set; }
[LoadColumn(12), ColumnName("BattingAverage")]
public float BattingAverage { get; set; }
[LoadColumn(13), ColumnName("SluggingPct")]
public float SluggingPct { get; set; }
[LoadColumn(14), ColumnName("AllStarAppearances")]
public float AllStarAppearances { get; set; }
[LoadColumn(15), ColumnName("MVPs")]
public float MVPs { get; set; }
[LoadColumn(16), ColumnName("TripleCrowns")]
public float TripleCrowns { get; set; }
[LoadColumn(17), ColumnName("GoldGloves")]
public float GoldGloves { get; set; }
[LoadColumn(18), ColumnName("MajorLeaguePlayerOfTheYearAwards")]
public float MajorLeaguePlayerOfTheYearAwards { get; set; }
[LoadColumn(19), ColumnName("TB")]
public float TB { get; set; }
[LoadColumn(20), ColumnName("LastYearPlayed")]
public float LastYearPlayed { get; set; }
[LoadColumn(21), ColumnName("ID")]
public float ID { get; set; }
public MLBBaseballBatter CalculateStatisticsProratedBySeason(int numberOfSeasons)
{
var batter = new MLBBaseballBatter
{
FullPlayerName = this.FullPlayerName,
ID = 100f,
InductedToHallOfFame = false,
LastYearPlayed = 0f,
OnHallOfFameBallot = false,
YearsPlayed = numberOfSeasons * 1f,
AB = (this.AB/this.YearsPlayed) * numberOfSeasons,
R = (this.R / this.YearsPlayed) * numberOfSeasons,
H = (this.H / this.YearsPlayed) * numberOfSeasons,
Doubles = (this.Doubles / this.YearsPlayed) * numberOfSeasons,
Triples = (this.Triples / this.YearsPlayed) * numberOfSeasons,
HR = (float) Math.Round(
((this.HR / this.YearsPlayed) * numberOfSeasons), 0,
MidpointRounding.AwayFromZero),
RBI = (this.RBI / this.YearsPlayed) * numberOfSeasons,
SB = (this.SB / this.YearsPlayed) * numberOfSeasons,
BattingAverage = 0.350f,
SluggingPct = 0.65f,
AllStarAppearances = (float) Math.Round(
(Decimal)(this.AllStarAppearances / this.YearsPlayed) * numberOfSeasons,
0,
MidpointRounding.AwayFromZero),
MVPs = (this.MVPs / this.YearsPlayed) * numberOfSeasons,
TripleCrowns = (this.TripleCrowns / this.YearsPlayed) * numberOfSeasons,
GoldGloves = (this.GoldGloves / this.YearsPlayed) * numberOfSeasons,
MajorLeaguePlayerOfTheYearAwards = (this.MajorLeaguePlayerOfTheYearAwards / this.YearsPlayed) * numberOfSeasons,
TB = (float) Math.Round(
((this.TB / this.YearsPlayed) * numberOfSeasons), 0, MidpointRounding.AwayFromZero)
};
return batter;
}
public MLBHOFPrediction GetHallOfFameInductionPredictionBasedOn500HrRule()
{
var mlbHofPrediction = new MLBHOFPrediction
{
Prediction = false,
Probability = 0f,
Score = 0f
};
if (this.HR >= 500)
{
mlbHofPrediction.Probability = 1f;
mlbHofPrediction.Prediction = true;
}
return mlbHofPrediction;
}
}
public class MLBHOFPrediction
{
[ColumnName("PredictedLabel")]
public bool Prediction { get; set; }
[ColumnName("Probability")]
public float Probability { get; set; }
[ColumnName("Score")]
public float Score { get; set; }
}
}