metering

German energy metering for Rust

Turn meter readings into interval profiles, community credits and billing quantities with decimal arithmetic and the Europe/Berlin market calendar.

cargo add metering

Working with meter data

Find the settlement window

A Berlin electricity day spans 92, 96 or 100 quarters. The gas day begins at 06:00 local time.

Time and the calendar →

Build an interval profile

Derive a Lastgang from consecutive register readings. Identify gaps, register wraps and meter exchanges.

Series and readings →

Settle community generation

Credit each participant per quarter under the agreement’s rounding, with exact totals for the whole billing period.

Allocation →

Aggregate an autumn electricity day

use metering::prelude::*;

// This autumn Liefertag spans 100 quarters.
let day = DayBoundary::Strom.day(date(2026, 10, 25)).unwrap();
let slots = day
    .intervals(Resolution::QUARTER_HOUR)
    .map(|slot| MeterInterval::quarter_hour(slot.start(), dec!(0.25), QualityFlag::Measured))
    .collect::<Result<Vec<_>, _>>()
    .unwrap();
let series = Series::new(Resolution::QUARTER_HOUR, DayBoundary::Strom, slots).unwrap();

let period = aggregate(&series, day).unwrap();
assert_eq!(period.arbeitsmenge, dec!(25));            // exact Decimal kWh
assert_eq!(period.spitzenleistung_kw, Some(dec!(1)));  // kW, from kWh × 3600 ÷ s
assert_eq!(period.coverage.pct(), Some(dec!(100)));    // against the declared day