This project implements a real-time sensor data dashboard using FastAPI for the backend and Server-Sent Events (SSE) to push data to a simple HTML frontend. The dashboard visualizes simulated sensor readings.
- Real-time sensor data visualization.
- Backend built with FastAPI, providing a RESTful API and SSE endpoint.
- Frontend uses HTML, CSS (DaisyUI/TailwindCSS), and JavaScript to display dynamic charts.
- Automated testing with
pytest.
sensor-dashboard/
├── .venv/ # Python virtual environment
├── app.py # FastAPI application entry point
├── utils.py # Utility functions and data models (SensorData, recent_readings)
├── test_app.py # Pytest unit tests for the application
├── templates/ # HTML templates
│ ├── base.html # Base HTML structure
│ ├── index.html # Main dashboard page
│ └── chart_data.html # Partial HTML for chart data updates
├── pyproject.toml # Project dependencies and metadata
├── uv.lock # UV lock file for dependencies
└── README.md # This README file
Follow these steps to set up and run the project locally:
-
Navigate to the project directory:
cd sensor-dashboard -
Install dependencies using
uv:If you don't have
uvinstalled, you can install it viapip:pip install uv
Then, install the project dependencies:
uv pip install -r requirements.txt # (Note: If requirements.txt is not present, uv will install from pyproject.toml)Self-correction: The project uses
pyproject.tomlanduv.lockfor dependency management.uv pip installwithout-rwill install frompyproject.toml. -
Run the application:
uvicorn app:app --reload --port 8000
The application will be accessible at
http://127.0.0.1:8000.
To run the unit tests for the application, ensure you have pytest and httpx installed (they should be installed with the main dependencies if using uv):
uv run pytest test_app.pyThis will execute the tests defined in test_app.py.
