-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_holdout_dataset_without_average.py
69 lines (46 loc) · 3.57 KB
/
create_holdout_dataset_without_average.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
import csv
import sys
import os
if len(sys.argv) !=2:
print("this script takes a batch size as command line argument ")
sys.exit()
batch_size = int(sys.argv[1])
if batch_size % 2 != 0:
print("batch size has to be even ")
sys.exit()
filename_training_csv = "Holdout_output/training210.csv"
filename_testing_csv = "Holdout_output/testing210.csv"
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_training_csv, 'w') as f:
writer = csv.writer(f)
writer.writerow(d)
f.close()
with open(filename_testing_csv, 'w') as f:
writer = csv.writer(f)
writer.writerow(d)
f.close()
directory = os.fsencode("output/")
batch = batch_size
half_batch = batch_size/2
for file in sorted(os.listdir(directory)):
filename = os.fsdecode(file) #we process the singe csv file
if filename.endswith(".csv"):
print ("processing file : " + filename)
with open("output/" + filename, 'r') as inp, open(filename_training_csv, 'a') as train_csv,open(filename_testing_csv,'a') as test_csv:
train_writer = csv.writer(train_csv)
test_writer = csv.writer(test_csv)
inp.readline() #remove attributes labels
for row in csv.reader(inp):
if len(row) >167 and (row[168]== 'hap' or row[168]== 'sad' or row[168]== 'neu' or row[168]== 'ang') :
if batch == batch_size:
train_writer.writerow(row[2:-3])
batch = 0
#print("batch setted to 0")
elif batch == half_batch :
test_writer.writerow(row[2:-3])
batch+=1
else:
#print("incrementing batch")
batch+=1
else:
pass