-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputDataProcessed.py
More file actions
89 lines (70 loc) · 3.26 KB
/
inputDataProcessed.py
File metadata and controls
89 lines (70 loc) · 3.26 KB
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
import pandas as pd
import statistics as stat
import constants
import inputDataRaw as inputData
#projections
def updatedProjection(row):
return stat.mean([row['FantasyPointsRotowire'], row['FantasyPointsDraftKings']])
def updatedProjectionMomentum(row):
return updatedProjection(row) * row['MomentumMultiplier']
#todo this should be a multiplier
def updatedProjectionFloor(row):
avgProjected = updatedProjection(row)
#the .75 intervalL should be less than avg projected but not less than by more than 25% to cap the weight of this metric
if ((avgProjected > row['.75-interval-L']) & ((row['.75-interval-L']*1.25) >= avgProjected)):
return stat.mean([avgProjected, row['.75-interval-L']])
else:
return avgProjected
def updatedProjectionAll(row):
return updatedProjectionFloor(row) * row['MomentumMultiplier']
# to be updated whenever a new projectionType is added
projectionMethods = {
constants.PROJECTION_TYPES['average']: updatedProjection,
constants.PROJECTION_TYPES['floor']: updatedProjectionFloor,
constants.PROJECTION_TYPES['momentum']: updatedProjectionMomentum,
constants.PROJECTION_TYPES['all']: updatedProjectionAll
}
#value (points per $1000 spent)
def updatedValue(row):
newValue = (1000*row['FP']) / row['OperatorSalary']
return newValue
#boolean whether floor was included (ie whether within 25% range of avg projection)
def includedHistoricalFloor(row):
avgProjected = stat.mean([row['FantasyPointsRotowire'], row['FantasyPointsDraftKings']])
return (avgProjected > row['.75-interval-L']) & ((row['.75-interval-L']*1.25) >= avgProjected)
#manual overrides
def filterWithConfig(config):
def filter(row):
return filterPositionBySalary(row, config) & filterPositionByValue(row, config) & filterPlayer(row, config)
return filter
def filterPositionBySalary(row, config):
salaryRangeConfig = config["preProcessConfig"]["positionConfig"]["salaryRange"]
positionConfig = salaryRangeConfig.get(row['Position'], None)
if (positionConfig):
return (row['OperatorSalary'] > positionConfig.get('min')) & (row['OperatorSalary'] < positionConfig.get('max'))
else:
return True
def filterPositionByValue(row, config):
valueRangeConfig = config["preProcessConfig"]["positionConfig"]["valueRange"]
positionConfig = valueRangeConfig.get(row['Position'], None)
if (positionConfig):
return (row['Val'] > positionConfig.get('min')) & (row['Val'] < positionConfig.get('max'))
else:
return True
def filterPlayer(row, config):
playersToOmit = config["preProcessConfig"]["playerConfig"]["playersToOmit"]
if (len(playersToOmit)):
return row['Name'] not in playersToOmit
else:
return True
def getInputDataProcessed(config):
df_final = inputData.df_final_input
df_final = df_final[df_final.Position.isin(constants.VALID_POSITIONS)]
df_final['FP'] = df_final.apply(projectionMethods[config['projectionType']], axis=1)
df_final['Val'] = df_final.apply(updatedValue, axis=1)
df_final['inclFlr'] = df_final.apply(includedHistoricalFloor, axis=1)
if config['preProcess'] == True:
df_final = df_final[df_final.apply(filterWithConfig(config), axis=1)]
df_final = df_final[['Name', 'Team', 'Position', 'Val', 'OperatorSalary', 'FP']]
df_final.columns = ['Name', 'Team', 'Pos', 'Val', 'Sal', 'FP']
return df_final