flexibility 0.1.0

Grid flexibility as exact, replayable arithmetic: limits, baselines, UFTP-exact settlement, and UFTP, EEBUS, S2, OpenADR, IEC 104 converters.
Documentation
//! 003 user story 4: score a method exactly.

use flexibility::jiff::Timestamp;
use flexibility::jiff::tz::TimeZone;
use flexibility::{Error, Grid, IspDuration, Series, accuracy, kw};

fn grid(n: u32) -> Grid {
    Grid::new(
        Timestamp::UNIX_EPOCH,
        IspDuration::FIFTEEN_MINUTES,
        n,
        TimeZone::UTC,
    )
    .unwrap()
}

#[test]
fn metrics_are_exact() {
    let baseline = Series::filled(grid(3), kw!(10));
    let actual = Series::new(grid(3), vec![kw!(9), kw!(10), kw!(11)]).unwrap();
    let s = accuracy::score([(&baseline, &actual)]).unwrap();
    assert_eq!(s.count, 3);
    assert_eq!(s.bias.watts(), 0);
    assert_eq!(s.rmse.watts(), 816);
    assert_eq!(s.rrmse_basis_points, Some(816));
}

#[test]
fn bias_shows_over_estimation_across_pairs() {
    let b = Series::filled(grid(2), kw!(5));
    let a1 = Series::filled(grid(2), kw!(4));
    let a2 = Series::filled(grid(2), kw!(4.5));
    let s = accuracy::score([(&b, &a1), (&b, &a2)]).unwrap();
    assert_eq!((s.count, s.bias.watts(), s.rmse.watts()), (4, 750, 790));
}

#[test]
fn nothing_to_score_is_refused() {
    assert!(matches!(accuracy::score([]), Err(Error::NoData { .. })));
    let a = Series::filled(grid(2), kw!(1));
    let b = Series::filled(grid(3), kw!(1));
    assert!(matches!(
        accuracy::score([(&a, &b)]),
        Err(Error::GridMismatch { .. })
    ));
    let zero = Series::filled(grid(2), kw!(0));
    assert_eq!(
        accuracy::score([(&a, &zero)]).unwrap().rrmse_basis_points,
        None
    );
}