Refactor statistic analytics to deterministic full-data aggregations#52
Refactor statistic analytics to deterministic full-data aggregations#52IanTheMitten wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3138f8b062
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const startAt = start ? getLocalDayStart(start).getTime() : null; | ||
| const endExclusive = end | ||
| ? new Date(end.getFullYear(), end.getMonth(), end.getDate() + 1).getTime() |
There was a problem hiding this comment.
Guard invalid date bounds before filtering transactions
If the month input is cleared (value === ''), parseMonthInputValue produces an invalid Date, and filterByDateRange turns that into NaN bounds. Because the checks only test for null, comparisons like timestamp < startAt and timestamp >= endExclusive both evaluate false, so all transactions are returned instead of an empty/invalid-state result. This is a regression from the prior sampling path (which yielded no selected days for invalid month input) and can silently show incorrect analytics.
Useful? React with 👍 / 👎.
Motivation
Description
src/components/statistic/aggregation.tswhich centralizes day-key logic and implementsfilterByDateRange,revenueByWeekday,topDaysByRevenue,revenueByTimePeriod,topProducts, andtopCustomers(all operate over full transaction arrays and use the transactiontimestamp).src/components/statistic/StatisticPage.tsxto compute explicit date bounds and callfilterByDateRange(...), then pass filtered transactions to all statistic UI components;StatisticDateRangenow only exposesthisMonthandchosenMonth.WeekdayRevenueBarChartnow usesrevenueByWeekdaywith explicit weekend exclusion,timePeriodAnalytics/TimePeriodRevenueBarChartandTimePeriodCumulativeLineuserevenueByTimePeriodand cumulative series computed from filtered transactions, andProductAverageRevenueTablenow ranks products usingtopProducts(inventory adjustment / sampling math removed).src/components/statistic/analyticsSampling.tsand stripping sampling controls fromDateRangeSelector.tsx.Testing
npm run build(Vite production build) and the build completed successfully.Codex Task