Skip to main content

DWD API FastAPI

A FastAPI application that serves as a proxy for the DWD ASP.NET API, providing tank data with forecasting capabilities.

Features

  • Tank Data API: Fetch hydraulics and quality data for tanks
  • Forecasting: Extend time series data by 25% using averaged values
  • Interactive Documentation: Built-in Swagger UI and ReDoc
  • Graph Testing: Python script to visualize data similar to React app

API Endpoints

Core Endpoints

  • GET / - Health check
  • GET /tanks - List all available tanks
  • GET /tanks/{tank_id}/metrics - Get available hydraulics metrics
  • GET /tanks/{tank_id}/species - Get available quality species

Data Endpoints

  • GET /tanks/{tank_id}/hydraulics - Get hydraulics data
  • GET /tanks/{tank_id}/quality - Get quality data
  • GET /tanks/{tank_id}/graph-data - Get combined graph data with optional forecasting

Graph Data Endpoint Parameters

  • hydraulics_metric: Hydraulics metric to fetch (e.g., "Head", "Demand")
  • quality_species: Quality species to fetch (e.g., "AGE", "Chlorine")
  • scenario_id: Scenario ID (default: 1)
  • include_forecast: Include forecast data (default: true)

Installation

  1. Install dependencies:
pip install -r requirements.txt
  1. Run the application:
uvicorn main:app --reload --host 0.0.0.0 --port 8000
  1. Access the API documentation:
  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

Testing

Run the graph testing script to visualize data:

python test_graph.py

This will:

  • Fetch tank data from the FastAPI
  • Create matplotlib graphs similar to the React app
  • Show both real and forecast data
  • Save data to JSON files for analysis

Forecasting

The forecasting feature extends time series data by 25% using:

  • Averaged Values: All numeric fields are averaged from historical data
  • Time Extension: New timestamps are generated based on average intervals
  • Marked Data: Forecast points are marked with isForecast: true

Data Flow

  1. FastAPI receives request for tank data
  2. Fetches data from ASP.NET API endpoints
  3. Applies forecasting logic (if requested)
  4. Returns combined hydraulics and quality data
  5. Frontend can consume this data for visualization

Configuration

The application connects to the ASP.NET API at:

  • Base URL: Configured in main.py
  • Endpoints: /api/EN2/TankHydr and /api/EN2/TankQual

Development

  • Main Application: main.py
  • Testing Script: test_graph.py
  • Documentation: Tank_Graph_Data_Flow.md
  • Dependencies: requirements.txt