Skip to content

feat(pragmastats): adds to stats cache#3596

Merged
jqnatividad merged 5 commits into
masterfrom
pragmastats-adds-to-stats-cache
Mar 9, 2026
Merged

feat(pragmastats): adds to stats cache#3596
jqnatividad merged 5 commits into
masterfrom
pragmastats-adds-to-stats-cache

Conversation

@jqnatividad

Copy link
Copy Markdown
Collaborator

No description provided.

jqnatividad and others added 2 commits March 9, 2026 14:40
One-sample mode now appends 7 robust statistic columns (ps_n, ps_center,
ps_spread, ps_center_lower, ps_center_upper, ps_spread_lower,
ps_spread_upper) to the .stats.csv cache file, matching the moarstats
pattern. Added --standalone flag to preserve the old standalone CSV
output, plus --stats-options, --round, and --force flags. Extracted
get_stats_csv_path() to util.rs for sharing between moarstats and
pragmastat.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…idation

- Write to temp file then rename when updating stats cache in-place,
  preventing cache corruption on partial write failures (e.g. disk full)
- Error out if stats CSV lacks required 'field' or 'type' columns
  instead of silently producing empty ps_* fields
- Build complete StringRecord per row instead of individual write_field
  calls, making column count mismatches easier to catch
- Clarify --force behavior: always regenerates full baseline stats
  then recomputes ps_* columns

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jqnatividad jqnatividad requested a review from Copilot March 9, 2026 19:08
Comment thread tests/test_pragmastat.rs Fixed
Comment thread tests/test_pragmastat.rs Fixed
Comment thread tests/test_pragmastat.rs Fixed
Comment thread tests/test_pragmastat.rs Fixed
Comment thread tests/test_pragmastat.rs Fixed
Comment thread tests/test_pragmastat.rs Fixed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates pragmastat so that (in one-sample mode) it can append computed ps_* columns into the existing .stats.csv cache file by default, while providing a --standalone flag to preserve the prior “print CSV to stdout” behavior.

Changes:

  • Make one-sample pragmastat default to cache-append behavior; add --standalone to force old stdout CSV output.
  • Add shared util::get_stats_csv_path and refactor moarstats to use it.
  • Expand the pragmastat test suite with cache-append scenarios and adjust existing tests to use --standalone when they expect stdout output.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
tests/test_pragmastat.rs Updates existing tests for the new default behavior and adds new tests covering cache-append behavior.
src/util.rs Adds a shared helper to compute the absolute .stats.csv path for an input CSV.
src/cmd/pragmastat.rs Implements cache-append mode, adds new CLI flags (--standalone, --stats-options, --round, --force), and updates help text.
src/cmd/moarstats.rs Removes local stats-path logic and delegates to util::get_stats_csv_path.

Comment thread src/cmd/pragmastat.rs
Comment thread src/cmd/pragmastat.rs Outdated
Comment thread src/cmd/pragmastat.rs Outdated
Comment thread src/cmd/pragmastat.rs Outdated
Comment thread src/cmd/pragmastat.rs Outdated
Comment thread src/cmd/pragmastat.rs Outdated
Comment thread src/cmd/pragmastat.rs
jqnatividad and others added 3 commits March 9, 2026 15:16
- --force only recomputes ps_* columns, no longer regenerates baseline stats
  (avoids clobbering moarstats columns)
- Auto-generated stats inherit --delimiter and --no-headers from input
- Derive ColType from stats CSV "type" column instead of result_map
- Fix temp file naming: append ".tmp" suffix instead of with_extension()
- Add Windows-safe rename (remove before rename since fs::rename won't overwrite)
- Wire --round through all standalone formatting paths; remove redundant
  fmt_point_round/fmt_spread_round helpers

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… rename

Move ColType derivation inside the `if is_numeric_type` block so it's
only computed when actually used, avoiding a misleading fallback that
mapped non-numeric types to `ColType::Numeric`.

Replace the non-atomic Windows rename (remove_file + rename) with a
safer backup strategy: rename original to .bak, rename .tmp to target,
then delete .bak — ensuring the original is recoverable if the process
crashes mid-rename.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jqnatividad jqnatividad merged commit 9673f2a into master Mar 9, 2026
16 of 17 checks passed
@jqnatividad jqnatividad deleted the pragmastats-adds-to-stats-cache branch March 9, 2026 19:48
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.

3 participants