-
Notifications
You must be signed in to change notification settings - Fork 2
/
handle_data.py
47 lines (41 loc) · 1.15 KB
/
handle_data.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
#from numpy import genfromtxt
#data = genfromtxt('raw.csv',delimiter
import numpy as np
def isfloat(value):
try:
float(value)
return True
except ValueError:
return False
def lengthoffile(filepath):
num_lines = sum(1 for line in open(filepath))
return num_lines
def getpatid(filepath):
count = 0
with open(filepath, "r") as filestream:
for line in filestream:
if(count>1):
pat_id = line.split(",")[3]
break
return pat_id
store = []
#This is the name you change
filepath = 'raw.csv'
#length of file
lenoffil = lengthoffile(filepath)
#tsUnixNano, accel_x,accel_y,accel_z,gyro_x,gyro_y,gyro_z,ir,red,ir_filt,red_filt
idx = [2]+list(range(11,21))
#tsUnixNano, accel_x,accel_y,accel_z,gyro_x,gyro_y,gyro_z,ir,red,ir_filt,red_filt
#idx = [2]+list(range(12,18))
f = open(filepath, "r")
for i,line in enumerate(f):
currentline = line[:-1].split(",")
if(i == 0):
names = [currentline[i] for i in idx]
else:
store.append([float(currentline[i]) if isfloat(currentline[i]) else np.nan for i in idx])
print("{} %\r".format(round((i/lenoffil)*100,2)), end = '')
f.close()
out = np.array(store)
np.save("data", out)
np.save("data_names", names)