How pourmousavi/bess-scada-data works
1. Overall shape
- This is a single FastAPI application that serves both an API and a static browser UI.
- The core architectural boundary is: browser UI → REST API → AEMO NEMWEB fetchers/processors.
2. Frontend layer
- app/static/index.html, css/style.css, and js/app.js implement a vanilla HTML/CSS/JS client.
- The UI renders interactive Plotly.js time-series charts, pulls data from the API, and handles user-driven filtering/download actions.
- There is no separate frontend build system; the static assets are served directly by FastAPI.
3. API entrypoint and routing
- app/main.py initializes the FastAPI app and serves the static files.
- app/routers/api.py contains the REST surface described in the README: BESS list, SCADA data, dispatch/energy data, downloads, quality flags, app info, and analytics.
- The router is the main orchestration point that connects request parameters to the relevant service modules.
4. AEMO data access layer
- app/services/aemo_fetcher.py and app/services/dispatch_fetcher.py are the external-data ingestion layer.
- They retrieve archive/current ZIP bundles from AEMO NEMWEB using HTTP, including remote archive access for the older bundled SCADA files.
- This layer is responsible for dealing with AEMO’s file formats and archive layout, not business logic.
5. Data transformation layer
- app/services/data_processor.py and app/services/dispatch_processor.py use Polars to filter, normalize, and shape the raw CSV payloads into API-ready data.
- This is where the domain-specific rules live: date filtering, interval handling, output shaping, and CSV/Parquet preparation.
- The processors are the bridge between AEMO’s raw archive structure and the client-facing query model.
6. Two primary data products
- SCADA / PUBLIC_NEXT_DAY_FPPMW: 4-second measurements with MEASURED_MW and MW_QUALITY_FLAG.
- Dispatch / DISPATCH_UNIT_SOLUTION: 5-minute interval dispatch and energy storage fields such as INITIALMW and ENERGY_STORAGE.
- The API exposes these as separate paths and download formats, so the architecture has two parallel data pipelines rather than one generic one.
7. Reference data and fallback assets
- app/services/gen_info_fetcher.py fetches the live BESS list from AEMO generation information, with a 24-hour cache behavior noted in the README.
- app/data/bess_list.json is the local fallback if the live list is unavailable.
- app/data/quality_flags.json provides the static description map for SCADA quality flags.
8. Analytics and operational telemetry
- app/services/analytics.py adds a small internal persistence boundary for request logging, apparently backed by SQLite.
- The /api/analytics endpoint is token-protected via ANALYTICS_TOKEN, separating operational stats from the public data API.
- This is the only clear server-side persistence path; the main datasets themselves are not stored on the server.
9. Runtime and deployment
- The project targets Python 3.11, runs with Uvicorn, and is containerized via Dockerfile.
- Deployment is intended for Hugging Face Spaces, and the repo includes GitHub Actions to refresh the BESS list and sync the app to HF.
- That means the architecture is optimized for stateless request handling in containers, with external data fetched on demand.
10. Maintenance and automation
- scripts/refresh_bess_list.py is a maintenance utility for regenerating the fallback BESS list.
- GitHub Actions in .github/workflows/refresh_bess_list.yml and sync_to_hf.yml automate data refresh and deployment sync.
- These jobs support the live-data architecture by keeping bundled metadata current without introducing a server-side database for the main datasets.
Main entry points: api.py REST API · gen_info_fetcher.py Gen info fetcher · index.html UI shell · main.py FastAPI app
Components 18
Browser UI
Static client served directly by FastAPI.
- UI shell · Browser entry page for the client.
app/static/index.html - Styles · Presentation styling for the browser UI.
app/static/css/style.css - Client app · Vanilla JS client that calls the API and renders charts.
app/static/js/app.js
API Layer
FastAPI entrypoint and REST routing.
- FastAPI app · Creates the application and serves static assets.
app/main.py - REST API · Main request orchestration for app endpoints.
app/routers/api.py - Config · Runtime settings and environment-driven configuration.
app/config.py
Data Services
External fetchers, processors, reference data, and analytics.
- AEMO fetcher · Downloads NEMWEB archive and current ZIP bundles.
app/services/aemo_fetcher.py - Dispatch fetcher · Retrieves dispatch unit solution data from AEMO.
app/services/dispatch_fetcher.py - Gen info fetcher · Loads the live BESS generation information list with caching.
app/services/gen_info_fetcher.py - SCADA processor · Filters and shapes PUBLIC_NEXT_DAY_FPPMW data for API responses.
app/services/data_processor.py - Dispatch processor · Normalizes DISPATCH_UNIT_SOLUTION intervals and exports.
app/services/dispatch_processor.py - Analytics · Persists request logging and serves protected analytics.
app/services/analytics.py - BESS fallback · Local fallback list for generation metadata.
app/data/bess_list.json - Quality flags · Static descriptions for SCADA quality flags.
app/data/quality_flags.json - BESS meta · Metadata for the bundled BESS list refresh.
app/data/bess_list_meta.json
Operations
Containerization, workflows, and maintenance scripts.
- Container · Container image and runtime definition.
Dockerfile - Refresh script · Regenerates the bundled BESS list.
scripts/refresh_bess_list.py - GitHub Actions · Automation for data refresh and Hugging Face sync.
.github/workflows/sync_to_hf.yml
Connections 21
- UI shell → Client app: loads · The HTML shell loads the client logic.
- UI shell → Styles: styles · The HTML shell is styled by the CSS asset.
- Client app → REST API: API calls · Browser actions fetch data and trigger downloads through the REST API.
- FastAPI app → UI shell: serves · FastAPI serves the static browser UI.
- FastAPI app → REST API: mounts · Application wires the API router into the FastAPI app.
- REST API → Config: reads config · Endpoint behavior depends on environment settings and tokens.
- REST API → Gen info fetcher: BESS list · Retrieves the current generation information reference list.
- REST API → AEMO fetcher: SCADA source · Fetches NEMWEB archives for SCADA data.
- REST API → Dispatch fetcher: dispatch source · Fetches dispatch solution data from AEMO.
- REST API → SCADA processor: scada API · Transforms raw SCADA payloads into query results and downloads.
- REST API → Dispatch processor: dispatch API · Transforms dispatch payloads into query results and downloads.
- REST API → Quality flags: flag map · Exposes the static quality-flag descriptions.
- REST API → Analytics: analytics · Writes and reads protected operational telemetry.
- Gen info fetcher → BESS fallback: fallback · Uses the bundled BESS list when live fetch is unavailable.
- Gen info fetcher → BESS meta: metadata · Tracks refresh metadata for the bundled reference list.
- SCADA processor → AEMO fetcher: raw input · Processes the SCADA archive payloads fetched from AEMO.
- Dispatch processor → Dispatch fetcher: raw input · Processes dispatch ZIP payloads fetched from AEMO.
- Refresh script → BESS fallback: regenerates · Maintenance script rebuilds the fallback BESS list.
- GitHub Actions → Refresh script: runs · Automation invokes the refresh script.
- GitHub Actions → Container: deploys · Automation supports containerized sync and release flow.
- Container → FastAPI app: runs · Container starts the FastAPI application under Uvicorn.