-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
114 lines (102 loc) · 3.25 KB
/
helpers.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
from datetime import datetime
def round_suffix(rank: int) -> str:
ith = {1: "st", 2: "nd", 3: "rd"}.get(
rank % 10 * (rank % 100 not in [11, 12, 13]), "th"
)
return f"{str(rank)}{ith}"
def dedupe(lst):
dup_free_set = set()
for x in lst:
t = tuple(x)
if t not in dup_free_set:
dup_free_set.add(t)
return list(dup_free_set)
def seconds_text(refresh_time: int, nowtime: datetime.utcnow()) -> str:
secs = round((nowtime - datetime.utcfromtimestamp(refresh_time)).total_seconds())
if secs > 60:
days = secs // 86400
hours = (secs - days * 86400) // 3600
minutes = (secs - days * 86400 - hours * 3600) // 60
result = (
("{}d, ".format(days) if days else "")
+ ("{}h, ".format(hours) if hours else "")
+ ("{}m, ".format(minutes) if minutes else "")
)
return result[0:-2]
else:
return "0m"
def render_players(players: list, rank_type: str):
starting_qbs = [
player
for player in players
if player["fantasy_position"] == "QB"
if player["fantasy_designation"] == "STARTER"
]
starting_rbs = [
player
for player in players
if player["fantasy_position"] == "RB"
if player["fantasy_designation"] == "STARTER"
]
starting_wrs = [
player
for player in players
if player["fantasy_position"] == "WR"
if player["fantasy_designation"] == "STARTER"
]
starting_tes = [
player
for player in players
if player["fantasy_position"] == "TE"
if player["fantasy_designation"] == "STARTER"
]
flex = [player for player in players if player["fantasy_position"] == "FLEX"]
super_flex = [
player for player in players if player["fantasy_position"] == "SUPER_FLEX"
]
rec_flex = [
player for player in players if player["fantasy_position"] == "REC_FLEX"
]
bench_qbs = [
player
for player in players
if player["fantasy_position"] == "QB"
if player["fantasy_designation"] == "BENCH"
]
bench_rbs = [
player
for player in players
if player["fantasy_position"] == "RB"
if player["fantasy_designation"] == "BENCH"
]
bench_wrs = [
player
for player in players
if player["fantasy_position"] == "WR"
if player["fantasy_designation"] == "BENCH"
]
bench_tes = [
player
for player in players
if player["fantasy_position"] == "TE"
if player["fantasy_designation"] == "BENCH"
]
starters = {
"qb": starting_qbs,
"rb": starting_rbs,
"wr": starting_wrs,
"te": starting_tes,
"flex": flex,
"super_flex": super_flex,
"rec_flex": rec_flex,
}
bench = {"qb": bench_qbs, "rb": bench_rbs, "wr": bench_wrs, "te": bench_tes}
if rank_type == "power":
picks = [
player for player in players if player["fantasy_designation"] == "PICKS"
]
picks_ = {"picks": picks}
team_spots = {"starters": starters, "bench": bench, "picks": picks_}
elif rank_type == "contender":
team_spots = {"starters": starters, "bench": bench}
return team_spots