forked from BenBrostoff/draftfast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_constraints.py
79 lines (56 loc) · 2.01 KB
/
query_constraints.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
def add_constraints(query_args, remove):
def filter_fn(player):
kwargs = {'player': player, 'query_args': query_args}
return _is_not_selected(player, remove) and \
_is_above_projected_points(**kwargs) and \
_is_below_cost(**kwargs) and \
_is_above_min_cost(**kwargs) and \
_is_below_proj_ownership_pct(**kwargs) and \
not _is_banned_player(**kwargs) and \
_is_selected_team(**kwargs) and \
_is_home(**kwargs) and \
_is_within_avg(**kwargs)
return filter_fn
def lock_override(fn):
def override_fn(**kwargs):
if kwargs['player'].lock:
return True
return fn(**kwargs)
return override_fn
def _is_not_selected(player, remove):
return player.name not in remove
@lock_override
def _is_above_projected_points(player, query_args):
return player.proj >= int(query_args.lp) or player.pos in ['DST']
@lock_override
def _is_below_cost(player, query_args):
return player.cost <= int(query_args.ms)
@lock_override
def _is_above_min_cost(player, query_args):
return player.cost >= int(query_args.sp)
@lock_override
def _is_below_proj_ownership_pct(player, query_args):
return player.projected_ownership_pct <= int(query_args.po)
@lock_override
def _is_selected_team(player, query_args):
if player.team is None:
return False
if not query_args.teams or player.pos in ['DST']:
return True
return player.team in query_args.teams
def _is_banned_player(player, query_args):
if player.pos == 'DST' and query_args.banned:
return player.name.strip() in [
n.strip() for n in query_args.banned
]
if not query_args.banned:
return False
return player.name in query_args.banned
@lock_override
def _is_home(player, query_args):
if query_args.home:
return player.is_home
return True
@lock_override
def _is_within_avg(player, query_args):
return abs(player.v_avg) < abs(float(query_args.v_avg))