Skip to content

Commit e5ff9f9

Browse files
committed
har_trees: Initial script for reading data
The values look quite suspicious right now
1 parent 8d9db59 commit e5ff9f9

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

examples/har_trees/read_data.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
3+
import os
4+
5+
import pandas
6+
import numpy
7+
8+
def load_har_record(path, samplerate):
9+
suffix = '.npy'
10+
11+
files = []
12+
13+
for f in os.listdir(path):
14+
if f.endswith(suffix):
15+
p = os.path.join(path, f)
16+
try:
17+
data = numpy.load(p, allow_pickle=True)
18+
except Exception as e:
19+
print(e)
20+
continue
21+
22+
df = pandas.DataFrame(data.T, columns=['x', 'y', 'z'])
23+
t = numpy.arange(0, len(df)) * (1.0/samplerate)
24+
df['time'] = t
25+
df = df.set_index('time')
26+
classname = f.split('_')[1].rstrip(suffix)
27+
28+
files.append(dict(data=df, filename=f, classname=classname))
29+
30+
#print(f, data.shape)
31+
32+
out = pandas.DataFrame.from_records(files)
33+
out = out.set_index('filename')
34+
return out
35+
36+
p = '/home/jon/temp/micropython-test-esptool/har_record'
37+
data = load_har_record(p, samplerate=100)
38+
39+
print(data.head())
40+
print(data.shape)
41+
42+
import plotly.express
43+
44+
for idx, f in data.iterrows():
45+
d = f.data.reset_index()
46+
fig = plotly.express.line(d, x='time', y=['x', 'y', 'z'])
47+
fig.show()

0 commit comments

Comments
 (0)