-
Notifications
You must be signed in to change notification settings - Fork 0
/
index - Copy.Rmd
792 lines (662 loc) · 24.9 KB
/
index - Copy.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
---
title: "2023 NFL Moneyline Picks"
output:
flexdashboard::flex_dashboard:
theme:
version: 4
bootswatch: spacelab
orientation: rows
vertical_layout: fill
social: ["menu"]
source_code: embed
navbar:
- { title: "Created by: Daniel Baller", icon: "fa-github", href: "https://github.com/danielpballer" }
---
```{r setup, include=FALSE}
# source_code: embed
library(flexdashboard)
library(tidyverse)
library(data.table)
library(formattable)
library(ggpubr)
library(ggrepel)
library(gt)
library(glue)
library(ggthemes)
library(hrbrthemes)
library(sparkline)
library(plotly)
library(htmlwidgets)
library(mdthemes)
library(ggtext)
library(ggnewscale)
library(DT)
source("./Functions/functions2.R")
thematic::thematic_rmd(font = "auto")
```
```{r Reading in our picks files, include=FALSE}
current_week = 6 #Set what week it is
week_1 = read_csv("./CSV_Data_Files/2023 NFL Week 1.csv")
week_2 = read_csv("./CSV_Data_Files/2023 NFL Week 2.csv")
week_3 = read_csv("./CSV_Data_Files/2023 NFL Week 3.csv")
week_4 = read_csv("./CSV_Data_Files/2023 NFL Week 4.csv")
week_5 = read_csv("./CSV_Data_Files/2023 NFL Week 5.csv")
week_6 = read_csv("./CSV_Data_Files/2023 NFL Week 6.csv")
# week_7 = read_csv("./CSV_Data_Files/2023 NFL Week 7.csv")
# week_8 = read_csv("./CSV_Data_Files/2023 NFL Week 8.csv")
# week_9 = read_csv("./CSV_Data_Files/2023 NFL Week 9.csv")
# week_10 = read_csv("./CSV_Data_Files/2023 NFL Week 10.csv")
# week_11 = read_csv("./CSV_Data_Files/2023 NFL Week 11.csv")
# week_12 = read_csv("./CSV_Data_Files/2023 NFL Week 12.csv")
# week_13 = read_csv("./CSV_Data_Files/2023 NFL Week 13.csv")
# week_14 = read_csv("./CSV_Data_Files/2023 NFL Week 14.csv")
# week_15 = read_csv("./CSV_Data_Files/2023 NFL Week 15.csv")
# week_16 = read_csv("./CSV_Data_Files/2023 NFL Week 16.csv")
# week_17 = read_csv("./CSV_Data_Files/2023 NFL Week 17.csv")
# week_18 = read_csv("./CSV_Data_Files/2023 NFL Week 18.csv")
# week_19 = read_csv("./CSV_Data_Files/2023 NFL Wild Card.csv")
# week_20 = read_csv("./CSV_Data_Files/2023 NFL Divisional Round.csv")
# week_21 = read_csv("./CSV_Data_Files/2023 NFL Conference Round.csv")
# week_22 = read_csv("./CSV_Data_Files/2023 NFL Super Bowl.csv")
#reading in scores
Scores = read_csv(glue::glue("./CSV_Data_Files/NFL_Scores_{current_week}.csv"))
#reading in CBS Prediction Records
cbs = read_csv(glue::glue("./CSV_Data_Files/CBS_Experts_{current_week}.csv")) %>%
mutate(Percent = round(Percent,4))
cbs_season = read_csv(glue::glue("./CSV_Data_Files/CBS_Experts_Season_{current_week}.csv"))
#reading in ESPN Prediction Records
espn = read_csv(glue::glue("./CSV_Data_Files/ESPN_Experts_{current_week}.csv"))%>%
mutate(Percent = round(Percent,4))
espn_season = read_csv(glue::glue("./CSV_Data_Files/ESPN_Experts_Season_{current_week}.csv"))%>%
mutate(Percent = round(Percent,4))
#Odds not working for the 2023 season. Need to fix scrape code for next year.
#Reading in the moneyline odds for each team and cleaning the team names
# odds_wk1 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_1.csv"))
# odds_wk2 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_2.csv"))
# odds_wk3 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_3.csv"))
# odds_wk4 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_4.csv"))
# odds_wk5 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_5.csv"))
# odds_wk6 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_6.csv"))
# odds_wk7 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_7.csv"))
# odds_wk8 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_8.csv"))
# odds_wk9 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_9.csv"))
# odds_wk10 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_10.csv"))
# odds_wk11 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_11.csv"))
# odds_wk12 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_12.csv"))
# odds_wk13 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_13.csv"))
# odds_wk14 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_14.csv"))
# odds_wk15 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_15.csv"))
# odds_wk16 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_16.csv"))
# odds_wk17 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_17.csv"))
# odds_wk18 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_18.csv"))
# odds_wk19 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_19.csv"))
# odds_wk20 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_20.csv"))
# odds_wk21 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_21.csv"))
# odds_wk22 = read_csv(glue::glue("./CSV_Data_Files/Moneyline_Odds_22.csv"))
####################UPDATE THESE###############################
inst.picks = list(week_1, week_2, week_3, week_4, week_5, week_6)#, week_7, week_8, week_9, week_10, week_11, week_12, week_13, week_14, week_15, week_16, week_17, week_18, week_19, week_20, week_21) #add in the additional weeks
# odds = rbind(odds_wk1, odds_wk2, odds_wk3, odds_wk4, odds_wk5, odds_wk6, odds_wk7, odds_wk8,
# odds_wk9, odds_wk10, odds_wk11, odds_wk12) #add in the additional weeks
####################END OF UPDATE##############################
weeks = as.list(seq(1:current_week)) #creating a list of each week number
```
```{r read in scores clean data, include=FALSE}
#Cleaning Odds Data
# cl_odds = odds_cleaning(odds)
#Cleaning scores data
Scores = cleaning2(Scores)
#creating a list of winners for each week
winners = map(weeks, weekly_winners)
#creating a vector of this weeks winners
this_week = pull(winners[[length(winners)]])
#Getting the number of games for each week
weekly_number_of_games = map_dbl(weeks, week_number_games)
```
```{r Group Predictions, include=FALSE}
#Creating the list of everyones predictions each week.
games = map(inst.picks, games_fn)
#Creating the prediction table.
pred_table = map(games, pred_table_fn)
#Adding who won to the predictions
with_winners = map2(pred_table, winners, adding_winners)
#Creating results for each week.
results = map2(with_winners,weekly_number_of_games, results_fn)
```
```{r Displaying Group Results, echo=FALSE}
#Displaying the group results
inst_group_table = results[[length(results)]] %>% gt() %>%
cols_align(
align = "center") %>%
tab_header(
title = md("This Week's Predictions"),
#subtitle = md(glue("Week {length(results)}"))
) %>%
tab_style(
style = cell_text(color = "red", weight = "bold"),
locations = cells_body(
columns = c(Correct),
rows = Correct =="No"
)) %>%
tab_style(
style = cell_text(color = "green", weight = "bold"),
locations = cells_body(
columns = c(Correct),
rows = Correct =="Yes"
)) %>%
tab_options(
data_row.padding = px(3),
container.height = "100%"
)
```
```{r Weekly and season Group Results, include=FALSE}
# Printing the weekly and season win percentage
#how many games correct, incorrect, and not picked each week
weekly_group_correct = map(results, weekly_group_correct_fn)
#how many games were picked each week
weekly_games_picked = map2(weekly_group_correct, weekly_number_of_games, weekly_games_picked_fn)
#Calculating the number of correct picks for each week
weekly_group_correct_picks = map(weekly_group_correct, weekly_group_correct_picks_fn)
#Calculating weekly win percentage
weekly_win_percentage = map2(weekly_group_correct_picks, weekly_games_picked, weekly_win_percentage_fn)
#Calculating season win percentage
season_win_percentage = round(sum(unlist(weekly_group_correct_picks))/sum(unlist(weekly_games_picked)),4)
#Calculating number of games picked this season
season_games = sum(unlist(weekly_games_picked))
#calculating season wins
season_wins = sum(unlist(weekly_group_correct_picks))
#calculating the number of people who picked this week
Total = dim(inst.picks[[length(weeks)]])[1]
```
```{r plotting group results, include=FALSE}
#Previous Weeks
group_season_for_plotting = unlist(weekly_win_percentage) %>% as.data.frame() %>%
rename(`Win Percentage` = ".") %>%
add_column(Week = unlist(weeks))
```
```{r Plotting the group results, echo=FALSE}
inst_group_season_plot = group_season_for_plotting %>%
ggplot(aes(x = as.factor(Week), y = `Win Percentage`))+
geom_point()+
geom_path(aes(x = Week))+
ylim(c(0, 1)) +
xlab("NFL Week") +
ylab("Correct Percentage")+
ggtitle("Weekly Group Correct Percentage")+
theme_classic()+
theme(plot.title = element_text(hjust = 0.5, size = 18))
```
```{r beating cbs week, include=FALSE}
#Creating a list of correct percentages for each week.
cbs_weekly_percent = map(weeks, cbs_percent)
#Creating a list of how many cbs experts we beat each week.
cbs_experts_beat = map2(cbs_weekly_percent, weekly_win_percentage, experts_beat)
#Creating a list of how many cbs experts picked each week.
cbs_experts_total = map(cbs_weekly_percent, experts_tot)
```
```{r beating cbs season, include=FALSE}
#Creating a list of correct percentages for each week.
cbs_season_percent = map(weeks, cbs_season_percent)
#Creating a list of how many cbs experts we beat each week.
cbs_experts_beat_season = map2(cbs_season_percent, season_win_percentage, experts_beat)
#Creating a list of how many cbs experts picked each week.
cbs_experts_season_total = map(cbs_season_percent, experts_tot)
```
```{r beating ESPN week, include=FALSE}
#Creating a list of correct percentages for each week.
espn_weekly_percent = map(weeks, espn_percent)
#Creating a list of how many cbs experts we beat each week.
espn_experts_beat = map2(espn_weekly_percent, weekly_win_percentage, experts_beat)
#Creating a list of how many cbs experts picked each week.
espn_experts_total = map(espn_weekly_percent, experts_tot)
```
```{r beating ESPN season, include=FALSE}
#Creating a list of correct percentages for each week.
espn_season_percent = map(weeks, espn_season_percent)
#Creating a list of how many cbs experts we beat each week.
espn_experts_beat_season = map2(espn_season_percent, season_win_percentage, experts_beat)
#Creating a list of how many cbs experts picked each week.
espn_experts_season_total = map(espn_season_percent, experts_tot)
```
```{r individual results, include=FALSE}
#Creating a list of individual results for each week.
weekly_indiv = pmap(list(inst.picks, winners, weeks), indiv_weekly_pred)
#Combining each week into one dataframe and calculating percentage Correct for this week.
full_season = weekly_indiv %>% reduce(full_join, by = "Name") %>%
mutate(Percent = round(pull(.[,ncol(.)]/weekly_number_of_games[[length(weekly_number_of_games)]]),4))
#Creating a dataframe with only the weekly picks
a = full_season %>% select(starts_with("Week"))
#Creating a vector of how many weeks each person picked over the season
tot_week = NULL
help = NULL
for (i in 1:dim(a)[1]){
for(j in 1:length(a)){
help[j] = ifelse(is.na(a[i,j])==T,0,1)
tot_week[i] = sum(help)
}
}
#Creating a vector of how many games each person picked over the season
tot_picks= NULL
help = NULL
for (i in 1:dim(a)[1]){
for(j in 1:length(a)){
help[j] = unlist(weekly_games_picked)[j]*ifelse(is.na(a[i,j])==T,0,1)
tot_picks[i] = sum(help)
}
}
#Creatign a vector of how many games each person picked correct over the season
tot_correct = NULL
help = NULL
for (i in 1:dim(a)[1]){
tot_correct[i] = sum(a[i,], na.rm = T)
}
#adding how many weeks each person picked, season correct percentage, and adjusted season percentag to the data frame and sorting the data
indiv_disp = full_season %>% add_column(`Weeks Picked` = tot_week) %>%
add_column(tot_correct)%>%
add_column(tot_picks)%>%
mutate(`Season Percent` = round(tot_correct/tot_picks,4))%>%
mutate(`Adj Season Percent` = round(`Season Percent`*(tot_week/length(a)),4)) %>%
select(-tot_correct, -tot_picks) %>%
arrange(desc(Percent), desc(`Season Percent`)) %>%
mutate(Percent = ifelse(is.na(Percent)==T, 0, Percent))
```
```{r individual percentages, include=FALSE}
#Calculating individual percentages for each week.
weekly_indiv_percent = map2(weekly_indiv, as.list(weekly_number_of_games), indiv_percent) %>% reduce(full_join, by = "Name")
weekly_indiv_percent_plot = weekly_indiv_percent %>%
pivot_longer(cols = starts_with("Week"), names_to = "Week", values_to = "Percent")%>%
mutate(Percent = ifelse(is.na(Percent)==T, 0, Percent)) %>%
mutate(Week = as.factor(Week))
levels = NULL
for(i in 1:length(weeks)){
levels[i] = glue("Week {i}")
}
weekly_indiv_percent_plot = weekly_indiv_percent_plot %>%
mutate(Week = factor(Week, levels))
```
```{r sparklines, include=FALSE}
#adding sparklines
plot_group = function(name, df){
plot_object =
ggplot(data = df,
aes(x = as.factor(Week), y=Percent, group = 1))+
geom_path(size = 7)+
scale_y_continuous(limits = c(0,1))+
theme_void()+
theme(legend.position = "none")
return(plot_object)
}
sparklines =
weekly_indiv_percent_plot %>%
group_by(Name) %>%
nest() %>%
mutate(plot = map2(Name, data, plot_group)) %>%
select(-data)
indiv_disp_2 = indiv_disp %>%
inner_join(sparklines, by = "Name") %>%
mutate(`Season Trend` = NA)
```
```{r Printing Individual Table2, echo=FALSE}
# Printing the individual Table
indiv_table = indiv_disp_2 %>% gt() %>%
cols_align(
align = "center") %>%
tab_header(
title = md("Individual Results"),
subtitle = md(glue("Week {length(weeks)}"))
) %>%
tab_style(
style = cell_text(color = "red", weight = "bold"),
locations = cells_body(
columns = c(Percent),
rows = Percent<.5
)) %>%
tab_style(
style = cell_text(color = "green", weight = "bold"),
locations = cells_body(
columns = c(Percent),
rows = Percent>.5
)) %>%
tab_style(
style = cell_text(color = "red", weight = "bold"),
locations = cells_body(
columns = c(`Season Percent`),
rows = `Season Percent`<.5
)) %>%
tab_style(
style = cell_text(color = "green", weight = "bold"),
locations = cells_body(
columns = c(`Season Percent`),
rows = `Season Percent`>.5
))%>%
tab_style(
style = cell_text(color = "red", weight = "bold"),
locations = cells_body(
columns = c(`Adj Season Percent`),
rows = `Adj Season Percent`<.5
)) %>%
tab_style(
style = cell_text(color = "green", weight = "bold"),
locations = cells_body(
columns = c(`Adj Season Percent`),
rows = `Adj Season Percent`>.5
)) %>%
tab_options(
container.width = pct(100),
data_row.padding = px(1),
container.height = "100%"
) %>%
tab_spanner(
label = "Weekly # Correct",
columns = starts_with(c("Week "))
) %>%
text_transform(
locations = cells_body(c(`Season Trend`)),
fn = function(x){
map(indiv_disp_2$plot, ggplot_image, height = px(30), aspect_ratio = 4)
}) %>%
cols_hide(c(plot))
indiv_winners = indiv_disp_2 %>% filter(Percent == max(Percent)) %>% select(Name) %>% pull() %>% paste(collapse = ", ")
indiv_season = indiv_disp_2 %>% filter(`Season Percent` == max(`Season Percent`)) %>% select(Name) %>% pull() %>% paste(collapse = ", ")
indiv_season_adj = indiv_disp_2 %>% filter(`Adj Season Percent` == max(`Adj Season Percent`)) %>% select(Name) %>% pull()%>% paste(collapse = ", ")
```
```{r Printing Season Leaderboard, echo=FALSE}
# Printing the Season Leaderboard
season_leaderboard = indiv_disp_2 %>% select(Name, starts_with("Week ")) %>%
pivot_longer(starts_with("Week"),names_to = "Week", values_to = "Correct") %>%
group_by(Week) %>%
mutate(Correct = case_when(is.na(Correct)==T~0,
TRUE~Correct)) %>%
mutate(Donut = case_when(Correct==max(Correct)~1,
TRUE~0)) %>%
ungroup() %>%
group_by(Name) %>%
summarise(`Donuts Won` = sum(Donut)) %>%
#mutate(`Donuts Won` = strrep("award,", Donuts)) %>%
right_join(.,indiv_disp_2) %>%
select(-starts_with("Week "), -Percent) %>%
mutate(`Season Rank` = min_rank(desc(`Season Percent`)),.before = Name) %>%
arrange(`Season Rank`) %>%
gt() %>%
cols_align(
align = "center") %>%
tab_header(
title = md("Season Leaderboard (Season Percent)"),
subtitle = md(glue("Week {length(weeks)}"))
) %>%
# fmt_icon(
# columns = `Donuts Won`,
# fill_color = "gold",
# ) %>%
tab_style(
style = cell_text(color = "red", weight = "bold"),
locations = cells_body(
columns = c(`Season Percent`),
rows = `Season Percent`<.5
)) %>%
tab_style(
style = cell_text(color = "green", weight = "bold"),
locations = cells_body(
columns = c(`Season Percent`),
rows = `Season Percent`>.5
))%>%
tab_style(
style = cell_text(color = "red", weight = "bold"),
locations = cells_body(
columns = c(`Adj Season Percent`),
rows = `Adj Season Percent`<.5
)) %>%
tab_style(
style = cell_text(color = "green", weight = "bold"),
locations = cells_body(
columns = c(`Adj Season Percent`),
rows = `Adj Season Percent`>.5
)) %>%
tab_options(
container.width = pct(100),
data_row.padding = px(1),
container.height = "100%"
) %>%
tab_spanner(
label = "Weekly # Correct",
columns = starts_with(c("Week "))
) %>%
text_transform(
locations = cells_body(c(`Season Trend`)),
fn = function(x){
map(indiv_disp_2$plot, ggplot_image, height = px(30), aspect_ratio = 4)
}) %>%
cols_hide(columns = c(plot))
```
```{r Printing Adj Season Leaderboard, echo=FALSE}
# Printing the Adj Season Leaderboard
adj_season_leaderboard = indiv_disp_2 %>% select(Name, starts_with("Week ")) %>%
pivot_longer(starts_with("Week"),names_to = "Week", values_to = "Correct") %>%
group_by(Week) %>%
mutate(Correct = case_when(is.na(Correct)==T~0,
TRUE~Correct)) %>%
mutate(Donut = case_when(Correct==max(Correct)~1,
TRUE~0)) %>%
ungroup() %>%
group_by(Name) %>%
summarise(`Donuts Won` = sum(Donut)) %>%
#mutate(`Donuts Won` = strrep("award,", Donuts)) %>%
right_join(.,indiv_disp_2) %>%
select(-starts_with("Week "), -Percent) %>%
mutate(`Season Rank` = min_rank(desc(`Adj Season Percent`)),.before = Name) %>%
arrange(`Season Rank`) %>%
gt() %>%
cols_align(
align = "center") %>%
tab_header(
title = md("Season Leaderboard (Adjusted Season Percent)"),
subtitle = md(glue("Week {length(weeks)}"))
) %>%
# fmt_icon(
# columns = `Donuts Won`,
# fill_color = "gold",
# ) %>%
tab_style(
style = cell_text(color = "red", weight = "bold"),
locations = cells_body(
columns = c(`Season Percent`),
rows = `Season Percent`<.5
)) %>%
tab_style(
style = cell_text(color = "green", weight = "bold"),
locations = cells_body(
columns = c(`Season Percent`),
rows = `Season Percent`>.5
))%>%
tab_style(
style = cell_text(color = "red", weight = "bold"),
locations = cells_body(
columns = c(`Adj Season Percent`),
rows = `Adj Season Percent`<.5
)) %>%
tab_style(
style = cell_text(color = "green", weight = "bold"),
locations = cells_body(
columns = c(`Adj Season Percent`),
rows = `Adj Season Percent`>.5
)) %>%
tab_options(
container.width = pct(100),
data_row.padding = px(1),
container.height = "100%"
) %>%
tab_spanner(
label = "Weekly # Correct",
columns = starts_with(c("Week "))
) %>%
text_transform(
locations = cells_body(c(`Season Trend`)),
fn = function(x){
map(indiv_disp_2$plot, ggplot_image, height = px(30), aspect_ratio = 4)
}) %>%
cols_hide(columns = c(plot))
```
```{r instructor formattable, echo=FALSE}
improvement_formatter <-
formatter("span",
style = x ~ formattable::style(
font.weight = "bold",
color = ifelse(x > .5, "green", ifelse(x < .5, "red", "black"))),
x ~ icontext(ifelse(x == max(x), "star", ""), x))
indiv_disp_3 = indiv_disp_2 %>% select(-plot)
indiv_disp_3$`Season Trend` = apply(indiv_disp_3[,2:(1+length(weeks))], 1, FUN = function(x) as.character(htmltools::as.tags(sparkline(as.numeric(x), type = "line", chartRangeMin = 0, chartRangeMax = 1, fillColor = "white"))))
indiv_table_2 = as.htmlwidget(formattable(indiv_disp_3,
align = c("l", rep("c", NROW(indiv_disp_3)-1)),
list(`Season Percent` = color_bar("#FA614B"),
`Season Percent`= improvement_formatter,
`Adj Season Percent`= improvement_formatter)))
indiv_table_2$dependencies = c(indiv_table_2$dependencies, htmlwidgets:::widget_dependencies("sparkline", "sparkline"))
```
```{r Plotting individual results over the season2, echo=FALSE, out.width = "100%"}
#Creating the individual plot.
inst_indiv_plots = weekly_indiv_percent_plot %>%
ggplot(aes(x = factor(Week), y = Percent, color = Name))+
geom_point()+
geom_path(aes(x = as.factor(Week), y = Percent, color = Name,
group = Name))+
ylim(c(0, 1)) +
labs(x = "NFL Week",
y = "Correct Percentage",
title = "Weekly Individual Correct Percentage")+
facet_wrap(~Name)+
theme_classic()+
theme(legend.position = "none",
plot.title = element_text(hjust = 0.5, size = 18),
axis.text.x=element_text(angle =45, vjust = 1, hjust = 1))
```
```{r data for data page}
inst.data = map2(inst.picks, weeks, disp_data) %>% bind_rows()
```
```{r fivethirtyeight}
inst_538 = map(results, five38) %>% unlist() %>% sum()
```
```{r pregame, eval=FALSE, include=FALSE}
#Predictions for the week
#Creating the list of group predictions each week.
games = map(inst.picks, games_fn)
#Creating the prediction table.
pred_table = map(games, pred_table_fn)
#Printing table of instructor predictions
pred_table[[length(pred_table)]] %>% mutate(Game = row_number()) %>%
rename(`Votes For` = votes_for, `Votes Against` = votes_against) %>%
gt() %>%
cols_align(
align = "center") %>%
tab_header(
title = md("This Week's Predictions"),
subtitle = md(glue("Week {length(weeks)}"))
) %>%
tab_options(
data_row.padding = px(3)
)
```
Group Predictions
==========================================================================
Sidebar {.sidebar}
-------------------------------------
#### CBS Sports
<font size="4">
This week we beat or tied `r cbs_experts_beat[[length(weeks)]]` of `r cbs_experts_total[[length(weeks)]]` CBS Sports' Experts.
For the season we are currently beating or tied with `r cbs_experts_beat_season[[length(weeks)]]` of `r cbs_experts_season_total[[length(weeks)]]` CBS Sports' Experts.
</font>
#### ESPN
<font size="4">
We also beat or tied `r espn_experts_beat[[length(weeks)]]` of `r espn_experts_total[[length(weeks)]]` ESPN Experts.
For the season we are currently beating or tied with `r espn_experts_beat_season[[length(weeks)]]` of `r espn_experts_season_total[[length(weeks)]]` ESPN Experts.
</font>
Row
--------------------------------------
### Win percentage for the week
```{r}
inst_rate <- weekly_win_percentage[[length(weekly_win_percentage)]]*100
gauge(inst_rate, min = 0, max = 100, symbol = '%', gaugeSectors(
success = c(55, 100), warning = c(40, 54), danger = c(0, 39)
))
```
### Season Win Percentage
```{r}
inst_season <- season_win_percentage*100
gauge(inst_season, min = 0, max = 100, symbol = '%', gaugeSectors(
success = c(55, 100), warning = c(40, 54), danger = c(0, 39)
))
```
### Games Correct
```{r}
valueBox(value = season_wins,icon = "fa-trophy",caption = "Correct Games this Season")
```
### Games Picked
```{r}
valueBox(value = season_games,icon = "fa-clipboard-list",caption = "Games Picked this Season")
```
### Number of predictions
```{r}
valueBox(value = Total,icon = "fa-users",caption = "Predictions this week")
```
Row
--------------------------------------
###
```{r}
inst_group_table
```
###
```{r}
ggplotly(inst_group_season_plot) %>%
layout(title = list(y = .93, xref = "plot"),
margin = list(t = 40))
```
Individual Predictions
==========================================================================
Sidebar {.sidebar}
-------------------------------------
#### Best Picks of the Week.
<font size="4">
`r indiv_winners`
</font>
#### Best Season Correct Percentage
<font size="4">
`r indiv_season`
</font>
#### Best Adjusted Season Correct Percentage
<font size="4">
`r indiv_season_adj`
* Adjusted season percentage accounts for the number of weeks picked.
</font>
row {.tabset}
--------------------------------------
### Individual Table
```{r}
indiv_table
```
<!--
### Individual Table2
```{r, out.height="100%"}
indiv_table_2
```
-->
### Individual Plots
```{r, out.width="100%"}
ggplotly(inst_indiv_plots)
```
### Season Leaderboard
```{r, out.width="100%"}
season_leaderboard
```
### Adjusted Season Leaderboard
```{r, out.width="100%"}
adj_season_leaderboard
```
Data
==========================================================================
```{r}
datatable(
inst.data, extensions = 'Buttons', options = list(
dom = 'Blfrtip',
buttons = c('copy', 'csv', 'excel', 'pdf', 'print'),
lengthMenue = list( c(10, 25, 50, 100, -1), c(10, 25, 50, 100, "All") )
)
)
```