-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparser_file
97 lines (79 loc) · 2.99 KB
/
parser_file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import pandas as pd
def csv_reader():
#df = pd.read_csv('new_file.csv')
df = pd.read_csv('./uploads/left_leg_athlete_demo.csv')
#splicing for the time data row
splice = None
for i in range(df.shape[0]):
df.fillna(0.0)
#Von homer computer 1 research only files
if 'Tim' in str(df.iloc[i][0]):
splice = i
df = df[splice:]
#right leg focus
right_leg = ['time', 'tib_anterior_rle', 'peroneals_rle', 'med_gastro_rle', 'lat_gastro_rle']
# parses for the first four columns removing unecessary columns
df = df.iloc[:, 0:5]
df = df.set_axis(right_leg, axis='columns', inplace=False)
df = df.reset_index(drop=True)
df = df[1:]
break
#Von homer computer 2
elif 'Tim' in str(df.iloc[i][1]):
#splice columns
splice = i
df = df[splice:]
# removes unwanted columns
df = df.drop(columns=['Subject info', 'Project 1'])
df = df.drop(df.columns[-1], axis=1)
# setting columns labels
right_leg = ['time', 'tib_anterior_rle', 'peroneals_rle', 'med_gastro_rle', 'lat_gastro_rle']
left_leg = ['time', 'tib_anterior_lle', 'peroneals_lle', 'med_gastro_lle', 'lat_gastro_lle']
if 'LT' in df.iloc[0][2]:
df = df.set_axis(left_leg, axis='columns', inplace=False)
else:
df = df.set_axis(right_leg, axis='columns', inplace=False)
df = df.reset_index(drop=True)
df = df[1:]
break
return df
def sum_of_duration(df):
bad,ok,good = 0,0,0
#0 - 33 bad
#33-66 ok
#66 - 100 good
rle,lle = 'rle','lle'
leg_muscles = ['tib_anterior_lle', 'peroneals_lle', 'med_gastro_lle', 'lat_gastro_lle']
sum_duration = {'tib_anterior_lle':[], 'peroneals_lle':[], 'med_gastro_lle':[], 'lat_gastro_lle':[]}
#drop unecessary columns
df=df.drop(['time',], axis=1)
# #Von Homer Athlete File
# if 'Sum of Duration' in df.loc[i][0]:
#normalize entire dataframe trail
df.fillna(0.0)
df = df.astype(float)
df = df.abs() #Von said the absolute variable was fine
#TODO remove when VON Sends normalized files
df = df.clip(lower=0, upper=500)
dfn = ((df-df.min())/(df.max() - df.min())) * 100
#Sum of duration counter
for i in leg_muscles:
# i = abs(float(i))
good,bad,ok = 0,0,0
for index in dfn[i]:
if index > 0 and index < 33:
good = 1 + good
elif index >= 33 and index < 66:
ok = 1 + ok
else:
bad = 1 + bad
# apply percentages to the duration next
list_length = dfn.shape[0]
good = round((good/list_length) * 100)
bad = round((bad/list_length) * 100)
ok = round((ok/list_length) * 100)
sum_duration[i] = [good,ok,bad]
return sum_duration
s = csv_reader()
s = sum_of_duration(s)
print(s)