Skip to content

Add math engine, report panel, and CSV export (Milestone 4)#2

Merged
Friss merged 3 commits into
mainfrom
milestone-4-math-engine-reports
Apr 3, 2026
Merged

Add math engine, report panel, and CSV export (Milestone 4)#2
Friss merged 3 commits into
mainfrom
milestone-4-math-engine-reports

Conversation

@Friss
Copy link
Copy Markdown
Owner

@Friss Friss commented Apr 3, 2026

Summary

  • Math expression engine in i3rs-core: recursive descent parser, evaluator with 20+ built-in functions (smooth, derivative, integrate, trig, etc.), automatic frequency resampling across channels, flexible name resolution
  • Math channel UI: editor panel for defining/editing computed channels, integrated into channel browser and graph panels via ChannelId abstraction
  • Report panel: min/max/avg/stddev per plotted channel per lap with session-wide totals
  • CSV export: exports plotted channels over current zoom range, handles mixed frequencies
  • Math file persistence: save/load math channel definitions as JSON, included in workspace saves

Test plan

  • cargo build --release — clean build, zero warnings
  • cargo test — 53 tests passing (35 core + 14 integration + 4 CLI)
  • Manual: open test file, define math channel (e.g. derivative(Speed)), verify it appears in browser and plots correctly
  • Manual: open report panel, verify stats match expectations per lap
  • Manual: export CSV, verify values match plotted data
  • Manual: save/load workspace with math channels, verify persistence

Implement the core features of Milestone 4: computed math channels,
statistical reporting, and data export.

Math Engine (i3rs-core):
- Recursive descent expression parser with operator precedence
- Evaluator with 20+ built-in functions (smooth, derivative, integrate,
  abs, trig, pow, clamp, etc.)
- Automatic frequency resampling when mixing channels of different rates
- Flexible channel name resolution (underscore/space/dot, case-insensitive)
- CSV export with multi-frequency resampling

UI Integration (i3rs-app):
- ChannelId enum (Physical/Math) replacing raw usize throughout
- Math editor panel: add/edit/delete/evaluate expressions with error display
- Math channels in channel browser with drag-and-drop support
- Math channels plottable on graphs identically to physical channels
- Report panel: min/max/avg/stddev per channel per lap
- Math file save/load (JSON) and workspace persistence
- CSV export of plotted channels via File menu

Shared utilities:
- compute_channel_stats() in state.rs (unified from duplicate impls)
- MathChannelDef::new() constructor
- Extracted draw_legend_entry() helper from near-duplicate methods
- build_channel_data_map() only decodes referenced channels
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements Milestone 4, introducing a math expression engine, a statistics report panel, and CSV export functionality. Key changes include a hand-written recursive descent parser and evaluator for math expressions, a math channel editor UI, and a new ChannelId abstraction to unify physical and math channels across the application. Feedback highlights critical performance concerns in the report panel due to per-frame statistics recalculation, the need for dependency resolution when evaluating math channels, and a suggestion to use the trapezoidal rule for more accurate numerical integration.

Comment thread crates/i3rs-app/src/panels/report.rs Outdated
Comment thread crates/i3rs-app/src/panels/report.rs Outdated
Comment thread crates/i3rs-app/src/panels/math_editor.rs
Comment thread crates/i3rs-app/src/panels/math_editor.rs
Comment thread crates/i3rs-core/src/math_engine.rs
…names

- Cache report panel statistics in ReportCache, only recompute when
  displayed channels or laps change (fixes per-frame O(N) recomputation)
- Evaluate math channels in topological dependency order using Kahns
  algorithm so inter-channel references resolve correctly
- Reject duplicate math channel names (case-insensitive check against
  both physical and existing math channels)
- Switch cumulative_integral to trapezoidal rule for better accuracy
@Friss
Copy link
Copy Markdown
Owner Author

Friss commented Apr 3, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements Milestone 4, introducing a math expression engine, a math channel editor, and a statistics report panel. Key features include a recursive descent parser, an evaluator with built-in functions and automatic resampling, and CSV export capabilities. The UI has been refactored to support both physical and math channels via a unified ChannelId. Review feedback focuses on performance optimizations, specifically addressing O(L^2) complexity in the report panel, redundant decoding of physical channels, and excessive memory allocations caused by unnecessary data cloning during resampling and evaluation.

Comment thread crates/i3rs-app/src/panels/report.rs Outdated
Comment thread crates/i3rs-app/src/panels/math_editor.rs
Comment thread crates/i3rs-app/src/panels/math_editor.rs
Comment thread crates/i3rs-app/src/panels/math_editor.rs Outdated
Comment thread crates/i3rs-app/src/panels/math_editor.rs
Comment thread crates/i3rs-core/src/math_engine.rs Outdated
- Use O(1) selected lap check instead of O(L) position() search in report
- Remove redundant in_degree initialization in topological sort
- Use Cow in resample() to avoid clone when frequencies already match
@Friss
Copy link
Copy Markdown
Owner Author

Friss commented Apr 3, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements Milestone 4, introducing a comprehensive math engine and reporting system. Key additions include a recursive descent expression parser, an evaluator with built-in DSP functions (smoothing, derivatives, integrals), a math channel editor UI, and a statistics report panel. The architecture now utilizes a unified ChannelId to handle both physical and computed channels across the graph and browser panels. Feedback focuses on performance optimizations for large telemetry datasets, specifically addressing unnecessary data cloning during evaluation, the lack of scalar broadcasting for constants, and $O(N^2)$ complexity in the topological sort. Additionally, improvements were suggested for numerical stability in statistics calculations and consistency in resampling methods between the UI and CSV exports.

Comment thread crates/i3rs-app/src/panels/math_editor.rs
Comment thread crates/i3rs-core/src/math_engine.rs
Comment thread crates/i3rs-core/src/math_engine.rs
Comment thread crates/i3rs-core/src/export.rs
Comment thread crates/i3rs-app/src/state.rs
Comment thread crates/i3rs-app/src/panels/math_editor.rs
Comment thread crates/i3rs-app/src/panels/math_editor.rs
@Friss Friss merged commit 51e615d into main Apr 3, 2026
1 check passed
@Friss Friss deleted the milestone-4-math-engine-reports branch April 3, 2026 02:56
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