Skip to content

Commit

Permalink
Provide option to save raw TotTag files, defaulting to no
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgecrw committed Nov 15, 2023
1 parent 11223ff commit e39b158
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion software/management/dashboard/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def plot_data(title, x_axis_label, y_axis_label, x_axis_data, y_axis_data):
axis.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
axis.xaxis.set_label_text(x_axis_label)
axis.yaxis.set_label_text(y_axis_label)
axis.figure.autofmt_xdate(rotation=45, bottom=0.3)
plt.plot(x_axis_data, y_axis_data)
plt.show()

Expand All @@ -34,7 +35,7 @@ def get_voltage_time_series(data, tottag_label):
plot_data('Battery Voltage for {}'.format(tottag_label), 'Date and Time', 'Voltage (mV)', timestamps, voltages)

def get_motion_time_series(data, tottag_label):
motions = data.loc['m'].fillna(method='pad')
motions = data.loc['m'].ffill()
timestamps = mdates.date2num([datetime.fromtimestamp(ts) for ts in motions.keys()])
plot_data('Motion Status for {}'.format(tottag_label), 'Date and Time', 'Motion Status', timestamps, motions)

Expand Down
7 changes: 4 additions & 3 deletions software/management/dashboard/tottag.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,16 @@ def unpack_experiment_details(data):
'labels': experiment_struct[(6+6*MAX_NUM_DEVICES):],
}

def process_tottag_data(from_uid, storage_directory, details, data):
def process_tottag_data(from_uid, storage_directory, details, data, save_raw_file=False):
uid_to_labels = defaultdict(lambda: 'Unknown')
for i in range(details['num_devices']):
label = details['labels'][i].decode().rstrip('\x00')
uid_to_labels[int(details['uids'][i][0])] = label if label else details['uids'][i][0]
i = 0
log_data = defaultdict(dict)
with open(os.path.join(storage_directory, uid_to_labels[from_uid] + '.ttg'), 'wb') as file:
file.write(data)
if save_raw_file:
with open(os.path.join(storage_directory, uid_to_labels[from_uid] + '.ttg'), 'wb') as file:
file.write(data)
while i < len(data):
timestamp = struct.unpack('<I', data[i+1:i+5])[0]
if data[i] == STORAGE_TYPE_VOLTAGE:
Expand Down

0 comments on commit e39b158

Please sign in to comment.