Last active
March 18, 2025 14:40
-
-
Save chausen/3ec2a6f95d8b65c69396ea57f5be5a5f to your computer and use it in GitHub Desktop.
compare steps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
df_day1 = pd.read_csv("day1_processed.csv") | |
df_day2 = pd.read_csv("day2_processed.csv") | |
# Each has columns like: ["relative_time_s", "CPU_usage", "FPS", ...]. | |
# We assume day1["relative_time_s"]=0 at the start of Day 1's test, day2["relative_time_s"]=0 at start of Day 2's test, etc. | |
# Hypothetical times in seconds from the start of each day's recording | |
STEP_TIMES = { | |
"Step1": { | |
"Day1": (300, 480), # Step 1 goes from 5 min (300s) to 8 min (480s) on Day 1 | |
"Day2": (600, 780), # Step 1 goes from 10 min (600s) to 13 min (780s) on Day 2 | |
}, | |
"Step2": { | |
"Day1": (480, 600), # maybe step 2 picks up immediately after step 1 on Day 1 | |
"Day2": (780, 900), | |
} | |
} | |
# function for extracting a step from a day | |
def extract_step_data(df, step_name, day_name, start_end): | |
start_s, end_s = start_end | |
# 1. Subset rows for the step time range | |
subset = df[(df["relative_time_s"] >= start_s) & (df["relative_time_s"] <= end_s)].copy() | |
# 2. Shift time so step starts at t=0 | |
subset["step_time_s"] = subset["relative_time_s"] - start_s | |
# 3. Add metadata | |
subset["step"] = step_name | |
subset["day"] = day_name | |
return subset | |
# use function to combine extracted step from multiple days | |
all_steps_data = [] | |
for step_name, days_dict in STEP_TIMES.items(): | |
for day_name, (start_s, end_s) in days_dict.items(): | |
if day_name == "Day1": | |
step_data = extract_step_data(df_day1, step_name, day_name, (start_s, end_s)) | |
elif day_name == "Day2": | |
step_data = extract_step_data(df_day2, step_name, day_name, (start_s, end_s)) | |
# if more days, handle them similarly... | |
all_steps_data.append(step_data) | |
# Combine them into one DataFrame | |
df_steps_combined = pd.concat(all_steps_data, ignore_index=True) | |
# now df_steps_combined has data like: | |
# ["relative_time_s", "step_time_s", "CPU_usage", "FPS", "step", "day", ...] | |
# example plot | |
import seaborn as sns | |
# Filter to Step1 only: | |
df_step1 = df_steps_combined[df_steps_combined["step"] == "Step1"] | |
# Simple lineplot with Seaborn, CPU_usage vs. step_time_s, color by day: | |
sns.lineplot(data=df_step1, x="step_time_s", y="CPU_usage", hue="day") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment