# Rust Tauri MVP Design ## Goal Build a Windows desktop MVP for the building-material radioactivity judgment system. The first version covers manual entry of repeated Ra-226, Th-232, and K-40 measurements, Rust-side uncertainty calculation, and display of IRa, Ir, relative uncertainty, and the acceptance conclusion. ## Source Documents - `temp/项目报价单.md`: original Rust + Tauri quotation scope. - `temp/项目报价单_B方案.md`: C# alternative quotation. - `temp/项目报价单_C方案.md`: Python alternative quotation. - `temp/不确定度公式.pdf`: formula reference for calculation and judgment. ## Technology Choice Use Rust + Tauri + React + TypeScript. Rust owns the formula engine and later storage/reporting commands. React owns data entry and presentation. Ant Design is the preferred UI library because this app is form-heavy and table-heavy. ## MVP Scope Included: - Manual entry of repeated measured values for Ra-226, Th-232, and K-40. - Configurable calibration parameters with defaults from the PDF table 3: - Ra: `a = 0.916`, `U = 6.3%`, `k = 2` - Th: `a = 0.884`, `U = 6.9%`, `k = 2` - K: `a = 0.961`, `U = 6.7%`, `k = 2` - A-type uncertainty: - `n >= 6`: sample standard deviation divided by `sqrt(n)`. - `2 <= n < 6`: range method using table 2 coefficients. - B-type uncertainty: - `urB = U / k` - `uB = a * urB` - Calibrated activity values: - `C = measured * calibration_factor` - Indices: - `IRa = C_Ra / 200` - `Ir = C_Ra / 370 + C_Th / 260 + C_K / 4200` - Combined nuclide uncertainty and index uncertainty. - Relative uncertainty and three-state conclusion: - both relative uncertainties <= 20%: `OK` - otherwise, if sample count is below 6: `请增加试验次数至 6 次` - otherwise: `校准仪器后重新测量` Excluded from first pass: - SQLite history. - Excel import/export. - PDF report export. - Installer packaging. These are second-stage modules after the formula path is verified. ## Architecture The repository root starts as a Rust library crate named `ceramic-radioactivity`. It exposes calculation data structures and a pure `calculate_sample` function. Tauri integration will call this function from a command, and the React UI will pass plain JSON data to the command. Planned modules: - `src/lib.rs`: public exports. - `src/calculator.rs`: formula implementation. - `src/domain.rs`: input, output, calibration parameters, and conclusion types. - `tests/calculator_tests.rs`: formula behavior tests. The front end will be added after Rust tests pass: - `src-tauri`: Tauri application shell. - `ui`: React + TypeScript + Ant Design UI. ## Error Handling The calculator returns validation errors for: - fewer than 2 measurements for any nuclide; - unequal measurement counts across nuclides; - non-finite numeric values; - missing range coefficient for the `2 <= n < 6` range method. The UI displays validation failures without saving or exporting anything. ## Testing The Rust calculator is tested first. Tests cover: - mean and calibrated activity calculation; - A-type uncertainty for both standard-deviation and range methods; - default B-type uncertainty; - index calculation; - conclusion switching between `OK`, `请增加试验次数至 6 次`, and `校准仪器后重新测量`. The first implementation target is a deterministic unit test based on hand-computed small input values, then a sample-shaped test using the PDF table 1 data.