How sergigarriga/car-stats-dashboard works
Project type and purpose
• This is a single-page, full-stack (monolithic) Streamlit web application for analyzing PHEV driving data.
• Purpose: Load trip data from a CSV, perform cleaning/transformation, compute statistics and predictions (including AI-powered explanations), and render interactive visualizations.
File structure
• Top level:
• src/ – application code
– main.py: entry point (Streamlit app)
– components/menu.py: UI/sidebar/menu definitions
– utils/data_processing.py: data ingestion, cleaning, transformations
– utils/predictions.py: future projections logic
– utils/ai_caller.py: (in README) AI model integration
– assets/car_stats.csv: sample data
• tests/ – pytest unit tests for data_processing, predictions, AI calls
• requirements.txt, README.md, LICENSE, .gitignore
README for additional insights
• Confirms use of Streamlit for UI, Pandas/Numpy for data, Plotly for visualizations, and optionally an external AI service.
• Describes features: dashboards, filtering, cost/savings analysis, data explorer, AI-generated chart explanations.
Main components & their interactions
a. Presentation Layer
– Streamlit server (main.py)
– UI Components (menu.py)
– Plotly chart rendering
b. Business Logic Layer
– DataProcessing module
• load_data()
• clean and normalize columns
– Predictions module
• compute historical averages
• project next-month metrics
– AI Caller module
• format chart metadata
• invoke external AI model (e.g., OpenAI API)
c. Data Layer
– CSV file (assets/car_stats.csv)
– In-memory Pandas DataFrame
d. External Services
– AI model endpoint (optional)
e. Testing Layer
– pytest harness
– Mocked AI calls, unit tests on utils
Architectural patterns & design principles
• Layered architecture separating UI, business logic, and data access.
• Single-process, modular code organization (packages for components and utils).
• Dependency injection via function parameters for testability (e.g., enabling mock CSV inputs or AI responses).
• Interactive, event-driven flow driven by Streamlit reruns on user input.