2025 04 15.lap timers feature - SergeiGolos/wod-wiki GitHub Wiki

Lap Timers Feature Design Document

Background

Existing Workout Execution Process

The wod.wiki platform currently processes workout scripts through a well-defined pipeline:

  1. Lexer & Parser: The workout text is tokenized in timer.tokens.ts and parsed into a structured syntax tree in timer.parser.ts.
  2. Visitor & Interpretation: The timer.visitor.ts transforms the syntax tree into a runtime structure.
  3. Runtime Execution: The Runtime component processes the workout script via an event-driven architecture.
  4. UI Rendering: The execution state is reflected through DisplayUpdateAction, SetButtonAction, and SetResultAction.

Currently, the system supports basic workout structures including:

  • Time-based exercises (:20, 1:30)
  • Repetition-based exercises (21 Pullups)
  • Weight/resistance tracking (95lb Thrusters)
  • Distance measurements (25m Run)
  • Round notations like (21-15-9) or (5)

However, the platform lacks sophisticated lap/round tracking for complex workout structures that involve grouping, round-robin rotations, or composition of exercises.

Current Limitations

  1. Limited Group Tracking: The system doesn't effectively track progress within grouped exercises.
  2. No Round-Robin Support: There's no way to rotate through a list of exercises in a round-robin fashion.
  3. Composition Gaps: Combining multiple exercises as a single unit lacks proper runtime tracking.
  4. Metrics Aggregation: Analytics don't properly aggregate metrics across laps/rounds/groups.

Runtime Metric Structure

The platform uses a RuntimeMetric type that includes:

  • effort: Exercise name
  • repetitions: Count
  • resistance: Weight value and unit (optional)
  • distance: Distance value and unit (optional)

This structure needs extension to support grouping and lap information.

Feature Design: Lap/Group/Round-Robin Counters

Conceptual Mechanics

We're introducing three group operation types that will be identified by specific operators:

  1. Round-Robin Operator (-): Each iteration of the parent round moves to the next item in the list.

    (3)
      - 10 Pullups
      - 20 Pushups
      - 30 Squats
    

    This would execute: Round 1: Pullups, Round 2: Pushups, Round 3: Squats

  2. Compose Operator (+): All children are executed as a single unit per round.

    (3)
      + 10 Pullups
      + 20 Pushups
      + 30 Squats
    

    This would execute: Round 1-3: Pullups, then Pushups, then Squats (all three exercises in each round)

  3. Repeat (no operator): Each child individually goes through the parent's round count.

    (3)
      10 Pullups
      20  Pushups
    

    This would execute: 3 rounds of Pullups, then 3 rounds of Pushups

Implementation Mechanics

Parser & Visitor Changes

  • The visitor needs to annotate StatementNode with group type (roundrobin, compose, repeat)
  • Nested groups require hierarchical tracking of lap/round state

Runtime Changes

  • Extend the runtime state to track:
    • Current group type
    • Current lap/round within each group
    • Group execution context
  • Implement specialized compiler strategies for each group type

UI Changes

  • Update TimerDisplay to show current lap/round/group context
  • Enhance ResultsDisplay to visualize group structure
  • Add group-aware visualization cues

Implementation Approach

Phase 1: Core Architecture Updates

  • Parser & Type Extensions

    • Extend StatementNode interface to include group type property
    • Update the parsing logic to recognize operators
    • Create new node types for grouped execution if necessary
  • Visitor Enhancements

    • Refactor visitor to annotate StatementNodes with group type (roundrobin, compose, repeat) based on operator. ✅ 2025-04-15T01:51:54-04:00
    • Properly nest group contexts in the generated runtime structure
    • Handle hierarchical round counting
  • Runtime Execution

    • Extend runtime to track lap/round state per group with correct semantics
    • Implement round-robin execution logic: rotate among children each round
    • Implement compose execution logic: execute all children as a set per round
    • Implement state tracking for complex nested groups
    • Ensure proper event generation for group transitions

Phase 2: UI & Metrics Integration

  • Timer Display Updates

    • Expose lap/round counters for UI display and metrics
    • Update TimerDisplay to visualize lap/group/roundrobin counters
    • Implement visual indicators for current group type
    • Design clear navigation cues for group transitions
  • Results Display Enhancements

    • Update ResultsDisplay to visualize lap/group/roundrobin counters
    • Group metrics by lap/round/group structure
    • Visualize progress across groups
    • Provide aggregated metrics per group type
  • Metric System Extension

    • Update parser and runtime types to support lap/group/roundrobin counters
    • Add metrics handling for lap/group/roundrobin in analytics and results
    • Update analytics to aggregate metrics by lap/group/roundrobin
    • Add group context to RuntimeMetric
    • Implement aggregation logic for nested groups
    • Ensure proper attribution of metrics to groups

Phase 3: Testing & Documentation

  • Unit Testing #future

    • Add tests for parser, runtime, and UI to validate lap/group/roundrobin logic
    • Add/extend tests for visitor, runtime, and UI for these cases
    • Test parser with various group structures
    • Validate runtime execution for each group type
    • Verify metrics aggregation
  • Integration Testing #future

    • Test full execution pipeline with complex workouts
    • Validate UI rendering of group structures
    • Ensure proper metrics display
  • Documentation

    • Write and update documentation for new lap/group/roundrobin counter features
    • Update syntax documentation
    • Create usage examples for each group type
    • Document runtime behavior for complex cases

Summary

  • Feature Summary Implement lap/group/roundrobin lap counters, supporting tracking and display of laps for workouts with group or round-robin structures in both runtime and UI.

    This feature enhances the workout tracking system by adding support for complex workout structures including round-robin rotation, composition of exercises, and proper lap counting across nested groups.

In Progress

Done

  • 2025-04-15T01:43:12-04:00 - Analyze requirements for lap/group/roundrobin lap counting in wod.wiki syntax and runtime. ✅ 2025-04-15T22:15:00-04:00

    Three group operation types identified:

    • '-' (round-robin-operator): Each instance of the parent round goes to the next item in the list
    • '+' (compose-operator): Include all children as a single round
    • Default (no operator): Each child independently goes through the parent group's rounds
  • 2025-04-15T01:50:48-04:00 - Refactor visitor to annotate StatementNodes with group type (roundrobin, compose, repeat) based on operator. ✅ 2025-04-15T01:51:54-04:00

⚠️ **GitHub.com Fallback** ⚠️