# 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) | | Frontend | Mobile-friendly HTML | --- ## Excel sheet columns | Date | Time | Odometer start (km) | Odometer end (km) | Trip (km) | Notes | |------------|-------|---------------------|-------------------|-----------|-------| | 2026-03-18 | 08:14 | 84 273 | 84 320 | 47 | Ride 1 | | 2026-03-18 | 09:05 | 84 320 | 84 391 | 71 | 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 # start of ride 1 reading_2: Option # end of ride 1 / start of ride 2 reading_3: Option # end of ride 2 } ``` 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 ↓ server reads: 84 273 ✓ 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 → store reading_1 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 → return summary GET /download → serve mileage_log.xlsx ``` --- ## Implementation steps 1. Set up Axum server with in-memory session state (DashMap or Mutex) 2. Create a single `/upload` endpoint that accepts `step=1|2|3` + multipart image 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. After step 2: calculate ride 1 km, return intermediate confirmation 6. After step 3: calculate ride 2 km, append both rows to the Excel file, clear session 7. Mobile-friendly step-by-step HTML UI (progress indicator, camera capture) 8. `GET /download` endpoint to serve the Excel file