generated from dynastyprocess/data-sfb12
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_sleeper.R
60 lines (53 loc) · 1.99 KB
/
update_sleeper.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
library(ffscrapr)
library(dplyr)
library(data.table)
library(tidyr)
library(purrr)
library(stringr)
library(piggyback)
library(cli)
leagues <- sleeper_userleagues("ScottFishBowl", 2023) |>
select(league_id, league_name) |>
filter(str_detect(league_name,"\\#SFB13")) |>
filter(!str_detect(league_name, "Mirror")) |>
mutate(league_id = as.character(league_id))
fwrite(leagues,"league_ids_sleeper.csv")
get_draft <- function(league_id){
cli::cli_alert("League ID: {league_id}")
conn <- sleeper_connect(2023, league_id, rate_limit = F)
suppressWarnings(ff_draft(conn))
}
drafts <- leagues |>
select(league_id, league_name) |>
mutate(drafts = map(league_id, possibly(get_draft, otherwise = tibble()))) |>
unnest(drafts) |>
group_by(league_id) |>
mutate(overall = row_number()) |>
ungroup()
adp <- drafts |>
filter(!is.na(player_id)) |>
group_by(league_id) |>
mutate(overall = row_number()) |>
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(drafts,"output/draft_picks_sleeper.csv",quote = TRUE)
fwrite(adp,"output/adp_sleeper.csv",quote = TRUE)
update_time <- format(Sys.time(), tz = "America/Toronto", usetz = TRUE)
writeLines(update_time, "output/timestamp.txt")
pb_upload("output/draft_picks_sleeper.csv", repo = "dynastyprocess/data-sfb13", tag = "data-sleeper")
pb_upload("output/adp_sleeper.csv", repo = "dynastyprocess/data-sfb13", tag = "data-sleeper")
pb_upload("output/timestamp.txt", repo = "dynastyprocess/data-sfb13", tag = "data-sleeper")