ocpi-tariffs 0.20.0

OCPI tariff calculations
Documentation
use std::sync::LazyLock;

use crate::{json::schema, json_schema};

/// The fields and structure allowed for a V211 tariff.
pub static TARIFF_SCHEMA: LazyLock<schema::Element> = LazyLock::new(|| {
    json_schema!({
        "id",
        "currency",
        "tariff_alt_text": [{
            "language",
            "text"
        }],
        "tariff_alt_url",
        "elements": [{
            "price_components": [{
                "type",
                "price",
                "step_size"
            }],
            "restrictions": {
                "start_time",
                "end_time",
                "start_date",
                "end_date",
                "min_kwh",
                "max_kwh",
                "min_power",
                "max_power",
                "min_duration",
                "max_duration",
                "day_of_week": [],
            }
        }],
        "energy_mix": {
            "is_green_energy",
            "energy_sources": [{
                "source",
                "percentage"
            }],
            "environ_impact": [{
                "source",
                "amount"
            }],
            "supplier_name",
            "energy_product_name",
        },
        "last_updated",
    })
});

/// The fields and structure allowed for a V211 CDR.
pub static CDR_SCHEMA: LazyLock<schema::Element> = LazyLock::new(|| {
    json_schema!({
        "id",
        "start_date_time",
        "stop_date_time",
        "auth_id",
        "auth_method",
        "location": {
            "id",
            "type",
            "name",
            "address",
            "city",
            "postal_code",
            "country",
            "coordinates": {
                "latitude",
                "longitude"
            },
            "related_locations",
            "evses": [{
                "uid",
                "evse_id",
                "status",
                "status_schedule": [{
                    "period_begin",
                    "period_end",
                    "status"
                }],
                "capabilities": [],
                "connectors": [{
                    "id",
                    "standard",
                    "format",
                    "power_type",
                    "voltage",
                    "amperage",
                    "tariff_id",
                    "terms_and_conditions",
                    "last_updated"
                }],
                "floor_level",
                "coordinates": {
                    "latitude",
                    "longitude"
                },
                "physical_reference",
                "directions": [{
                    "language",
                    "text"
                }],
                "parking_restrictions",
                "images": [{
                    "url",
                    "thumbnail",
                    "category",
                    "type",
                    "width",
                    "height"
                }],
                "last_updated"
            }],
            "directions": [{
                "language",
                "text"
            }],
            "operator": {
                "name",
                "website",
                "logo": {
                    "url",
                    "thumbnail",
                    "category",
                    "type",
                    "width",
                    "height"
                }
            },
            "suboperator": {
                "name",
                "website",
                "logo": {
                    "url",
                    "thumbnail",
                    "category",
                    "type",
                    "width",
                    "height"
                }
            },
            "owner": {
                "name",
                "website",
                "logo": {
                    "url",
                    "thumbnail",
                    "category",
                    "type",
                    "width",
                    "height"
                }
            },
            "facilities": [],
            "time_zone",
            "opening_times": [{
                "regular_hours": [{
                    "weekday",
                    "period_begin",
                    "period_end"
                }],
                "twentyfourseven",
                "exceptional_openings": [{
                    "period_begin",
                    "period_end"
                }],
                "exceptional_closings": [{
                    "period_begin",
                    "period_end"
                }]
            }],
            "charging_when_closed",
            "images": [{
                "url",
                "thumbnail",
                "category",
                "type",
                "width",
                "height"
            }],
            "energy_mix": {
                "is_green_energy",
                "energy_sources": [{
                    "source",
                    "percentage"
                }],
                "environ_impact": [{
                    "source",
                    "amount"
                }],
                "supplier_name",
                "energy_product_name",
            },
            "last_updated",
        },
        "meter_id",
        "currency",
        "tariffs": [{
            "id",
            "currency",
            "tariff_alt_text": [{
                "language",
                "text"
            }],
            "tariff_alt_url",
            "elements": [{
                "price_components": [{
                    "type",
                    "price",
                    "step_size"
                }],
                "restrictions": {
                    "start_time",
                    "end_time",
                    "start_date",
                    "end_date",
                    "min_kwh",
                    "max_kwh",
                    "min_power",
                    "max_power",
                    "min_duration",
                    "max_duration",
                    "day_of_week": [],
                }
            }],
            "energy_mix": {
                "is_green_energy",
                "energy_sources",
                "environ_impact",
                "supplier_name",
                "energy_product_name",
            },
            "last_updated",
        }],
        "charging_periods": [{
            "start_date_time",
            "dimensions": [{
                "type",
                "volume"
            }]
        }],
        "total_cost",
        "total_energy",
        "total_time",
        "total_parking_time",
        "remark",
        "last_updated",
    })
});