Browser captures GPS coords on step 1, server reverse-geocodes via Nominatim, and location is stored in session + written to both Excel rows. https://claude.ai/code/session_015myTTMs6yDsAGarATe5ePZ
118 lines
4.1 KiB
Markdown
118 lines
4.1 KiB
Markdown
# Mileage Tracking Automation — Plan
|
|
|
|
## How it works
|
|
|
|
1. Open the web app on your phone
|
|
2. Take **3 photos** in sequence:
|
|
- **Photo 1** — odometer at the start of ride 1
|
|
- **Photo 2** — odometer at the end of ride 1 / start of ride 2
|
|
- **Photo 3** — odometer at the end of ride 2
|
|
3. Claude Vision API reads each number automatically
|
|
4. Two trip rows are calculated and saved to the Excel sheet
|
|
5. Download the sheet anytime
|
|
|
|
---
|
|
|
|
## Stack
|
|
|
|
| Layer | Technology |
|
|
|-------------|-----------------------------|
|
|
| Backend | Rust + Axum |
|
|
| AI / OCR | Claude API (vision) |
|
|
| Spreadsheet | rust_xlsxwriter (Excel) |
|
|
| Geocoding | browser Geolocation API + reverse-geocode REST API |
|
|
| Frontend | Mobile-friendly HTML |
|
|
|
|
---
|
|
|
|
## Excel sheet columns
|
|
|
|
| Date | Time | Odometer start (km) | Odometer end (km) | Trip (km) | Location | Notes |
|
|
|------------|-------|---------------------|-------------------|-----------|-----------------|--------|
|
|
| 2026-03-18 | 08:14 | 84 273 | 84 320 | 47 | Amsterdam, NL | Ride 1 |
|
|
| 2026-03-18 | 09:05 | 84 320 | 84 391 | 71 | Haarlem, NL | Ride 2 |
|
|
|
|
---
|
|
|
|
## Files to create
|
|
|
|
```
|
|
Driverthing/
|
|
├── src/
|
|
│ ├── main.rs # Axum server + routes + session state
|
|
│ ├── claude.rs # Claude API vision call
|
|
│ └── excel.rs # Excel read/write logic
|
|
├── templates/
|
|
│ └── index.html # Mobile step-by-step camera upload UI
|
|
├── Cargo.toml
|
|
└── mileage_log.xlsx # Generated, gitignored
|
|
```
|
|
|
|
---
|
|
|
|
## Session state (in-memory)
|
|
|
|
Between the 3 uploads the server holds a simple session with:
|
|
|
|
```
|
|
session {
|
|
reading_1: Option<u32> # start of ride 1
|
|
reading_2: Option<u32> # end of ride 1 / start of ride 2
|
|
reading_3: Option<u32> # end of ride 2
|
|
location: Option<String> # reverse-geocoded from GPS at step 1
|
|
}
|
|
```
|
|
|
|
When all three readings are present, two rows are written to Excel and the
|
|
session is cleared.
|
|
|
|
---
|
|
|
|
## UI flow (single page, steps replace each other)
|
|
|
|
```
|
|
Step 1: "Take photo of odometer — START of ride 1"
|
|
[Camera button] → upload (browser also sends GPS coords)
|
|
↓ server reads: 84 273 ✓
|
|
↓ GPS reverse-geocoded: "Amsterdam, NL" ✓
|
|
|
|
Step 2: "Take photo of odometer — END of ride 1 / START of ride 2"
|
|
[Camera button] → upload
|
|
↓ server reads: 84 320 ✓
|
|
↓ Ride 1: 47 km (shown on screen)
|
|
|
|
Step 3: "Take photo of odometer — END of ride 2"
|
|
[Camera button] → upload
|
|
↓ server reads: 84 391 ✓
|
|
↓ Ride 2: 71 km (shown on screen)
|
|
↓ Both rows saved ✓
|
|
|
|
Done screen: summary + [Download Excel] + [Start new session]
|
|
```
|
|
|
|
---
|
|
|
|
## Flow (technical)
|
|
|
|
```
|
|
POST /upload?step=1 → read photo + GPS coords → reverse-geocode location
|
|
→ store reading_1 + location in session
|
|
POST /upload?step=2 → read photo → store reading_2 → calc ride1 delta → show
|
|
POST /upload?step=3 → read photo → store reading_3 → calc ride2 delta
|
|
→ write 2 rows to Excel (both with same location) → return summary
|
|
GET /download → serve mileage_log.xlsx
|
|
```
|
|
|
|
---
|
|
|
|
## Implementation steps
|
|
|
|
1. Set up Axum server with in-memory session state (DashMap or Mutex<HashMap>)
|
|
2. Create a single `/upload` endpoint that accepts `step=1|2|3` + multipart image + optional lat/lon form fields
|
|
3. Send each uploaded image (base64) to Claude Vision API: "What is the odometer reading in km? Reply with only the number."
|
|
4. Parse the integer from the response and store it in the session
|
|
5. At step 1: reverse-geocode lat/lon via a free API (e.g. nominatim.openstreetmap.org) → store city/address in session
|
|
6. After step 2: calculate ride 1 km, return intermediate confirmation
|
|
7. After step 3: calculate ride 2 km, append both rows (with location) to the Excel file, clear session
|
|
8. Mobile-friendly step-by-step HTML UI: request GPS on load, attach coords to each upload, progress indicator
|
|
9. `GET /download` endpoint to serve the Excel file
|