-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.R
122 lines (95 loc) · 4.95 KB
/
data.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
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
#Jose Fernandez
#Sample Table to Push Notes to Players
# Sep 2020
#####################################################################################
#load library
library(tidyverse)
######################################################################################
#load raw data (the raw data is not provided for this example)
game_logs <- read_feather("gamelogs.feather") %>%
filter(Season == "2019-20") %>%
mutate(Month = lubridate::month(Date), Week = lubridate::week(Date)) %>%
filter(Month == 1) %>%
filter(Team == "Los Angeles Clippers")
######################################################################################
#format table + add button column
weekLoad <- game_logs %>%
group_by(Player) %>%
mutate(Date2 = lag(Date)) %>%
mutate(dates = Date - Date2) %>%
mutate(B2B = ifelse(is.na(dates), 0, ifelse(dates == 1, 1, 0))) %>%
summarise(Games = n(),
totalMins = sum(MINS),
M.Trend = spk_chr(MINS,
type = "line",
lineColor = "deeppink",
fillColor = "transparent",
minSpotColor = "skyblue",
maxSpotColor = "orangered",
spotColor = F,
chartRangeMinX = 1,
chartRangeMinX = 60,
normalRangeMin = mean(MINS)-(sd(MINS) * 0.5),
normalRangeMax = mean(MINS)+(sd(MINS) * 0.5),
chartRangeClip = T,
tooltipChartTitle = "Minutes Played"),
M.Dist = spk_chr(MINS,
type = "box",
lineColor="deeppink",
boxFillColor = "pink",
whiskerColor = "transparent",
outlierLineColor = "white",
outlierFillColor = "white",
medianColor = "deeppink",
minValue = 1,
maxValue = 60,
showOutliers = F,
tooltipChartTitle = "Minutes Distribution"),
totalLoad = sum(Load),
L.Trend = spk_chr(Load,
type = "line",
lineColor = "deeppink",
fillColor = "transparent",
minSpotColor = "skyblue",
maxSpotColor = "orangered",
spotColor = F,
chartRangeMinX = 0,
chartRangeMinX = 100,
normalRangeMin = mean(MINS)-(sd(MINS) * 0.5),
normalRangeMax = mean(MINS)+(sd(MINS) * 0.5),
chartRangeClip = T,
tooltipChartTitle = "Game Load"),
L.Dist = spk_chr(Load,
type = "box",
lineColor="deeppink",
boxFillColor = "pink",
whiskerColor = "transparent",
outlierLineColor = "white",
outlierFillColor = "white",
medianColor = "deeppink",
minValue = 0,
maxValue = 100,
showOutliers = F,
tooltipChartTitle = "Minutes Distribution"),
B2B = sum(B2B),
Participation = mean(Participation)) %>%
select(Player, totalLoad, L.Trend, L.Dist, totalMins, M.Trend, M.Dist, Games, B2B) %>%
ungroup()
photo <- game_logs %>% distinct(Player, Photo)
table <- full_join(weekLoad, photo, by = c("Player")) %>%
na.omit() %>%
arrange(desc(totalLoad, totalMins, Games)) %>%
select(Photo, Player, totalLoad, L.Trend, L.Dist, totalMins, M.Trend, M.Dist, Games, B2B) %>%
mutate(Photo = paste('<img src =',' "', Photo,'" ', 'height="45"></img>', sep = ""))
table2 <- table %>% arrange(desc("totalLoad"))%>%
#this mutate statement creates a column of buttons that can be executed with just one modal
mutate(SMS = sapply(1:nrow(table), function(i){
sprintf("<button id='inf%d' type='button' class='btn btn-default action-button shiny-bound-input'><i class= 'glyphicon glyphicon-send'/></button>",i)
})) %>%
formattable::formattable(
list(
totalLoad = color_tile("white", "indianred"),
totalMins = color_tile("white", "indianred")
)
)
#####################################################################################