Add AverageMotorWattage field to lap data and implement calculation method#296
Add AverageMotorWattage field to lap data and implement calculation method#296dastine0308 wants to merge 5 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughLapController 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
packages/server/src/controllers/LapController/LapController.tspackages/shared/src/types.ts
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
packages/server/src/controllers/LapController/LapController.tspackages/shared/src/types.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/server/src/controllers/LapController/LapController.ts
9068448 to
5f0b78b
Compare
…sCurrent and BusVoltage
There was a problem hiding this comment.
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 | 🟠 MajorSwap argument order for battery-seconds calculation
Line 213 calls
getSecondsRemainingUntilChargedOrDepletedwith reversed arguments. The method signature expects(averagePackCurrent, packAmpHours), but it currently receives(amphoursValue, averagePackCurrent), which materially skewsBatterySecondsRemaining.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
📒 Files selected for processing (1)
packages/server/src/controllers/LapController/LapController.ts
Screenshot
Summary by CodeRabbit