-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransform_sckel.py
50 lines (39 loc) · 1.28 KB
/
transform_sckel.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
import os
import json
from skeleton_features import all_features, joints
#f = open("pos.txt")
top = ['player', 'created_at']
sensor_pos = ['X', 'Y', 'Z', 'alpha', 'beta', 'gamma']
valid_sensors = ['daq-01', 'daq-02', 'daq-03']
raw_data_path = '/home/ami/cosmin/proiecte/posture-recognition/raw-data-test'
def validJson(m):
if (m['type'] != 'skeleton'):
return False;
elif (m['sensor_id'] not in valid_sensors):
return False
else:
return True
def outputCsvFile(function, infileName, outfileName):
print 'Processing file', infileName
f = open(infileName)
out = open(outfileName, 'w')
for line in f:
if len(line.strip()) > 0:
m = json.loads(line)
if (validJson(m)):
function(m, out)
out.close()
def outputCsvLine(m, out):
for j in joints:
for p in ['X', 'Y', 'Z']:
out.write(str(m['skeleton_3D'][j][p]))
out.write(', ')
out.write('\n')
def outputFeaturesCsvLine(m, out):
features = all_features(m['skeleton_3D'])
for f in features:
out.write(str(f))
out.write(', ')
out.write('\n')
for f in os.listdir(raw_data_path):
outputCsvFile(outputFeaturesCsvLine, raw_data_path + '/' + f, '/tmp/' + f + '.fts')