nglod33 5 years ago
parent
commit
7bb5b3dc44
4 changed files with 115 additions and 9 deletions
  1. +63
    -0
      data_preparation/IndividualMetrics.R
  2. +16
    -6
      data_preparation/createWorkSequenceData.R
  3. +18
    -3
      data_preparation/exponentialSmoothing.R
  4. +18
    -0
      data_preparation/readData.R

+ 63
- 0
data_preparation/IndividualMetrics.R View File

@ -1,4 +1,5 @@
source("readData.R") source("readData.R")
source("exponentialSmoothing.R")
library(tidyverse) library(tidyverse)
@ -6,6 +7,9 @@ library(tidyverse)
RPEData <-readNArpeData() RPEData <-readNArpeData()
wellnessData <- readWellnessData() wellnessData <- readWellnessData()
normalizedWellnessData <- readNormalizedMetrics() normalizedWellnessData <- readNormalizedMetrics()
RPEData RPEData
@ -130,17 +134,26 @@ dailyLoadCol[is.na(dailyLoadCol)] <- 0
acuteChronicRatioCol[is.na(acuteChronicRatioCol)] <- 0 acuteChronicRatioCol[is.na(acuteChronicRatioCol)] <- 0
accuteFatigueSliding <- slidingWindowSmooth(acuteChronicRatioCol)
massiveTibble <- tibble(day = dayCol, massiveTibble <- tibble(day = dayCol,
playerID = playerid, playerID = playerid,
DailyLoad = dailyLoadCol, DailyLoad = dailyLoadCol,
DailyLoadSliding = slidingWindowSmooth(DailyLoad),
acuteChronicRatio = acuteChronicRatioCol, acuteChronicRatio = acuteChronicRatioCol,
acuteChronicRatioSliding = slidingWindowSmooth(acuteChronicRatioCol),
trainDuration = trainDuration, trainDuration = trainDuration,
trainDurationSliding = slidingWindowSmooth(trainDuration),
sleepHours = sleepHoursCol, sleepHours = sleepHoursCol,
sleepHoursSliding = slidingWindowSmooth(sleepHours),
fatigue = fatigueRawCol, fatigue = fatigueRawCol,
fatigueSliding = slidingWindowSmooth(fatigue),
sleepQuality = sleepQualityCol, sleepQuality = sleepQualityCol,
soreness = sorenessCol, soreness = sorenessCol,
sorenessSliding = slidingWindowSmooth(soreness),
fatigueNorm = normFatCol, fatigueNorm = normFatCol,
fatigueNormSliding = slidingWindowSmooth(fatigueNorm),
sorenessNorm = normSoreCol, sorenessNorm = normSoreCol,
sleepHoursNorm = normSleepHours, sleepHoursNorm = normSleepHours,
sleepQualityNorm = normSleepQuality, sleepQualityNorm = normSleepQuality,
@ -150,3 +163,53 @@ massiveTibble <- tibble(day = dayCol,
BestOutOfMyselfUnknown = unknownCol) BestOutOfMyselfUnknown = unknownCol)
write.csv(massiveTibble, "cleaned/personal.csv") write.csv(massiveTibble, "cleaned/personal.csv")
ggplot(data = massiveTibble) +
theme(plot.title = element_text(hjust = 0.5)) +
ggtitle("Normalized Soreness Box Plots") +
geom_boxplot(na.rm = T, mapping = aes(y=sorenessNorm, group = playerID), outlier.colour = "red", outlier.shape = 1) +
labs(group = "Player ID", y = "Normalized Soreness Values") +
coord_flip() +
theme_bw()
ggplot(data = massiveTibble) +
theme(plot.title = element_text(hjust = 0.5)) +
ggtitle("Normalized Sleep Quality Box Plots") +
geom_boxplot(na.rm = T, mapping = aes(y=sleepQualityNorm, group = playerID), outlier.colour = "red", outlier.shape = 1) +
labs(group = "Player ID", y = "Normalized Sleep Quality") +
coord_flip() +
theme_bw()
ggplot(data = massiveTibble) +
theme(plot.title = element_text(hjust = 0.5)) +
ggtitle("Soreness Box Plots") +
geom_boxplot(na.rm = T, mapping = aes(y=sleepQuality, group = playerID), outlier.colour = "red", outlier.shape = 1) +
labs(group = "Player ID", y = "Sleep Quality") +
coord_flip() +
theme_bw()
ggplot(data = massiveTibble) +
theme(plot.title = element_text(hjust = 0.5)) +
ggtitle("Team's Percieved Fatigue") +
geom_point(mapping = aes(x=day, y=fatigue)) +
labs(x = "Days Since August First 2017", y = "Teams Fatigue")+
theme_bw()
ggplot(data = massiveTibble) +
theme(plot.title = element_text(hjust = 0.5)) +
ggtitle("Team's Percieved Fatigue") +
geom_point(mapping = aes(x=day, y=sorenessSliding)) +
labs(x = "Days Since August First 2017", y = "Accute Fatugue ")+
theme_bw()
ggplot(data = massiveTibble) +
theme(plot.title = element_text(hjust = 0.5)) +
ggtitle("Team's Percieved Fatigue") +
geom_point(mapping = aes(x=sleepQuality, y=fatigueNorm)) +
labs(x = "Days Since August First 2017", y = "Accute Fatugue ") +
theme_bw()

+ 16
- 6
data_preparation/createWorkSequenceData.R View File

@ -23,13 +23,12 @@ for(day in dayList)
averageWorkLoad <- c(averageWorkLoad, mean(daylyActivities$SessionLoad, na.rm = T)) averageWorkLoad <- c(averageWorkLoad, mean(daylyActivities$SessionLoad, na.rm = T))
workLoad <- c(workLoad, sum(daylyActivities$SessionLoad, na.rm = T)) workLoad <- c(workLoad, sum(daylyActivities$SessionLoad, na.rm = T))
} }
plot(dayList, averageWorkLoad, main="Average Work Load") plot(dayList, averageWorkLoad, main="Average Work Load")
plot(dayList, workLoad, main="Daily Total Work Load") plot(dayList, workLoad, main="Daily Total Work Load")
fatigueFunction <- function(workLoad, index) fatigueFunction <- function(workLoad, index)
{ {
if(index == 1) if(index == 1)
@ -52,8 +51,6 @@ plot(dayList, smoothedFatigue)
fatigueData <- readFatigueSums() fatigueData <- readFatigueSums()
dayNum <- max(fatigueData$TimeSinceAugFirst) dayNum <- max(fatigueData$TimeSinceAugFirst)
@ -79,11 +76,13 @@ for(day in dayList)
plot(dayList, smoothedFatigueData) plot(dayList, smoothedFatigueData)
workTibble <- tibble(day = dayList, totalWork = workLoad,
workTibble <- tibble(day = dayList, totalWork = workLoad,
averageWorkLoad = averageWorkLoad, averageWorkLoad = averageWorkLoad,
smoothedWork = smoothedWork, smoothedWork = smoothedWork,
smoothedFatigueData = smoothedFatigueData) smoothedFatigueData = smoothedFatigueData)
plot(workTibble$totalWork, fatigueData$fatigueSum[-1])
workGraph <- ggplot(data = workTibble) + workGraph <- ggplot(data = workTibble) +
theme(plot.title = element_text(hjust = 0.5)) + theme(plot.title = element_text(hjust = 0.5)) +
ggtitle("Team's Smoothed Work") + ggtitle("Team's Smoothed Work") +
@ -99,6 +98,14 @@ fatGraph <- ggplot(data = workTibble) +
theme_bw() theme_bw()
ggplot(data = workTibble) +
theme(plot.title = element_text(hjust = 0.5)) +
ggtitle("Team's Percieved Fatigue") +
geom_point(mapping = aes(x=smoothedWork, y=smoothedFatigueData)) +
labs(x = "Smoothed Work Per Day", y = "Teams Average Normalized Fatigue")+
theme_bw()
for(gameDay in games$Date) for(gameDay in games$Date)
{ {
fatGraph <- fatGraph + geom_vline(xintercept = gameDay, linetype="dotted", fatGraph <- fatGraph + geom_vline(xintercept = gameDay, linetype="dotted",
@ -106,10 +113,13 @@ for(gameDay in games$Date)
workGraph <- workGraph + geom_vline(xintercept = gameDay, linetype="dotted", workGraph <- workGraph + geom_vline(xintercept = gameDay, linetype="dotted",
color = "blue", size=1.0) color = "blue", size=1.0)
} }
workGraph workGraph
fatGraph fatGraph
write.csv(dataTibble, "cleaned/expSmoothWorkAndFatigueData.csv")
write.csv(workTibble, "cleaned/expSmoothWorkAndFatigueData.csv")

+ 18
- 3
data_preparation/exponentialSmoothing.R View File

@ -6,7 +6,7 @@ fatigueFunction <- function(workLoad, index)
} }
else else
{ {
return(workLoad[index] + 0.7*fatigueFunction(workLoad, index -1))
return(workLoad[index] + (exp(1)^(-1/15))**fatigueFunction(workLoad, index -1))
} }
} }
@ -23,6 +23,21 @@ smoothVector <- function(dataV)
} }
smoothVector(c(1,2,3,4))
plot(1:100, smoothVector(1:100))
slidingWindowSmooth <- function(dataV, windowSize = 7)
{
dataNew <- c()
for(i in 1:windowSize)
{
dataNew <- c(dataNew, mean(dataV[c(1:i)]))
}
for(i in (windowSize + 1):length(dataV))
{
dataNew <- c(dataNew, mean(dataV[(i-7):i]))
}
dataNew
}

+ 18
- 0
data_preparation/readData.R View File

@ -21,3 +21,21 @@ readNArpeData <- function()
{ {
as_tibble(read.csv("./cleaned/time_series_notnormalized_with_continuousNan_rpe.csv")) as_tibble(read.csv("./cleaned/time_series_notnormalized_with_continuousNan_rpe.csv"))
} }
readNormalizedMetrics <- function()
{
as_tibble(read.csv("./cleaned/time_series_normalized_wellness.csv"))
}
readFatigueSums <- function()
{
as_tibble(read.csv("./cleaned/fatigue_total_sum.csv"))
}
readGameRandChanges <- function()
{
as_tibble(read.csv("./cleaned/time_series_days_ranked.csv"))
}

Loading…
Cancel
Save