Skip to content

fix(stat): harden --stat flag across the full stack#136

Merged
fahimfaisaal merged 19 commits into
mainfrom
fix/stat-flag-maintenance
Jun 19, 2026
Merged

fix(stat): harden --stat flag across the full stack#136
fahimfaisaal merged 19 commits into
mainfrom
fix/stat-flag-maintenance

Conversation

@fahimfaisaal

Copy link
Copy Markdown
Member

Summary

  • Stat.Value *float64 — pointer field enables explicit zero encoding; F64() helper for assignments; all parsers updated
  • shared.StatConfig methodsStatEnabled() / StatMath() on the receiver collapse 5×2 copy-pasted methods into delegation one-liners
  • MaterialiseStatFlags — single helper replaces 5 identical Materialise stat blocks; nil flags → nil pointer (omitted by omitempty) instead of always-emitted zero struct
  • ChartConfigNeedsCorrelation — shared predicate removes duplicate inline logic in pipeline.go and ui.go
  • Aggregate nil bugAggregateDataPoints was silently dropping sums when either Value was nil (treated nil as skip, not 0)
  • deepCloneData shallow-copy bugcopy() of []Stat shared *float64 pointers between src and dst; now deep-copies each pointer
  • RewriteStatArg file-eating bug--stat counts consumed counts as a stat value even when a file named counts existed; os.Stat check guards it
  • validateStat — replaced hand-rolled fatal validation with ApplyValidationRules (warn-and-default, consistent with chart subcommands)
  • hasStats UI guardenabled !== false (true for legacy files) → enabled === true (false for legacy files)
  • --stat help text — added missing confidence category to both flag descriptions
  • Template chunkSelectChunks / GenerateUI gain needsHeatmapChunk so the heatmap ECharts module is included whenever correlations are requested, regardless of active chart tab

Test plan

  • All Go tests pass (task test)
  • All 223 UI tests pass (pnpm test in ui/)
  • vizb bar bench.txt --stat — Stats button visible, all categories shown
  • vizb bar bench.txt --stat=counts — only counts shown
  • vizb bar bench.txt — no Stats button, JSON output has no "stat" key
  • echo '{}' > counts && vizb bar countscounts treated as file, not stat value
  • Legacy HTML file (no stat field) — Stats button absent

Replace regular double-centering (/n) with Székely & Rizzo 2014
U-centering (/(n-2)) in bcCenter, clamp dCor² to 0 with Math.max
instead of Math.abs, raise guard from m<3 to m<4 since the
1/(n*(n-3)) factor is undefined at n=3, and update the V-shape
test to use n=15 where U-centering produces positive dCovXY.
- Updated test name from '< 3 complete pairs' to '< 4 complete pairs'
- Added missing n=3 test case to the boundary check (1/(m*(m-3)) undefined)
- Fixed comment in distanceCorr function to reflect n<4 boundary

Co-Authored-By: fahimfaisaal <[email protected]>
Zero-valued measurements were silently omitted from JSON output because the
old float64 field used omitempty. *float64 + F64() lets callers explicitly
encode zero while nil still serialises as absent.
…lone

- Add StatConfig.StatEnabled/StatMath methods as single source of truth
- Add MaterialiseStatFlags to build *StatConfig from flag slice (nil = omit)
- Add ChartConfigNeedsCorrelation shared predicate
- Fix AggregateDataPoints: treat nil Value as 0 not skip (data loss bug)
- Fix deepCloneData: deep-copy *float64 pointers to avoid shared mutation
…ateUI

Ships the heatmap echarts module even when heatmap is not a visible chart
tab, so StatsPanel correlation renderer works regardless of chart selection.
…Stat field

Extends ChartConfig interface with StatEnabled/StatMath. All five chart
configs carry a *StatConfig field and delegate to StatConfig methods so
logic lives in one place. Materialise uses shared.MaterialiseStatFlags
so absent --stat produces nil (omitted from JSON) not a zero-value struct.
Each chart subcommand's RunE now reads stat flags from the cobra config
registry and passes them to Materialise, which calls MaterialiseStatFlags
once. Removes the per-chart inline stat-block duplication.
- RewriteStatArg: skip consuming next arg if it resolves to a real file
- validateStat: replace hand-rolled fatal validation with ApplyValidationRules
- settingsNeedCorrelation / anyDatasetNeedsCorrelation: use shared predicate
- applyStatToSettings: add exhaustive default panic
- options: add 'confidence' to --stat help text (was missing from both strings)
- ChartCard: hasStats checks stat.enabled===true (not !=false) so legacy
  files without a stat field never show the Stats button
- StatsPanel / stats.worker: correlation method picker and adaptive scale
- chartConfig / common: stat-aware series and axis config helpers
- bar/line/pie/radar chart options: consume stat math for category gating
@fahimfaisaal
fahimfaisaal merged commit 3d17211 into main Jun 19, 2026
1 check passed
@fahimfaisaal
fahimfaisaal deleted the fix/stat-flag-maintenance branch June 19, 2026 14:53
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