From e39b158a4a87f8f7413cb554ec1827a79ebd464d Mon Sep 17 00:00:00 2001 From: Will Hedgecock Date: Wed, 15 Nov 2023 15:50:07 -0600 Subject: [PATCH] Provide option to save raw TotTag files, defaulting to no --- software/management/dashboard/processing.py | 3 ++- software/management/dashboard/tottag.py | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/software/management/dashboard/processing.py b/software/management/dashboard/processing.py index de2eb57e..4d438a60 100644 --- a/software/management/dashboard/processing.py +++ b/software/management/dashboard/processing.py @@ -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() @@ -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) diff --git a/software/management/dashboard/tottag.py b/software/management/dashboard/tottag.py index a040284f..62702c82 100644 --- a/software/management/dashboard/tottag.py +++ b/software/management/dashboard/tottag.py @@ -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('