Fork of Lightning_Report adding: - n8n_report_branch.json: workflow branch for storm-triggered report delivery - report_service/: FastAPI microservice wrapping create_docx_report() so n8n can produce byte-identical reports without fighting the Python Code sandbox Made-with: Cursor
3.3 KiB
3.3 KiB
Batch Report Generation Guide
Overview
The batch generation system automates lightning report generation for multiple wind farms by fetching data from the API and processing them in batch.
Setup
1. Install Dependencies
pip install -r requirements.txt
2. Create .env File
Create a .env file in the project root with your API key:
API_KEY=your_api_key_here
3. Create Configuration File
Copy wind_farms_config.example.json to wind_farms_config.json and configure your wind farms:
cp wind_farms_config.example.json wind_farms_config.json
Edit wind_farms_config.json with your farms' details.
Configuration
API Configuration
{
"api_config": {
"base_url": "https://risk.tarla.io/api",
"timeout_seconds": 30,
"retry_attempts": 3,
"default_query_range": {
"method": "current_month"
}
}
}
Wind Farm Configuration
Each farm can have:
- enabled:
trueorfalse- Controls whether to generate report - location_bounds.method:
"auto"(calculate from turbines) or"manual"(specify) - location_bounds.padding_km: Extra buffer beyond max distance ring (default: 5km)
- date_range.method:
"auto"(use query_range to fetch, then detect from data) or"manual"(specify dates)
Query Range Options (for auto date_range)
"current_month": First day of current month to today"last_month": Entire previous month"days_back": Last N days (requiresdaysparameter)"custom": Specific dates (requiresstart_dateandend_date)
Usage
Process All Enabled Farms
python batch_generate.py --config wind_farms_config.json
List Farms
python batch_generate.py --config wind_farms_config.json --list-farms
Process Specific Farm
python batch_generate.py --config wind_farms_config.json --farm-id dagpazari_RES
Process All Farms (Ignore Enabled Flag)
python batch_generate.py --config wind_farms_config.json --force-all
Process Disabled Farm
python batch_generate.py --config wind_farms_config.json --farm-id disabled_farm --force
How It Works
Location Bounds Auto-Calculation
- Calculate Centroid: Average of all turbine coordinates
- Find Max Distance: Maximum distance from centroid to any turbine
- Add Distance Ring: Add max distance ring (e.g., 30km)
- Add Padding: Add padding (e.g., 5km)
- Result: Center (centroid) + Radius (total distance)
Output
- Reports are saved to each farm's
output_directoryin the config - Batch summary saved to
reports/batch_summary_YYYY-MM-DD.json - Log file:
batch_generation_YYYY-MM-DD.log
API Endpoints
The system uses:
- Lightning data:
https://risk.tarla.io/api/lightning-data/historical/ - Storm data:
https://risk.tarla.io/api/storm-data/historical/
Parameters:
queryType=circlecenterLongitude(longitude first)centerLatituderadius(in meters)startDate=YYYY-MM-DDendDate=YYYY-MM-DD
Troubleshooting
API Key Not Found
Ensure .env file exists with API_KEY=your_key
No Data Fetched
- Check API credentials
- Verify date range is correct
- Check if location bounds cover the area
- Verify API endpoint URLs
Farm Skipped
- Check if
enabled: falsein config - Use
--forceflag to process disabled farms