Skip to content

Commit b90bf70

Browse files
abrichrclaude
andcommitted
fix: add pixel_ratio and audio_start_time to CaptureSession
HTML visualizer referenced these attributes which didn't exist on CaptureSession. Added properties with safe fallbacks and updated html.py to use getattr with defaults. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0b5219d commit b90bf70

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

openadapt_capture/capture.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,34 @@ def audio_path(self) -> Path | None:
314314
audio_path = self.capture_dir / "audio.flac"
315315
return audio_path if audio_path.exists() else None
316316

317+
@property
318+
def pixel_ratio(self) -> float:
319+
"""Display pixel ratio (physical/logical), e.g. 2.0 for Retina.
320+
321+
Defaults to 1.0 if not stored in the recording.
322+
"""
323+
# Check if the Recording model has a pixel_ratio column
324+
ratio = getattr(self._recording, "pixel_ratio", None)
325+
if ratio is not None:
326+
return float(ratio)
327+
# Check the config JSON for pixel_ratio
328+
config = getattr(self._recording, "config", None)
329+
if isinstance(config, dict) and "pixel_ratio" in config:
330+
return float(config["pixel_ratio"])
331+
return 1.0
332+
333+
@property
334+
def audio_start_time(self) -> float | None:
335+
"""Start timestamp of the audio recording, or None if unavailable."""
336+
# Check the AudioInfo relationship for the timestamp
337+
audio_infos = getattr(self._recording, "audio_info", None)
338+
if audio_infos:
339+
first = audio_infos[0] if isinstance(audio_infos, list) else audio_infos
340+
ts = getattr(first, "timestamp", None)
341+
if ts is not None:
342+
return float(ts)
343+
return None
344+
317345
def raw_events(self) -> list[PydanticActionEvent]:
318346
"""Get all raw action events (unprocessed).
319347

openadapt_capture/visualize/html.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ def create_html(
5353
capture_id = capture.id
5454
duration = capture.duration or 0
5555
screen_width, screen_height = capture.screen_size
56-
pixel_ratio = capture.pixel_ratio
57-
audio_start_time = capture._metadata.audio_start_time
56+
pixel_ratio = getattr(capture, "pixel_ratio", 1.0)
57+
audio_start_time = getattr(capture, "audio_start_time", None)
5858

5959
# Get actions
6060
actions = list(capture.actions())

0 commit comments

Comments
 (0)