Ver Fonte

Added back.R and made some changes in ANkle

Rens Zuurbier há 9 anos atrás
pai
commit
03feddf890
3 ficheiros alterados com 109 adições e 17 exclusões
  1. 20 15
      code/ankle.R
  2. 87 0
      code/back.R
  3. 2 2
      code/main.R

+ 20 - 15
code/ankle.R

@@ -1,8 +1,3 @@
-# For loop to add 1.1m to all the data of AnkleLeft.y to determine real height.
-#for (j in 1:(nrow(DATA))) {
-#  DATA$AnkleLeft.y + 1.1
-#}
-
 plot(DATA[patient$WALKING,]$AnkleLeft.y,
      type = "l",
      ylab = "Hoogte",
@@ -13,7 +8,7 @@ par(new=TRUE)
 plot(DATA[patient$WALKING,]$AnkleRight.y,
      type = "l",
      ylab = "Hoogte",
-     col = ifelse(DATA$AnkleRight.y > -1.1, "orange", "purple"),
+     col = ifelse(DATA$AnkleRight.y > -1.1, "blue", "purple"),
      ylim = c(-1.15, -0.9)
 )
 
@@ -22,7 +17,7 @@ meanLine <- mean(DATA[patient$WALKING,]$AnkleLeft.y)
 
 ##-LEFT-##
 #Creates vector which contains the values above the mean height (1e quarter)
-Q1 <- c()
+Q1 <- NULL
 for(i in patient$WALKING){
   if (DATA[i,]$AnkleLeft.y > meanLine){
     Q1 <- c(Q1, DATA[i,]$AnkleLeft.y)
@@ -33,7 +28,7 @@ for(i in patient$WALKING){
 meanQ1 <- mean(Q1)
 
 #Creates vector which containts the values under the mean height value (3e quarter)
-Q3 <- c()
+Q3 <- NULL
 for(i in patient$WALKING){
   if(DATA[i,]$AnkleLeft.y < meanLine){
     Q3 <- c(Q3, DATA[i,]$AnkleLeft.y)
@@ -48,7 +43,7 @@ DiffAnkleLeft <- abs(meanQ3 - meanQ1)
 
 ##-RIGHT-##
 #Creates vector which contains the values above the mean height (1e quarter)
-Q1 <- C()
+Q1 <- NULL
 for(i in patient$WALKING){
   if(DATA[i,]$AnkleRight.y > meanLine){
     Q1 <- c(Q1, DATA[i,]$AnkleRight.y)
@@ -59,7 +54,7 @@ for(i in patient$WALKING){
 meanQ1 <- mean(Q1)
 
 #Creates vector which contains the values above the mean height (3e quarter)
-Q3 <- c()
+Q3 <- NULL
 for(i in patient$WALKING){
   if(DATA[i,]$AnkleRight.y < meanLine){
     Q3 <- c(Q3, DATA[i,]$AnkleRight.y)
@@ -76,14 +71,24 @@ DiffAnkleRight
 
 if(DiffAnkleLeft < 0.05 || DiffAnkleRight < 0.05){
   print("The patient barely lift his foot up, there is a potentional falling risk")
-}
-else {
+}else {
   print("The patient walks just fine according his ankles")
-  }
+}
 
 #Creates Smoothline of the left ankle
 SmoothAnkleLeft <- smooth.spline(DATA[patient$WALKING,]$AnkleLeft.y, spar=0.35)
-lines(SmoothAnkleLeft, col = "green")
+plot(SmoothAnkleLeft, col = "green",
+     type = "l",
+     ylim = c(-1.17, -0.9),
+     ylab = "Hoogte",
+     xlab = "Index")
 
+
+par(new=TRUE)
 SmoothAnkleRight <- smooth.spline(DATA[patient$WALKING,]$AnkleRight.y, spar=0.35)
-lines(SmoothAnkleRight, col = "purple")
+plot(SmoothAnkleRight, col = "blue",
+     type = "l",
+     ylim = c(-1.17, -0.9),
+     ylab = "Hoogte",
+     xlab = "Index")
+

+ 87 - 0
code/back.R

@@ -0,0 +1,87 @@
+library(dplyr)
+
+path = file(file.choose())
+file = read.csv(path, stringsAsFactors = FALSE, header = T, sep = ",")
+
+axis = data.frame(
+  axis = character(),
+  stringsAsFactors = FALSE
+)
+
+xAxis = "X"
+yAxis = "Y"
+zAxis = "Z"
+
+x = 1
+y = 2
+z = 3
+
+for (i in 1:(nrow(file))) {
+  if (i / z == 1) {
+    z = i + 3
+    axis[i,1] = zAxis
+  }else if(i / y == 1){
+    y = i + 3
+    axis[i,1] = yAxis
+  }else if(i / x == 1){
+    x = i + 3
+    axis[i,1] = xAxis
+  }
+}
+
+fileWithAxis = cbind(file, axis)
+angleBody = select(fileWithAxis,Time, axis,SpineBase, Head)
+rm(xAxis,yAxis,zAxis, x, y , z, file,axis, fileWithAxis)
+
+valueBetweenTwoValue = data.frame(
+  Time = integer(),
+  Difference = double(),
+  stringsAsFactors = FALSE
+)
+
+for (i in 1:nrow(angleBody)) {
+  valueBetweenTwoValue[i,1] = angleBody[i,1]
+  valueBetweenTwoValue[i,2] = angleBody[i,3] - angleBody[i,4]
+}
+
+valueBetweenTwoValue = abs(valueBetweenTwoValue)
+
+calculateAngle = data.frame(
+  Time = integer(),
+  Angle = double(),
+  stringsAsFactors = FALSE
+)
+
+doCalculateAngle = function(x){
+  O = x[1]
+  A = x[3]
+  S = sqrt((O^2)+(A^2))
+  newA = x[2]
+  radian = atan(S/newA)
+  degrees = radian*(180/pi)
+  return(degrees)
+}
+
+initialTime = valueBetweenTwoValue[1,1]
+
+count = 1;
+timeDivision = 10^7
+
+for(i in seq(from=1, to=nrow(valueBetweenTwoValue), by=3)){
+  calculateAngle[count,1] = (valueBetweenTwoValue[i,1] - initialTime)/timeDivision
+  vector = valueBetweenTwoValue$Difference[i:(i+2)]
+  calculateAngle[count,2] = doCalculateAngle(vector)
+  count = count + 1
+}
+
+plot(calculateAngle$Time,calculateAngle$Angle, xlab = "Second", ylab = "Degrees", main = "Angele of body", type = "l")
+
+View(calculateAngle)
+
+healthyPercentage = 20
+
+if(mean(calculateAngle[, 2]) > healthyPercentage){
+  print("High risk")
+}else{
+  print("Low risk")
+}

+ 2 - 2
code/main.R

@@ -48,5 +48,5 @@ Console.NewLine("DATA PREPERATION DONE")
 source("code/state.R")
 
 source("code/head.R")
-#source("code/ankle.R")
-#source("code/back.R")
+source("code/ankle.R")
+source("code/back.R")