Skip to content

Instantly share code, notes, and snippets.

@chausen
Created March 18, 2025 14:22
Show Gist options
  • Select an option

  • Save chausen/c0bce20b3de019c231ef05fdf74dd79e to your computer and use it in GitHub Desktop.

Select an option

Save chausen/c0bce20b3de019c231ef05fdf74dd79e to your computer and use it in GitHub Desktop.
Handling raw per-frame data
import pandas as pd
# 1. Read raw PresentMon CSV
df = pd.read_csv("presentmon_raw.csv")
# 2. Convert "TimeInSeconds" to a time-based index (Step 1)
df["timestamp"] = pd.to_timedelta(df["TimeInSeconds"], unit="s")
df.set_index("timestamp", inplace=True)
# ------------------
# Approach A: Simple FPS Count
# ------------------
fps_series = df["TimeInSeconds"].resample("1S").count() # frames per 1 second
fps_series.name = "FPS"
df_fps = pd.DataFrame(fps_series)
df_fps.to_csv("presentmon_fps_1s.csv")
# ------------------
# Approach B: Frame-Time Aggregations
# ------------------
# Rename the relevant column (if needed)
df.rename(columns={"MsBetweenPresents": "frame_time_ms"}, inplace=True)
agg_df = df.resample("1S").agg({
"frame_time_ms": ["mean", "min", "max", "count"]
})
agg_df.columns = ["_".join(col) for col in agg_df.columns] # flatten multilevel columns
# Optional: derive average FPS
agg_df["fps_mean"] = 1000.0 / agg_df["frame_time_ms_mean"] # (1000 ms / avg frame time)
# Save aggregated data
agg_df.to_csv("presentmon_aggregated_1s.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment