Commit 253a0c0
authored
Aggregation support (#1328)
* Implement data aggregation (day, week, month, year) across the Overview and Table screens to improve long-term data visualization and management.
### Core Changes
- **Data Aggregation Engine**: Introduced `MeasurementAggregationUseCase` to group and average measurements by time period, including automatic trend and difference calculations between periods.
- **Enhanced `MeasurementFacade`**: Updated the data pipeline to support optional aggregation levels as a final processing step.
- **Interactive Drill-down**:
- Overview and Table screens now support a "drill-down" mode to view raw measurements for a specific aggregated period.
- Aggregated Table rows now feature a `ChevronRight` icon to navigate to period details.
- **Unified Filtering**: Updated the filter menu in Graph, Table, and Overview screens to include a new "Aggregation" section.
- **UI Enhancements**:
- Aggregated list items now display the number of raw measurements in the period.
- Added an average symbol (⌀) prefix for values representing aggregated periods.
- Updated `MeasurementCard` and `TableScreen` to handle period-based selection and batch actions (Delete/Export/Change User).
### Localization & Navigation
- Added string resources for aggregation levels (None, Day, Week, Month, Year) in English and German.
- Registered new drill-down routes in `AppNavigation` and `Routes`.
- Updated `Enums.kt` to include `AggregationLevel` and restored Hebrew (iw) to the language list.
* Introduce `AggregatedMeasurement` model and unify data access through a centralized `screenFlow` in `SharedViewModel`.
- Create `AggregatedMeasurement` model to encapsulate enriched measurements with period metadata (start/end bounds, count, and stable keys).
- Add `screenFlow` to `SharedViewModel` as a reactive, cached entry point for screens, handling user selection, time-range resolution, and aggregation logic internally.
- Add `drillDownFlow` to `SharedViewModel` for accessing raw measurements within fixed time windows.
- Refactor `OverviewScreen`, `TableScreen`, `GraphScreen`, and `StatisticsScreen` to consume the unified flows, simplifying UI logic.
- Move period labeling and bound calculation logic into `AggregationLevel` enum.
- Update `MeasurementFacade` to support the new aggregated pipeline and improve type safety.
- Optimize chart data loading by reusing the cached `screenFlow`.
* Improve data pipeline stability and UI performance in the Overview and Table screens with the following changes:
* **ViewModel & Data Flow**:
* Switch `StateFlow` sharing strategies from `WhileSubscribed(5000)` to `Eagerly` for `selectedUserId`, `selectedUser`, `measurementTypes`, and measurement flows. This prevents UI flickers, empty-list flashes, and accidental pipeline teardowns during navigation.
* Implement a cache for `drillDownFlow` and include `useSmoothing` in the `screenFlow` cache key to prevent redundant cold flow restarts and state collisions.
* Fix `MeasurementFilterUseCases` to correctly handle null bounds, ensuring inclusive filtering for start and end timestamps.
* **Performance Optimizations**:
* Introduce `remember`ed lookup maps (O(1)) in `OverviewScreen` and `TableScreen` for aggregated items and measurement types, replacing linear scans during recomposition.
* Reuse pre-computed period bounds from `AggregatedMeasurement` instead of recomputing them in the UI layer.
* **Table Screen & Selection Mode**:
* Fix selection logic in aggregated mode by using `filter` and `first` on `StateFlows` to avoid capturing initial `Loading` states.
* Optimize multi-item operations (delete/change user) by snapshotting data before processing, preventing "missing item" errors when Room emits updates mid-loop.
* Enable selection mode and filter actions within the drill-down view.
* Refactor selection state management to use `Set<String>` for more efficient toggling and updates.
* Refactor measurement smoothing to apply after aggregation.
Specific changes:
- In `MeasurementFacade`, reordered the processing pipeline to perform data aggregation before applying smoothing algorithms.
- Updated `MeasurementSmoothingUseCases` to operate on `AggregatedMeasurement` instead of `EnrichedMeasurement`, ensuring smoothing is applied to averaged period values.
- In `SharedViewModel`, refactored `typesToSmoothAndDisplay` to be a reactive `StateFlow` derived directly from `measurementTypes`, automatically filtering for enabled numeric types.
- Cleaned up internal logic and improved documentation within `MeasurementSmoothingUseCases` regarding series block splitting and timestamp alignment.
* Refactor measurement smoothing and aggregation logic for improved performance and consistency.
- Removed redundant filtering of measurement types in `MeasurementSmoothingUseCases`, relying on `typesToSmoothFlow` to provide pre-filtered enabled numeric IDs.
- Optimized smoothed timestamp lookups in `MeasurementSmoothingUseCases` by using a `HashSet` for O(1) complexity.
- Updated `MeasurementAggregationUseCase` to use the minimum timestamp of a group for period calculations instead of the midpoint, ensuring more consistent boundary mapping.
- Simplified the `applySmoothing` signature in `MeasurementFacade` to match these changes.1 parent 73cfb82 commit 253a0c0
19 files changed
Lines changed: 3151 additions & 2468 deletions
File tree
- android_app/app/src/main
- java/com/health/openscale
- core
- data
- facade
- model
- usecase
- ui
- screen
- components
- graph
- overview
- statistics
- table
- res
- values-de
- values
Lines changed: 96 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
81 | 87 | | |
82 | 88 | | |
83 | 89 | | |
| |||
99 | 105 | | |
100 | 106 | | |
101 | 107 | | |
102 | | - | |
| 108 | + | |
103 | 109 | | |
104 | 110 | | |
105 | 111 | | |
| |||
458 | 464 | | |
459 | 465 | | |
460 | 466 | | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
461 | 556 | | |
462 | 557 | | |
463 | 558 | | |
| |||
0 commit comments