-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.py
139 lines (91 loc) · 3.18 KB
/
export.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import sys
from pathlib import Path
import json
import sqlite3
import numpy as np
import h5py
from slugify import slugify
from lib.pparser import emRadParser
config_file = Path('config.json')
if config_file.exists():
config = json.load(open('config.json', 'r'))
else:
config = dict()
json.dump(config, open('config.json', 'w+'))
if not config.get('DBFilename'):
print("Error: DBFile not Configured")
sys.exit()
db_file = Path(config.get('DBFilename'))
print (config.get('DBFilename'))
if not db_file.exists():
print("Error: DBFile not Found")
sys.exit()
parser = emRadParser()
connection = sqlite3.connect(config.get('DBFilename'), check_same_thread=False)
c = connection.cursor()
c.execute("SELECT rowid, * FROM measurements WHERE processed = 0")
rows = c.fetchall()
for row in rows:
rowid = row[0]
measurement_id = row[1]
comment = row[2]
sensor_id = int(row[3])
start = row[4]
stop = row[5]
print("Got Measurement ID:" , measurement_id)
series0 = []
series1 = []
series2 = []
series3 = []
c.execute("SELECT * FROM packets WHERE sensor_id = ? and timestamp BETWEEN ? and ?", (sensor_id*4, start, stop))
packets = c.fetchall()
for packet in packets:
series0.append(parser.parse(packet[5]))
try:
series0 = np.concatenate(series0)
except:
series0 = np.array([])
c.execute("SELECT * FROM packets WHERE sensor_id = ? and timestamp BETWEEN ? and ?", (sensor_id*4+1, start, stop))
packets = c.fetchall()
for packet in packets:
series1.append(parser.parse(packet[5]))
try:
series1 = np.concatenate(series1)
except:
series1 = np.array([])
c.execute("SELECT * FROM packets WHERE sensor_id = ? and timestamp BETWEEN ? and ?", (sensor_id*4+2, start, stop))
packets = c.fetchall()
for packet in packets:
series2.append(parser.parse(packet[5]))
try:
series2 = np.concatenate(series2)
except:
series2 = np.array([])
c.execute("SELECT * FROM packets WHERE sensor_id = ? and timestamp BETWEEN ? and ?", (sensor_id*4+3, start, stop))
packets = c.fetchall()
for packet in packets:
series3.append(parser.parse(packet[5]))
try:
series3 = np.concatenate(series3)
except:
series3 = np.array([])
filename = "data_" + slugify(measurement_id) + ".h5"
path = Path(filename)
if path.exists():
print("File already exist, export Skipped")
else:
hf = h5py.File(filename, 'w')
g = hf.create_group('Radar')
g.attrs["measurement_id"] = measurement_id
g.attrs["comment"] = comment
g.attrs["sensor_id"] = sensor_id
g.attrs["start"] = start
g.attrs["stop"] = stop
g.create_dataset('rad1', data=series0)
g.create_dataset('rad2', data=series1)
g.create_dataset('rad3', data=series2)
g.create_dataset('rad4', data=series3)
hf.close()
c.execute("UPDATE measurements SET processed = 1 WHERE rowid = ?", (rowid,))
connection.commit()
connection.close()