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.

152 lines
4.6 KiB

  1. source("readData.R")
  2. library(tidyverse)
  3. RPEData <-readNArpeData()
  4. wellnessData <- readWellnessData()
  5. normalizedWellnessData <- readNormalizedMetrics()
  6. RPEData
  7. playerIDS <- playerIds <-unique(RPEData$PlayerID)
  8. numDays <- max(RPEData$TimeSinceAugFirst)
  9. dayList <- 0:numDays
  10. dayCol <- c()
  11. playerid <- c()
  12. dailyLoadCol <- c()
  13. acuteChronicRatioCol <- c()
  14. trainDuration <- c()
  15. sleepHoursCol <- c()
  16. fatigueRawCol <- c()
  17. sleepQualityCol <- c()
  18. sorenessCol <- c()
  19. normFatCol <-c()
  20. normSoreCol <- c()
  21. normSleepHours <- c()
  22. normSleepQuality <- c()
  23. notatAllCol <- c()
  24. absCol <-c()
  25. somewhatCol <- c()
  26. unknownCol <- c()
  27. for(day in dayList)
  28. {
  29. for(id in playerIDS)
  30. {
  31. cat("Player:", id, "Day:", day, "\n", sep=" ")
  32. trainDay <- subset(RPEData, TimeSinceAugFirst == day & PlayerID == id)
  33. #workLoad <- c(workLoad, sum(daylyActivities$SessionLoad, na.rm = T))
  34. wellnessDay <- subset(wellnessData, TimeSinceAugFirst == day & PlayerID == id)
  35. normalizedDay <- subset(normalizedWellnessData, TimeSinceAugFirst == day & playerID == id)
  36. #if(length(normalizedDay$playerID) > 0)
  37. #{
  38. # print("good")
  39. #}
  40. dayCol <- c(dayCol, day)
  41. playerid <- c(playerid, id)
  42. if(length(wellnessDay$SleepHours) > 0)
  43. {
  44. fatigueRawCol <- c(fatigueRawCol, mean(wellnessDay$Fatigue, na.rm =T))
  45. sleepQualityCol <- c(sleepQualityCol, mean(wellnessDay$SleepQuality, na.rm = T))
  46. sleepHoursCol <- c(sleepHoursCol, sum(wellnessDay$SleepHours, na.rm = T))
  47. sorenessCol <- c(sorenessCol, mean(wellnessDay$Soreness, na.rm = T))
  48. }
  49. else
  50. {
  51. sleepQualityCol <- c(sleepQualityCol, median(wellnessData$SleepQuality, na.rm = T))
  52. sleepHoursCol <- c(sleepHoursCol, median(wellnessData$SleepHours))
  53. fatigueRawCol <- c(fatigueRawCol, median(wellnessData$Fatigue))
  54. sorenessCol <- c(sorenessCol, median(wellnessData$Soreness))
  55. }
  56. if(length(normalizedDay$normSoreness) > 0)
  57. {
  58. normFatCol <- c(normFatCol, mean(normalizedDay$normFatigue, na.rm=T))
  59. normSoreCol <- c(normSoreCol, mean(normalizedDay$normSoreness, na.rm = T))
  60. normSleepHours <- c(normSleepHours, mean(normalizedDay$normSleepHours, na.rm =T))
  61. normSleepQuality <- c(normSleepQuality, mean(normalizedDay$normSleepQuality, na.rm=T))
  62. }
  63. else
  64. {
  65. normFatCol <- c(normFatCol, mean(normalizedWellnessData$normFatigue, na.rm=T))
  66. normSoreCol <- c(normSoreCol, mean(normalizedWellnessData$normSoreness, na.rm = T))
  67. normSleepHours <- c(normSleepHours, mean(normalizedWellnessData$normSleepHours, na.rm =T))
  68. normSleepQuality <- c(normSleepQuality, mean(normalizedWellnessData$normSleepQuality, na.rm=T))
  69. }
  70. if(length(trainDay$SessionLoad) > 0)
  71. {
  72. dailyLoadCol <- c(dailyLoadCol, mean(trainDay$DailyLoad,na.rm = T))
  73. acuteChronicRatioCol <- c(acuteChronicRatioCol, mean(trainDay$AcuteChronicRatio, na.rm =T))
  74. trainDuration <- c(trainDuration, sum(trainDay$Duration, na.rm = T))
  75. notatAllCol <- c(notatAllCol, max(trainDay$BestOutOfMyselfNotAtAll))
  76. absCol <- c(absCol, max(trainDay$BestOutOfMyselfAbsolutely))
  77. somewhatCol <- c(somewhatCol, max(trainDay$BestOutOfMyselfSomewhat))
  78. unknownCol <- c(unknownCol, max(trainDay$BestOutOfMyselfUnknown))
  79. }
  80. else
  81. {
  82. dailyLoadCol <- c(dailyLoadCol, 0)
  83. acuteChronicRatioCol <- c(acuteChronicRatioCol, 0)
  84. trainDuration <- c(trainDuration, 0)
  85. notatAllCol <- c(notatAllCol, 0)
  86. absCol <- c(absCol, 0)
  87. somewhatCol <- c(somewhatCol, 0)
  88. unknownCol <- c(unknownCol, 1)
  89. }
  90. }
  91. }
  92. dailyLoadCol[is.na(dailyLoadCol)] <- 0
  93. acuteChronicRatioCol[is.na(acuteChronicRatioCol)] <- 0
  94. massiveTibble <- tibble(day = dayCol,
  95. playerID = playerid,
  96. DailyLoad = dailyLoadCol,
  97. acuteChronicRatio = acuteChronicRatioCol,
  98. trainDuration = trainDuration,
  99. sleepHours = sleepHoursCol,
  100. fatigue = fatigueRawCol,
  101. sleepQuality = sleepQualityCol,
  102. soreness = sorenessCol,
  103. fatigueNorm = normFatCol,
  104. sorenessNorm = normSoreCol,
  105. sleepHoursNorm = normSleepHours,
  106. sleepQualityNorm = normSleepQuality,
  107. BestOutOfMyselfNotAtAll = notatAllCol,
  108. BestOutOfMyselfAbsolutely = absCol,
  109. BestOutOfMyselfSomewhat = somewhatCol,
  110. BestOutOfMyselfUnknown = unknownCol)
  111. write.csv(massiveTibble, "cleaned/personal.csv")