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.

191 lines
4.7 KiB

  1. source("readData.R")
  2. library(tidyverse)
  3. RPEData <-readNArpeData()
  4. numDays <- max(RPEData$TimeSinceAugFirst)
  5. dayList <- 0:numDays
  6. workLoad <- c()
  7. averageWorkLoad <- c()
  8. for(day in dayList)
  9. {
  10. daylyActivities <- subset(RPEData, TimeSinceAugFirst == day)
  11. cat("day: ", day, "\n",sep="")
  12. cat("Activity count:", length(daylyActivities$DailyLoad), "\n", sep="")
  13. averageWorkLoad <- c(averageWorkLoad, mean(daylyActivities$SessionLoad, na.rm = T))
  14. workLoad <- c(workLoad, sum(daylyActivities$SessionLoad, na.rm = T))
  15. }
  16. plot(dayList, averageWorkLoad, main="Average Work Load")
  17. plot(dayList, workLoad, main="Daily Total Work Load")
  18. fatigueFunction <- function(workLoad, index)
  19. {
  20. if(index == 1)
  21. {
  22. return(workLoad[1])
  23. }
  24. else
  25. {
  26. return(workLoad[index] + (exp(1)^(-1/15))*fatigueFunction(workLoad, index -1))
  27. }
  28. }
  29. smoothedWork <- c()
  30. for(day in dayList)
  31. {
  32. smoothedWork <- c(smoothedWork, fatigueFunction(workLoad, day + 1))
  33. }
  34. plot(dayList, smoothedFatigue)
  35. fatigueData <- readFatigueSums()
  36. dayNum <- max(fatigueData$TimeSinceAugFirst)
  37. dayList <- 0:dayNum
  38. slidingAverage <- c()
  39. window <- 21 - 1
  40. for(day in window:dayNum)
  41. {
  42. windowAverage <- mean(fatigueData$fatigueSum[c((day-window):day)], na.rm = T)
  43. slidingAverage <- c(slidingAverage, windowAverage)
  44. }
  45. smoothedFatigueData <- c()
  46. for(day in dayList)
  47. {
  48. smoothedFatigueData <- c(smoothedFatigueData, fatigueFunction(fatigueData$fatigueSum, day + 1))
  49. }
  50. plot(dayList, smoothedFatigueData)
  51. workTibble <- tibble(day = dayList, totalWork = workLoad,
  52. averageWorkLoad = averageWorkLoad,
  53. smoothedWork = smoothedWork,
  54. smoothedFatigueData = smoothedFatigueData)
  55. plot(workTibble$totalWork, fatigueData$fatigueSum[-1])
  56. workGraph <- ggplot(data = workTibble) +
  57. theme(plot.title = element_text(hjust = 0.5)) +
  58. ggtitle("Team's Smoothed Work") +
  59. geom_point(mapping = aes(x=day, y=smoothedWork)) +
  60. labs(x = "Days Since August First 2017", y = "Teams Training Work")+
  61. theme_bw()
  62. fatGraph <- ggplot(data = workTibble) +
  63. theme(plot.title = element_text(hjust = 0.5)) +
  64. ggtitle("Team's Percieved Fatigue") +
  65. geom_point(mapping = aes(x=day, y=smoothedFatigueData)) +
  66. labs(x = "Days Since August First 2017", y = "Teams Average Normalized Fatigue")+
  67. theme_bw()
  68. ggplot(data = workTibble) +
  69. theme(plot.title = element_text(hjust = 0.5)) +
  70. ggtitle("Team's Percieved Fatigue") +
  71. geom_point(mapping = aes(x=smoothedWork, y=smoothedFatigueData)) +
  72. labs(x = "Smoothed Work Per Day", y = "Teams Average Normalized Fatigue")+
  73. theme_bw()
  74. for(gameDay in games$Date)
  75. {
  76. fatGraph <- fatGraph + geom_vline(xintercept = gameDay, linetype="dotted",
  77. color = "blue", size=1.0)
  78. workGraph <- workGraph + geom_vline(xintercept = gameDay, linetype="dotted",
  79. color = "blue", size=1.0)
  80. }
  81. workGraph
  82. fatGraph
  83. write.csv(workTibble, "cleaned/expSmoothWorkAndFatigueData.csv")
  84. slidingAverage <- c()
  85. window <- 31 - 1
  86. for(day in window:numDays)
  87. {
  88. windowAverage <- mean(workLoad[c((day-window):day)])
  89. slidingAverage <- c(slidingAverage, windowAverage)
  90. }
  91. plot(window:numDays, slidingAverage, main="Sliding Average")
  92. plot(density(slidingAverage), main="Sliding Average Density")
  93. plot(density(workLoad), main="Total Work Load Average")
  94. dataTibble <- tibble(TimeSinceAugFirst = window:numDays, slidingWorkAverage = slidingAverage)
  95. workGraph <- ggplot(data = dataTibble) +
  96. theme(plot.title = element_text(hjust = 0.5)) +
  97. ggtitle("Team's 7 Day Moving Average") +
  98. geom_point(mapping = aes(x=TimeSinceAugFirst, y=slidingWorkAverage)) +
  99. labs(x = "Days Since August Seventh 2017", y = "Teams Total Daily Load")+
  100. theme_bw()
  101. for(gameDay in games$Date)
  102. {
  103. workGraph <- workGraph + geom_vline(xintercept = gameDay, linetype="dotted",
  104. color = "blue", size=1.0)
  105. }
  106. workGraph
  107. write.csv(dataTibble, "cleaned/slidingWorkAverageSevenDay.csv")
  108. ################################ Wellness Data ###################################
  109. graphingTib <- tibble(slidingAverage = slidingAverage, days = window:dayNum)
  110. fGraph <- ggplot(data = graphingTib) +
  111. theme(plot.title = element_text(hjust = 0.5)) +
  112. ggtitle("Team's Average Normalized Fatigue") +
  113. geom_point(mapping = aes(x=days, y=slidingAverage)) +
  114. labs(x = "Days Since August Twenty First 2017", y = "Teams Average Normalized Fatigue")+
  115. theme_bw()
  116. for(gameDay in games$Date)
  117. {
  118. fGraph <- fGraph + geom_vline(xintercept = gameDay, linetype="dotted",
  119. color = "blue", size=1.0)
  120. }
  121. fGraph
  122. plot(density(slidingAverage))
  123. plot(window:dayNum, slidingAverage)