refactor: modular architecture with unified error handling and DashMap concurrency

- Break monolithic records.rs into commands/, output/, parsing/ modules
- Add lib.rs with shared types (AppError, Car, BestCarRecord, etc.)
- Replace Arc<Mutex<HashMap>> with DashMap for concurrent access
- Add unified AppError enum with thiserror
- Add configurable CLI paths (--my-cars, --cars-db, --times-dir, --tracks-db)
- Add serde deserialization for Car struct
- Add CSV escaping for fields with commas/quotes/newlines
- Fix track name splitting: split_once -> rsplit_once for _a handling
- Add integration tests, proptest property-based tests, and unit tests
- Add rustfmt.toml configuration
- Update documentation (API, ARCHITECTURE, DATA_STRUCTURES, README)
This commit is contained in:
Jan-Peter von Hunnius 2026-05-08 16:19:01 +02:00
parent 9d57b18a4e
commit a9a46ee551
24 changed files with 3541 additions and 1470 deletions

View file

@ -235,15 +235,10 @@ const MAX_RQ: u8 = 113;
**Car Database Processing:**
```rust
// Parse cars_repo.json
let cars_data: Vec<Value> = serde_json::from_str(&file_content)?;
for car in cars_data {
let car = Car {
rid: car["rid"].as_str().unwrap_or(""),
brand: car["brand"].as_str().unwrap_or(""),
// ... other fields
};
}
// Parse cars_repo.json — uses serde derive for deserialization
let cars: Vec<Car> = serde_json::from_str(&content)?;
// Falls back to manual Value-based parsing if serde deserialization fails
// (for backward compatibility with older JSON formats)
```
**Timing Data Processing:**
@ -303,8 +298,9 @@ BestCarRecord {
**RQ Range Analysis:**
- Test each car from its base RQ up to `MAX_RQ` (113)
- Compare against existing best times
- Compare against existing best times using `DashMap` entry API
- Update records if better performance found
- Uses `DashMap` for fine-grained concurrent access (no global lock)
## Data Quality Measures
@ -345,8 +341,8 @@ BestCarRecord {
### Memory Usage
**Large Data Structures**:
- `BEST_CARS` HashMap: Contains all best records across RQ ranges
- Individual timing files: Loaded and parsed sequentially
- `AnalysisContext.best_cars` (`DashMap<TripletKey, Vec<BestCarRecord>>`): Contains all best records across RQ ranges
- Individual timing files: Loaded and parsed sequentially via `spawn_blocking`
- User collection: Small, loaded once
**Optimization Strategies**: