Skip to content
Snippets Groups Projects
Commit 985cf7fa authored by dy1g18's avatar dy1g18
Browse files

python file to extrapolate data

parent 30e85c01
No related branches found
No related tags found
No related merge requests found
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
import numpy as np
import os
import glob
accuracy = glob.glob('C:\\Users\\ASUS-CORE-i7\\Desktop\\data\\accuracy\\*.txt')
motion = glob.glob('C:\\Users\\ASUS-CORE-i7\\Desktop\\data\\motion\\*.txt')
xs,ys,heads,arms,yss = [],[],[],[],[]
fig,axs = plt.subplots(2)
def read_accuracy():
for x in accuracy:
if not os.path.isfile(x):
print("File does not exist")
else:
with open(x) as f:
content = f.readlines()
arm_av = [x.split()[0] for x in content]
neck_av = [x.split()[1] for x in content]
average = sum(map(int, arm_av))/len(arm_av)
ys.append(average)
average = sum(map(int, neck_av))/len(neck_av)
yss.append(average)
xs.append(x.split("_")[1][0:-4])
def read_motion():
for x in motion:
if not os.path.isfile(x):
print("File does not exist")
else:
with open(x) as f:
content = f.readlines()
heads.append(content[0].split()[0])
arms.append(content[0].split()[1])
def extrapolate(x1,y,y1,y2,x2):
return x1 + ((y-y1)/(y2-y1)*(x2-x1))
def create_accuracy_graph():
read_accuracy()
arms_xs = [1,extrapolate(1,80,int(ys[0]),int(ys[-1]),int(xs[-1]))]
neck_xs = [1,extrapolate(1,80,int(yss[0]),int(ys[-1]),int(xs[-1]))]
axs[0].plot(list(map(int,arms_xs)), [int(ys[0]),80], color='g',label='Acc of arms')
axs[0].plot(list(map(int,neck_xs)), [int(yss[0]),80], color='r',label='Acc of neck')
axs[0].set_xlabel('Sessions')
axs[0].set_ylabel('Accuracy of Motion (%)')
axs[0].set_title('Accuracy of limb movement over time')
axs[0].legend()
def create_rom_graph():
read_motion()
arms_xs = [1,extrapolate(1,160,int(arms[0]),int(arms[-1]),int(xs[-1]))]
neck_xs = [1,extrapolate(1,75,int(heads[0]),int(heads[-1]),int(xs[-1]))]
axs[1].plot(list(map(int,arms_xs)), [int(arms[0]),160], color='g',label='Arm ROM')
axs[1].plot(list(map(int,neck_xs)), [int(heads[0]),75], color='r',label='Neck ROM')
axs[1].legend()
axs[1].set_xlabel('Sessions')
axs[1].set_ylabel('Degrees')
axs[1].set_title('Range Of Motion')
create_accuracy_graph()
create_rom_graph()
plt.show()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment