source('../gpx_validation.R') # GPX dataset processing / shared OpenCPU functions
suppressMessages(library(plyr))
suppressMessages(library(ggplot2))
temp <- list()
data_dir <- "C:/Users/rober/Desktop/Repositories/gpx_processing/data_backup/"
valid_datasets <- c("14-05.gpx","2016-06-18 10.14.52 Stopwatch.gpx","Current.gpx",
"Meg.gpx","Scout.gpx","TeamEchoCurrent.gpx","Track_ 018-02-24 145845.gpx",
"Track_14-08 1.gpx","Track_2015-07-05 215817.gpx","Track_2015-07-09 151556.gpx","Track_2015-07-09 183806.gpx","Track_2015-07-10 132200.gpx","Track_2015-07-15 204324.gpx","Track_2015-07-24 164157.gpx","Track_2015-07-29 130706.gpx","Track_2016-04-30 115630.gpx","Track_2016-06-18 131319.gpx","Track_2018-02-10 104731 Task 1.gpx","Track_2018-02-10 110234 Task 2.gpx","Track_2018-02-10 113753 Task 14B.gpx","Track_2018-02-10 150828 Task 29B.gpx","Track_ALPHA05-14 125702.gpx","Track_K9MEG06-18 124555.gpx","Track_QUEBEC5-14 154550.gpx","Track_T18 800 001 TASK2.gpx","Track_T18 800 001.gpx")
hardcode_response <- c("Trail","Sweep","Trail","Canine","Canine","Sweep","Sweep","Sweep","Trail","Trail","Offtrail","Offtrail","Trail","Offtrail","None","Trail","Offtrail","Trail","Trail","Sweep","Trail","Offtrail","Canine","Offtrail","Trail","Sweep")
# build datasets
# meg.gpx / scout.gpx returning warnings
for (i in 1:length(valid_datasets)){
name <- valid_datasets[i]
cat(name)
temp[[name]] <- invisible(gpx_validation(paste0(data_dir,valid_datasets[i])))
temp[[name]]$dt_ts <- strptime(temp[[name]]$DateTime, "%Y-%m-%dT%H:%M:%SZ")
temp[[name]]$name <- name
temp[[name]]$type <- hardcode_response[i]
}
df_all <- do.call("rbind", temp)
rm(temp);
completeFun <- function(data, desiredCols) {
completeVec <- complete.cases(data[, desiredCols])
return(data[completeVec, ])
}
df_all$Speed_mph <- df_all$Speed*2.23694
df_all_clean<-df_all[ which(df_all$Speed_mph < 5.5), ]
df_all_clean<-df_all_clean[df_all_clean$type != "None", ]
#df_all_clean<-df_all_clean[df_all_clean$Gradient != 1, ]
#df_all_clean<-df_all_clean[df_all_clean$Speed != -1, ]
df_all_clean<- df_all_clean[is.finite(df_all_clean$Pace), ]
df_all_clean<-completeFun(df_all_clean, "Gradient")
df_all_clean$gradient_bin <- cut(df_all_clean$Gradient, breaks = seq(-1, 1, by = .2),labels= c("-1:-0.8","-0.8:-0.6","-0.6:-0.4","-0.4:-0.2","-0.2:0","0:0.2","0.2:0.4","0.4:0.6","0.6:0.8","0.8:1"))
plot(df_all_clean$gradient_bin, main="Total Slope Bin Distribution", las=2)
grid(NA, 6, lwd = 2) # grid only in y-direction
The number of GPX points collected per category:
count(df_all_clean,'type')
## type freq
## 1 Canine 2364
## 2 Offtrail 4937
## 3 Sweep 2762
## 4 Trail 8024
# Find the mean of each group
cdat <- ddply(df_all_clean, "type", summarise, speed_mean=mean(Speed_mph))
# Overlaid category by speed
ggplot(df_all_clean, aes(x=Speed_mph, fill=type)) +
geom_density(alpha=.4)+
geom_vline(data=cdat, aes(xintercept=speed_mean, colour=type),
linetype="dashed", size=1)
# Overlaid category by speed
cdat <- ddply(df_all_clean, "type", summarise, gradient_mean=mean(Gradient))
ggplot(df_all_clean, aes(x=Gradient, fill=type)) +
geom_density(alpha=.4)#+
#geom_vline(data=cdat, aes(xintercept=gradient_mean, colour=type),
# linetype="dashed", size=1)
cdat
## type gradient_mean
## 1 Canine 0.001516263
## 2 Offtrail -0.002112702
## 3 Sweep -0.005936567
## 4 Trail 0.010023197
# Find the mean of each group
cdat <- ddply(df_all_clean, "type", summarise, speed_mean=mean(Speed_mph))
# Overlaid category by speed
ggplot(df_all_clean, aes(x=Speed_mph, fill=gradient_bin)) +
geom_density(alpha = 0.8)+ facet_grid(~ gradient_bin)
suppressMessages(library(dplyr))
suppressMessages(library(plyr))
suppressMessages(detach(package:plyr))
summary_table <- df_all_clean[,-which(names(df_all_clean) == "dt_ts")] %>%
group_by(gradient_bin, type) %>%
summarise(mean_speed_mph =mean(Speed_mph),
sd_speed_mph = sd(Speed_mph),
mean_gradient =mean(Gradient),
sd_gradient = sd(Gradient),
n = n())
knitr::kable(summary_table)
gradient_bin | type | mean_speed_mph | sd_speed_mph | mean_gradient | sd_gradient | n |
---|---|---|---|---|---|---|
-1:-0.8 | Canine | 0.3917022 | NaN | -0.8507135 | NaN | 1 |
-1:-0.8 | Offtrail | 2.1968784 | 1.5348322 | -0.9169833 | 0.0605081 | 119 |
-1:-0.8 | Sweep | 0.2412910 | 0.1665461 | -0.8527038 | 0.0282116 | 5 |
-1:-0.8 | Trail | 1.9077815 | 1.5939766 | -0.8987107 | 0.0665529 | 33 |
-0.8:-0.6 | Canine | 0.3939401 | 0.7646847 | -0.7142950 | 0.0657076 | 5 |
-0.8:-0.6 | Offtrail | 1.6840895 | 1.3269149 | -0.6957599 | 0.0583680 | 69 |
-0.8:-0.6 | Sweep | 0.2705009 | 0.4058029 | -0.6730929 | 0.0417845 | 12 |
-0.8:-0.6 | Trail | 0.5899044 | 0.7166783 | -0.6777289 | 0.0535312 | 180 |
-0.6:-0.4 | Canine | 0.1339957 | 0.1050167 | -0.4846921 | 0.0576446 | 13 |
-0.6:-0.4 | Offtrail | 1.2860436 | 1.2351801 | -0.5035349 | 0.0534584 | 91 |
-0.6:-0.4 | Sweep | 0.3247667 | 0.4563737 | -0.4846872 | 0.0597499 | 37 |
-0.6:-0.4 | Trail | 0.6690066 | 0.7588153 | -0.4954423 | 0.0564542 | 371 |
-0.4:-0.2 | Canine | 0.4464989 | 0.5061638 | -0.2799671 | 0.0472953 | 14 |
-0.4:-0.2 | Offtrail | 1.5217304 | 1.4256832 | -0.2766653 | 0.0548936 | 238 |
-0.4:-0.2 | Sweep | 0.7084654 | 0.6216136 | -0.2727426 | 0.0536451 | 138 |
-0.4:-0.2 | Trail | 1.0076387 | 0.8808683 | -0.2887168 | 0.0614294 | 536 |
-0.2:0 | Canine | 1.6401466 | 1.3281969 | -0.0101412 | 0.0282067 | 1935 |
-0.2:0 | Offtrail | 2.0370174 | 1.3383613 | -0.0651933 | 0.0512141 | 1919 |
-0.2:0 | Sweep | 1.2709192 | 0.8569567 | -0.0471732 | 0.0508101 | 1336 |
-0.2:0 | Trail | 1.6032192 | 0.9704841 | -0.0653258 | 0.0524795 | 2994 |
0:0.2 | Canine | 2.4681992 | 1.4556238 | 0.0550072 | 0.0427611 | 350 |
0:0.2 | Offtrail | 1.9806244 | 1.3504840 | 0.0669564 | 0.0514221 | 1925 |
0:0.2 | Sweep | 1.3752710 | 0.8950086 | 0.0586867 | 0.0500931 | 1096 |
0:0.2 | Trail | 1.4669402 | 0.9300597 | 0.0696386 | 0.0532572 | 2588 |
0.2:0.4 | Canine | 0.4412990 | 0.5009832 | 0.2742552 | 0.0541178 | 24 |
0.2:0.4 | Offtrail | 1.6920608 | 1.4947684 | 0.2782249 | 0.0551065 | 342 |
0.2:0.4 | Sweep | 0.5242615 | 0.5955061 | 0.2765223 | 0.0552231 | 97 |
0.2:0.4 | Trail | 0.6873911 | 0.6930150 | 0.2895390 | 0.0577477 | 616 |
0.4:0.6 | Canine | 0.1818154 | 0.2651837 | 0.4862341 | 0.0604409 | 16 |
0.4:0.6 | Offtrail | 1.6585966 | 1.5340305 | 0.4805323 | 0.0574218 | 103 |
0.4:0.6 | Sweep | 0.2742005 | 0.2908812 | 0.5026658 | 0.0565024 | 31 |
0.4:0.6 | Trail | 0.4096611 | 0.4870509 | 0.4945920 | 0.0610039 | 433 |
0.6:0.8 | Canine | 0.1175910 | 0.0678071 | 0.6415098 | 0.0316956 | 4 |
0.6:0.8 | Offtrail | 1.3887864 | 1.3852242 | 0.6936878 | 0.0575746 | 53 |
0.6:0.8 | Sweep | 0.6405772 | 0.6630740 | 0.6837427 | 0.0424058 | 6 |
0.6:0.8 | Trail | 0.3583758 | 0.5214141 | 0.6835255 | 0.0572388 | 246 |
0.8:1 | Canine | 0.1903592 | 0.0434022 | 0.8349803 | 0.0363651 | 2 |
0.8:1 | Offtrail | 2.2120646 | 1.3777464 | 0.9380486 | 0.0576874 | 78 |
0.8:1 | Sweep | 0.7332900 | 1.1040618 | 0.9276828 | 0.0811735 | 4 |
0.8:1 | Trail | 2.1136737 | 1.6486937 | 0.9383412 | 0.0631945 | 27 |