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.

215 lines
7.0 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. for(day in dayList)
  29. {
  30. for(id in playerIDS)
  31. {
  32. cat("Player:", id, "Day:", day, "\n", sep=" ")
  33. trainDay <- subset(RPEData, TimeSinceAugFirst == day & PlayerID == id)
  34. #workLoad <- c(workLoad, sum(daylyActivities$SessionLoad, na.rm = T))
  35. wellnessDay <- subset(wellnessData, TimeSinceAugFirst == day & PlayerID == id)
  36. normalizedDay <- subset(normalizedWellnessData, TimeSinceAugFirst == day & playerID == id)
  37. #if(length(normalizedDay$playerID) > 0)
  38. #{
  39. # print("good")
  40. #}
  41. dayCol <- c(dayCol, day)
  42. playerid <- c(playerid, id)
  43. if(length(wellnessDay$SleepHours) > 0)
  44. {
  45. fatigueRawCol <- c(fatigueRawCol, mean(wellnessDay$Fatigue, na.rm =T))
  46. sleepQualityCol <- c(sleepQualityCol, mean(wellnessDay$SleepQuality, na.rm = T))
  47. sleepHoursCol <- c(sleepHoursCol, sum(wellnessDay$SleepHours, na.rm = T))
  48. sorenessCol <- c(sorenessCol, mean(wellnessDay$Soreness, na.rm = T))
  49. }
  50. else
  51. {
  52. sleepQualityCol <- c(sleepQualityCol, median(wellnessData$SleepQuality, na.rm = T))
  53. sleepHoursCol <- c(sleepHoursCol, median(wellnessData$SleepHours))
  54. fatigueRawCol <- c(fatigueRawCol, median(wellnessData$Fatigue))
  55. sorenessCol <- c(sorenessCol, median(wellnessData$Soreness))
  56. }
  57. if(length(normalizedDay$normSoreness) > 0)
  58. {
  59. normFatCol <- c(normFatCol, mean(normalizedDay$normFatigue, na.rm=T))
  60. normSoreCol <- c(normSoreCol, mean(normalizedDay$normSoreness, na.rm = T))
  61. normSleepHours <- c(normSleepHours, mean(normalizedDay$normSleepHours, na.rm =T))
  62. normSleepQuality <- c(normSleepQuality, mean(normalizedDay$normSleepQuality, na.rm=T))
  63. }
  64. else
  65. {
  66. normFatCol <- c(normFatCol, mean(normalizedWellnessData$normFatigue, na.rm=T))
  67. normSoreCol <- c(normSoreCol, mean(normalizedWellnessData$normSoreness, na.rm = T))
  68. normSleepHours <- c(normSleepHours, mean(normalizedWellnessData$normSleepHours, na.rm =T))
  69. normSleepQuality <- c(normSleepQuality, mean(normalizedWellnessData$normSleepQuality, na.rm=T))
  70. }
  71. if(length(trainDay$SessionLoad) > 0)
  72. {
  73. dailyLoadCol <- c(dailyLoadCol, mean(trainDay$DailyLoad,na.rm = T))
  74. acuteChronicRatioCol <- c(acuteChronicRatioCol, mean(trainDay$AcuteChronicRatio, na.rm =T))
  75. trainDuration <- c(trainDuration, sum(trainDay$Duration, na.rm = T))
  76. notatAllCol <- c(notatAllCol, max(trainDay$BestOutOfMyselfNotAtAll))
  77. absCol <- c(absCol, max(trainDay$BestOutOfMyselfAbsolutely))
  78. somewhatCol <- c(somewhatCol, max(trainDay$BestOutOfMyselfSomewhat))
  79. unknownCol <- c(unknownCol, max(trainDay$BestOutOfMyselfUnknown))
  80. }
  81. else
  82. {
  83. dailyLoadCol <- c(dailyLoadCol, 0)
  84. acuteChronicRatioCol <- c(acuteChronicRatioCol, 0)
  85. trainDuration <- c(trainDuration, 0)
  86. notatAllCol <- c(notatAllCol, 0)
  87. absCol <- c(absCol, 0)
  88. somewhatCol <- c(somewhatCol, 0)
  89. unknownCol <- c(unknownCol, 1)
  90. }
  91. }
  92. }
  93. dailyLoadCol[is.na(dailyLoadCol)] <- 0
  94. acuteChronicRatioCol[is.na(acuteChronicRatioCol)] <- 0
  95. accuteFatigueSliding <- slidingWindowSmooth(acuteChronicRatioCol)
  96. massiveTibble <- tibble(day = dayCol,
  97. playerID = playerid,
  98. DailyLoad = dailyLoadCol,
  99. DailyLoadSliding = slidingWindowSmooth(DailyLoad),
  100. acuteChronicRatio = acuteChronicRatioCol,
  101. acuteChronicRatioSliding = slidingWindowSmooth(acuteChronicRatioCol),
  102. trainDuration = trainDuration,
  103. trainDurationSliding = slidingWindowSmooth(trainDuration),
  104. sleepHours = sleepHoursCol,
  105. sleepHoursSliding = slidingWindowSmooth(sleepHours),
  106. fatigue = fatigueRawCol,
  107. fatigueSliding = slidingWindowSmooth(fatigue),
  108. sleepQuality = sleepQualityCol,
  109. soreness = sorenessCol,
  110. sorenessSliding = slidingWindowSmooth(soreness),
  111. fatigueNorm = normFatCol,
  112. fatigueNormSliding = slidingWindowSmooth(fatigueNorm),
  113. sorenessNorm = normSoreCol,
  114. sleepHoursNorm = normSleepHours,
  115. sleepQualityNorm = normSleepQuality,
  116. BestOutOfMyselfNotAtAll = notatAllCol,
  117. BestOutOfMyselfAbsolutely = absCol,
  118. BestOutOfMyselfSomewhat = somewhatCol,
  119. BestOutOfMyselfUnknown = unknownCol)
  120. write.csv(massiveTibble, "cleaned/personal.csv")
  121. ggplot(data = massiveTibble) +
  122. theme(plot.title = element_text(hjust = 0.5)) +
  123. ggtitle("Normalized Soreness Box Plots") +
  124. geom_boxplot(na.rm = T, mapping = aes(y=sorenessNorm, group = playerID), outlier.colour = "red", outlier.shape = 1) +
  125. labs(group = "Player ID", y = "Normalized Soreness Values") +
  126. coord_flip() +
  127. theme_bw()
  128. ggplot(data = massiveTibble) +
  129. theme(plot.title = element_text(hjust = 0.5)) +
  130. ggtitle("Normalized Sleep Quality Box Plots") +
  131. geom_boxplot(na.rm = T, mapping = aes(y=sleepQualityNorm, group = playerID), outlier.colour = "red", outlier.shape = 1) +
  132. labs(group = "Player ID", y = "Normalized Sleep Quality") +
  133. coord_flip() +
  134. theme_bw()
  135. ggplot(data = massiveTibble) +
  136. theme(plot.title = element_text(hjust = 0.5)) +
  137. ggtitle("Soreness Box Plots") +
  138. geom_boxplot(na.rm = T, mapping = aes(y=sleepQuality, group = playerID), outlier.colour = "red", outlier.shape = 1) +
  139. labs(group = "Player ID", y = "Sleep Quality") +
  140. coord_flip() +
  141. theme_bw()
  142. ggplot(data = massiveTibble) +
  143. theme(plot.title = element_text(hjust = 0.5)) +
  144. ggtitle("Team's Percieved Fatigue") +
  145. geom_point(mapping = aes(x=day, y=fatigue)) +
  146. labs(x = "Days Since August First 2017", y = "Teams Fatigue")+
  147. theme_bw()
  148. ggplot(data = massiveTibble) +
  149. theme(plot.title = element_text(hjust = 0.5)) +
  150. ggtitle("Team's Percieved Fatigue") +
  151. geom_point(mapping = aes(x=day, y=sorenessSliding)) +
  152. labs(x = "Days Since August First 2017", y = "Accute Fatugue ")+
  153. theme_bw()
  154. ggplot(data = massiveTibble) +
  155. theme(plot.title = element_text(hjust = 0.5)) +
  156. ggtitle("Team's Percieved Fatigue") +
  157. geom_point(mapping = aes(x=sleepQuality, y=fatigueNorm)) +
  158. labs(x = "Days Since August First 2017", y = "Accute Fatugue ") +
  159. theme_bw()