datafest competition 2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

303 lines
9.2 KiB

  1. source("readData.R")
  2. source("exponentialSmoothing.R")
  3. library(tidyverse)
  4. RPEData <-readNArpeData()
  5. wellnessData <- readWellnessData()
  6. normalizedWellnessData <- readNormalizedMetrics()
  7. RPEData
  8. playerIDS <- playerIds <-unique(RPEData$PlayerID)
  9. numDays <- max(RPEData$TimeSinceAugFirst)
  10. dayList <- 0:numDays
  11. dayCol <- c()
  12. playerid <- c()
  13. dailyLoadCol <- c()
  14. acuteChronicRatioCol <- c()
  15. trainDuration <- c()
  16. sleepHoursCol <- c()
  17. fatigueRawCol <- c()
  18. sleepQualityCol <- c()
  19. sorenessCol <- c()
  20. normFatCol <-c()
  21. normSoreCol <- c()
  22. normSleepHours <- c()
  23. normSleepQuality <- c()
  24. notatAllCol <- c()
  25. absCol <-c()
  26. somewhatCol <- c()
  27. unknownCol <- c()
  28. desireCol <- c()
  29. for(day in dayList)
  30. {
  31. for(id in playerIDS)
  32. {
  33. cat("Player:", id, "Day:", day, "\n", sep=" ")
  34. trainDay <- subset(RPEData, TimeSinceAugFirst == day & PlayerID == id)
  35. #workLoad <- c(workLoad, sum(daylyActivities$SessionLoad, na.rm = T))
  36. wellnessDay <- subset(wellnessData, TimeSinceAugFirst == day & PlayerID == id)
  37. normalizedDay <- subset(normalizedWellnessData, TimeSinceAugFirst == day & playerID == id)
  38. #if(length(normalizedDay$playerID) > 0)
  39. #{
  40. # print("good")
  41. #}
  42. dayCol <- c(dayCol, day)
  43. playerid <- c(playerid, id)
  44. if(length(wellnessDay$SleepHours) > 0)
  45. {
  46. desireCol <- c(desireCol, wellnessDay$Desire)
  47. fatigueRawCol <- c(fatigueRawCol, mean(wellnessDay$Fatigue, na.rm =T))
  48. sleepQualityCol <- c(sleepQualityCol, mean(wellnessDay$SleepQuality, na.rm = T))
  49. sleepHoursCol <- c(sleepHoursCol, sum(wellnessDay$SleepHours, na.rm = T))
  50. sorenessCol <- c(sorenessCol, mean(wellnessDay$Soreness, na.rm = T))
  51. }
  52. else
  53. {
  54. desireCol <- c(desireCol, median(wellnessData$Desire))
  55. sleepQualityCol <- c(sleepQualityCol, median(wellnessData$SleepQuality, na.rm = T))
  56. sleepHoursCol <- c(sleepHoursCol, median(wellnessData$SleepHours))
  57. fatigueRawCol <- c(fatigueRawCol, median(wellnessData$Fatigue))
  58. sorenessCol <- c(sorenessCol, median(wellnessData$Soreness))
  59. }
  60. if(length(normalizedDay$normSoreness) > 0)
  61. {
  62. normFatCol <- c(normFatCol, mean(normalizedDay$normFatigue, na.rm=T))
  63. normSoreCol <- c(normSoreCol, mean(normalizedDay$normSoreness, na.rm = T))
  64. normSleepHours <- c(normSleepHours, mean(normalizedDay$normSleepHours, na.rm =T))
  65. normSleepQuality <- c(normSleepQuality, mean(normalizedDay$normSleepQuality, na.rm=T))
  66. }
  67. else
  68. {
  69. normFatCol <- c(normFatCol, mean(normalizedWellnessData$normFatigue, na.rm=T))
  70. normSoreCol <- c(normSoreCol, mean(normalizedWellnessData$normSoreness, na.rm = T))
  71. normSleepHours <- c(normSleepHours, mean(normalizedWellnessData$normSleepHours, na.rm =T))
  72. normSleepQuality <- c(normSleepQuality, mean(normalizedWellnessData$normSleepQuality, na.rm=T))
  73. }
  74. if(length(trainDay$SessionLoad) > 0)
  75. {
  76. dailyLoadCol <- c(dailyLoadCol, mean(trainDay$DailyLoad,na.rm = T))
  77. acuteChronicRatioCol <- c(acuteChronicRatioCol, mean(trainDay$AcuteChronicRatio, na.rm =T))
  78. trainDuration <- c(trainDuration, sum(trainDay$Duration, na.rm = T))
  79. notatAllCol <- c(notatAllCol, max(trainDay$BestOutOfMyselfNotAtAll))
  80. absCol <- c(absCol, max(trainDay$BestOutOfMyselfAbsolutely))
  81. somewhatCol <- c(somewhatCol, max(trainDay$BestOutOfMyselfSomewhat))
  82. unknownCol <- c(unknownCol, max(trainDay$BestOutOfMyselfUnknown))
  83. }
  84. else
  85. {
  86. dailyLoadCol <- c(dailyLoadCol, 0)
  87. acuteChronicRatioCol <- c(acuteChronicRatioCol, 0)
  88. trainDuration <- c(trainDuration, 0)
  89. notatAllCol <- c(notatAllCol, 0)
  90. absCol <- c(absCol, 0)
  91. somewhatCol <- c(somewhatCol, 0)
  92. unknownCol <- c(unknownCol, 1)
  93. }
  94. }
  95. }
  96. dailyLoadCol[is.na(dailyLoadCol)] <- 0
  97. acuteChronicRatioCol[is.na(acuteChronicRatioCol)] <- 0
  98. accuteFatigueSliding <- slidingWindowSmooth(acuteChronicRatioCol)
  99. massiveTibble <- tibble(day = dayCol,
  100. playerID = playerid,
  101. DailyLoad = dailyLoadCol,
  102. DailyLoadSliding = slidingWindowSmooth(DailyLoad),
  103. acuteChronicRatio = acuteChronicRatioCol,
  104. acuteChronicRatioSliding = slidingWindowSmooth(acuteChronicRatioCol),
  105. trainDuration = trainDuration,
  106. trainDurationSliding = slidingWindowSmooth(trainDuration),
  107. sleepHours = sleepHoursCol,
  108. sleepHoursSliding = slidingWindowSmooth(sleepHours),
  109. fatigue = fatigueRawCol,
  110. fatigueSliding = slidingWindowSmooth(fatigue),
  111. sleepQuality = sleepQualityCol,
  112. soreness = sorenessCol,
  113. sorenessSliding = slidingWindowSmooth(soreness),
  114. fatigueNorm = normFatCol,
  115. fatigueNormSliding = slidingWindowSmooth(fatigueNorm),
  116. sorenessNorm = normSoreCol,
  117. sleepHoursNorm = normSleepHours,
  118. sleepQualityNorm = normSleepQuality,
  119. BestOutOfMyselfNotAtAll = notatAllCol,
  120. BestOutOfMyselfAbsolutely = absCol,
  121. BestOutOfMyselfSomewhat = somewhatCol,
  122. BestOutOfMyselfUnknown = unknownCol,
  123. desire = desireCol)
  124. write.csv(massiveTibble, "cleaned/personal.csv")
  125. library(devtools)
  126. source_gist("524eade46135f6348140")
  127. ## Mini Graphs
  128. library(devtools)
  129. source_gist("524eade46135f6348140")
  130. # first section
  131. ggplot(data = massiveTibble, aes(x = DailyLoad, y = fatigueNorm, label=sorenessNorm)) +
  132. stat_smooth_func(geom="text",method="lm",hjust=0,vjust=-2,parse=TRUE) +
  133. geom_smooth(method="lm",se=FALSE) +
  134. labs(x = "Daily Load", y = "Normalized Fatigue Sccore")+
  135. theme_bw() +
  136. ylim(-6,4) +
  137. ggtitle("Daily Work Load vs Fatigue") +
  138. geom_point()
  139. ggplot(data = massiveTibble, aes(x = acuteChronicRatioSliding, y = fatigueNorm, label=sorenessNorm)) +
  140. stat_smooth_func(geom="text",method="lm",hjust=0,vjust=-2,parse=TRUE) +
  141. geom_smooth(method="lm",se=FALSE) +
  142. labs(x = "Acute Chronic Ratio Smoothed Data", y = "Normalized Fatigue Sccore")+
  143. theme_bw() +
  144. ylim(-6,4) +
  145. geom_point() +
  146. ggtitle("Acute Chronic Ratio vs Fatigue")
  147. # Second section
  148. ggplot(data = massiveTibble, aes(x = sleepHoursNorm, y = fatigueNorm, label=sorenessNorm)) +
  149. stat_smooth_func(geom="text",method="lm",hjust=0,vjust=-2,parse=TRUE) +
  150. geom_smooth(method="lm",se=FALSE) +
  151. labs(x = "Normalized Hours of Sleep", y = "Normalized Fatigue Sccore")+
  152. theme_bw() +
  153. ylim(-6,4) +
  154. ggtitle("Hours of Sleep vs Fatigue") +
  155. geom_point()
  156. ggplot(data = massiveTibble, aes(x = sorenessNorm, y = fatigueNorm, label=sorenessNorm)) +
  157. stat_smooth_func(geom="text",method="lm",hjust=0,vjust=-2,parse=TRUE) +
  158. geom_smooth(method="lm",se=FALSE) +
  159. labs(x = "Normalized Soreness", y = "Normalized Fatigue Sccore")+
  160. theme_bw() +
  161. ylim(-6,4) +
  162. ggtitle("Soreness vs Fatigue") +
  163. geom_point()
  164. ggplot(data = massiveTibble) +
  165. theme(plot.title = element_text(hjust = 0.5)) +
  166. ggtitle("Team's Percieved Fatigue") +
  167. geom_point(mapping = aes(x=day, y=sorenessSliding)) +
  168. labs(x = "Days Since August First 2017", y = "Accute Fatugue ")+
  169. theme_bw() +
  170. stat_smooth_func(geom="text",method="lm",hjust=0,parse=TRUE) +
  171. geom_smooth(method="lm",se=FALSE) +
  172. geom_point() + facet_wrap(~class)
  173. ggplot(data = massiveTibble) +
  174. theme(plot.title = element_text(hjust = 0.5)) +
  175. ggtitle("Normalized Soreness Box Plots") +
  176. geom_boxplot(na.rm = T, mapping = aes(y=sorenessNorm, group = playerID), outlier.colour = "red", outlier.shape = 1) +
  177. labs(group = "Player ID", y = "Normalized Soreness Values") +
  178. coord_flip() +
  179. theme_bw()
  180. ggplot(data = massiveTibble) +
  181. theme(plot.title = element_text(hjust = 0.5)) +
  182. ggtitle("Normalized Sleep Quality Box Plots") +
  183. geom_boxplot(na.rm = T, mapping = aes(y=sleepQualityNorm, group = playerID), outlier.colour = "red", outlier.shape = 1) +
  184. labs(group = "Player ID", y = "Normalized Sleep Quality") +
  185. coord_flip() +
  186. theme_bw()
  187. ggplot(data = massiveTibble) +
  188. theme(plot.title = element_text(hjust = 0.5)) +
  189. ggtitle("Soreness Box Plots") +
  190. geom_boxplot(na.rm = T, mapping = aes(y=sleepQuality, group = playerID), outlier.colour = "red", outlier.shape = 1) +
  191. labs(group = "Player ID", y = "Sleep Quality") +
  192. coord_flip() +
  193. theme_bw()
  194. ggplot(data = massiveTibble) +
  195. theme(plot.title = element_text(hjust = 0.5)) +
  196. ggtitle("Team's Percieved Fatigue") +
  197. geom_point(mapping = aes(x=day, y=fatigueNormSliding)) +
  198. labs(x = "Days Since August First 2017", y = "Teams Fatigue")+
  199. theme_bw()
  200. ggplot(data = massiveTibble) +
  201. theme(plot.title = element_text(hjust = 0.5)) +
  202. ggtitle("Team's Percieved Fatigue") +
  203. geom_point(mapping = aes(x=day, y=sorenessSliding)) +
  204. labs(x = "Days Since August First 2017", y = "Accute Fatugue ")+
  205. theme_bw()
  206. ggplot(data = massiveTibble) +
  207. theme(plot.title = element_text(hjust = 0.5)) +
  208. ggtitle("Team's Percieved Fatigue") +
  209. geom_point(mapping = aes(x=sleepQuality, y=fatigueNorm)) +
  210. labs(x = "Days Since August First 2017", y = "Accute Fatugue ") +
  211. theme_bw()