-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev_funs.R
96 lines (80 loc) · 2.77 KB
/
dev_funs.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
DST_DEV <- readr::read_csv(file = "dst_fp_dev.csv",col_types = "dcdd") %>%
rename(`50th` = q_upper,`10th` = q_lower) %>%
tidyr::gather(key = "pct",value = "val",`50th`,`10th`) %>%
filter(age <= 30)
SPR_DEV <- readr::read_csv(file = "spr_fp_dev.csv",col_types = "dcdd") %>%
rename(`50th` = q_upper,`10th` = q_lower) %>%
tidyr::gather(key = "pct",value = "val",`50th`,`10th`) %>%
filter(age <= 30)
#### DISTANCE ####
dev_dst_data <- function(con,compid){
if (is.null(compid) || compid == ""){
return(NULL)
}
dst_src <- dplyr::tbl(src = con,"v_distance")
dev_dst_data <- dst_src %>%
filter(compid %in% local(compid) & !is.na(fispoints)) %>%
select(eventid,compid,fisid,name,gender,age,date,fispoints) %>%
collect()
dev_dst_data
}
dev_dst_plot <- function(dev_dst_data){
if (is.null(dev_dst_data) || nrow(dev_dst_data) == 0){
return(NULL)
}
n_skier <- n_distinct(dev_dst_data$compid)
if (n_skier < 4) {
fw <- facet_wrap(~name,scales = "free_y",ncol = 1)
} else {
fw <- facet_wrap(~name,scales = "free_y")
}
dev_ref <- dev_dst_data %>%
select(name,gender) %>%
distinct() %>%
left_join(DST_DEV,by = "gender") %>%
filter(age <= max(dev_dst_data$age))
ggplot() +
fw +
geom_point(data = dev_dst_data,aes(x = age,y = fispoints),alpha = 0.5,na.rm = TRUE) +
geom_line(data = dev_ref,aes(x = age,y = val,color = pct,group = pct),na.rm = TRUE) +
scale_color_manual(values = c(`50th` = "blue",`10th` = "red")) +
labs(x = "Age",y = "FIS Points",color = "Target FIS Point %-tile",
caption = "@statskier - statisticalskier.com") +
theme(legend.position = "top")
}
#### SPRINT ####
dev_spr_data <- function(con,compid){
if (is.null(compid) || compid == ""){
return(NULL)
}
spr_src <- dplyr::tbl(src = con,"v_sprint")
dev_spr_data <- spr_src %>%
filter(compid %in% local(compid) & !is.na(fispoints)) %>%
select(eventid,compid,fisid,name,gender,age,date,fispoints) %>%
collect()
dev_spr_data
}
dev_spr_plot <- function(dev_spr_data){
if (is.null(dev_spr_data) || nrow(dev_spr_data) == 0){
return(NULL)
}
n_skier <- n_distinct(dev_spr_data$compid)
if (n_skier < 4) {
fw <- facet_wrap(~name,scales = "free_y",ncol = 1)
} else {
fw <- facet_wrap(~name,scales = "free_y")
}
dev_ref <- dev_spr_data %>%
select(name,gender) %>%
distinct() %>%
left_join(SPR_DEV,by = "gender") %>%
filter(age <= max(dev_spr_data$age))
ggplot() +
fw +
geom_point(data = dev_spr_data,aes(x = age,y = fispoints),alpha = 0.5,na.rm = TRUE) +
geom_line(data = dev_ref,aes(x = age,y = val,color = pct,group = pct),na.rm = TRUE) +
scale_color_manual(values = c(`50th` = "blue",`10th` = "red")) +
labs(x = "Age",y = "FIS Points",color = "Target FIS Point %-tile",
caption = "@statskier - statisticalskier.com") +
theme(legend.position = "top")
}