Skip to main content

Crate energy_tariff

Crate energy_tariff 

Source
Expand description

Types and calculations for a site’s electricity contracts.

The tariff is data: a SiteTariff holds contracts, and each contract holds the charges that apply. This crate computes each charge that is present. It does not open files, fetch prices, read invoices, or predict peaks.

Parse with SiteTariff::from_json and SiteTariff::from_toml. Both encodings share one serde schema. File open is the caller’s job.

use energy_tariff::{SiteTariff, TariffError};

fn load(toml: &str, json: &str) -> Result<SiteTariff, TariffError> {
    let from_toml = SiteTariff::from_toml(toml)?;
    let from_json = SiteTariff::from_json(json)?;
    assert_eq!(from_toml, from_json);
    Ok(from_toml)
}

Structs§

CalendarDate
A calendar day in the proleptic Gregorian calendar.
ChargeName
Name of one ledger line: {contract}:{kind}.
CivilMinute
Civil local time: month, ISO weekday, minute of day.
CoincidentPeakRule
A coincident-peak rule: 4 or 12 intervals per year, an annual dollars-per-kilowatt rate.
DateRange
Inclusive start and end calendar days.
DemandCharge
A monthly demand charge: dollars per kilowatt-month, 15- or 30-minute window, optional ratchet.
DemandHistory
Prior months’ demand peaks, keyed by YearMonth.
DemandResult
Peak, interval, ratchet, and dollars for one demand charge.
EnergyAdder
A non-zero dollars-per-megawatt-hour adder on a price series.
EnergyPrices
The two energy price series a site may be billed against.
FacilitiesCharge
Dollars per kilowatt, applied to FacilitiesBasis.
FixedCharge
A reported fixed charge. Present in ledgers; never an optimisation lever.
HedgedRate
A hedged flat energy rate, in dollars per megawatt-hour. Negative and non-finite values are refused.
Kilowatt
Kilowatt. Interval demand samples are this.
KilowattHour
Kilowatt-hour. Hourly energy load is this.
LedgerInputs
Inputs every present charge may need. Unused fields are ignored.
MeterScope
Which meters a contract applies to. Any non-empty label.
Minutes
Demand-interval length in minutes. Only 15 or 30.
MonthBill
Energy, demand, facilities, and fixed for one month.
MonthInputs
Inputs for month_bill. Unused slices are ignored. There is no clock.
PeakExposure
Dollar exposure plus, when the charge is not passed through, the reason.
Ratchet
Lookback that floors billed kW at a percentage of recent peaks.
RateWithSource
A rate plus where it came from and whether anyone has verified it.
SiteAlias
A site’s alias: lowercase letters, digits and hyphens, at least one character.
SiteTariff
A site alias and the contracts that apply there.
TimeOfUse
Optional time-of-use window on a demand charge, hours 0..=23 local.
TouPeriod
One time-of-use window: which local times it covers, and its energy rate.
TouSchedule
A non-empty set of time-of-use periods that do not overlap.
Usd
US dollars. Every ledger amount is this.
UsdPerMwh
Dollars per megawatt-hour. Energy prices and a hedged flat rate are this.
YearMonth
Year and month for demand billing. Not a wall clock.

Enums§

Charge
One present charge on a contract.
FacilitiesBasis
What the facilities rate multiplies.
PassThrough
Whether a coincident-peak charge is billed through to the site.
RateUnit
Unit a RateWithSource is denominated in.
Settlement
How energy is priced for a contract.
TariffError
Why a constructor, parse, or calculation refused its input.

Functions§

coincident_peak_exposure
coincident_peak_exposure(rule, kw_at_intervals) is mean kW times dollars-per-kilowatt-year.
demand_bill
demand_bill(charge, kw_by_interval, month, history) is billed kW times dollars-per-kilowatt-month.
demand_charge
demand_charge(charge, kw_by_interval, month, history) is the peak and the dollars.
energy_bill
energy_bill(settlement, load_kwh_by_hour, prices) is kWh × dollars-per-megawatt-hour / 1000.
energy_bill_local
energy_bill_local(settlement, load_kwh_by_hour, local, prices) is energy_bill with civil local time for a time-of-use settlement.
facilities_bill
facilities_bill(charge, ratcheted_kw) is rate_per_kw times the basis kilowatts.
ledgers
ledgers(tariff, inputs) is one (name, amount) per present charge.
marginal_demand_value
marginal_demand_value(interval_mean_kw, running_peak_kw, month, history, charge) is the dollars this interval would add to the demand charge if it became the new peak.
month_bill
month_bill(tariff, inputs) sums each of the four fields across every contract.