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.

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