Browse Source

Added r scripts for generating individual metrics to the git repository.

master
Jeffery Russell 5 years ago
parent
commit
48cd21b6d0
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("exponentialSmoothing.R")
library(tidyverse)
@ -6,6 +7,9 @@ library(tidyverse)
RPEData <-readNArpeData()
wellnessData <- readWellnessData()
normalizedWellnessData <- readNormalizedMetrics()
RPEData
@ -130,17 +134,26 @@ dailyLoadCol[is.na(dailyLoadCol)] <- 0
acuteChronicRatioCol[is.na(acuteChronicRatioCol)] <- 0
accuteFatigueSliding <- slidingWindowSmooth(acuteChronicRatioCol)
massiveTibble <- tibble(day = dayCol,
playerID = playerid,
DailyLoad = dailyLoadCol,
DailyLoadSliding = slidingWindowSmooth(DailyLoad),
acuteChronicRatio = acuteChronicRatioCol,
acuteChronicRatioSliding = slidingWindowSmooth(acuteChronicRatioCol),
trainDuration = trainDuration,
trainDurationSliding = slidingWindowSmooth(trainDuration),
sleepHours = sleepHoursCol,
sleepHoursSliding = slidingWindowSmooth(sleepHours),
fatigue = fatigueRawCol,
fatigueSliding = slidingWindowSmooth(fatigue),
sleepQuality = sleepQualityCol,
soreness = sorenessCol,
sorenessSliding = slidingWindowSmooth(soreness),
fatigueNorm = normFatCol,
fatigueNormSliding = slidingWindowSmooth(fatigueNorm),
sorenessNorm = normSoreCol,
sleepHoursNorm = normSleepHours,
sleepQualityNorm = normSleepQuality,
@ -150,3 +163,53 @@ massiveTibble <- tibble(day = dayCol,
BestOutOfMyselfUnknown = unknownCol)
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))
workLoad <- c(workLoad, sum(daylyActivities$SessionLoad, na.rm = T))
}
plot(dayList, averageWorkLoad, main="Average Work Load")
plot(dayList, workLoad, main="Daily Total Work Load")
fatigueFunction <- function(workLoad, index)
{
if(index == 1)
@ -52,8 +51,6 @@ plot(dayList, smoothedFatigue)
fatigueData <- readFatigueSums()
dayNum <- max(fatigueData$TimeSinceAugFirst)
@ -79,11 +76,13 @@ for(day in dayList)
plot(dayList, smoothedFatigueData)
workTibble <- tibble(day = dayList, totalWork = workLoad,
workTibble <- tibble(day = dayList, totalWork = workLoad,
averageWorkLoad = averageWorkLoad,
smoothedWork = smoothedWork,
smoothedFatigueData = smoothedFatigueData)
plot(workTibble$totalWork, fatigueData$fatigueSum[-1])
workGraph <- ggplot(data = workTibble) +
theme(plot.title = element_text(hjust = 0.5)) +
ggtitle("Team's Smoothed Work") +
@ -99,6 +98,14 @@ fatGraph <- ggplot(data = workTibble) +
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)
{
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",
color = "blue", size=1.0)
}
workGraph
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
{
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"))
}
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