From 826ab3d49d351afab34a0bdfe5557f7734a44013 Mon Sep 17 00:00:00 2001 From: umarkhan135 Date: Mon, 10 Mar 2025 16:59:33 -0400 Subject: [PATCH 1/2] visualizing all sensors --- vis_all.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 vis_all.py diff --git a/vis_all.py b/vis_all.py new file mode 100644 index 0000000..10f554f --- /dev/null +++ b/vis_all.py @@ -0,0 +1,53 @@ +import sys +import json +import matplotlib.pyplot as plt +from collections import defaultdict +from datetime import datetime + +def main(): + if len(sys.argv) != 2: + print(f"Usage: python {sys.argv[0]} ") + sys.exit(1) + + file_path = sys.argv[1] + + # Dictionary to store only the roll data (plus timestamps) for each sensor + sensor_data = defaultdict(lambda: {"timestamp": [], "roll": []}) + + with open(file_path, 'r') as file: + for line in file: + line = line.strip() + if not line: + continue + record = json.loads(line) + + timestamp = datetime.strptime(record['timestamp'], "%Y-%m-%d %H:%M:%S.%f") + + for sensor in record['sensors']: + loc = sensor['location'] + sensor_data[loc]['timestamp'].append(timestamp) + sensor_data[loc]['roll'].append(sensor['euler']['roll']) + + # You can adjust this order or remove sensors if needed + sensor_order = [ + "Left Knee", "Left Ankle", + "Right Ankle", "Right Hip", + "Right Knee", "Left Hip" + ] + + # Plot all sensors' roll data on a single plot + plt.figure(figsize=(10, 6)) + for loc in sensor_order: + plt.plot(sensor_data[loc]['timestamp'], sensor_data[loc]['roll'], label=loc) + + plt.title("Roll Data Over Time for Each Sensor") + plt.xlabel("Time") + plt.ylabel("Roll (degrees)") + plt.legend() + plt.grid(True) + plt.tight_layout() + plt.show() + +if __name__ == "__main__": + main() + From bdf392428456432080899b307e4088f2e313ca25 Mon Sep 17 00:00:00 2001 From: umarkhan135 Date: Mon, 10 Mar 2025 17:34:04 -0400 Subject: [PATCH 2/2] subsample data to get a general understanding of what data looks like, for more precise depiction use other script --- vis_all.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/vis_all.py b/vis_all.py index 10f554f..25a09d1 100644 --- a/vis_all.py +++ b/vis_all.py @@ -28,19 +28,25 @@ def main(): sensor_data[loc]['timestamp'].append(timestamp) sensor_data[loc]['roll'].append(sensor['euler']['roll']) - # You can adjust this order or remove sensors if needed + # Adjust this order if needed sensor_order = [ "Left Knee", "Left Ankle", "Right Ankle", "Right Hip", "Right Knee", "Left Hip" ] - # Plot all sensors' roll data on a single plot - plt.figure(figsize=(10, 6)) + # Subsampling factor: plot every 10th point, for example + subsample_factor = 10 + + plt.figure(figsize=(20, 6)) + for loc in sensor_order: - plt.plot(sensor_data[loc]['timestamp'], sensor_data[loc]['roll'], label=loc) + # Take every 10th point + timestamps = sensor_data[loc]['timestamp'][::subsample_factor] + rolls = sensor_data[loc]['roll'][::subsample_factor] + plt.plot(timestamps, rolls, label=loc) - plt.title("Roll Data Over Time for Each Sensor") + plt.title("Roll Data Over Time (Subsampled)") plt.xlabel("Time") plt.ylabel("Roll (degrees)") plt.legend() @@ -50,4 +56,3 @@ def main(): if __name__ == "__main__": main() -