flexpool-telemetry 0.2.0

flexpool live telemetry: quality, plausibility, a bounded store with quarter-hour aggregation, pool summaries and the sandbox simulator. No I/O; time is an input.
Documentation
//! Live telemetry for flexpool.
//!
//! Measurements arrive from devices (or the sandbox simulator) as power in kW — generator
//! convention: feed-in and battery discharge positive — and battery state of charge in percent.
//! This crate decides their [`Quality`], keeps them in a bounded [`Store`], aggregates them per
//! quarter hour and sums them per pool. It reads no clock: every function takes `now`.
//!
//! Times are Unix seconds (`i64`); values are measurements (`f64` at the API, `f32` in the rings).
//! Nothing here becomes a market quantity, so no value crosses the quantisation boundary.

mod quality;
pub mod sim;
mod store;
mod summary;

pub use quality::{
    FUTURE_TOLERANCE_SECS, Flags, Quality, Quantity, Reading, classify, plausible, stale_limit,
};
pub use store::{
    AssetNow, CLOCK_STEP_SECS, Pushed, QUARTER_BYTES, QUARTERS_MAX, QuarterAggregate, RECENT_MAX,
    RECENT_SECS, Recent, Store,
};
pub use summary::{PoolLive, QualityCounts, summarise};

/// Seconds in a quarter hour.
pub const QUARTER_SECS: i64 = 900;

/// The start of the quarter hour containing `t` (Berlin quarters align with UTC quarters).
#[must_use]
pub const fn quarter_start(t: i64) -> i64 {
    t - t.rem_euclid(QUARTER_SECS)
}

/// An asset's rated power in kW as a float (for plausibility and simulation only).
#[must_use]
pub fn rated_kw(asset: &flexpool_portfolio::Asset) -> f64 {
    use rust_decimal::prelude::ToPrimitive;
    asset.rated_kw.value().to_f64().unwrap_or(0.0)
}

/// A battery's usable energy in kWh as a float, if it has one.
#[must_use]
pub fn energy_kwh(asset: &flexpool_portfolio::Asset) -> Option<f64> {
    use rust_decimal::prelude::ToPrimitive;
    asset.energy_kwh.and_then(|e| e.value().to_f64())
}