-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Svyatoslav Rogozin edited this page Dec 11, 2024
·
2 revisions
This wiki outlines the backend and frontend workflows for the application, providing an overview of key components, their interconnections, and operational guidelines.
The backend is built using a Python Flask application. It handles API requests, processes data, and manages the database.
- Framework: Flask serves as the web framework.
-
CORS: Enabled using
flask_cors
to allow API requests from specific origins. -
File Structure:
-
station_status_app.py
: Main application logic. -
config.yaml
: Database and table configuration. -
templates/index.html
: Placeholder for the homepage.
-
- The
load_config
function readsconfig.yaml
for settings such as:- Database connection details.
- Table mappings and respective columns.
- Missing configuration files log an error and terminate the application.
- Logs are written to
app.log
with:- Log Level:
INFO
- Format:
timestamp - loglevel - message
- Encoding: UTF-8
- Log Level:
- The
get_connection
function uses ODBC Driver 18 for SQL Server to connect to the database, with credentials fromconfig.yaml
. - Errors are logged for troubleshooting.
- The
fetch_data
function retrieves table data by:- Querying the latest timestamp (
TmStamp
). - Filtering data within a calculated time range.
- Returning results as a list of dictionaries.
- Querying the latest timestamp (
-
Function:
calculate_hf_status
-
Purpose: Evaluates HF data by:
- Checking total rows.
- Identifying missing columns and values.
- Detecting issues like excessive NA values or identical consecutive readings.
- Outcome: Status ("Online" or "Offline") and a list of violations.
-
Function:
calculate_lf_status
-
Purpose: Assesses LF data for:
- Sufficient observations.
- Consecutive invalid values (e.g., NA).
- Outcome: Similar to HF data.
- The
calculate_quality_data
function generates statistics for specified columns:- Total non-NA values.
- Mean values (if applicable).
-
Endpoint:
/api/station_combined_status/<station_name>
-
Workflow:
- Validates the station name.
- Retrieves HF and LF table configurations.
- Fetches HF and LF data.
- Calculates quality metrics and status.
- Combines metrics, statuses, and violations into a JSON response.
- Returns the response with timestamps and an overall status.
- Timestamps are in UTC and converted if needed using
datetime
andpytz
.
- Flask app runs with:
- Debug Mode: Enabled (for development).
- Host:
0.0.0.0
(binds to all interfaces). - Port:
5000
.
- User requests station status via API.
- Backend validates and fetches data.
- Quality metrics and statuses are calculated.
- JSON response is prepared and sent to the frontend.
The frontend is built to provide an interactive map interface for displaying EC station statuses.
- Framework: React serves as the frontend framework.
- Map Integration: Leaflet.js is used for rendering the map and handling geospatial data.
-
Station Configuration:
- Example:
const stations = [ { name: "StationA", fullName: "Station A Full Name", coords: [58.123, 26.789], apiUrl: "https://example.com/api/status/StationA" } ]; export default stations;
- Example:
- The
Map.js
component:- Initializes the map with predefined bounds and zoom levels.
- Loads station markers dynamically by fetching status data from the backend API.
- Example:
const map = L.map('map', { minZoom: 7, maxZoom: 12, maxBounds: [[57.9, 25.5], [58.9, 27.5]] }).setView([58.3, 26.5], 8);
- Fetch station data using the
fetchStationData
utility function. - Add markers for each station:
stations.forEach(async (station) => { const data = await fetchStationData(station.apiUrl); const marker = L.marker(station.coords).bindPopup(`${station.fullName}: ${data.status}`); marker.addTo(map); });
- CSS for styling map markers is managed in
src/styles/map.css
. - Example:
.station-marker { background-color: white; border: 2px solid black; border-radius: 50%; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; font-size: 12px; }
- Map is initialized and rendered with Leaflet.
- Station data is fetched from the backend API.
- Markers are dynamically added to the map.
- Users interact with the map to view station statuses.