Skip to content

Refactor statistic analytics to deterministic full-data aggregations#52

Open
IanTheMitten wants to merge 1 commit into
mainfrom
codex/create-aggregation-functions-for-statistics
Open

Refactor statistic analytics to deterministic full-data aggregations#52
IanTheMitten wants to merge 1 commit into
mainfrom
codex/create-aggregation-functions-for-statistics

Conversation

@IanTheMitten

Copy link
Copy Markdown
Owner

Motivation

  • Replace non-deterministic sampling-based statistic math with deterministic, full-data aggregations driven by transaction timestamps as the single source of truth.
  • Provide a single local-day key strategy and reusable aggregation helpers so charts/tables operate consistently on full filtered transaction sets.
  • Keep school-only weekday logic explicit by excluding weekends at the aggregation layer.

Description

  • Add src/components/statistic/aggregation.ts which centralizes day-key logic and implements filterByDateRange, revenueByWeekday, topDaysByRevenue, revenueByTimePeriod, topProducts, and topCustomers (all operate over full transaction arrays and use the transaction timestamp).
  • Rewire src/components/statistic/StatisticPage.tsx to compute explicit date bounds and call filterByDateRange(...), then pass filtered transactions to all statistic UI components; StatisticDateRange now only exposes thisMonth and chosenMonth.
  • Update UI/components to consume the new aggregations: WeekdayRevenueBarChart now uses revenueByWeekday with explicit weekend exclusion, timePeriodAnalytics / TimePeriodRevenueBarChart and TimePeriodCumulativeLine use revenueByTimePeriod and cumulative series computed from filtered transactions, and ProductAverageRevenueTable now ranks products using topProducts (inventory adjustment / sampling math removed).
  • Remove the sampling subsystem and its statistic-side usage by deleting src/components/statistic/analyticsSampling.ts and stripping sampling controls from DateRangeSelector.tsx.

Testing

  • Ran npm run build (Vite production build) and the build completed successfully.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +78 to +80
const startAt = start ? getLocalDayStart(start).getTime() : null;
const endExclusive = end
? new Date(end.getFullYear(), end.getMonth(), end.getDate() + 1).getTime()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant