-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
512 lines (512 loc) · 22.8 KB
/
.Rhistory
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
"Quarter 4 [15:00-10:00]",
"Quarter 4 [10:00-5:00]",
"Quarter 4 [5:00-End]",
"Overtime") -> game_clock_chunked
# Pull in png pixel sizes
df_team_info$Logo_Path_Height <- 0
df_team_info$Logo_Path_Width <- 0
df_team_info$Shadow_Logo_Path_Height <- 0
df_team_info$Shadow_Logo_Path_Width <- 0
df_team_info$Wordmark_Path_Height <- 0
df_team_info$Wordmark_Path_Width <- 0
for(i in 1:nrow(df_team_info)) {
png_dim <- dim(readPNG(paste("www/", df_team_info$Logo_Path[i], sep = "")))
df_team_info$Logo_Path_Height[i] <- png_dim[1]
df_team_info$Logo_Path_Width[i] <- png_dim[2]
png_dim <- dim(readPNG(paste("www/", df_team_info$Shadow_Logo_Path[i], sep = "")))
df_team_info$Shadow_Logo_Path_Height[i] <- png_dim[1]
df_team_info$Shadow_Logo_Path_Width[i] <- png_dim[2]
png_dim <- dim(readPNG(paste("www/", df_team_info$Wordmark_Path[i], sep = "")))
df_team_info$Wordmark_Path_Height[i] <- png_dim[1]
df_team_info$Wordmark_Path_Width[i] <- png_dim[2]
}
View(df_team_info)
View(df_team_info)
df_team_info <- read.csv("Team_Info.csv", header = T, stringsAsFactors = F)
View(df_team_info)
shiny::runApp()
library(rsconnect)
library(tidyverse)
# Update Master Files
file.copy(from = "/Users/robweber/Documents/Professional/First Line/World Lacrosse/Master File Backup/MLAX_Worlds_Master_File.csv",
to = "/Users/robweber/Documents/Professional/First Line/World Lacrosse/MLAX_Germany_Reporting_Dashboard_1/", overwrite = TRUE)
file.copy(from = "/Users/robweber/Documents/Professional/First Line/World Lacrosse/Master File Backup/WLAX_Worlds_Master_File.csv",
to = "/Users/robweber/Documents/Professional/First Line/World Lacrosse/WLAX_Germany_Reporting_Dashboard_1/", overwrite = TRUE)
runApp()
deployApp("/Users/robweber/Documents/Professional/First Line/World Lacrosse/WLAX_Germany_Reporting_Dashboard_1",
appName = "WLAX_Germany_Reporting_Dashboard_1", account = "robertweber98", forceUpdate = TRUE)
library(rsconnect)
library(tidyverse)
# Update Master Files
file.copy(from = "/Users/robweber/Documents/Professional/First Line/World Lacrosse/Master File Backup/MLAX_Worlds_Master_File.csv",
to = "/Users/robweber/Documents/Professional/First Line/World Lacrosse/MLAX_Germany_Reporting_Dashboard_1/", overwrite = TRUE)
file.copy(from = "/Users/robweber/Documents/Professional/First Line/World Lacrosse/Master File Backup/WLAX_Worlds_Master_File.csv",
to = "/Users/robweber/Documents/Professional/First Line/World Lacrosse/WLAX_Germany_Reporting_Dashboard_1/", overwrite = TRUE)
# Deploying
runApp()
runApp()
deployApp("/Users/robweber/Documents/Professional/First Line/World Lacrosse/WLAX_Germany_Reporting_Dashboard_1",
appName = "WLAX_Germany_Reporting_Dashboard_1", account = "robertweber98", forceUpdate = TRUE)
##################### 2024 Germany Women's Dashboard #####################
############## Setup ##############
#### Librarying ####
library(shiny) # base
library(tidyverse) # data manipulation, etc
library(shinydashboard) # aesthetics
library(shinyWidgets) # fancy boxes and inputs
library(shinycssloaders) # loading spinners
library(plotly) # viz
library(png) # reading png files
library(scales) # for "percent" function
library(lubridate) # to treat game dates correctly
library(DT) #datatable controls
library(leaflet) # munual continuous color scales
#### Options ####
options(warn=-1)
options(dplyr.summarise.inform = FALSE)
#### Reading in External Data/Info ####
df_master <- read.csv("WLAX_Worlds_Master_File.csv", header = T, stringsAsFactors = F)
df_team_info <- read.csv("Team_Info.csv", header = T, stringsAsFactors = F)
goal_marker_coords <- read.csv("Lacrosse-Goal-2_MarkerCoords.csv", header = T, stringsAsFactors = F)
field_marker_coords <- read.csv("Lacrosse-Field-2_Grid_MarkerCoords.csv", header = T, stringsAsFactors = F)
#### Plot Pictures ####
goal_base <- "www/Lacrosse-Goal-2.png"
field_base <- "www/Lacrosse-Field-2.png"
field_grid <- "www/Lacrosse-Field-2_Grid.png"
field_transparent <- "www/Lacrosse-Field-2_Transparent.png"
shot_angle <- "www/Release Point for Tracking_6zones.png"
#### Parameters ####
# Report team
report_team_row <- which(df_team_info$Team == "Germany")
# Game list
df_master$Game <- paste(df_master$Game_Date, ": ", df_master$Home_Team, " vs. ", df_master$Away_Team, sep = "")
game_list <- df_master %>%
group_by(Game_Date, Game) %>%
count() %>%
ungroup() %>%
select(-n) %>%
mutate(Game_Date = as.Date(Game_Date, "%m/%d/%Y")) %>%
arrange(desc(Game_Date), Game)
game_list <- game_list$Game
# Starting Game Row
starting_game_row <- 1
# dates data frame object for server
df_dates <- df_master %>%
group_by(Game_Date, Game, Home_Team, Away_Team) %>%
count() %>%
ungroup() %>%
select(-n)
# Goalie List
all_goalies <- unique(c(df_master$Home_Goalie_Name, df_master$Away_Goalie_Name))
# Field Location Bin df
fieldloc_bins <- data.frame("Bin" = c("Back Right", "Back Left", "Right Back", "Left Back",
"1", "2", "3",
"4", "5", "6",
"7", "8", "9",
"Right Front", "Left Front", "Crease Right", "Crease Left",
"Behind the Net", "Right Under", "Left Under"),
"x_max" = c(0.729, 0.729, 0.845, 0.845,
0.788, 0.788, 0.788,
0.845, 0.845, 0.845,
0.902, 0.902, 0.902,
0.99, 0.99, 0.99, 0.99,
2, 2, 2),
"x_min" = c(-1, -1, 0.729, 0.729,
0.729, 0.729, 0.729,
0.788, 0.788, 0.788,
0.845, 0.845, 0.845,
0.845, 0.845, 0.902, 0.902,
0.99, 0.99, 0.99),
"y_max" = c(2, 0.49, 2, 0.15,
0.372, 0.6181, 0.8505,
0.372, 0.6181, 0.8505,
0.372, 0.6181, 0.8505,
2, 0.15, 0.8505, 0.49,
0.696, 2, 0.299),
"y_min" = c(0.49, -1, 0.8505, -1,
0.15, 0.372, 0.6181,
0.15, 0.372, 0.6181,
0.15, 0.372, 0.6181,
0.8505, -1, 0.49, 0.15,
0.299, 0.696, -1),
stringsAsFactors = F)
# Shot On, Off, and Post lists
shot_on <- c("5-Hole", "Left Leg", "Left Shoulder", "Under Left Arm", "Right Leg", "Right Shoulder", "Under Right Arm")
shot_off <- c("Left Miss", "Right Miss", "Top Miss")
shot_post <- c("Crossbar", "Left Post", "Right Post")
# General shooting percentages
gen_shoot_per <- length(which(df_master$Event_Type == "Shot" & (df_master$Result == "Goal" | df_master$Result == "Miss")))
gen_shoot_per <- length(which(df_master$Event_Type == "Shot" & df_master$Result == "Goal")) / gen_shoot_per
shoton_shoot_per <- length(which(df_master$Event_Type == "Shot" & df_master$Net_Location %in% shot_on))
shoton_shoot_per <- length(which(df_master$Result == "Goal")) / shoton_shoot_per
# Need to add some image sourcing objects to the team info df
df_team_info$HTML <- "none"
for(i in 1:nrow(df_team_info)) {
df_team_info$HTML[i] <- sprintf(paste("<img src = '", df_team_info$Logo_Path[i],
"' width = 30px><div class = 'jhr'>%s</div></img>", sep = ""),
df_team_info$Full_Name[i])
}
# Field bin Dataframe
field_df.b <- data.frame("Field_Location_Bin" = c("Back Right", "Back Left", "Right Back", "Left Back",
"1", "2", "3", "4", "5", "6", "7", "8", "9",
"Right Front", "Left Front", "Crease Right", "Crease Left",
"Behind the Net", "Right Under", "Left Under"),
stringsAsFactors = F)
# Shot Location Dataframe
goal_info.b <- data.frame("Net_Location" = rep(c("5-Hole", "Chest", "Crossbar", "Empty Net",
"Left Leg", "Left Miss", "Left Shoulder", "Left Post", "Under Left Arm",
"Right Leg", "Right Miss", "Right Shoulder", "Right Post", "Under Right Arm",
"Top Miss")),
stringsAsFactors = F)
# Shot Angle bin Dataframe
shotangle_info.b <- data.frame("Shot_Angle_Bin" = c("Dive/Other", "LowRight", "MidRight", "HighRight", "HighLeft", "MidLeft", "LowLeft"),
stringsAsFactors = F)
shot_angle_coords <- data.frame("Shot_Angle_Bin" = c("Dive/Other", "LowRight", "MidRight", "HighRight", "HighLeft", "MidLeft", "LowLeft"),
"Dot_Loc_x" = c(0.227, 0.74, 0.975, 0.74, 0.26, 0.025, 0.26),
"Dot_Loc_y" = c(0.435, 0.11, 0.50, 0.89, 0.89, 0.50, 0.11),
stringsAsFactors = F)
# Game Clock Chunked Ranges
c("Quarter 1 [15:00-10:00]",
"Quarter 1 [10:00-5:00]",
"Quarter 1 [5:00-End]",
"Quarter 2 [15:00-10:00]",
"Quarter 2 [10:00-5:00]",
"Quarter 2 [5:00-End]",
"Quarter 3 [15:00-10:00]",
"Quarter 3 [10:00-5:00]",
"Quarter 3 [5:00-End]",
"Quarter 4 [15:00-10:00]",
"Quarter 4 [10:00-5:00]",
"Quarter 4 [5:00-End]",
"Overtime") -> game_clock_chunked
# Pull in png pixel sizes
df_team_info$Logo_Path_Height <- 0
df_team_info$Logo_Path_Width <- 0
df_team_info$Shadow_Logo_Path_Height <- 0
df_team_info$Shadow_Logo_Path_Width <- 0
df_team_info$Wordmark_Path_Height <- 0
df_team_info$Wordmark_Path_Width <- 0
for(i in 1:nrow(df_team_info)) {
png_dim <- dim(readPNG(paste("www/", df_team_info$Logo_Path[i], sep = "")))
df_team_info$Logo_Path_Height[i] <- png_dim[1]
df_team_info$Logo_Path_Width[i] <- png_dim[2]
png_dim <- dim(readPNG(paste("www/", df_team_info$Shadow_Logo_Path[i], sep = "")))
df_team_info$Shadow_Logo_Path_Height[i] <- png_dim[1]
df_team_info$Shadow_Logo_Path_Width[i] <- png_dim[2]
png_dim <- dim(readPNG(paste("www/", df_team_info$Wordmark_Path[i], sep = "")))
df_team_info$Wordmark_Path_Height[i] <- png_dim[1]
df_team_info$Wordmark_Path_Width[i] <- png_dim[2]
}
runApp()
df_player <- df_master
df1 <- df_player %>%
filter(!is.na(Player1_Name)) %>%
group_by(Team, Player1, Player1_Name) %>%
summarise("Max_Date" = max(mdy(Game_Date))) %>%
ungroup() %>%
rename("Player_Num" = Player1,
"Player_Name" = Player1_Name)
df2 <- df_player %>%
filter(!is.na(Primary_Assist_Name)) %>%
group_by(Team, Primary_Assist, Primary_Assist_Name) %>%
summarise("Max_Date" = max(mdy(Game_Date))) %>%
ungroup() %>%
rename("Player_Num" = Primary_Assist,
"Player_Name" = Primary_Assist_Name)
df3 <- df_player %>%
filter(!is.na(Secondary_Assist_Name)) %>%
group_by(Team, Secondary_Assist, Secondary_Assist_Name) %>%
summarise("Max_Date" = max(mdy(Game_Date))) %>%
ungroup() %>%
rename("Player_Num" = Secondary_Assist,
"Player_Name" = Secondary_Assist_Name)
df4 <- df_player %>%
filter(!is.na(Rebound_Name) & Rebound_Type == "Offensive") %>%
group_by(Team, Rebound, Rebound_Name) %>%
summarise("Max_Date" = max(mdy(Game_Date))) %>%
ungroup() %>%
rename("Player_Num" = Rebound,
"Player_Name" = Rebound_Name)
df5 <- df_player %>%
filter(!is.na(Rebound_Name) & Rebound_Type == "Defensive") %>%
mutate(Defensive_Team = ifelse(Team == Home_Team, Away_Team, Home_Team)) %>%
group_by(Defensive_Team, Rebound, Rebound_Name) %>%
summarise("Max_Date" = max(mdy(Game_Date))) %>%
ungroup() %>%
rename("Player_Num" = Rebound,
"Player_Name" = Rebound_Name,
"Team" = Defensive_Team)
df6 <- df_player %>%
filter(!is.na(FO_Home_Name)) %>%
group_by(Home_Team, FO_Home, FO_Home_Name) %>%
summarise("Max_Date" = max(mdy(Game_Date))) %>%
ungroup() %>%
rename("Player_Num" = FO_Home,
"Player_Name" = FO_Home_Name,
"Team" = Home_Team)
df7 <- df_player %>%
filter(!is.na(FO_Away_Name)) %>%
group_by(Away_Team, FO_Away, FO_Away_Name) %>%
summarise("Max_Date" = max(mdy(Game_Date))) %>%
ungroup() %>%
rename("Player_Num" = FO_Away,
"Player_Name" = FO_Away_Name,
"Team" = Away_Team)
df8 <- df_player %>%
filter(!is.na(Home_Goalie_Name)) %>%
group_by(Home_Team, Home_Goalie, Home_Goalie_Name) %>%
summarise("Max_Date" = max(mdy(Game_Date))) %>%
ungroup() %>%
rename("Player_Num" = Home_Goalie,
"Player_Name" = Home_Goalie_Name,
"Team" = Home_Team)
df9 <- df_player %>%
filter(!is.na(Away_Goalie_Name)) %>%
group_by(Away_Team, Away_Goalie, Away_Goalie_Name) %>%
summarise("Max_Date" = max(mdy(Game_Date))) %>%
ungroup() %>%
rename("Player_Num" = Away_Goalie,
"Player_Name" = Away_Goalie_Name,
"Team" = Away_Team)
df_player2 <- rbind(df1, df2, df3, df4, df5, df6, df7, df8, df9)
df_player2 <- left_join(df_player2, df_team_info %>% select(Team, Team_Type), by = "Team")
df_player2 <- df_player2 %>%
mutate(Max_Date = ifelse(Team_Type == "Club", ymd("1900-01-01"), Max_Date)) %>%
mutate(Max_Date = as_date(Max_Date))
df_player2 <- df_player2 %>%
group_by(Player_Name) %>%
mutate(Player_Max_Date = max(as_date(Max_Date)))
df_player2 <- df_player2 %>%
group_by(Player_Name) %>%
summarise(Team = max(Team[which(Max_Date == Player_Max_Date)]),
Player_Num = max(Player_Num[which(Max_Date == Player_Max_Date)]))
df_player2 <- df_player2 %>%
ungroup() %>%
rowwise() %>%
mutate(LastName = str_split_fixed(Player_Name, ". ", 2)[2]) %>%
ungroup() %>%
arrange(Team, LastName)
df_player2 <- df_player2 %>%
filter(Team == "England")
View(df_player2)
df_mf <- df_master %>%
filter(Event_Type == "Shot" & (Player1_Name == "L. Catton" | Primary_Assist_Name == "L. Catton" | Secondary_Assist_Name == "L. Catton")) %>%
mutate(Home_Team = ifelse(Home_Team == Team, df_player2$Team[df_player2$Player_Name == "L. Catton"], "Opponent"),
Away_Team = ifelse(Away_Team == Team, df_player2$Team[df_player2$Player_Name == "L. Catton"], "Opponent")) %>%
mutate(Team = df_player2$Team[df_player2$Player_Name == "L. Catton"])
# need to go game by game and figure out which side of the floor each side started on and played the 3rd quarter on to figure out coord switching
df_mf_sides <- df_mf %>%
filter(Quarter %in% c(1, 3) & !is.na(Team)) %>%
group_by(Game, Team) %>%
summarise(Field_Side = ifelse(length(which(Location1_x < 0.5)) > length(which(Location1_x > 0.5)), "West", "East"))
View(df_mf_sides)
# normalize the event locations so that they're always with respect to the same side of the field for either team
# the goal is to get it so that side1 is on the east side of the field and side2 is on the west side of the field
for(i in unique(df_mf$Game)) {
for(j in which(df_mf$Game == i)[which(!is.na(df_mf$Team[which(df_mf$Game == i)]))]) {
if((df_mf$Team[j] == df_player2$Team[df_player2$Player_Name == "L. Catton"]) &
(df_mf_sides$Field_Side[df_mf_sides$Game == i & df_mf_sides$Team == df_player2$Team[df_player2$Player_Name == "L. Catton"]] == "East")) {
if(df_mf$Quarter[j] == 2) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
} else {
if(df_mf$Quarter[j] == 4) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
}
}
} else {
if((df_mf$Team[j] == df_player2$Team[df_player2$Player_Name == "L. Catton"]) &
(df_mf_sides$Field_Side[df_mf_sides$Game == i & df_mf_sides$Team == df_player2$Team[df_player2$Player_Name == "L. Catton"]] == "West")) {
if(df_mf$Quarter[j] == 1) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
} else {
if(df_mf$Quarter[j] == 3) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
} else {
if(df_mf$Quarter[j] == 5) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
}
}
}
} else {
if((df_mf$Team[j] != df_player2$Team[df_player2$Player_Name == "L. Catton"]) &
(df_mf_sides$Field_Side[df_mf_sides$Game == i & df_mf_sides$Team != df_player2$Team[df_player2$Player_Name == "L. Catton"]] == "East")) {
if(df_mf$Quarter[j] == 1) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
} else {
if(df_mf$Quarter[j] == 3) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
} else {
if(df_mf$Quarter[j] == 5) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
}
}
}
} else {
if(df_mf$Quarter[j] == 2) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
} else {
if(df_mf$Quarter[j] == 4) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
}
}
}
}
}
}
}
df_mf$Team[j] == df_player2$Team[df_player2$Player_Name == "L. Catton"]
df_mf_sides$Field_Side[df_mf_sides$Game == i & df_mf_sides$Team == df_player2$Team[df_player2$Player_Name == "L. Catton"]] == "East"
View(df_mf_sides)
View(df_mf_sides)
View(df_mf)
df_mf_sides <- df_mf %>%
filter(Quarter %in% c(1, 3) & !is.na(Team))
unique(df_mf$Game)
# need to go game by game and figure out which side of the floor each side started on and played the 3rd quarter on to figure out coord switching
df_mf_sides <- df_mf %>%
filter(Quarter %in% c(1, 3) & !is.na(Team)) %>%
group_by(Game, Team) %>%
summarise(Field_Side = ifelse(length(which(Location1_x < 0.5)) > length(which(Location1_x > 0.5)), "West", "East"))
# need to go game by game and figure out which side of the floor each side started on and played the 3rd quarter on to figure out coord switching
df_mf_sides <- df_mf %>%
filter(!is.na(Team)) %>%
group_by(Game, Team) %>%
summarise(Field_Side = ifelse((length(which(Location1_x < 0.5)) > length(which(Location1_x > 0.5)) & (Quarter %in% c(1, 3))), "West", "East"))
# need to go game by game and figure out which side of the floor each side started on and played the 3rd quarter on to figure out coord switching
df_mf_sides <- df_mf %>%
filter(!is.na(Team)) %>%
group_by(Game, Team) %>%
summarise(Field_Side = ifelse(length(which(Location1_x[Quarter %in% c(1, 3)] < 0.5)) > length(which(Location1_x[Quarter %in% c(1, 3)] > 0.5)), "West", "East"))
# normalize the event locations so that they're always with respect to the same side of the field for either team
# the goal is to get it so that side1 is on the east side of the field and side2 is on the west side of the field
for(i in unique(df_mf$Game)) {
for(j in which(df_mf$Game == i)[which(!is.na(df_mf$Team[which(df_mf$Game == i)]))]) {
if((df_mf$Team[j] == df_player2$Team[df_player2$Player_Name == "L. Catton"]) &
(df_mf_sides$Field_Side[df_mf_sides$Game == i & df_mf_sides$Team == df_player2$Team[df_player2$Player_Name == "L. Catton"]] == "East")) {
if(df_mf$Quarter[j] == 2) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
} else {
if(df_mf$Quarter[j] == 4) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
}
}
} else {
if((df_mf$Team[j] == df_player2$Team[df_player2$Player_Name == "L. Catton"]) &
(df_mf_sides$Field_Side[df_mf_sides$Game == i & df_mf_sides$Team == df_player2$Team[df_player2$Player_Name == "L. Catton"]] == "West")) {
if(df_mf$Quarter[j] == 1) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
} else {
if(df_mf$Quarter[j] == 3) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
} else {
if(df_mf$Quarter[j] == 5) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
}
}
}
} else {
if((df_mf$Team[j] != df_player2$Team[df_player2$Player_Name == "L. Catton"]) &
(df_mf_sides$Field_Side[df_mf_sides$Game == i & df_mf_sides$Team != df_player2$Team[df_player2$Player_Name == "L. Catton"]] == "East")) {
if(df_mf$Quarter[j] == 1) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
} else {
if(df_mf$Quarter[j] == 3) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
} else {
if(df_mf$Quarter[j] == 5) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
}
}
}
} else {
if(df_mf$Quarter[j] == 2) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
} else {
if(df_mf$Quarter[j] == 4) {
df_mf$Location1_x[j] <- 0.5 + -1*(df_mf$Location1_x[j] - 0.5)
df_mf$Location1_y[j] <- 0.5 + -1*(df_mf$Location1_y[j] - 0.5)
df_mf$Location2_x[j] <- 0.5 + -1*(df_mf$Location2_x[j] - 0.5)
df_mf$Location2_y[j] <- 0.5 + -1*(df_mf$Location2_y[j] - 0.5)
}
}
}
}
}
}
}
runApp()
library(rsconnect)
library(tidyverse)
# Update Master Files
file.copy(from = "/Users/robweber/Documents/Professional/First Line/World Lacrosse/Master File Backup/MLAX_Worlds_Master_File.csv",
to = "/Users/robweber/Documents/Professional/First Line/World Lacrosse/MLAX_Germany_Reporting_Dashboard_1/", overwrite = TRUE)
file.copy(from = "/Users/robweber/Documents/Professional/First Line/World Lacrosse/Master File Backup/WLAX_Worlds_Master_File.csv",
to = "/Users/robweber/Documents/Professional/First Line/World Lacrosse/WLAX_Germany_Reporting_Dashboard_1/", overwrite = TRUE)
deployApp("/Users/robweber/Documents/Professional/First Line/World Lacrosse/WLAX_Germany_Reporting_Dashboard_1",
appName = "WLAX_Germany_Reporting_Dashboard_1", account = "robertweber98", forceUpdate = TRUE)
shiny::runApp()
runApp()
runApp()
library(rsconnect)
library(tidyverse)
deployApp("/Users/robweber/Documents/Professional/First Line/World Lacrosse/MLAX_Germany_Reporting_Dashboard_1",
appName = "MLAX_Germany_Reporting_Dashboard_1", account = "robertweber98", forceUpdate = TRUE)
deployApp("/Users/robweber/Documents/Professional/First Line/World Lacrosse/WLAX_Germany_Reporting_Dashboard_1",
appName = "WLAX_Germany_Reporting_Dashboard_1", account = "robertweber98", forceUpdate = TRUE)