grid_tariffs/
power_tariffs.rs1use chrono::DateTime;
2use chrono_tz::Tz;
3use serde::Serialize;
4
5use crate::{
6 Language, Money,
7 costs::{CostPeriods, CostPeriodsSimple, LoadType},
8};
9
10#[derive(Debug, Clone, Serialize)]
11#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
12pub enum PowerTariff {
13 Unverified,
14 NotImplemented,
15 Periods {
16 method: TariffCalculationMethod,
17 periods: CostPeriods,
18 },
19}
20
21impl PowerTariff {
22 pub const fn is_unverified(&self) -> bool {
23 matches!(self, Self::Unverified)
24 }
25
26 pub(super) const fn new(method: TariffCalculationMethod, periods: CostPeriods) -> Self {
27 Self::Periods { method, periods }
28 }
29
30 pub(super) fn kw_cost(
31 &self,
32 timestamp: DateTime<Tz>,
33 fuse_size: u16,
34 yearly_consumption: u32,
35 ) -> Money {
36 let cost = Money::ZERO;
37 match self {
38 PowerTariff::Unverified | PowerTariff::NotImplemented => cost,
39 PowerTariff::Periods { method, periods } => {
40 for period in periods.iter() {
41 let money = period.cost().cost_for(fuse_size, yearly_consumption);
42 }
43 cost
44 }
45 }
46 }
47
48 pub fn simplified(
49 &self,
50 fuse_size: u16,
51 yearly_consumption: u32,
52 language: Language,
53 ) -> PowerTariffSimplified {
54 PowerTariffSimplified::new(self, fuse_size, yearly_consumption, language)
55 }
56}
57
58#[derive(Debug, Clone, Copy, Serialize)]
60#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
61pub enum TariffCalculationMethod {
62 AverageDays(u8),
64 AverageHours(u8),
66}
67
68#[derive(Debug, Clone, Serialize)]
70#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
71pub enum PowerTariffSimplified {
72 Unverified,
73 NotImplemented,
74 Periods {
75 method: TariffCalculationMethod,
76 periods: CostPeriodsSimple,
77 },
78}
79
80impl PowerTariffSimplified {
81 fn new(fee: &PowerTariff, fuse_size: u16, yearly_consumption: u32, language: Language) -> Self {
82 match *fee {
83 PowerTariff::Unverified => PowerTariffSimplified::Unverified,
84 PowerTariff::NotImplemented => PowerTariffSimplified::NotImplemented,
85 PowerTariff::Periods { method, periods } => PowerTariffSimplified::Periods {
86 method,
87 periods: CostPeriodsSimple::new(periods, fuse_size, yearly_consumption, language),
88 },
89 }
90 }
91}