How aryanambre77/distance-calculator works
Project type and purpose
• This is a small command‐line (CLI) Python utility whose purpose is to calculate distances (aerial and road) between two user‐specified locations and estimate travel time (ETA) based on a selected transport mode. It integrates with the MapQuest geocoding API to retrieve coordinates.
File structure
• Top level:
• README.md – describes project, dependencies, usage
• project.py – likely the main entry point, handles I/O, API calls, ties modules together
• time cal.py – contains the ETA calculation logic (speeds, time computations)
• No separate “src” or “lib” folders; instead flat structure with two Python scripts.
• No database or web server components.
README for additional insights
• Describes use of Haversine formula for aerial distance, then a simple formula for road distance (aerial × 1.3).
• Lists transport modes (Walk, Motorcycle, Car, Train, Aeroplane) & their average speeds.
• Notes reliance on MapQuest API (requires API key) and lack of exception handling.
a. Main Components
1. User Interface (CLI) – prompts user, reads input (origin, destination, mode)
2. Geocoding Module – issues HTTP requests to MapQuest API, parses JSON to get lat/lon
3. Distance Calculation Module – implements Haversine formula and road‐distance adjustment
4. ETA Calculation Module – uses selected mode’s speed to compute travel time
5. Output Module – formats and displays results to the console
6. External Service – MapQuest API
b. Component Interactions
• CLI → Geocoding Module: send location strings
• Geocoding Module → MapQuest API: REST call, receive coordinates
• Geocoding Module → CLI and Distance Module: return lat/lon
• Distance Module → CLI and ETA Module: return aerial & road distances
• CLI → ETA Module: supply chosen mode and distance
• ETA Module → CLI: return travel time
• CLI → User: display distance & ETA
c. Architectural patterns / design principles
– Separation of concerns: I/O (CLI), external integration, pure computation (distance & time)
– Single responsibility: each script/module does one logical task
d. Technologies / frameworks
– Python 3.x
– requests (or urllib) for HTTP calls to MapQuest
– Math module for Haversine formula
– Standard library for CLI I/O
1. Sketch a left‐to‐right flow:
[User] → (1) [CLI I/O] → (2) [Geocoding Module] → (3) {MapQuest API}
← coordinates ← ↑
→ (4) [Distance Module] → distances →
↓
(5) [ETA Module] → time →
↓
(6) [CLI I/O] → [User]
5. Key formulas (e.g., Haversine formula, road = 1.3 × aerial, ETA = distance ÷ speed).