UID = 327909786517508096
Looks like the user names and the roster IDs are the same for each season.
In that case we drop the league_id and dedupe
Do we maybe treat these like fixtures?
We need everyones record against everyone else.
lads_l <- list()
for(i in 1: length(users_rosters$display_name))
{
lads_l[[i]] <- user_matchups %>% arrange(season, week, matchup_id) %>%
select(-league_id, -user_id, -roster_id) %>%
select(week, season, name = display_name, matchup_id, points) %>%
filter(name == users_rosters$display_name[i]) %>%
left_join(user_matchups %>% arrange(season, week, matchup_id) %>%
select(-league_id, -user_id, -roster_id) %>%
select(week, season, name = display_name, matchup_id, points),
by = c("season", "week", "matchup_id")) %>%
filter(name.x != name.y)
}
lads_df <- bind_rows(lads_l) %>%
rename(name = name.x,
against = name.y,
points = points.x,
against_points = points.y) %>%
mutate(points_diff = points - against_points,
result = case_when(points > against_points ~ "won",
points < against_points ~ "lost",
points == against_points ~ "drawn"))
I am intrigued to see how far it can go and the results. For example I feel particularly hard done by and like I’ve narrowly missed out which in turn hurts my overall totals. On result stats I’m the 2nd worst player in the league and am basically livid about and therefore trying to find an excuse
So for example I’m statistically the 2 worst overall player according to the total games won and lost as my record in season is 17-22. But what I’m really interested in is how unlucky have I been for example, are my losses within 10 points compared to someone who’s overall record is loads better but has played crap teams at the right time etc
The primary thing is to come up with stats to create some needle between managers, find the grudge matches and stats that would annoy someone
*Form over the past X match ups
lads_df %>%
filter(name == "Hopolaughs") %>%
group_by(against) %>%
summarise(ave_points_diff = round(mean(points_diff))) %>%
inner_join(
lads_df %>%
filter(name == "Hopolaughs") %>%
tabyl(against, result)
) %>%
arrange(ave_points_diff)
## Joining, by = "against"
## # A tibble: 9 x 5
## against ave_points_diff drawn lost won
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 BigBadRon -17 1 4 1
## 2 WUTANGDAN -9 1 5 2
## 3 sdr2043 -3 1 3 3
## 4 matt4976 3 0 4 3
## 5 bazz88 4 1 2 3
## 6 Gmen6 7 1 2 2
## 7 Esquisite 8 1 2 3
## 8 elmorgan 14 1 2 3
## 9 KorbenDallas9ers 17 1 2 2
lads_df %>%
group_by(against, name) %>%
summarise(ave_points_diff = round(mean(points_diff))) %>%
ggplot((aes(against, desc(ave_points_diff), fill = name))) +
geom_bar(stat = "identity") +
facet_wrap(~name, ncol = 5) +
coord_flip() +
theme(legend.position = "none")
## `summarise()` has grouped output by 'against'. You can override using the `.groups` argument.
#lads_df %>%
# mutate(match_up = paste(name, against, sep = " v ")) %>%
# tabyl(match_up, result)
lads_df %>%
group_by(name, against) %>%
summarise(points_diff = mean(points_diff)) %>%
ggplot(aes(fct_reorder(name, points_diff),
fct_reorder(against, points_diff),
fill = points_diff, label = round(points_diff))) +
geom_tile() +
shadowtext::geom_shadowtext() +
#geom_text(colour = "white") +
coord_flip() +
hrbrthemes::theme_ipsum() +
ggtitle("Average Points Diff per Match Up") +
theme(legend.position = "none") +
theme(axis.text.x = element_text(size = 10, angle = 40, hjust = 1),
axis.text.y = element_text(size = 10)) +
scale_fill_viridis_c(option = "magma") +
theme(axis.title.x = element_blank(), axis.title.y = element_blank())
match_win_loss_l <- list()
for(i in 1:length(users_rosters$display_name)) {
match_win_loss_l[[i]] <-
lads_df %>%
filter(name == users_rosters$display_name[i]) %>%
group_by(against) %>%
summarise(ave_points_diff = round(mean(points_diff))) %>%
inner_join(
lads_df %>%
filter(name == users_rosters$display_name[i]) %>%
tabyl(against, result)
) %>%
arrange(ave_points_diff) %>%
mutate(name = users_rosters$display_name[i])
}
## Joining, by = "against"
## Joining, by = "against"
## Joining, by = "against"
## Joining, by = "against"
## Joining, by = "against"
## Joining, by = "against"
## Joining, by = "against"
## Joining, by = "against"
## Joining, by = "against"
## Joining, by = "against"
match_win_loss_df <- bind_rows(match_win_loss_l) %>%
left_join(
lads_df %>%
count(name, result) %>%
filter(result == "won") %>%
mutate(win_rank = rank(n)) %>%
select(name, win_rank)
) %>%
left_join(
lads_df %>%
count(name, result) %>%
filter(result == "won") %>%
mutate(win_rank = rank(n)) %>%
select(name, win_rank),
by = c("against" = "name")
) %>%
rename(name_rank = win_rank.x,
against_rank = win_rank.y) %>%
select(name, name_rank, against, against_rank, everything()) %>%
mutate(rank_diff = name_rank - against_rank)
## Joining, by = "name"
What is the lowest ranked winning record?
match_win_loss_df %>%
filter(rank_diff < 0) %>%
filter(won >= lost) %>%
arrange(rank_diff)
## # A tibble: 16 x 9
## name name_rank against against_rank ave_points_diff drawn lost won
## <chr> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 bazz88 1 matt49~ 8 7 1 2 2
## 2 elmorgan 4 BigBad~ 9 11 1 2 4
## 3 sdr2043 4 BigBad~ 9 7 1 2 2
## 4 elmorgan 4 matt49~ 8 3 1 2 2
## 5 KorbenDalla~ 2 Esquis~ 6 21 1 1 4
## 6 Hopolaughs 4 Gmen6 7 7 1 2 2
## 7 sdr2043 4 Gmen6 7 17 1 1 3
## 8 Gmen6 7 WUTANG~ 10 -1 1 2 3
## 9 bazz88 1 sdr2043 4 1 1 3 3
## 10 Hopolaughs 4 Esquis~ 6 8 1 2 3
## 11 Esquisite 6 matt49~ 8 19 1 1 3
## 12 Gmen6 7 BigBad~ 9 7 1 2 3
## 13 KorbenDalla~ 2 Hopola~ 4 -17 1 2 2
## 14 KorbenDalla~ 2 sdr2043 4 -5 1 3 3
## 15 Esquisite 6 Gmen6 7 -4 1 2 3
## 16 BigBadRon 9 WUTANG~ 10 -5 1 2 2
## # ... with 1 more variable: rank_diff <dbl>
Average points difference for wins and losses?
lads_df %>%
group_by(name, against, result) %>%
filter(!result == "drawn") %>%
summarise(points_diff = mean(points_diff)) %>%
ggplot(aes(fct_reorder(name, points_diff),
fct_reorder(against, points_diff),
fill = points_diff, label = round(points_diff))) +
geom_tile() +
shadowtext::geom_shadowtext() +
#geom_text(colour = "white") +
coord_flip() +
hrbrthemes::theme_ipsum() +
ggtitle("Ave Points Diff per Match Up by result") +
theme(legend.position = "none") +
theme(axis.text.x = element_text(size = 10, angle = 40, hjust = 1),
axis.text.y = element_text(size = 10)) +
scale_fill_viridis_c(option = "magma") +
theme(axis.title.x = element_blank(), axis.title.y = element_blank()) +
facet_wrap(~result)