refactor: extract lib.rs, remove club module, add bounded concurrency

- Extract shared types (Car, BestCarRecord, AnalysisContext) into src/lib.rs
- Replace global static BEST_CARS with injected AnalysisContext for testability
- Add semaphore-bounded concurrency (limit 20) in parse_all_times()
- Replace hardcoded track name match with track_names.json loaded via include_str!
- Replace magic number 115 with const MAX_RQ: u8 = 113
- Improve floating-point tie comparison with TIME_TOLERANCE (5ms) constant
- Remove src/club.rs binary (topdrives.club no longer maintained)
- Remove scraper dependency from Cargo.toml
- Remove tracks.txt (replaced by track_names.json)
- Remove empty/placeholder test bodies
- Improve error handling in get_file() for response body read
- Add load_my_cars_data() combining owned + wishlist extraction in one I/O
- Update CHANGELOG, README, and all docs to reflect changes
This commit is contained in:
Jan-Peter von Hunnius 2026-05-06 20:20:15 +02:00
parent 6a68469239
commit 89fa69e3c8
14 changed files with 874 additions and 2037 deletions

View file

@ -17,6 +17,7 @@ A comprehensive Rust-based tool for analyzing car performance data in the Top Dr
- [Quick Start](#quick-start)
- [Usage Guide](#usage-guide)
- [Commands Reference](#commands-reference)
- [Daily Workflow](#daily-workflow)
- [Data Sources](#data-sources)
- [Configuration](#configuration)
- [Development](#development)
@ -148,6 +149,36 @@ The analyzer supports multiple track conditions:
| `details` | Show detailed timing data for all tracks | None |
| `track` | Show best car for specific track | `<track_name> <condition> <rq>` |
## 📅 Daily Workflow
The typical daily workflow uses `full_script` which runs `fetch` followed by all analysis commands in sequence:
```bash
cargo run --bin records -- full_script
```
This generates the following output files:
| File | Description |
|------|-------------|
| `best.csv` | Ranked list of best cars — used to evaluate if a car is worth keeping |
| `details.csv` | Detailed timing data for all tracks/conditions — used to find the best config for a car |
| `add.csv` | Cars to add to wishlist — missing cars not yet wishlisted, prefixed with `+` |
| `remove.csv` | Cars to remove from wishlist — stale wishlist entries, prefixed with `-` |
| `trash.csv` | Owned cars that can be safely removed |
| `sorted.csv` | Best cars sorted by count (descending) |
| `very_best.csv` | Best cars with count ≥ 10 |
| `wishlist.csv` | Missing cars already on wishlist |
### Workflow Steps
1. **Fetch** fresh data from the community repository
2. **Analyze** your collection against the latest timing data
3. **Review** `best.csv` to see how your cars rank
4. **Check** `add.csv` for cars worth adding to your wishlist
5. **Clean up** `remove.csv` entries from your wishlist
6. **Sell** cars listed in `trash.csv` that are no longer useful
## 📊 Data Sources
### Car Data
@ -160,6 +191,11 @@ The analyzer supports multiple track conditions:
- **Coverage**: All tracks and conditions in Top Drives
- **Format**: Structured track definitions with conditions
### Track Names
- **Source**: `track_names.json` (included in repository)
- **Format**: JSON mapping track codes to human-readable names
- **Loaded**: At compile time via `include_str!`
### User Collection
- **File**: `my_cars.json`
- **Format**: Top Drives game export format
@ -172,10 +208,11 @@ The analyzer supports multiple track conditions:
top_drives/
├── src/
│ ├── records.rs # Main analyzer binary
│ └── club.rs # Alternative data source
│ └── lib.rs # Shared library (track name translations)
├── times/ # Car performance data (1000+ files)
├── cars_repo.json # Car database
├── tracks_repo.json # Track definitions
├── track_names.json # Track code → name mappings
├── my_cars.json # Your car collection
└── Cargo.toml # Rust project configuration
```
@ -184,15 +221,20 @@ top_drives/
- **reqwest**: HTTP client for data fetching
- **serde_json**: JSON parsing and serialization
- **tokio**: Asynchronous runtime
- **scraper**: HTML parsing for alternative data source
- **futures**: Async utility combinators
- **once_cell**: Lazy static initialization
## 🔧 Development
### Project Structure
The project consists of two main binaries:
The project consists of a single binary with a shared library:
1. **records**: Primary analysis tool using JSON data
2. **club**: Alternative tool scraping topdrives.club
1. **records**: Primary analysis tool using JSON data (`src/records.rs`)
2. **lib**: Shared library with track name translations (`src/lib.rs`)
### Key Constants
- `MAX_RQ: u8 = 113` — Maximum RQ level used in analysis (defined in `records.rs`)
### Key Data Structures
@ -232,9 +274,8 @@ cargo build
# Release build
cargo build --release
# Run specific binary
# Run the analyzer
cargo run --bin records
cargo run --bin club
```
## 🤝 Contributing
@ -252,6 +293,8 @@ Track definitions are stored in `tracks_repo.json`. Each track includes:
- Supported conditions
- Track type classification
Track name mappings are stored in `track_names.json` and loaded at compile time.
### Adding Car Data
New car performance data should be submitted to the upstream repository following their contribution guidelines.
@ -272,4 +315,4 @@ The tool fetches fresh data each time you run the `fetch` command. Keep your loc
---
*Built with ❤️ for the Top Drives community*
*Built with ❤️ for the Top Drives community*