generated from dynastyprocess/data-sfb12
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_mfl.R
70 lines (60 loc) · 2.39 KB
/
update_mfl.R
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
library(ffscrapr)
library(dplyr)
library(data.table)
library(tidyr)
library(purrr)
library(stringr)
library(piggyback)
library(cli)
options(dplyr.summarise.inform = FALSE,
piggyback.verbose = FALSE)
mfl_user_agent <- function(league_id){
paste0(Sys.getenv("MFL_USER_AGENT"), league_id)
}
# leagues <- mfl_getendpoint(mfl_connect(2023),"leagueSearch",SEARCH="#SFB13") |>
# pluck("content","leagues","league") |>
# rbindlist(fill = TRUE) |>
# filter(str_detect(name,"^\\#SFB13"), !str_detect(name, " Mock ")) |>
# select(-homeURL, league_name = name, league_id = id)
#
# fwrite(leagues,"league_ids_mfl.csv",quote = TRUE)
leagues <- fread("league_ids_mfl.csv")
get_draft <- function(league_id){
Sys.sleep(1)
cli::cli_alert("League ID: {league_id}")
conn <- mfl_connect(2023, league_id, user_agent = mfl_user_agent(league_id), rate_limit = TRUE)
ff_draft(conn)
}
drafts <- leagues |>
mutate(drafts = map(league_id, possibly(get_draft, otherwise = tibble()))) |>
unnest(drafts)
fwrite(drafts,"output/draft_picks_mfl.csv",quote = TRUE)
update_time <- format(Sys.time(), tz = "America/Toronto", usetz = TRUE)
writeLines(update_time, "output/timestamp.txt")
pb_upload("output/draft_picks_mfl.csv", repo = "dynastyprocess/data-sfb13", tag = "data-mfl")
pb_upload("output/timestamp.txt", repo = "dynastyprocess/data-sfb13", tag = "data-mfl")
drafts <- fread("output/draft_picks_mfl.csv")
adp <- drafts |>
filter(!is.na(player_id)) |>
group_by(league_id,pos) |>
mutate(pos_rank = rank(overall)) |>
group_by(player_id, player_name, pos, team) |>
summarise(
n = n(),
overall_avg = mean(overall, na.rm = TRUE) |> round(2),
overall_sd = sd(overall, na.rm = TRUE) |> round(2),
pos_avg = mean(pos_rank, na.rm = TRUE) |> round(2),
pos_sd = sd(pos_rank, na.rm = TRUE) |> round(2),
overall_min = min(overall, na.rm = TRUE),
overall_max = max(overall, na.rm = TRUE),
pos_min = min(pos_rank, na.rm = TRUE),
pos_max = max(pos_rank, na.rm = TRUE)
) |>
ungroup() |>
arrange(overall_avg,-n)
fwrite(adp,"output/adp_mfl.csv")
update_time <- format(Sys.time(), tz = "America/Toronto", usetz = TRUE)
writeLines(update_time, "output/timestamp.txt")
pb_upload("output/adp_mfl.csv", repo = "dynastyprocess/data-sfb13", tag = "data-mfl")
pb_upload("output/timestamp.txt", repo = "dynastyprocess/data-sfb13", tag = "data-mfl")
cli::cli_alert_success("Successfully got all picks and ADP!")