Skip to content

Update RaceTab and lapdata to use timescale#279

Open
alexwhelan12 wants to merge 1 commit intomainfrom
Update-RaceTab-with-Timescale
Open

Update RaceTab and lapdata to use timescale#279
alexwhelan12 wants to merge 1 commit intomainfrom
Update-RaceTab-with-Timescale

Conversation

@alexwhelan12
Copy link
Contributor

@alexwhelan12 alexwhelan12 commented Jan 31, 2026

Summary by CodeRabbit

Release Notes

  • Refactor
    • Improved lap data structure organization for enhanced consistency and performance across the application.

✏️ Tip: You can customize this high-level summary in your review settings.

@alexwhelan12 alexwhelan12 requested a review from a team as a code owner January 31, 2026 23:05
@vercel
Copy link

vercel bot commented Jan 31, 2026

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

Project Deployment Actions Updated (UTC)
helios-telemetry Ready Ready Preview, Comment Jan 31, 2026 11:05pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 31, 2026

📝 Walkthrough

Walkthrough

This PR flattens the lap data structure from a nested object format to top-level fields across the client, server, and shared type definitions. Column accessors, field references, and data construction patterns are updated to reflect the new flat structure, affecting table configuration, components, store logic, and type definitions.

Changes

Cohort / File(s) Summary
Shared Type Definitions
packages/shared/src/types.ts
Flattened ILapData and IFormattedLapData interfaces by moving nested data object fields (AmpHours, AveragePackCurrent, AverageSpeed, BatterySecondsRemaining, Distance, EnergyConsumed, LapTime, NetPowerOut, TimeStamp, TotalPowerIn, TotalPowerOut) to top-level properties; removed outer timestamp field.
Client Store
packages/client/src/stores/useLapData.ts
Updated formatLapData to populate top-level numeric fields with two-decimal rounding; removed nested data object and timestamp property; removed setLapData method from LapDataState; refactored fetchLapData to format laps before state update.
Client Components
packages/client/src/components/config/lapTableConfig.ts, packages/client/src/components/tabs/RaceTab.tsx, packages/client/src/components/molecules/RaceTabMolecules/RaceTabTable.tsx
Updated column accessor keys from "data.X" to "X" format (e.g., "data.timeStamp" → "TimeStamp"); changed default sorting and freeze logic from "data_timeStamp" to "TimeStamp"; removed fetchLapData from store destructuring.
Server Controller
packages/server/src/controllers/LapController/LapController.ts
Updated LapData construction to use flat top-level fields instead of nested data object; updated documentation references from DynamoDB to TimescaleDB; broadcast and insert flow adapted to new lapData structure.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • burtonjong
  • promatty
  • justin-phxm

🐰 Flat and clean, our data now flows,
No nested depths where confusion grows,
TimeStamp shines at the top with grace,
Each field finds its rightful place!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title partially relates to the changeset by mentioning TimescaleDB, but misleadingly suggests database migration as the primary change when the core focus is restructuring lap data from nested to flat fields. Revise the title to reflect the primary change: 'Flatten lap data structure from nested to top-level fields' or 'Refactor lap data schema to use flat field structure' would more accurately describe the changeset.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch Update-RaceTab-with-Timescale

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.

@alexwhelan12 alexwhelan12 reopened this Jan 31, 2026
@alexwhelan12 alexwhelan12 changed the title fix: update types of fetched lap data Update RaceTab and lapdata to use timescale Jan 31, 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

Caution

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

⚠️ Outside diff range comments (2)
packages/client/src/components/config/lapTableConfig.ts (1)

11-38: ⚠️ Potential issue | 🟡 Minor

TimeStamp sorting relies on hardcoded date format parsing.

The custom sortingFn parses dates assuming a specific format (MM/DD/YYYY HH:MM) that matches toLocaleString("en-US") output. However, toLocaleString("en-US") actually produces format like "1/31/2026, 3:05:08 PM" which includes:

  • Commas
  • AM/PM indicator
  • Seconds

The current parser will fail or produce incorrect results with this format.

🐛 Proposed fix using Date constructor directly
     sortingFn: (rowA, rowB, columnId) => {
-      const parseDate = (dateString: string) => {
-        const parts = dateString.split(" ");
-
-        const dateParts = parts[0]?.split("/");
-        const timeParts = parts[1]?.split(":");
-
-        if (!dateParts || !timeParts) {
-          throw new Error("Invalid Time");
-        }
-        const hour = Number(timeParts[0]);
-        const minute = Number(timeParts[1]);
-
-        const day = Number(dateParts[1]);
-        const month = Number(dateParts[0]);
-        const year = Number(dateParts[2]);
-        return new Date(year, month - 1, day, hour, minute).getTime();
-      };
-      const dateA = parseDate(rowA.getValue(columnId));
-      const dateB = parseDate(rowB.getValue(columnId));
+      const dateA = new Date(rowA.getValue(columnId)).getTime();
+      const dateB = new Date(rowB.getValue(columnId)).getTime();

       return dateB - dateA;
     },
packages/shared/src/types.ts (1)

436-476: ⚠️ Potential issue | 🟡 Minor

Remove or repurpose the unused LapData class.

The LapData class is exported but never imported or instantiated anywhere in the codebase—it appears to be dead code. All active usage is of the ILapData interface instead. Additionally, there are naming inconsistencies between the class (camelCase: timestamp, lapTime, etc.) and the interface (PascalCase: TimeStamp, LapTime, etc.), and field mismatches (lapNumber and lapsRemaining exist only in the class; Rfid exists only in the interface).

Either remove the class if it's no longer needed, or if it's intended for future use, align it with ILapData to prevent confusion.

🤖 Fix all issues with AI agents
In `@packages/client/src/components/molecules/RaceTabMolecules/RaceTabTable.tsx`:
- Line 53: In the RaceTabTable component update the JSX className string (the
className prop that includes `${cell.id.includes("TimeStamp") ? "left-0 z-10" :
""}`) to fix the typo by replacing "w-fullpx-4" with two separate Tailwind
classes "w-full px-4" so the utility classes are correctly parsed.
🧹 Nitpick comments (1)
packages/client/src/stores/useLapData.ts (1)

19-19: Consider making locale configurable for internationalization.

The hardcoded "en-US" locale may not be appropriate for all users. If internationalization is planned, consider using the user's browser locale or a configurable setting.

TimeStamp: new Date(lapPacket.TimeStamp).toLocaleString(),

{row.getVisibleCells().map((cell) => (
<td
className={`text-gray-900 w-fullpx-4 sticky w-24 border-b-2 border-r-2 border-helios py-2 text-center text-sm first:border-l-2 dark:text-white ${cell.id.includes("data_timeStamp") ? "left-0 z-10" : ""}`}
className={`text-gray-900 w-fullpx-4 sticky w-24 border-b-2 border-r-2 border-helios py-2 text-center text-sm first:border-l-2 dark:text-white ${cell.id.includes("TimeStamp") ? "left-0 z-10" : ""}`}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Typo in className: missing space between utility classes.

The string "w-fullpx-4" should be "w-full px-4" - there's a missing space between the Tailwind classes.

🐛 Proposed fix
-                  className={`text-gray-900 w-fullpx-4 sticky w-24 border-b-2 border-r-2 border-helios py-2 text-center text-sm first:border-l-2 dark:text-white ${cell.id.includes("TimeStamp") ? "left-0 z-10" : ""}`}
+                  className={`text-gray-900 w-full px-4 sticky w-24 border-b-2 border-r-2 border-helios py-2 text-center text-sm first:border-l-2 dark:text-white ${cell.id.includes("TimeStamp") ? "left-0 z-10" : ""}`}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
className={`text-gray-900 w-fullpx-4 sticky w-24 border-b-2 border-r-2 border-helios py-2 text-center text-sm first:border-l-2 dark:text-white ${cell.id.includes("TimeStamp") ? "left-0 z-10" : ""}`}
className={`text-gray-900 w-full px-4 sticky w-24 border-b-2 border-r-2 border-helios py-2 text-center text-sm first:border-l-2 dark:text-white ${cell.id.includes("TimeStamp") ? "left-0 z-10" : ""}`}
🤖 Prompt for AI Agents
In `@packages/client/src/components/molecules/RaceTabMolecules/RaceTabTable.tsx`
at line 53, In the RaceTabTable component update the JSX className string (the
className prop that includes `${cell.id.includes("TimeStamp") ? "left-0 z-10" :
""}`) to fix the typo by replacing "w-fullpx-4" with two separate Tailwind
classes "w-full px-4" so the utility classes are correctly parsed.

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.

1 participant