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.

219 lines
7.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. ggplot(data = massiveTibble) +
  126. theme(plot.title = element_text(hjust = 0.5)) +
  127. ggtitle("Normalized Soreness Box Plots") +
  128. geom_boxplot(na.rm = T, mapping = aes(y=sorenessNorm, group = playerID), outlier.colour = "red", outlier.shape = 1) +
  129. labs(group = "Player ID", y = "Normalized Soreness Values") +
  130. coord_flip() +
  131. theme_bw()
  132. ggplot(data = massiveTibble) +
  133. theme(plot.title = element_text(hjust = 0.5)) +
  134. ggtitle("Normalized Sleep Quality Box Plots") +
  135. geom_boxplot(na.rm = T, mapping = aes(y=sleepQualityNorm, group = playerID), outlier.colour = "red", outlier.shape = 1) +
  136. labs(group = "Player ID", y = "Normalized Sleep Quality") +
  137. coord_flip() +
  138. theme_bw()
  139. ggplot(data = massiveTibble) +
  140. theme(plot.title = element_text(hjust = 0.5)) +
  141. ggtitle("Soreness Box Plots") +
  142. geom_boxplot(na.rm = T, mapping = aes(y=sleepQuality, group = playerID), outlier.colour = "red", outlier.shape = 1) +
  143. labs(group = "Player ID", y = "Sleep Quality") +
  144. coord_flip() +
  145. theme_bw()
  146. ggplot(data = massiveTibble) +
  147. theme(plot.title = element_text(hjust = 0.5)) +
  148. ggtitle("Team's Percieved Fatigue") +
  149. geom_point(mapping = aes(x=day, y=fatigueNormSliding)) +
  150. labs(x = "Days Since August First 2017", y = "Teams Fatigue")+
  151. theme_bw()
  152. ggplot(data = massiveTibble) +
  153. theme(plot.title = element_text(hjust = 0.5)) +
  154. ggtitle("Team's Percieved Fatigue") +
  155. geom_point(mapping = aes(x=day, y=sorenessSliding)) +
  156. labs(x = "Days Since August First 2017", y = "Accute Fatugue ")+
  157. theme_bw()
  158. ggplot(data = massiveTibble) +
  159. theme(plot.title = element_text(hjust = 0.5)) +
  160. ggtitle("Team's Percieved Fatigue") +
  161. geom_point(mapping = aes(x=sleepQuality, y=fatigueNorm)) +
  162. labs(x = "Days Since August First 2017", y = "Accute Fatugue ") +
  163. theme_bw()