forked from JKRWard/MMM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
174 lines (123 loc) · 4.45 KB
/
README.Rmd
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
---
title: "March Mammal Madness"
author: "Jessica Ward"
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```
Repository containing our MMM2018 bracket entries.
Who will win? Will Kirsty retain her title as queen of the mammals??
Leaderboard
===========
```{r include=FALSE}
# I'm lazy so I use the librarian package when loading my packages
# note that using this package will install packages if they are not already
# contained within your library
librarian::shelf(tidyverse, here, plotly)
################################################################################
####################### MMM_2018 scoring #######################################
################################################################################
# create a list of all csv files in the folder for this year
fils <- list.files (path = "2018MMM", pattern="*.csv")
# create a list in which to store entries
fl <- list()
#loop through files and add to the list
#using here means that I can easily read files in a subdirectory
for (k in 1:length(fils)){
fl[[k]] <- read_csv(here("2018MMM",fils[k]))
}
# format the data creating a single vector with all answers from each player
ans <- list()
for(j in 1:length(fl)){
mast <- fl[[j]]
wild <- mast %>% select(Wildcard) %>%filter(!is.na(Wildcard))
a <- select(mast, Round_1:Round_5)
b <- select(mast, Round_5_1:Round_1_1) %>% rename(Round_1 = Round_1_1 ,Round_2 =
Round_2_1, Round_3 = Round_3_1, Round_4 = Round_4_1,
Round_5 = Round_5_1 )
cc <- bind_rows(a,b)
r1 <- cc %>% select(Round_1) %>% filter(!is.na(Round_1))
r1 <- r1$Round_1
r2 <- cc %>% select(Round_2) %>% filter(!is.na(Round_2))
r2 <- r2$Round_2
r3 <- cc %>% select(Round_3) %>% filter(!is.na(Round_3))
r3 <- r3$Round_3
r4 <- cc %>% select(Round_4) %>% filter(!is.na(Round_4))
r4 <- r4$Round_4
r5 <- cc %>% select(Round_5) %>% filter(!is.na(Round_5))
r5 <- r5$Round_5
wild <- wild$Wildcard
fin <- mast %>% select(Final) %>% filter(!is.na(Final))
fin <- fin$Final
out <- c(wild,r1,r2,r3,r4,r5,fin)
# store the vector in a list
ans[[j]] <- out
}
### counting points
# 1 = same 0 = different -- ony get points for answers that are the same as the master
# check where in the list the master file is
ans
master <- ans[[9]]
# create a list of players names
players <- sub(".*_", "", fils) %>% sub(".csv", "",.)
#players <- sub(".csv", "", players)
### check answers
scorelist <- list()
for (i in 1: length(players)){
## this checks answers for each round
playa <- ans[[i]]
mstr <- ans[[9]]
rnd1 <- playa[1:33] == mstr[1:33]
rnd2 <- playa[34:49] == mstr[34:49]
sweet <- playa[50:57]==mstr[50:57]
elite <- playa[58:61]==mstr[58:61]
roar <- playa[62:63]==mstr[62:63]
win <- playa[64]==mstr[64]
pts <- c(sum(rnd1),sum(rnd2*2), sum(sweet*3), sum(elite*5), sum(roar*8),sum(win*13))
scorelist[[i]] <- pts
}
leaderboard <- as.data.frame(do.call(rbind, scorelist))
colnames(leaderboard) <- c("Round_1", "Round_2", "Sweet_16", "Elite_8", "Final_roar", "Winner")
tardy <- c(1,0,0,0,0,0,1,0,0,1,1,1,0)
leaderboard$Player_name <- players
leaderboard$Tardigrade_tally <- tardy
leaderboard <- leaderboard %>%
select(Player_name, Tardigrade_tally, Round_1, Round_2, Sweet_16, Elite_8,
Final_roar, Winner) %>%
slice( -9) %>%
mutate(Total= rowSums(.[2:8])) %>%
arrange(desc(Total))
# creating a plot with cumulative points
#create sum column for after each round
pl_dat <- leaderboard %>% mutate(r2 = Round_1+Round_2) %>% mutate(r3 = r2+Sweet_16)
pl_dat <- leaderboard %>%
mutate(r1 =rowSums(.[2:3])) %>%
mutate(r2 =rowSums(.[2:4])) %>%
mutate(r3 =rowSums(.[2:5])) %>%
mutate(r4 =rowSums(.[2:6])) %>%
mutate(r5 =rowSums(.[2:7])) %>%
rename(r6 = Total) %>%
select(Player_name, r1, r2, r3, r4, r5, r6) %>%
gather("Round", "points", 2:7)
pl_dat$Round <- gsub("r","",pl_dat$Round)
p <- ggplot(data=pl_dat, aes(x=Round, y=points, group = Player_name, colour = Player_name)) +
geom_line() +
ggtitle("Point accumulation")
#+ scale_colour_manual(values=cols)
### points per round
# wildcard - 1 1
# round 1 - 1 2:33
# round 2 - 2 34:49
# sweet 16 - 3 50:57
# elite 8 - 5 58:61
# final roar - 8 62:63
#winner -13 64
```
```{r}
knitr::kable(leaderboard)
```
```{r}
p
#plotly::ggplotly(p)
```