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.

117 lines
2.8 KiB

  1. source("readData.R")
  2. library(tidyverse)
  3. RPEData <-readNArpeData()
  4. games <- readGameRandChanges
  5. numDays <- max(RPEData$TimeSinceAugFirst)
  6. dayList <- 0:numDays
  7. workLoad <- c()
  8. averageWorkLoad <- c()
  9. for(day in dayList)
  10. {
  11. daylyActivities <- subset(RPEData, TimeSinceAugFirst == day)
  12. cat("day: ", day, "\n",sep="")
  13. cat("Activity count:", length(daylyActivities$DailyLoad), "\n", sep="")
  14. averageWorkLoad <- c(averageWorkLoad, mean(daylyActivities$SessionLoad, na.rm = T))
  15. workLoad <- c(workLoad, sum(daylyActivities$SessionLoad, na.rm = T))
  16. }
  17. fatigueFunction <- function(workLoad, index)
  18. {
  19. if(index == 1)
  20. {
  21. return(workLoad[1])
  22. }
  23. else
  24. {
  25. return(workLoad[index] + (exp(1)^(-1/15))*fatigueFunction(workLoad, index -1))
  26. }
  27. }
  28. smoothedWork <- c()
  29. for(day in dayList)
  30. {
  31. smoothedWork <- c(smoothedWork, fatigueFunction(workLoad, day + 1))
  32. }
  33. fatigueData <- readFatigueSums()
  34. dayNum <- max(fatigueData$TimeSinceAugFirst)
  35. dayList <- 0:dayNum
  36. slidingAverage <- c()
  37. window <- 21 - 1
  38. for(day in window:dayNum)
  39. {
  40. windowAverage <- mean(fatigueData$fatigueSum[c((day-window):day)], na.rm = T)
  41. slidingAverage <- c(slidingAverage, windowAverage)
  42. }
  43. smoothedFatigueData <- c()
  44. for(day in dayList)
  45. {
  46. smoothedFatigueData <- c(smoothedFatigueData, fatigueFunction(fatigueData$fatigueSum, day + 1))
  47. }
  48. plot(dayList, smoothedFatigueData)
  49. workTibble <- tibble(day = dayList, totalWork = workLoad,
  50. averageWorkLoad = averageWorkLoad,
  51. smoothedWork = smoothedWork,
  52. smoothedFatigueData = smoothedFatigueData)
  53. plot(workTibble$totalWork, fatigueData$fatigueSum[-1])
  54. workGraph <- ggplot(data = workTibble) +
  55. theme(plot.title = element_text(hjust = 0.5)) +
  56. ggtitle("Team's Smoothed Work") +
  57. geom_point(mapping = aes(x=day, y=smoothedWork)) +
  58. labs(x = "Days Since August First 2017", y = "Teams Training Work")+
  59. theme_bw()
  60. fatGraph <- ggplot(data = workTibble) +
  61. theme(plot.title = element_text(hjust = 0.5)) +
  62. ggtitle("Team's Percieved Fatigue") +
  63. geom_point(mapping = aes(x=day, y=smoothedFatigueData)) +
  64. labs(x = "Days Since August First 2017", y = "Teams Average Normalized Fatigue")+
  65. theme_bw()
  66. ggplot(data = workTibble) +
  67. theme(plot.title = element_text(hjust = 0.5)) +
  68. ggtitle("Team's Percieved Fatigue") +
  69. geom_point(mapping = aes(x=smoothedWork, y=smoothedFatigueData)) +
  70. labs(x = "Smoothed Work Per Day", y = "Teams Average Normalized Fatigue")+
  71. theme_bw()
  72. for(gameDay in games$Date)
  73. {
  74. fatGraph <- fatGraph + geom_vline(xintercept = gameDay, linetype="dotted",
  75. color = "blue", size=1.0)
  76. workGraph <- workGraph + geom_vline(xintercept = gameDay, linetype="dotted",
  77. color = "blue", size=1.0)
  78. }
  79. workGraph
  80. fatGraph