ocpi-tariffs 0.54.0

OCPI tariff calculations
Documentation
//! Explain an OCPI object in human language.
//!
//! Where schema validation flags problems in a tariff, `explain` describes what a tariff says:
//! what it charges, for which dimension, and how the rate changes as a session progresses. The
//! explanation folds in how `ocpi-tariffs` interprets the spec, not just the raw field values.
//!
//! Use [`tariff::explain`](crate::tariff::explain) to explain a tariff.
//!
//! # What explaining is, and is not
//!
//! `explain` states what a tariff says. It finds no fault in the tariff and proposes no edit to it.
//! What it returns is prose, never a tariff. The warnings returned alongside the explanation come
//! from parsing the document rather than from explaining it.
//!
//! A tariff that makes no sense gets an explanation that makes no sense. An element whose
//! restrictions exclude every session is described like any other, under the bounds its author
//! wrote. Reporting that such a restriction is pointless belongs to [`lint`](crate::lint), and
//! repairing it belongs to [`tariff::fix`](crate::tariff::fix). Linting leaves the explanation
//! unchanged, so a caller who wants one covering only what a session can be charged fixes what
//! `lint` reports and explains the result.
//!
//! The explanation does make some decisions of its own. Each follows from how the pricing engine
//! reads a tariff rather than from a judgment about its author:
//!
//! - An element restricted to `reservation` is left out. It prices a kind of session the
//!   explanation is not about.
//! - A tier an earlier tier already covers is left out. The earlier tier supplies the rate, so
//!   the later one never does.
//! - A flat fee of zero gets no section when it is the only flat tier, because it charges nothing.
//! - The billing step stated for a dimension comes from the tiers a session can reach. A tier
//!   whose own bounds exclude every session bills nothing, so its step is not one a session meets.

#[cfg(test)]
mod test_en_us;

#[cfg(test)]
mod test_nl_nl;

#[cfg(test)]
mod test_real_world;

mod ir;
mod render;
mod tariff;

#[doc(inline)]
pub use render::Language;

use crate::{Verdict, tariff::Warning};

/// Explain the given tariff in the given language and return the explanation as Markdown.
pub(crate) fn tariff(
    tariff: &crate::tariff::Versioned<'_>,
    language: Language,
) -> Verdict<String, Warning> {
    tariff::explain(tariff, language)
}