-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.py
104 lines (96 loc) · 2.95 KB
/
tools.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
from datetime import date, datetime, timedelta, timezone
def get_season():
current_year = datetime.now().year
september_first = date(current_year, 9, 1)
days_to_add = (7 - september_first.weekday()) % 7
labor_day = september_first + timedelta(days=days_to_add)
end_of_week_1 = labor_day + timedelta(days=7)
today_est = datetime.now(timezone(timedelta(hours=-5))).date()
if today_est>end_of_week_1:
return current_year
else:
return current_year-1
def get_abbreviations():
team_abbreviations = {
"ARI": "Cardinals",
"ATL": "Falcons",
"BAL": "Ravens",
"BUF": "Bills",
"CAR": "Panthers",
"CHI": "Bears",
"CIN": "Bengals",
"CLE": "Browns",
"DAL": "Cowboys",
"DEN": "Broncos",
"DET": "Lions",
"GB": "Packers",
"HOU": "Texans",
"IND": "Colts",
"JAC": "Jaguars",
"KC": "Chiefs",
"LA": "Rams",
"LAC": "Chargers",
"LAR": "Rams",
"LV": "Raiders",
"MIA": "Dolphins",
"MIN": "Vikings",
"NE": "Patriots",
"NO": "Saints",
"NYG": "Giants",
"NYJ": "Jets",
"OAK": "Raiders",
"PHI": "Eagles",
"PIT": "Steelers",
"SD": "Chargers",
"SEA": "Seahawks",
"SF": "49ers",
"STL": "Rams",
"TB": "Buccaneers",
"TEN": "Titans",
"WAS": "Commanders"
}
return team_abbreviations
def get_relevant_columns():
relevant_columns = [
"player_display_name",
"position",
"carries",
"rushing_yards",
"rushing_tds",
"receptions",
"targets",
"receiving_yards",
"receiving_tds",
"tgt_sh",#target share
"ry_sh",#receiving yards shares
"wopr_y",#Weighted Opportunity Rating = 1.5 * Target Share + 0.7 * Share of Team Air Yards
"rtd_sh",#receiving touchdowns share
"yptmpa",#Receiving Yards Per Team Pass Attempt
"games",
"fantasy_points_ppr"
]
return relevant_columns
def format_team(team):
return team[:len(team) // 2]
def format_df(data, columns_to_keep):
return data.loc[:, columns_to_keep]
def get_value(input_value):
full_length = len(input_value)
for index in range(1, len(input_value)):
sub_string = input_value[0:index]
reps = full_length/len(sub_string)
if full_length%len(sub_string)==0:
if input_value==sub_string*int(reps):
return sub_string
return input_value
def fix_typos(data, bad_columns):
for column in bad_columns:
data[column] = data[column].apply(get_value)
return data
def fantasy_pros_format(player_name):
for ending in get_abbreviations().keys():
if player_name.endswith(ending):
return player_name[:-len(ending)]
elif player_name.endswith("("+ending+")"):
return player_name[:-len(ending)-2]
return player_name