Skip to content

Add AverageMotorWattage field to lap data and implement calculation method#296

Open
dastine0308 wants to merge 5 commits intomainfrom
TEL-330-Add-Motor-Wattage-Field-in-The-Lap-Data
Open

Add AverageMotorWattage field to lap data and implement calculation method#296
dastine0308 wants to merge 5 commits intomainfrom
TEL-330-Add-Motor-Wattage-Field-in-The-Lap-Data

Conversation

@dastine0308
Copy link
Contributor

@dastine0308 dastine0308 commented Mar 14, 2026

Screenshot

Screenshot 2026-03-14 at 4 15 05 PM

Summary by CodeRabbit

  • New Features
    • Lap data now includes an Average Motor Wattage metric (stored per lap).
    • The metric is computed from motor telemetry and gracefully handles missing data.
    • The metric is shown in formatted lap results, rounded to two decimal places, aiding energy usage and performance analysis.

@dastine0308 dastine0308 requested a review from a team as a code owner March 14, 2026 19:57
@vercel
Copy link

vercel bot commented Mar 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
helios-telemetry Ready Ready Preview, Comment Mar 14, 2026 10:33pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2026

📝 Walkthrough

Walkthrough

LapController now computes AverageMotorWattage from telemetry packets; the lap types and DB entity include the new field; the client formatting layer surfaces the value (rounded) for UI consumption.

Changes

Cohort / File(s) Summary
Lap controller
packages/server/src/controllers/LapController/LapController.ts
Added getAverageMotorWattage(packetArray: ITelemetryData[]): number and set AverageMotorWattage when building lap records from lastLapPackets.
Shared types
packages/shared/src/types.ts
Added AverageMotorWattage: number to ILapData and IFormattedLapData.
Client formatting
packages/client/src/stores/useLapData.ts
Mapped AverageMotorWattage into formatted lap output, rounded to two decimals.
Database entity
packages/db/src/entities/Lap.entity.ts
Added AverageMotorWattage: number column (@Column({ type: "float" })) to Lap entity for persistence.

Sequence Diagram(s)

sequenceDiagram
    participant Telemetry as TelemetryPackets
    participant Server as LapController (Server)
    participant DB as Database (Lap.entity)
    participant Client as Client (useLapData)

    rect rgba(135,206,250,0.5)
    Telemetry->>Server: stream packets / lastLapPackets
    Server->>Server: compute AverageMotorWattage (avg of voltage*current per motor)
    Server->>DB: persist lap record (includes AverageMotorWattage)
    end

    rect rgba(144,238,144,0.5)
    Client->>DB: fetch lap data
    DB->>Client: return lap record (includes AverageMotorWattage)
    Client->>Client: format AverageMotorWattage to 2 decimals
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • promatty
  • justin-phxm
  • burtonjong

Poem

🐰 I counted volts and currents with a hop and a twitch,
Averaged watts from motors without a glitch,
Laps now store the power I spy,
Rounded bright numbers hopping by,
Cheers — a rabbit's watt-worthy pitch! ⚡

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main changes: adding an AverageMotorWattage field and implementing its calculation method, which directly corresponds to the changeset across all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch TEL-330-Add-Motor-Wattage-Field-in-The-Lap-Data
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/server/src/controllers/LapController/LapController.ts`:
- Around line 446-470: The getTotalMotorWattage function currently sums
current*voltage across all telemetry packets, producing a value proportional to
number of samples instead of a true wattage; update getTotalMotorWattage (and
references to ITelemetryData/MotorDetails0/MotorDetails1) to return an average
power by dividing the summed wattage by the number of valid samples (or, if
intended, rename the function to reflect it returns a sample-sum/energy metric);
ensure you count only packets/motors where both BusCurrent and BusVoltage are
numbers when computing the divisor so the returned value is the correct average
wattage per sample.

In `@packages/shared/src/types.ts`:
- Line 433: IFormattedLapData is missing the TotalMotorWattage field and
formatLapData in useLapData.ts does not map it, causing data loss; update the
IFormattedLapData type to include TotalMotorWattage: number (matching ILapData)
and modify the formatLapData function in
packages/client/src/stores/useLapData.ts to map source.TotalMotorWattage (or the
ILapData property) into the returned formatted object so the client receives
TotalMotorWattage unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eda6b671-348b-458c-8da8-8b7e00423729

📥 Commits

Reviewing files that changed from the base of the PR and between 6624588 and bf45e8f.

📒 Files selected for processing (2)
  • packages/server/src/controllers/LapController/LapController.ts
  • packages/shared/src/types.ts

@dastine0308 dastine0308 changed the title Add TotalMotorWattage field to lap data and implement calculation method Add AverageMotorWattage field to lap data and implement calculation method Mar 14, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/shared/src/types.ts`:
- Line 425: ILapData gained AverageMotorWattage but it's not propagated; update
formatLapData() in packages/client/src/stores/useLapData.ts to map
AverageMotorWattage into the returned IFormattedLapData shape, add
AverageMotorWattage to the IFormattedLapData interface, add a corresponding
property and constructor parameter assignment in the LapData class, and add a
column/property for AverageMotorWattage in the ORM Lap.entity.ts so the value is
preserved when persisting and formatting.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f6672512-b162-4533-bc6d-e3e95feec1e6

📥 Commits

Reviewing files that changed from the base of the PR and between bf45e8f and 7860480.

📒 Files selected for processing (2)
  • packages/server/src/controllers/LapController/LapController.ts
  • packages/shared/src/types.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/server/src/controllers/LapController/LapController.ts

@dastine0308 dastine0308 force-pushed the TEL-330-Add-Motor-Wattage-Field-in-The-Lap-Data branch from 9068448 to 5f0b78b Compare March 14, 2026 20:19
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/server/src/controllers/LapController/LapController.ts (1)

212-216: ⚠️ Potential issue | 🟠 Major

Swap argument order for battery-seconds calculation

Line 213 calls getSecondsRemainingUntilChargedOrDepleted with reversed arguments. The method signature expects (averagePackCurrent, packAmpHours), but it currently receives (amphoursValue, averagePackCurrent), which materially skews BatterySecondsRemaining.

Suggested fix
-        BatterySecondsRemaining: this.getSecondsRemainingUntilChargedOrDepleted(
-          amphoursValue,
-          averagePackCurrent,
-        ),
+        BatterySecondsRemaining: this.getSecondsRemainingUntilChargedOrDepleted(
+          averagePackCurrent,
+          amphoursValue,
+        ),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/server/src/controllers/LapController/LapController.ts` around lines
212 - 216, The call that computes BatterySecondsRemaining passes arguments to
getSecondsRemainingUntilChargedOrDepleted in the wrong order (currently
getSecondsRemainingUntilChargedOrDepleted(amphoursValue, averagePackCurrent));
change it to getSecondsRemainingUntilChargedOrDepleted(averagePackCurrent,
amphoursValue) so the signature (averagePackCurrent, packAmpHours) is honored;
update the call near where AverageMotorWattage and BatterySecondsRemaining are
set in LapController (look for the variables amphoursValue and
averagePackCurrent and the getSecondsRemainingUntilChargedOrDepleted
invocation).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/server/src/controllers/LapController/LapController.ts`:
- Around line 212-216: The call that computes BatterySecondsRemaining passes
arguments to getSecondsRemainingUntilChargedOrDepleted in the wrong order
(currently getSecondsRemainingUntilChargedOrDepleted(amphoursValue,
averagePackCurrent)); change it to
getSecondsRemainingUntilChargedOrDepleted(averagePackCurrent, amphoursValue) so
the signature (averagePackCurrent, packAmpHours) is honored; update the call
near where AverageMotorWattage and BatterySecondsRemaining are set in
LapController (look for the variables amphoursValue and averagePackCurrent and
the getSecondsRemainingUntilChargedOrDepleted invocation).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7a6d4644-cf6b-47e8-83bc-96a7052bb500

📥 Commits

Reviewing files that changed from the base of the PR and between 38544a0 and 8126238.

📒 Files selected for processing (1)
  • packages/server/src/controllers/LapController/LapController.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants