Definitions / voltage_out_of_band
Voltage out of band
detector, runs realtimeA feeder whose end-of-line voltage has been outside the statutory band for several consecutive 15-minute readings, running now.
control · Head of Network Operations · version 1
The last min_readings readings up to now are all below low_pu or all above high_pu. The episode starts at the first out-of-band reading after the last in-band one within look_back_hours. Readings while the whole feeder is off (no voltage) do not count either way.
Latest change: First version.
SQL
WITH recent AS (
SELECT r.feeder_id, r."at", r.voltage_pu,
CASE WHEN r.voltage_pu < {low_pu} THEN 'low' WHEN r.voltage_pu > {high_pu} THEN 'high' ELSE 'ok' END AS band,
row_number() OVER (PARTITION BY r.feeder_id ORDER BY r."at" DESC) AS rn
FROM feeder_readings r
WHERE r."at" > {now} - INTERVAL ({look_back_hours}) HOUR AND r."at" <= {now} AND r.voltage_pu IS NOT NULL
),
tail AS (
SELECT feeder_id, min(band) AS band, max(band) AS band2, count(*) AS n, min(voltage_pu) AS vmin, max(voltage_pu) AS vmax
FROM recent WHERE rn <= {min_readings} GROUP BY feeder_id
),
runs AS (
SELECT t.feeder_id, t.band, t.vmin, t.vmax,
coalesce((SELECT min(r."at") FROM recent r WHERE r.feeder_id = t.feeder_id AND r.band = t.band
AND r."at" > coalesce((SELECT max(q."at") FROM recent q WHERE q.feeder_id = t.feeder_id AND q.band <> t.band),
TIMESTAMP '1900-01-01')), {now}) AS started_at,
(SELECT count(*) FROM recent r WHERE r.feeder_id = t.feeder_id AND r.band = t.band
AND r."at" > coalesce((SELECT max(q."at") FROM recent q WHERE q.feeder_id = t.feeder_id AND q.band <> t.band),
TIMESTAMP '1900-01-01')) AS readings
FROM tail t
WHERE t.n = {min_readings} AND t.band = t.band2 AND t.band <> 'ok'
)
SELECT 'feeder' AS subject_type, CAST(u.feeder_id AS TEXT) AS subject_id, u.feeder_id, u.started_at,
CASE WHEN u.vmin < {low_pu} - 0.04 OR u.vmax > {high_pu} + 0.04 THEN 'high' ELSE 'medium' END AS severity,
json_object(
'feeder_id', u.feeder_id,
'feeder', f.code,
'tie_feeder_id', f.tie_feeder_id,
'direction', u.band,
'lowest_pu', u.vmin,
'highest_pu', u.vmax,
'readings_out_of_band', u.readings,
'band', [{low_pu}, {high_pu}],
'deviation_pct', round(100 * greatest(1 - u.vmin, u.vmax - 1), 1)
) AS evidence
FROM runs u JOIN feeders f ON f.id = u.feeder_id
ORDER BY u.started_at, u.feeder_id
Tests
| meaning | test | result | observed | expected |
|---|---|---|---|---|
| control | count_between | pass | 2 | between 0.0 and 10.0 |
| control | unique | pass | {'duplicates': 0} | feeder_id unique |
| control | detector_shape | pass | {'missing_columns': [], 'bad_rows': 0, 'rows': 2} | columns ['subject_type', 'subject_id', 'started_at', 'evidence'], evidence is an object |