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§
- Calendar
Date - A calendar day in the proleptic Gregorian calendar.
- Charge
Name - Name of one ledger line:
{contract}:{kind}. - Civil
Minute - Civil local time: month, ISO weekday, minute of day.
- Coincident
Peak Rule - A coincident-peak rule: 4 or 12 intervals per year, an annual dollars-per-kilowatt rate.
- Date
Range - Inclusive start and end calendar days.
- Demand
Charge - A monthly demand charge: dollars per kilowatt-month, 15- or 30-minute window, optional ratchet.
- Demand
History - Prior months’ demand peaks, keyed by
YearMonth. - Demand
Result - Peak, interval, ratchet, and dollars for one demand charge.
- Energy
Adder - A non-zero dollars-per-megawatt-hour adder on a price series.
- Energy
Prices - The two energy price series a site may be billed against.
- Facilities
Charge - Dollars per kilowatt, applied to
FacilitiesBasis. - Fixed
Charge - A reported fixed charge. Present in ledgers; never an optimisation lever.
- Hedged
Rate - A hedged flat energy rate, in dollars per megawatt-hour. Negative and non-finite values are refused.
- Kilowatt
- Kilowatt. Interval demand samples are this.
- Kilowatt
Hour - Kilowatt-hour. Hourly energy load is this.
- Ledger
Inputs - Inputs every present charge may need. Unused fields are ignored.
- Meter
Scope - Which meters a contract applies to. Any non-empty label.
- Minutes
- Demand-interval length in minutes. Only 15 or 30.
- Month
Bill - Energy, demand, facilities, and fixed for one month.
- Month
Inputs - Inputs for
month_bill. Unused slices are ignored. There is no clock. - Peak
Exposure - Dollar exposure plus, when the charge is not passed through, the reason.
- Ratchet
- Lookback that floors billed kW at a percentage of recent peaks.
- Rate
With Source - A rate plus where it came from and whether anyone has verified it.
- Site
Alias - A site’s alias: lowercase letters, digits and hyphens, at least one character.
- Site
Tariff - A site alias and the contracts that apply there.
- Time
OfUse - 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.
- UsdPer
Mwh - Dollars per megawatt-hour. Energy prices and a hedged flat rate are this.
- Year
Month - Year and month for demand billing. Not a wall clock.
Enums§
- Charge
- One present charge on a contract.
- Facilities
Basis - What the facilities rate multiplies.
- Pass
Through - Whether a coincident-peak charge is billed through to the site.
- Rate
Unit - Unit a
RateWithSourceis denominated in. - Settlement
- How energy is priced for a contract.
- Tariff
Error - 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)isenergy_billwith civil local time for a time-of-use settlement.- facilities_
bill facilities_bill(charge, ratcheted_kw)israte_per_kwtimes 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.