-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaverage_trimmed_output.py
78 lines (58 loc) · 3.81 KB
/
average_trimmed_output.py
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
import csv
import sys
from decimal import Decimal
from create_classification_array import average_values
import numpy
def isLast(itr):
old = itr.next()
for new in itr:
yield False, old
old = new
yield True, old
if len(sys.argv) !=2:
print("a csv file for import is needed as command line argument")
sys.exit()
filename = str(sys.argv[1])
filename_output_csv = "averaged_output_NaN_Removed/"+filename[15:]
d= ["CH1_X1","CH1_Y1","CH1_Z1","CH2_X2","CH2_Y2","CH2_Z2","CH3_X3","CH3_Y3","CH3_Z3","FH1_X4","FH1_Y4","FH1_Z4","FH2_X5","FH2_Y5","FH2_Z5","FH3_X6","FH3_Y6","FH3_Z6","LC1_X7","LC1_Y7","LC1_Z7","LC2_X8","LC2_Y8","LC2_Z8","LC3_X9","LC3_Y9","LC3_Z9","LC4_X10","LC4_Y10","LC4_Z10","LC5_X11","LC5_Y11","LC5_Z11","LC6_X12","LC6_Y12","LC6_Z12","LC7_X13","LC7_Y13","LC7_Z13","LC8_X14","LC8_Y14","LC8_Z14","RC1_X15","RC1_Y15","RC1_Z15","RC2_X16","RC2_Y16","RC2_Z16","RC3_X17","RC3_Y17","RC3_Z17","RC4_X18","RC4_Y18","RC4_Z18","RC5_X19","RC5_Y19","RC5_Z19","RC6_X20","RC6_Y20","RC6_Z20","RC7_X21","RC7_Y21","RC7_Z21","RC8_X22","RC8_Y22","RC8_Z22","LLID_X23","LLID_Y23","LLID_Z23","RLID_X24","RLID_Y24","RLID_Z24","MH_X25","MH_Y25","MH_Z25","MNOSE_X26","MNOSE_Y26","MNOSE_Z26","LNSTRL_X27","LNSTRL_Y27","LNSTRL_Z27","TNOSE_X28","TNOSE_Y28","TNOSE_Z28","RNSTRL_X29","RNSTRL_Y29","RNSTRL_Z29","LBM0_X30","LBM0_Y30","LBM0_Z30","LBM1_X31","LBM1_Y31","LBM1_Z31","LBM2_X32","LBM2_Y32","LBM2_Z32","LBM3_X33","LBM3_Y33","LBM3_Z33","RBM0_X34","RBM0_Y34","RBM0_Z34","RBM1_X35","RBM1_Y35","RBM1_Z35","RBM2_X36","RBM2_Y36","RBM2_Z36","RBM3_X37","RBM3_Y37","RBM3_Z37","LBRO1_X38","LBRO1_Y38","LBRO1_Z38","LBRO2_X39","LBRO2_Y39","LBRO2_Z39","LBRO3_X40","LBRO3_Y40","LBRO3_Z40","LBRO4_X41","LBRO4_Y41","LBRO4_Z41","RBRO1_X42","RBRO1_Y42","RBRO1_Z42","RBRO2_X43","RBRO2_Y43","RBRO2_Z43","RBRO3_X44","RBRO3_Y44","RBRO3_Z44","RBRO4_X45","RBRO4_Y45","RBRO4_Z45","Mou1_X46","Mou1_Y46","Mou1_Z46","Mou2_X47","Mou2_Y47","Mou2_Z47","Mou3_X48","Mou3_Y48","Mou3_Z48","Mou4_X49","Mou4_Y49","Mou4_Z49","Mou5_X50","Mou5_Y50","Mou5_Z50","Mou6_X51","Mou6_Y51","Mou6_Z51","Mou7_X52","Mou7_Y52","Mou7_Z52","Mou8_X53","Mou8_Y53","Mou8_Z53","LHD_X60","LHD_Y60","LHD_Z60","RHD_X61","RHD_Y61","RHD_Z61","video_name","Class"]
with open(filename_output_csv, 'w') as f:
writer = csv.writer(f)
writer.writerow(d)
f.close()
values = [Decimal(0)] * 167
placeHolder = [Decimal(0)] * 167
count = Decimal(0)
video_name = "null"
with open(filename, 'r') as inp, open(filename_output_csv, 'a') as out:
writer = csv.writer(out)
inp.readline()
for row in csv.reader(inp):
if video_name != row[165] and count!= Decimal(0):
print("evaluating chunk : " + video_name)
values=average_values(values,count)
writer.writerow(values)
video_name = row[165]
values = [Decimal(0)] * 167
values[165] = video_name
values[166] = row[166]
count= Decimal(0)
for i in range(len(row)-2): # -2 -> index 165 and 166 are video_name and class attributes
try:
if row[i] != "NaN":
values[i] += Decimal(row[i])
placeHolder[i] = Decimal(row[i])
else:
values[i] += placeHolder[i]
except TypeError:
print ("Error -- ({}) Column({}) could not be converted to numpy.float!".format(row[i], placeHolder[i]) )
count = count +Decimal(1)
video_name= row[165]
values[165]= row[165]
values[166] = row[166]
inp.close()
with open(filename_output_csv, 'a') as out:
writer = csv.writer(out)
print("evaluating chunk : " + video_name)
values=average_values(values,count)
writer.writerow(values)
out.close()