$ show FlexMeasures/flexmeasures
FlexMeasures is a Flask-based energy flexibility management platform that ingests time-series sensor data, forecasts future values, schedules flexible assets (batteries, heat pumps, industrial processes) using linear optimization, and reports on performance. It provides a REST API (v3.0), a web UI with interactive charts, a CLI for data management, and background job queues (RQ) for forecasting, scheduling, and automation. The architecture is a multi-tenant web application with PostgreSQL, Redis, and optional Sentry monitoring. It features a plugin system for custom data generators (forecasters, schedulers, reporters) and automation handlers. The codebase is well-tested with extensive unit and integration tests, and follows modern Python practices (type hints, Marshmallow schemas, Click CLI).
The LLM identified 3 files worth highlighting for reuse:
Implements the StorageScheduler, a reusable optimization scheduler for battery-like assets. It formulates a linear programming problem (using Pyomo) to minimize cost or maximize profit given energy prices, state-of-charge constraints, and efficiency losses. The scheduler is parameterized via a flex model and can be extracted for use in other energy optimization projects with minimal adaptation.
Provides custom Marshmallow fields (SensorIdField, QuantityField, AwareDateTimeField, DurationField, etc.) that encapsulate domain-specific validation and serialization logic. These fields are reusable across API endpoints, CLI commands, and internal services, and can be extracted into a standalone library for any project needing validated sensor references, time-aware datetimes, or unit-aware quantities.
Defines the AutomationHandler base class and registration system for pluggable automation types (forecasting, scheduling, reporting, custom). Handlers declare a type, associated data generator, queue, and configuration/parameter schemas. The system automatically creates CLI commands, validates cron expressions, and dispatches RQ jobs. This pattern can be reused in any application needing extensible scheduled tasks with plugin support.