-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCostAnalysis.py
210 lines (123 loc) · 5.02 KB
/
CostAnalysis.py
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# Cost Analysis System
# last Update : 10.5.19
# Using the following links as references:
# https://www.faketeams.com/2013/1/10/3863908/deep-auction-league-strategy-calculating-dollar-values-part-1
# https://www.faketeams.com/2013/1/14/3877620/deep-auction-league-strategy-calculating-dollar-values-part-2
## move player value next to name and rank player by value
import pandas as pd
import numpy as np
##############################################
### Setting up Roster Postion requirements ###
##############################################
# Roster Settings:
# Number of player positions
RosterSpots = 25
catcher = 1
first = 1
second = 1
third = 1
short = 1
outfield = 3
utility = 1
startingP = 5
reliefP = 2
bench = RosterSpots - (catcher + first + second + third + short + outfield + utility + startingP + reliefP)
IL = 5
NumTeams = 14
##################################
## Step 1: Define Universe Size ##
##################################
TotalPlayers = (NumTeams * RosterSpots)
TotalCatcher = (NumTeams * catcher)
TotalFirst = (NumTeams * first)
TotalSecond = (NumTeams * second)
TotalThird = (NumTeams * third)
TotalShort = (NumTeams * short)
TotalOutfield = (NumTeams * outfield)
TotalHitters = (NumTeams * (catcher + first + second + third + short + outfield + utility))
TotalStartingP = (NumTeams * startingP)
TotalReliefP = (NumTeams * reliefP)
TotalPitchers = (NumTeams * (startingP + reliefP))
TotalBench = (NumTeams * bench)
TotalIL = (NumTeams * IL)
MaxPlayers = (NumTeams * (RosterSpots + IL))
####################################
## Step 2: Calculate Category AVG ##
####################################
# possibly run Points(currentYear) to create the most recent data to use?
bstats = pd.read_csv('data/bstats.csv')
pstats = pd.read_csv('data/pstats.csv')
bstatAVG = np.mean(bstats, axis = 0)
# print(bstatAVG)
pstatAVG = np.mean(pstats, axis = 0)
# print(pstatAVG)
bstats = bstats.drop('Unnamed: 0', 1)
pstats = pstats.drop('Unnamed: 0', 1)
#########################################
## Step 3: Calculate points for player ##
#########################################
# need to adjust the standard deviation (under the division sign to represent the the league)
# (most of a col - least of a col) / (Num of teams - 1 )
# remeber some stats are reversed like ERA, WHIP, etc...??
'''
for col in bstats:
col_AVG = col + '_AVG'
bstats[col_AVG] = (bstats[col] - bstatAVG[col] ) / 5
for col in pstats:
col_AVG = col + '_AVG'
pstats[col_AVG] = (pstats[col] - pstatAVG[col] ) / 5
'''
bstats['Points_AVG'] = (bstats['Points'] - bstatAVG['Points'] ) / ( (700 - 0) / (NumTeams - 1 ) )
pstats['Points_AVG'] = (pstats['Points'] - pstatAVG['Points'] ) / ( (700 - 0) / (NumTeams - 1 ) )
print( bstats.head() )
############################
## Step 4: Sum of AVG COl ##
############################
'''
bstats.fillna(0)
columns_AVG = [column for column in bstats.columns if '_AVG' in column]
print(columns_AVG)
bstats['TotalValue'] = bstats[columns_AVG].sum()
print( bstats.head() )
bstats.to_csv('data/CostAnalysis/CostAnalysis_Bat.csv', sep=',', index=False, encoding='utf-8')
print("Success")
'''
# Basing Price on Point total?
bstats['Points_Cost'] = (bstats['Points_AVG'] )
# print(bstats['Points_Cost'])
pstats['Points_Cost'] = (pstats['Points_AVG'] )
# print(pstats['Points_Cost'])
##############################
## Step 5: Money Allocation ##
##############################
# using point totals
Percent_Hitting = 60
Percent_Pitching = 100 - Percent_Hitting
LeagueBudget = 300
TotalCashSpent = LeagueBudget * NumTeams
TotalCashHitting = TotalCashSpent * (Percent_Hitting / 100)
TotalCashPitching = TotalCashSpent * (Percent_Pitching / 100)
PriceHitterZero = (TotalCashHitting / (TotalHitters + 7) )
PricePerPointBat = ( PriceHitterZero - 1 ) / 4 # check this math??
priceB = PriceHitterZero + (bstats['Points_Cost'] * PricePerPointBat )
bstats.insert(5, 'Price', priceB)
bstats['Price'] = bstats['Price'].round(decimals=2)
PricePitcherZero = (TotalCashPitching / (TotalPitchers + 7) )
PricePerPointPit = ( PricePitcherZero - 1 ) / 4 # check this math??
priceP = PricePitcherZero + (pstats['Points_Cost'] * PricePerPointPit )
pstats.insert(5, 'Price', priceP)
pstats['Price'] = pstats['Price'].round(decimals=2)
bstats.to_csv('data/CostAnalysis/CostAnalysis_Bat.csv', sep=',', index=False, encoding='utf-8')
pstats.to_csv('data/CostAnalysis/CostAnalysis_Pit.csv', sep=',', index=False, encoding='utf-8')
##############################
## Cost Analysis on Marcel ##
#############################
Proj = pd.read_csv('data/marcel/MarcelResultTotal.csv')
ProjAVG = np.mean(Proj, axis = 0)
Proj['Points_AVG'] = (Proj['Total_Points'] - ProjAVG['Total_Points'] ) / ( (750 - 350) / (NumTeams - 1 ) )
PriceZero = (TotalCashSpent / (MaxPlayers) )
PricePerPoint = ( ( PriceZero - 1 ) / 3 ) * 2
priceProj = PriceZero + (Proj['Points_AVG'] * PricePerPoint ) - 20
Proj.insert(2, 'Price', priceProj)
Proj['Price'] = Proj['Price'].round(decimals=2)
Proj.to_csv('data/CostAnalysis/CostAnalysis_Proj.csv', sep=',', index=False, encoding='utf-8')