Bladeren bron

Added function file and enchanged fall calc on steps

Deben Oldert 9 jaren geleden
bovenliggende
commit
924c4114ce
4 gewijzigde bestanden met toevoegingen van 24 en 3 verwijderingen
  1. 17 0
      code/functions.R
  2. 1 1
      code/head.R
  3. 2 2
      code/main.R
  4. 4 0
      code/state.R

+ 17 - 0
code/functions.R

@@ -0,0 +1,17 @@
+# FUNCTION FILE
+#
+# THIS FILE CONTAINS ALL THE FUNCTIONS THAT MIGTH BE USED GLOBALLY
+
+
+# specify_decimal. Set how many decimals an number should have
+#   x => numeric
+#   k => integer
+#
+# Returns => numeric with {k} decimals
+specify_decimal <- function(x, k) format(round(x, k), nsmall=k)
+
+# consistent. Check if a vactor contains all values between the start and the end
+#   a => vector containing integers
+#
+# Returns => bool, true contains all values/ false not
+consistent <- function(a) suppressWarnings(all(a == min(a):max(a)))

+ 1 - 1
code/head.R

@@ -13,7 +13,7 @@ for(i in 1:nrow(DATA)){
 
 
 #Check if patient is walking fast enough
-differ_ <- 0.1
+differ_ <- 0.5
 
 # Algorithm to calculate walk phase
 f <- function(x) (sin((x - 5) / 2.7) / 30) + WALKBASE

+ 2 - 2
code/main.R

@@ -1,9 +1,9 @@
 suppressMessages(library(dplyr))
 suppressMessages(library(stringr))
 
-WD <- getwd()
+source("code/functions.R")
 
-specify_decimal <- function(x, k) format(round(x, k), nsmall=k)
+WD <- getwd()
 
 CSV <- file.choose()
 

+ 4 - 0
code/state.R

@@ -67,6 +67,10 @@ DATA$index = as.integer(rownames(DATA))
 
 WALKING <- strtoi(rownames(DATA[DATA$state==1,]))
 
+if(!consistent(WALKING)){
+  stop("Patient not consistently walking, (Maybe he/she fell). Anyway, we can't analyse this data", call. = FALSE)
+}
+
 # CALCULATE STRAIGHT WALKING PATH
 yPrediction <-lm(Head.y ~ I(index^2)+index, data=DATA[min(WALKING):max(WALKING),])
 yPredicted <- as.vector(predict(yPrediction, data.frame(index=WALKING)))