From 48cd21b6d0d4829b47ee4234fd2921cbbdb62e0e Mon Sep 17 00:00:00 2001 From: jrtechs Date: Sat, 30 Mar 2019 23:34:16 -0400 Subject: [PATCH] Added r scripts for generating individual metrics to the git repository. --- data_preparation/IndividualMetrics.R | 63 +++++++++++++++++++++++ data_preparation/createWorkSequenceData.R | 22 +++++--- data_preparation/exponentialSmoothing.R | 21 ++++++-- data_preparation/readData.R | 18 +++++++ 4 files changed, 115 insertions(+), 9 deletions(-) diff --git a/data_preparation/IndividualMetrics.R b/data_preparation/IndividualMetrics.R index cfa8f78..f5c77ab 100644 --- a/data_preparation/IndividualMetrics.R +++ b/data_preparation/IndividualMetrics.R @@ -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() diff --git a/data_preparation/createWorkSequenceData.R b/data_preparation/createWorkSequenceData.R index 21cb979..b4b9c63 100644 --- a/data_preparation/createWorkSequenceData.R +++ b/data_preparation/createWorkSequenceData.R @@ -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") diff --git a/data_preparation/exponentialSmoothing.R b/data_preparation/exponentialSmoothing.R index b4ad16b..4178ba6 100644 --- a/data_preparation/exponentialSmoothing.R +++ b/data_preparation/exponentialSmoothing.R @@ -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)) \ No newline at end of file +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 +} \ No newline at end of file diff --git a/data_preparation/readData.R b/data_preparation/readData.R index f26b375..74bb97a 100644 --- a/data_preparation/readData.R +++ b/data_preparation/readData.R @@ -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")) +}