ffbot 1.2.12__tar.gz → 1.2.13__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ffbot-1.2.12 → ffbot-1.2.13}/PKG-INFO +2 -2
- ffbot-1.2.13/ffbot/constants.py +1 -0
- {ffbot-1.2.12 → ffbot-1.2.13}/ffbot/optimizer.py +73 -55
- {ffbot-1.2.12 → ffbot-1.2.13}/ffbot/scraper.py +15 -17
- {ffbot-1.2.12 → ffbot-1.2.13}/ffbot/utils.py +1 -1
- {ffbot-1.2.12 → ffbot-1.2.13}/ffbot.egg-info/PKG-INFO +2 -2
- {ffbot-1.2.12 → ffbot-1.2.13}/ffbot.egg-info/requires.txt +1 -1
- ffbot-1.2.12/ffbot/constants.py +0 -1
- {ffbot-1.2.12 → ffbot-1.2.13}/LICENSE +0 -0
- {ffbot-1.2.12 → ffbot-1.2.13}/README.md +0 -0
- {ffbot-1.2.12 → ffbot-1.2.13}/ffbot/__init__.py +0 -0
- {ffbot-1.2.12 → ffbot-1.2.13}/ffbot.egg-info/SOURCES.txt +0 -0
- {ffbot-1.2.12 → ffbot-1.2.13}/ffbot.egg-info/dependency_links.txt +0 -0
- {ffbot-1.2.12 → ffbot-1.2.13}/ffbot.egg-info/top_level.txt +0 -0
- {ffbot-1.2.12 → ffbot-1.2.13}/pyproject.toml +0 -0
- {ffbot-1.2.12 → ffbot-1.2.13}/setup.cfg +0 -0
- {ffbot-1.2.12 → ffbot-1.2.13}/setup.py +0 -0
- {ffbot-1.2.12 → ffbot-1.2.13}/tests/test_optimizer.py +0 -0
- {ffbot-1.2.12 → ffbot-1.2.13}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ffbot
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.13
|
|
4
4
|
Summary: Automate playing Yahoo Fantasy Football
|
|
5
5
|
Home-page: https://github.com/amarvin/fantasy-football-bot
|
|
6
6
|
Author: Alex Marvin
|
|
@@ -23,7 +23,7 @@ Requires-Dist: beautifulsoup4
|
|
|
23
23
|
Requires-Dist: loguru
|
|
24
24
|
Requires-Dist: lxml
|
|
25
25
|
Requires-Dist: pandas
|
|
26
|
-
Requires-Dist: pulp
|
|
26
|
+
Requires-Dist: pulp[cbc]
|
|
27
27
|
Requires-Dist: requests
|
|
28
28
|
Requires-Dist: tqdm
|
|
29
29
|
Requires-Dist: user_agent
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VERSION = "1.2.13"
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
from collections import Counter
|
|
2
2
|
|
|
3
3
|
import pandas as pd
|
|
4
|
+
import pulp
|
|
4
5
|
from loguru import logger
|
|
5
6
|
from pulp import (
|
|
6
|
-
PULP_CBC_CMD,
|
|
7
7
|
LpBinary,
|
|
8
8
|
LpContinuous,
|
|
9
9
|
LpMaximize,
|
|
10
10
|
LpProblem,
|
|
11
|
-
|
|
12
|
-
LpVariable,
|
|
11
|
+
LpSolverDefault,
|
|
13
12
|
lpSum,
|
|
14
13
|
value,
|
|
15
14
|
)
|
|
@@ -21,7 +20,7 @@ IR_STATUSES = {
|
|
|
21
20
|
"O",
|
|
22
21
|
"PUP", # e.g. PUP-R
|
|
23
22
|
}
|
|
24
|
-
|
|
23
|
+
LpSolverDefault.msg = False
|
|
25
24
|
|
|
26
25
|
|
|
27
26
|
def optimize(df, week, team, positions):
|
|
@@ -32,25 +31,25 @@ def optimize(df, week, team, positions):
|
|
|
32
31
|
|
|
33
32
|
# Game rules
|
|
34
33
|
positions = [x.strip() for x in positions.split(",")]
|
|
35
|
-
PossiblePositions =
|
|
36
|
-
QB
|
|
37
|
-
WR
|
|
38
|
-
RB
|
|
39
|
-
TE
|
|
40
|
-
K
|
|
41
|
-
DEF
|
|
34
|
+
PossiblePositions = {
|
|
35
|
+
"QB": {"QB", "Q/W/R/T"},
|
|
36
|
+
"WR": {"WR", "W/R/T", "W/T", "W/R", "Q/W/R/T"},
|
|
37
|
+
"RB": {"RB", "W/R/T", "W/R", "Q/W/R/T"},
|
|
38
|
+
"TE": {"TE", "W/R/T", "W/T", "Q/W/R/T"},
|
|
39
|
+
"K": {"K"},
|
|
40
|
+
"DEF": {"DEF", "D/ST"},
|
|
42
41
|
# IDP positions
|
|
43
|
-
CB
|
|
44
|
-
DE
|
|
45
|
-
DT
|
|
46
|
-
LB
|
|
47
|
-
S
|
|
48
|
-
|
|
42
|
+
"CB": {"CB", "D", "DB"},
|
|
43
|
+
"DE": {"D", "DE", "DL"},
|
|
44
|
+
"DT": {"D", "DL", "DT"},
|
|
45
|
+
"LB": {"D", "LB"},
|
|
46
|
+
"S": {"D", "DB", "S"},
|
|
47
|
+
}
|
|
49
48
|
# Remove positions not available in this league
|
|
50
49
|
for key, values in PossiblePositions.items():
|
|
51
|
-
PossiblePositions[key] =
|
|
50
|
+
PossiblePositions[key] = {
|
|
52
51
|
position for position in values if position in positions
|
|
53
|
-
|
|
52
|
+
}
|
|
54
53
|
PossiblePositions = {
|
|
55
54
|
key: values for key, values in PossiblePositions.items() if values
|
|
56
55
|
}
|
|
@@ -67,17 +66,17 @@ def optimize(df, week, team, positions):
|
|
|
67
66
|
POSITIONS = PositionMax.keys()
|
|
68
67
|
|
|
69
68
|
# Pre-process data
|
|
70
|
-
TIMES =
|
|
69
|
+
TIMES = list(range(week, 18))
|
|
71
70
|
PLAYERS = set()
|
|
72
|
-
Names =
|
|
73
|
-
Position =
|
|
74
|
-
Roster0 =
|
|
75
|
-
Owner =
|
|
76
|
-
Status =
|
|
77
|
-
FreeAgent =
|
|
78
|
-
Available =
|
|
79
|
-
Projections =
|
|
80
|
-
VOR =
|
|
71
|
+
Names = {}
|
|
72
|
+
Position = {}
|
|
73
|
+
Roster0 = {}
|
|
74
|
+
Owner = {}
|
|
75
|
+
Status = {}
|
|
76
|
+
FreeAgent = {}
|
|
77
|
+
Available = {}
|
|
78
|
+
Projections = {}
|
|
79
|
+
VOR = {}
|
|
81
80
|
for _, row in df.iterrows():
|
|
82
81
|
p = row["ID"]
|
|
83
82
|
PLAYERS.add(p)
|
|
@@ -91,7 +90,7 @@ def optimize(df, week, team, positions):
|
|
|
91
90
|
FreeAgent[p] = pd.isna(owner_id) and owner == "Free Agent"
|
|
92
91
|
Available[p] = pd.isna(owner_id)
|
|
93
92
|
for t in TIMES:
|
|
94
|
-
Projections[p, t] = float(row["Week {}"
|
|
93
|
+
Projections[p, t] = float(row[f"Week {t}"])
|
|
95
94
|
VOR[p] = row["VOR"]
|
|
96
95
|
# create other parameters
|
|
97
96
|
Discounts = {
|
|
@@ -122,14 +121,38 @@ def optimize(df, week, team, positions):
|
|
|
122
121
|
# Define optimization problem
|
|
123
122
|
prob = LpProblem("football", LpMaximize)
|
|
124
123
|
|
|
124
|
+
# Support PuLP v3 and v4
|
|
125
|
+
is_pulp_v3 = hasattr(pulp.LpVariable, "dicts")
|
|
126
|
+
if is_pulp_v3:
|
|
127
|
+
logger.info("PuLP v3 detected")
|
|
128
|
+
_add_variable_dicts = pulp.LpVariable.dicts
|
|
129
|
+
|
|
130
|
+
def _get_constraint_by_name(prob, constraint_name: str):
|
|
131
|
+
return prob.constraints[constraint_name]
|
|
132
|
+
|
|
133
|
+
def _solve(prob):
|
|
134
|
+
prob.solve(LpSolverDefault)
|
|
135
|
+
assert prob.status == pulp.LpStatusOptimal
|
|
136
|
+
|
|
137
|
+
else:
|
|
138
|
+
logger.info("PuLP v4 detected")
|
|
139
|
+
_add_variable_dicts = prob.add_variable_dicts
|
|
140
|
+
|
|
141
|
+
def _get_constraint_by_name(prob, constraint_name: str):
|
|
142
|
+
return prob.get_constraint_by_name(constraint_name)
|
|
143
|
+
|
|
144
|
+
def _solve(prob):
|
|
145
|
+
stats = prob.solve(LpSolverDefault)
|
|
146
|
+
assert stats.has_solution
|
|
147
|
+
|
|
125
148
|
# Define decision variables
|
|
126
|
-
roster =
|
|
127
|
-
add =
|
|
128
|
-
drop =
|
|
129
|
-
assign =
|
|
130
|
-
points =
|
|
131
|
-
points_total =
|
|
132
|
-
discounted_points_total =
|
|
149
|
+
roster = _add_variable_dicts("roster", PLAYERS, cat=LpBinary)
|
|
150
|
+
add = _add_variable_dicts("add", PLAYERS, cat=LpBinary)
|
|
151
|
+
drop = _add_variable_dicts("drop", PLAYERS, cat=LpBinary)
|
|
152
|
+
assign = _add_variable_dicts("assign", PlayerTimePosition, cat=LpBinary)
|
|
153
|
+
points = _add_variable_dicts("points", PlayerTime, cat=LpContinuous)
|
|
154
|
+
points_total = _add_variable_dicts("points total", PLAYERS, cat=LpContinuous)
|
|
155
|
+
discounted_points_total = _add_variable_dicts(
|
|
133
156
|
"discounted points total", PLAYERS, cat=LpContinuous
|
|
134
157
|
)
|
|
135
158
|
|
|
@@ -176,8 +199,7 @@ def optimize(df, week, team, positions):
|
|
|
176
199
|
# Solve optimization problem
|
|
177
200
|
solutions_headers = ["Add", "Drop", "Total points", "Discounted points", "VOR"]
|
|
178
201
|
solutions = []
|
|
179
|
-
prob
|
|
180
|
-
assert LpStatus[prob.status] == "Optimal"
|
|
202
|
+
_solve(prob)
|
|
181
203
|
known_drops = set()
|
|
182
204
|
n_drops = 0
|
|
183
205
|
for p in PLAYERS:
|
|
@@ -200,9 +222,8 @@ def optimize(df, week, team, positions):
|
|
|
200
222
|
known_adds = set()
|
|
201
223
|
n_adds = 1
|
|
202
224
|
while True:
|
|
203
|
-
prob
|
|
204
|
-
prob
|
|
205
|
-
assert LpStatus[prob.status] == "Optimal"
|
|
225
|
+
_get_constraint_by_name(prob, "max_adds").constant = -n_adds
|
|
226
|
+
_solve(prob)
|
|
206
227
|
this_add = ""
|
|
207
228
|
for p in PLAYERS:
|
|
208
229
|
if add[p].varValue and p not in known_adds:
|
|
@@ -229,12 +250,11 @@ def optimize(df, week, team, positions):
|
|
|
229
250
|
last_vor = vor
|
|
230
251
|
|
|
231
252
|
# Re-solve for each drop to acquire a free agent
|
|
232
|
-
|
|
253
|
+
_get_constraint_by_name(prob, "max_adds").constant = -100
|
|
233
254
|
while True:
|
|
234
255
|
n_drops += 1
|
|
235
|
-
prob
|
|
236
|
-
prob
|
|
237
|
-
assert LpStatus[prob.status] == "Optimal"
|
|
256
|
+
_get_constraint_by_name(prob, "max_drops").constant = -n_drops
|
|
257
|
+
_solve(prob)
|
|
238
258
|
this_drop = ""
|
|
239
259
|
this_add = ""
|
|
240
260
|
for p in PLAYERS:
|
|
@@ -266,12 +286,11 @@ def optimize(df, week, team, positions):
|
|
|
266
286
|
last_vor = vor
|
|
267
287
|
|
|
268
288
|
# Re-solve for each waiver claim add without dropping any players
|
|
269
|
-
|
|
270
|
-
prob
|
|
289
|
+
_get_constraint_by_name(prob, "only_add_free_agents").sense = pulp.LpConstraintGE
|
|
290
|
+
_get_constraint_by_name(prob, "max_adds").constant = 0
|
|
271
291
|
while True:
|
|
272
|
-
prob
|
|
273
|
-
prob
|
|
274
|
-
assert LpStatus[prob.status] == "Optimal"
|
|
292
|
+
_get_constraint_by_name(prob, "max_adds").constant = -n_adds
|
|
293
|
+
_solve(prob)
|
|
275
294
|
this_add = ""
|
|
276
295
|
for p in PLAYERS:
|
|
277
296
|
if add[p].varValue and p not in known_adds:
|
|
@@ -298,11 +317,10 @@ def optimize(df, week, team, positions):
|
|
|
298
317
|
last_vor = vor
|
|
299
318
|
|
|
300
319
|
# Re-solve for each drop to acquire a waiver claim
|
|
301
|
-
|
|
320
|
+
_get_constraint_by_name(prob, "max_adds").constant = -100
|
|
302
321
|
while True:
|
|
303
|
-
prob
|
|
304
|
-
prob
|
|
305
|
-
assert LpStatus[prob.status] == "Optimal"
|
|
322
|
+
_get_constraint_by_name(prob, "max_drops").constant = -n_drops
|
|
323
|
+
_solve(prob)
|
|
306
324
|
this_drop = ""
|
|
307
325
|
this_add = ""
|
|
308
326
|
for p in PLAYERS:
|
|
@@ -30,7 +30,7 @@ def create_session():
|
|
|
30
30
|
"User-Agent": generate_user_agent(),
|
|
31
31
|
}
|
|
32
32
|
# add retry loop
|
|
33
|
-
retry = Retry(backoff_factor=0.6, status_forcelist=[500, 502, 503, 504, 999])
|
|
33
|
+
retry = Retry(backoff_factor=0.6, status_forcelist=[404, 500, 502, 503, 504, 999])
|
|
34
34
|
adapter = HTTPAdapter(max_retries=retry)
|
|
35
35
|
s.mount("http://", adapter)
|
|
36
36
|
s.mount("https://", adapter)
|
|
@@ -52,22 +52,20 @@ def scrape(league, is_IDP: bool = False):
|
|
|
52
52
|
groups = SEARCH_PLAYER_GROUPS_IDP if is_IDP else SEARCH_PLAYER_GROUPS
|
|
53
53
|
s = create_session()
|
|
54
54
|
for group in groups:
|
|
55
|
-
logger.info("Scraping all {}..."
|
|
55
|
+
logger.info(f"Scraping all {group}...")
|
|
56
56
|
i = 0
|
|
57
57
|
while True:
|
|
58
58
|
# Request next 25 best players
|
|
59
59
|
s.headers["User-Agent"] = generate_user_agent()
|
|
60
60
|
r = s.get(
|
|
61
|
-
"https://football.fantasysports.yahoo.com/f1/{}/players"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
status="ALL",
|
|
70
|
-
),
|
|
61
|
+
f"https://football.fantasysports.yahoo.com/f1/{PUBLIC_LEAGUE_IDP if is_IDP else PUBLIC_LEAGUE}/players",
|
|
62
|
+
params={
|
|
63
|
+
"count": i * 25,
|
|
64
|
+
"pos": group,
|
|
65
|
+
"sort": "PR_S", # sort by projected season rank
|
|
66
|
+
"stat1": "K_K", # ranks
|
|
67
|
+
"status": "ALL",
|
|
68
|
+
},
|
|
71
69
|
)
|
|
72
70
|
i += 1
|
|
73
71
|
soup = bs(r.text, "lxml")
|
|
@@ -95,7 +93,7 @@ def scrape(league, is_IDP: bool = False):
|
|
|
95
93
|
s = create_session()
|
|
96
94
|
|
|
97
95
|
pid = row["ID"]
|
|
98
|
-
url = "https://football.fantasysports.yahoo.com/f1/{}/playernote"
|
|
96
|
+
url = f"https://football.fantasysports.yahoo.com/f1/{league}/playernote"
|
|
99
97
|
params = {"pid": pid}
|
|
100
98
|
s.headers["User-Agent"] = generate_user_agent()
|
|
101
99
|
r = s.get(url, params=params)
|
|
@@ -126,7 +124,7 @@ def scrape(league, is_IDP: bool = False):
|
|
|
126
124
|
# Weekly projections
|
|
127
125
|
df2 = pd.read_html(StringIO(html))[0]
|
|
128
126
|
for _, row2 in df2.iterrows():
|
|
129
|
-
week = "Week {
|
|
127
|
+
week = f"Week {row2['Week']}"
|
|
130
128
|
points = row2.get("Fan Pts")
|
|
131
129
|
if points is None:
|
|
132
130
|
continue
|
|
@@ -160,7 +158,7 @@ def scrape(league, is_IDP: bool = False):
|
|
|
160
158
|
df = df[columns]
|
|
161
159
|
|
|
162
160
|
# Calculate VOR
|
|
163
|
-
columns = ["Week {}"
|
|
161
|
+
columns = [f"Week {i}" for i in range(current_week(), 18)]
|
|
164
162
|
df["Remaining"] = df[columns].sum(axis=1)
|
|
165
163
|
available = df.loc[df["Owner ID"].isnull()]
|
|
166
164
|
means = (
|
|
@@ -180,7 +178,7 @@ def scrape(league, is_IDP: bool = False):
|
|
|
180
178
|
df.sort_values(by="VOR", ascending=False, inplace=True)
|
|
181
179
|
df = df.round(2)
|
|
182
180
|
|
|
183
|
-
logger.info("Total runtime: {
|
|
181
|
+
logger.info(f"Total runtime: {datetime.now() - startTime}")
|
|
184
182
|
return df
|
|
185
183
|
|
|
186
184
|
|
|
@@ -189,7 +187,7 @@ def current_week():
|
|
|
189
187
|
|
|
190
188
|
# Parse current week from a public league
|
|
191
189
|
s = create_session()
|
|
192
|
-
url = "https://football.fantasysports.yahoo.com/f1/{}/1"
|
|
190
|
+
url = f"https://football.fantasysports.yahoo.com/f1/{PUBLIC_LEAGUE}/1"
|
|
193
191
|
s.headers["User-Agent"] = generate_user_agent()
|
|
194
192
|
r = s.get(url)
|
|
195
193
|
soup = bs(r.text, "lxml")
|
|
@@ -16,7 +16,7 @@ def save(df, week):
|
|
|
16
16
|
|
|
17
17
|
# Create filename
|
|
18
18
|
startTime = datetime.now()
|
|
19
|
-
filename = join(folder, "{:%Y-%m-%d %H%M} week {}.csv"
|
|
19
|
+
filename = join(folder, f"{startTime:%Y-%m-%d %H%M} week {week}.csv")
|
|
20
20
|
|
|
21
21
|
# Save data
|
|
22
22
|
df.to_csv(filename, index=False)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ffbot
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.13
|
|
4
4
|
Summary: Automate playing Yahoo Fantasy Football
|
|
5
5
|
Home-page: https://github.com/amarvin/fantasy-football-bot
|
|
6
6
|
Author: Alex Marvin
|
|
@@ -23,7 +23,7 @@ Requires-Dist: beautifulsoup4
|
|
|
23
23
|
Requires-Dist: loguru
|
|
24
24
|
Requires-Dist: lxml
|
|
25
25
|
Requires-Dist: pandas
|
|
26
|
-
Requires-Dist: pulp
|
|
26
|
+
Requires-Dist: pulp[cbc]
|
|
27
27
|
Requires-Dist: requests
|
|
28
28
|
Requires-Dist: tqdm
|
|
29
29
|
Requires-Dist: user_agent
|
ffbot-1.2.12/ffbot/constants.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
VERSION = "1.2.12"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|