Flaring Monitor
The Flaring Monitor is a comprehensive flaring compliance service that tracks flare event volumes, validates Form R-32 filings, calculates emissions (CO2e), forecasts authorization exceedances, manages repair obligations, handles operational events with deduplication and submission guards, and provides burn rate projections.
Overview
Texas operators that flare or vent natural gas must comply with RRC Rule 32 (Statewide Rule 32). The flaring monitor provides the data backbone for this compliance workflow:
- Volume tracking — Ingest flaring events, compute cumulative volumes, and assess compliance against authorization limits
- Pre-filing validation — Validate Form R-32 data completeness before submission
- Emissions calculation — Compute CO2, CH4, and CO2-equivalent emissions for flaring and venting, assess EPA OOOOb applicability
- Predictive analysis — Forecast when an authorization will be exceeded using decline curve analysis and model infrastructure delay impacts
- Audit trail — Tag events with applicable regulatory frameworks (RRC, EPA, GHGRP) and write HMAC-signed audit entries
- Flare event CRUD — Full lifecycle management of individual flare events with correlation
- Burn rate projections — Calculate daily burn rates and project authorization exhaustion dates
- Repair obligations — Track repair commitments triggered by flare events
- Operational events — Unified event system for 5+ event types with deduplication rules, custom event types, and submission guards
Port & Language
| Property | Value |
|---|---|
| Port | 8007 |
| Language | Python 3.12 |
| Framework | FastAPI |
| Entry point | src/flaring/main.py |
Key Endpoints
Volume Tracking & Compliance
| Method | Path | Description |
|---|---|---|
POST | /flaring/ingest | Ingest flaring events and compute compliance status. |
POST | /flaring/assess | Assess current flaring volumes against authorization limits. |
POST | /flaring/validate | Validate Form R-32 data before submission. |
Emissions & Audit
| Method | Path | Description |
|---|---|---|
POST | /flaring/emissions | Calculate CO2e emissions from flaring/venting volumes. |
POST | /flaring/tag-frameworks | Tag a flaring event with applicable regulatory frameworks. |
POST | /flaring/form-pr | Generate Form PR-ready data from flaring events. |
Predictive Analysis
| Method | Path | Description |
|---|---|---|
POST | /flaring/forecast | Forecast authorization exceedance using decline curve analysis. |
POST | /flaring/infrastructure-delay | Model infrastructure delay impact on flaring compliance. |
Flare Events CRUD
| Method | Path | Description |
|---|---|---|
POST | /flare-events | Create a new flare event. |
GET | /flare-events | List flare events with filtering. |
GET | /flare-events/{event_id} | Get a single flare event. |
PUT | /flare-events/{event_id} | Update a flare event. |
POST | /flare-events/{event_id}/correlate | Correlate a flare event with another event. |
Burn Rate & Projections
| Method | Path | Description |
|---|---|---|
GET | /authorizations/{auth_id}/burn-rate | Get burn rate data for an authorization. |
GET | /authorizations/{auth_id}/projection | Project authorization exhaustion date. |
Repair Obligations
| Method | Path | Description |
|---|---|---|
GET | /repair-obligations | List repair obligations (overdue, upcoming, completed). |
PUT | /repair-obligations/{id} | Update repair status (completion date, narrative). |
Operational Events (Unified)
| Method | Path | Description |
|---|---|---|
POST | /events | Create an operational event (any type). Runs deduplication and guard rules. |
GET | /events | List operational events with filtering, pagination, sorting. |
GET | /events/{event_id} | Get a single operational event. |
PUT | /events/{event_id} | Update an operational event. |
PUT | /events/{event_id}/status | Transition event status. |
POST | /events/agent-draft | Create an agent-assisted draft event. |
Duplication Rules
| Method | Path | Description |
|---|---|---|
GET | /events/duplication-rules | List deduplication rules. |
POST | /events/duplication-rules | Create a deduplication rule. |
PUT | /events/duplication-rules/{id} | Update a deduplication rule. |
Custom Event Types
| Method | Path | Description |
|---|---|---|
GET | /events/types | List custom event type definitions. |
POST | /events/types | Create a custom event type. |
PUT | /events/types/{id} | Update a custom event type. |
Submission Guard Rules
| Method | Path | Description |
|---|---|---|
GET | /events/guard-rules | List submission guard rules. |
POST | /events/guard-rules | Create a guard rule. |
PUT | /events/guard-rules/{id} | Update a guard rule. |
Dashboard & Seeding
| Method | Path | Description |
|---|---|---|
GET | /flaring/dashboard/{operator_id} | Dashboard summary for an operator’s flaring compliance. |
POST | /seed-events | Seed demo events, duplication rules, and custom event types. |
GET | /health | Health check. |
Architecture
Module Breakdown
src/flaring/
├── main.py # FastAPI app, core endpoint definitions, background tasks
├── config.py # Settings and emission factor constants
├── schemas.py # Pydantic request/response models
├── volume_tracker.py # Flaring volume processing and compliance assessment
├── validation.py # Form R-32 pre-filing validation
├── prediction.py # Decline curve forecasting and infra delay modeling
├── audit_tagging.py # Regulatory framework tagging, Form PR generation, audit writes
├── burn_rate.py # Burn rate calculation and alert thresholds
├── burn_rate_routes.py # Burn rate API routes
├── event_routes.py # Flare event CRUD routes
├── repair_routes.py # Repair obligation routes
├── operational_event_routes.py # Unified operational event CRUD
├── duplication_engine.py # Event deduplication rule engine
├── duplication_rule_routes.py # Deduplication rule CRUD routes
├── event_type_service.py # Custom event type management
├── event_type_routes.py # Custom event type routes
├── submission_guard_engine.py # Pre-submission validation guard engine
├── guard_rule_service.py # Guard rule management service
├── guard_rule_routes.py # Guard rule routes
├── compliance_triggers.py # Event-driven compliance trigger logic
├── correlation.py # Event correlation logic
├── event_number.py # Sequential event number generation
├── override_capture.py # Override tracking for guard acknowledgments
├── seed_events.py # Demo operational event seeder
├── seed_duplication_rules.py # Demo deduplication rule seeder
└── seed_event_types.py # Demo custom event type seederEmissions Calculation
The /flaring/emissions endpoint computes emissions using EPA-standard factors:
| Factor | Value | Unit |
|---|---|---|
| CO2 per MCF flared | 0.054 | metric tons |
| CH4 slip per MCF (flared) | 0.00038 | metric tons |
| CH4 per MCF vented | 0.019 | metric tons |
| CH4 GWP (global warming potential) | 28 | CO2e multiplier |
| GHGRP threshold | 25,000 | metric tons CO2e/year |
EPA OOOOb applicability: Wells spudded after November 15, 2021 are subject to OOOOb methane emission standards.
Alert Thresholds
| Metric | Warning | Critical |
|---|---|---|
| Volume vs. authorization limit | 80% | 90% |
| Authorization days remaining | 150 days | 180 days (max) |
Nightly Burn Rate Recalculation
A background task runs every 24 hours (with a 60-second startup delay) that recalculates burn rates for all active authorizations:
- Query all distinct
authorization_idvalues fromflare_events - For each authorization, aggregate daily volumes
- Recalculate the burn rate and update projections
Operational Event Deduplication
When creating an operational event, the DuplicationRulesEngine checks the new event against configurable rules to detect potential duplicates:
- Rules define matching criteria (entity, time window, event type, severity)
- If a potential duplicate is detected, the API returns a warning
- The caller can acknowledge the duplication and proceed by setting
duplication_acknowledged: true
Submission Guards
The SubmissionGuardEngine evaluates pre-submission rules before an event can be created:
- Rules define conditions that must be met (e.g., required fields, minimum data quality)
- If a guard rule fails, the API returns the failing conditions
- The caller can acknowledge and override by setting
guard_acknowledged: true
Dependencies
Python Packages
| Package | Version | Purpose |
|---|---|---|
fastapi | ^0.115 | Web framework |
uvicorn | ^0.34 | ASGI server |
asyncpg | ^0.29 | PostgreSQL async driver |
httpx | ^0.28 | HTTP client for KG queries |
aegis-shared | local | Shared models, events, DB helpers |
Service Dependencies
| Service | Protocol | Purpose |
|---|---|---|
| Knowledge Graph Service (8003) | HTTP | Well and authorization data for dashboard |
| PostgreSQL | TCP | Flare events, operational events, repair obligations |
Configuration
| Environment Variable | Default | Description |
|---|---|---|
FLARING_HOST | 0.0.0.0 | Bind address |
FLARING_PORT | 8007 | Bind port |
DATABASE_URL | postgresql://aegis:aegis_local@localhost:5432/aegis | PostgreSQL connection |
KNOWLEDGE_GRAPH_SERVICE_URL | http://localhost:8003 | Knowledge graph service URL |
HMAC_SIGNING_KEY | aegis-local-hmac-key-change-in-production | Key for audit trail HMAC signatures |
DB_SCHEMA | ag_catalog | Database schema prefix |
Hardcoded emission factors and thresholds are in config.py. See the Emissions Calculation section above for values.
Running Locally
cd services/flaring-monitor
poetry install
poetry run uvicorn flaring.main:app --reload --port 8007Seeding Demo Data
# Seed operational events, duplication rules, and custom event types
curl -X POST http://localhost:8007/seed-eventsThe flaring monitor requires PostgreSQL for event storage. The knowledge graph service is only needed for the dashboard endpoint. All volume tracking, validation, and emissions calculation endpoints are self-contained.