consumption_analysis
consumption_analysis ¤
EnergyConsumptionEvents ¤
EnergyConsumptionEvents(
dataframe: DataFrame,
*,
event_uuid: str = "energy:consumption",
time_column: str = "systime",
uuid_column: str = "uuid"
)
Bases: Base
Energy: Consumption Analysis
Analyze energy consumption patterns from meter/sensor signals.
Supports two data models via constructor parameters:
-
Standard (ts-shape default)::
EnergyConsumptionEvents(df)
expects: systime | uuid | value_double¤
-
Raw CSV (time + id + value)::
EnergyConsumptionEvents(df, time_column="time", uuid_column="id")
expects: time | id | value¤
pass value_column="value" to each method¤
Methods: - consumption_by_window: Aggregate energy per time window from a meter UUID. - peak_demand_detection: Flag windows where consumption exceeds a threshold. - consumption_baseline_deviation: Compare actual vs rolling baseline. - energy_per_unit: Energy per production unit when paired with a counter. - normalize: Static helper to convert raw CSV format to standard schema.
normalize
staticmethod
¤
normalize(
df: DataFrame,
*,
series_id: str,
time_column: str = "time",
value_column: str = "value",
id_column: str | None = None
) -> pd.DataFrame
Convert a raw energy DataFrame to the standard ts-shape schema.
Handles two input formats:
- Two-column CSV: (time, value) —
series_idis assigned as uuid. - Three-column with explicit id: (time, id_column, value) — values from
id_columnare used as uuid;series_idis ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Raw DataFrame. |
required |
series_id
|
str
|
UUID to assign when no id_column is provided. |
required |
time_column
|
str
|
Name of the timestamp column in df. |
'time'
|
value_column
|
str
|
Name of the value column in df. |
'value'
|
id_column
|
str | None
|
Optional column name whose values become the uuid. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns: systime, uuid, value_double, is_delta |
consumption_by_window ¤
consumption_by_window(
meter_uuid: str,
*,
value_column: str = "value_double",
window: str = "1h",
agg: str = "sum"
) -> pd.DataFrame
Aggregate energy consumption per time window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meter_uuid
|
str
|
UUID of the energy meter signal. |
required |
value_column
|
str
|
Column containing energy readings. |
'value_double'
|
window
|
str
|
Resample window (e.g. '1h', '15min', '1D'). |
'1h'
|
agg
|
str
|
Aggregation method ('sum', 'mean', 'max'). |
'sum'
|
Returns:
| Name | Type | Description |
|---|---|---|
DataFrame |
DataFrame
|
start, uuid, source_uuid, is_delta, consumption |
peak_demand_detection ¤
peak_demand_detection(
meter_uuid: str,
*,
value_column: str = "value_double",
window: str = "15min",
threshold: float | None = None,
percentile: float = 0.95
) -> pd.DataFrame
Detect peak demand periods exceeding a threshold.
If threshold is None, uses the given percentile of windowed consumption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meter_uuid
|
str
|
UUID of the energy meter signal. |
required |
value_column
|
str
|
Column containing energy readings. |
'value_double'
|
window
|
str
|
Resample window for demand calculation. |
'15min'
|
threshold
|
float | None
|
Absolute demand threshold. If None, auto-calculated. |
None
|
percentile
|
float
|
Percentile to use for auto-threshold (default 95th). |
0.95
|
Returns:
| Name | Type | Description |
|---|---|---|
DataFrame |
DataFrame
|
start, uuid, source_uuid, is_delta, demand, threshold, is_peak |
consumption_baseline_deviation ¤
consumption_baseline_deviation(
meter_uuid: str,
*,
value_column: str = "value_double",
window: str = "1h",
baseline_periods: int = 24,
deviation_threshold: float = 0.2
) -> pd.DataFrame
Compare actual consumption vs rolling baseline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meter_uuid
|
str
|
UUID of the energy meter signal. |
required |
value_column
|
str
|
Column containing energy readings. |
'value_double'
|
window
|
str
|
Resample window for consumption. |
'1h'
|
baseline_periods
|
int
|
Number of windows for rolling baseline. |
24
|
deviation_threshold
|
float
|
Fractional deviation to flag (0.2 = 20%). |
0.2
|
Returns:
| Name | Type | Description |
|---|---|---|
DataFrame |
DataFrame
|
start, uuid, source_uuid, is_delta, consumption, baseline, deviation_pct, is_anomaly |
energy_per_unit ¤
energy_per_unit(
meter_uuid: str,
counter_uuid: str,
*,
energy_column: str = "value_double",
counter_column: str = "value_integer",
window: str = "1h"
) -> pd.DataFrame
Calculate energy consumption per production unit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meter_uuid
|
str
|
UUID of the energy meter signal. |
required |
counter_uuid
|
str
|
UUID of the production counter signal. |
required |
energy_column
|
str
|
Column with energy readings. |
'value_double'
|
counter_column
|
str
|
Column with counter readings. |
'value_integer'
|
window
|
str
|
Time window for aggregation. |
'1h'
|
Returns:
| Name | Type | Description |
|---|---|---|
DataFrame |
DataFrame
|
start, uuid, source_uuid, is_delta, energy, units_produced, energy_per_unit |