-
Notifications
You must be signed in to change notification settings - Fork 2
/
data_recorder.py
44 lines (34 loc) · 1.13 KB
/
data_recorder.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
import pickle
import datetime
import os
import pandas as pd
class DataRecorder:
"""Records movement data and saves to file"""
def __init__(self):
self.data = []
def reset(self):
self.data = []
def record(self, timestep, trial_number, current_position, target_position, online, decodername=None):
entry = {
"timestep": timestep,
"trial_number": trial_number,
"current_position": current_position,
"target_position": target_position,
"online": online,
"decodername": decodername,
}
self.data.append(entry)
def save_to_file(self):
if len(self.data) < 1:
print("no data - failed to save")
return
# convert to dataframe
df = pd.DataFrame(self.data)
# save to the data folder
datestr = datetime.datetime.now().strftime("%Y%m%d_%H%M")
fname = f"dataset_{datestr}.pkl"
fpath = os.path.join("data", "movedata", fname)
with open(fpath, "wb") as f:
pickle.dump(df, f)
print(f"Saved data to {fpath}")
self.reset()