aemo_rs/
dispatch_is.rs

1use crate::{FileKeyable, GetFromRawAemo, RawAemoFile, Result};
2use serde::{Deserialize, Serialize};
3
4#[derive(Deserialize, Serialize, Debug, Clone)]
5struct Price {
6    #[serde(deserialize_with = "crate::au_datetime_deserialize")]
7    settlement_date: chrono::NaiveDateTime,
8    run_no: i32,
9    region_id: Region,
10    dispatch_interval: u64,
11    intervention: i32,
12    regional_reference_price: f64,
13    eep: f64,
14    rop: f64,
15    apc_flag: i32,
16    market_suspended_flag: i32,
17    #[serde(deserialize_with = "crate::au_datetime_deserialize")]
18    last_changed: chrono::NaiveDateTime,
19    raise6sec_rrp: f64,
20    raise6sec_rop: f64,
21    raise6sec_apc_flag: i32,
22    raise60sec_rrp: f64,
23    raise60sec_rop: f64,
24    raise60sec_apc_flag: i32,
25    raise5min_rrp: f64,
26    raise5min_rop: f64,
27    raise5min_apc_flag: i32,
28    raiseregsec_rrp: f64,
29    raiseregsec_rop: f64,
30    raiseregsec_apc_flag: i32,
31    lower6sec_rrp: f64,
32    lower6sec_rop: f64,
33    lower6sec_apc_flag: i32,
34    lower60sec_rrp: f64,
35    lower60sec_rop: f64,
36    lower60sec_apc_flag: i32,
37    lower5min_rrp: f64,
38    lower5min_rop: f64,
39    lower5min_apc_flag: i32,
40    lowerregsec_rrp: f64,
41    lowerregsec_rop: f64,
42    lowerregsec_apc_flag: i32,
43    price_status: String,
44    pre_ap_energy_price: f64,
45    pre_ap_raise6_price: f64,
46    pre_ap_raise60_price: f64,
47    pre_ap_raise5min_price: f64,
48    pre_ap_raisereg_price: f64,
49    pre_ap_lower6_price: f64,
50    pre_ap_lower60_price: f64,
51    pre_ap_lower5min_price: f64,
52    pre_ap_lowerreg_price: f64,
53    cumul_pre_ap_energy_price: f64,
54    cumul_pre_ap_raise6_price: f64,
55    cumul_pre_ap_raise60_price: f64,
56    cumul_pre_ap_raise5min_price: f64,
57    cumul_pre_ap_raisereg_price: f64,
58    cumul_pre_ap_lower6_price: f64,
59    cumul_pre_ap_lower60_price: f64,
60    cumul_pre_ap_lower5min_price: f64,
61    cumul_pre_ap_lowerreg_price: f64,
62    ocd_status: String,
63    mii_status: String,
64}
65
66impl FileKeyable for Price {
67    fn key() -> crate::FileKey {
68        ("DISPATCH".into(), "PRICE".into(), 4)
69    }
70}
71
72impl GetFromRawAemo for Price {
73    type Output = Self;
74}
75
76#[derive(Clone, Debug, Deserialize, Serialize)]
77enum Region {
78    TAS1,
79    VIC1,
80    QLD1,
81    NSW1,
82    SA1,
83}
84
85#[derive(Clone, Debug, Deserialize, Serialize)]
86pub struct File {
87    header: crate::AemoHeader,
88    case_solution: Vec<CaseSolution>,
89    // local_price: Vec<LocalPrice>,
90    price: Vec<Price>,
91    regionsum: Vec<Regionsum>,
92    interconnectorres: Vec<Interconnectorres>,
93    constraint: Vec<Constraint>,
94    interconnection: Vec<Interconnection>,
95}
96
97impl crate::AemoFile for File {
98    fn from_raw(RawAemoFile { header, mut data }: RawAemoFile) -> Result<Self> {
99        Ok(Self {
100            header,
101            case_solution: CaseSolution::from_map(&mut data)?,
102            price: Price::from_map(&mut data)?,
103            regionsum: Regionsum::from_map(&mut data)?,
104            interconnectorres: Interconnectorres::from_map(&mut data)?,
105            constraint: Constraint::from_map(&mut data)?,
106            interconnection: Interconnection::from_map(&mut data)?,
107        })
108    }
109}
110
111#[derive(Deserialize, Serialize, Debug, Clone)]
112struct CaseSolution {
113    #[serde(deserialize_with = "crate::au_datetime_deserialize")]
114    settlementdate: chrono::NaiveDateTime,
115    runno: i32,
116    intervention: i32,
117    casesubtype: Option<String>,
118    solutionstatus: Option<i32>,
119    spdversion: Option<String>,
120    nonphysicallosses: Option<i32>,
121    totalobjective: Option<f64>,
122    totalareagenviolation: Option<f64>,
123    totalinterconnectorviolation: Option<f64>,
124    totalgenericviolation: Option<f64>,
125    totalramprateviolation: Option<f64>,
126    totalunitmwcapacityviolation: Option<f64>,
127    total5minviolation: Option<f64>,
128    totalregviolation: Option<f64>,
129    total6secviolation: Option<f64>,
130    total60secviolation: Option<f64>,
131    totalasprofileviolation: Option<f64>,
132    totalfaststartviolation: Option<f64>,
133    totalenergyofferviolation: Option<f64>,
134    #[serde(deserialize_with = "crate::au_datetime_deserialize")]
135    lastchanged: chrono::NaiveDateTime,
136}
137
138impl FileKeyable for CaseSolution {
139    fn key() -> crate::FileKey {
140        ("DISPATCH".into(), "CASE_SOLUTION".into(), 2)
141    }
142}
143
144impl GetFromRawAemo for CaseSolution {
145    type Output = Self;
146}
147
148// struct LocalPrice {
149//     settlementdate: chrono::NaiveDateTime,
150//     duid: String,
151//     local_price_adjustment:	f64,
152//     locally_constrained: i32,
153// }
154
155#[derive(Deserialize, Serialize, Debug, Clone)]
156struct Regionsum {
157    #[serde(deserialize_with = "crate::au_datetime_deserialize")]
158    settlementdate: chrono::NaiveDateTime,
159    runno: i64,
160    regionid: String,
161    dispatchinterval: i64,
162    intervention: i64,
163    totaldemand: f64,
164    availablegeneration: f64,
165    availableload: f64,
166    demandforecast: f64,
167    dispatchablegeneration: f64,
168    dispatchableload: Option<f64>,
169    netinterchange: f64,
170    excessgeneration: Option<f64>,
171    lower5mindispatch: Option<f64>,
172    lower5minimport: Option<f64>,
173    lower5minlocaldispatch: f64,
174    lower5minlocalprice: Option<f64>,
175    lower5minlocalreq: Option<f64>,
176    lower5minprice: Option<f64>,
177    lower5minreq: Option<f64>,
178    lower5minsupplyprice: Option<f64>,
179    lower60secdispatch: Option<f64>,
180    lower60secimport: Option<f64>,
181    lower60seclocaldispatch: f64,
182    lower60seclocalprice: Option<f64>,
183    lower60seclocalreq: Option<f64>,
184    lower60secprice: Option<f64>,
185    lower60secreq: Option<f64>,
186    lower60secsupplyprice: Option<f64>,
187    lower6secdispatch: Option<f64>,
188    lower6secimport: Option<f64>,
189    lower6seclocaldispatch: f64,
190    lower6seclocalprice: Option<f64>,
191    lower6seclocalreq: Option<f64>,
192    lower6secprice: Option<f64>,
193    lower6secreq: Option<f64>,
194    lower6secsupplyprice: Option<f64>,
195    raise5mindispatch: Option<f64>,
196    raise5minimport: Option<f64>,
197    raise5minlocaldispatch: f64,
198    raise5minlocalprice: Option<f64>,
199    raise5minlocalreq: Option<f64>,
200    raise5minprice: Option<f64>,
201    raise5minreq: Option<f64>,
202    raise5minsupplyprice: Option<f64>,
203    raise60secdispatch: Option<f64>,
204    raise60secimport: Option<f64>,
205    raise60seclocaldispatch: f64,
206    raise60seclocalprice: Option<f64>,
207    raise60seclocalreq: Option<f64>,
208    raise60secprice: Option<f64>,
209    raise60secreq: Option<f64>,
210    raise60secsupplyprice: Option<f64>,
211    raise6secdispatch: Option<f64>,
212    raise6secimport: Option<f64>,
213    raise6seclocaldispatch: f64,
214    raise6seclocalprice: Option<f64>,
215    raise6seclocalreq: Option<f64>,
216    raise6secprice: Option<f64>,
217    raise6secreq: Option<f64>,
218    raise6secsupplyprice: Option<f64>,
219    aggegatedispatcherror: Option<f64>,
220    aggregatedispatcherror: f64,
221    #[serde(deserialize_with = "crate::au_datetime_deserialize")]
222    lastchanged: chrono::NaiveDateTime,
223    initialsupply: f64,
224    clearedsupply: f64,
225    lowerregimport: Option<f64>,
226    lowerreglocaldispatch: f64,
227    lowerreglocalreq: Option<f64>,
228    lowerregreq: Option<f64>,
229    raiseregimport: Option<f64>,
230    raisereglocaldispatch: f64,
231    raisereglocalreq: Option<f64>,
232    raiseregreq: Option<f64>,
233    raise5minlocalviolation: Option<f64>,
234    raisereglocalviolation: Option<f64>,
235    raise60seclocalviolation: Option<f64>,
236    raise6seclocalviolation: Option<f64>,
237    lower5minlocalviolation: Option<f64>,
238    lowerreglocalviolation: Option<f64>,
239    lower60seclocalviolation: Option<f64>,
240    lower6seclocalviolation: Option<f64>,
241    raise5minviolation: Option<f64>,
242    raiseregviolation: Option<f64>,
243    raise60secviolation: Option<f64>,
244    raise6secviolation: Option<f64>,
245    lower5minviolation: Option<f64>,
246    lowerregviolation: Option<f64>,
247    lower60secviolation: Option<f64>,
248    lower6secviolation: Option<f64>,
249    raise6secactualavailability: f64,
250    raise60secactualavailability: f64,
251    raise5minactualavailability: f64,
252    raiseregactualavailability: f64,
253    lower6secactualavailability: f64,
254    lower60secactualavailability: f64,
255    lower5minactualavailability: f64,
256    lowerregactualavailability: f64,
257    lorsurplus: Option<f64>,
258    lrcsurplus: Option<f64>,
259    totalintermittentgeneration: f64,
260    demand_and_nonschedgen: f64,
261    uigf: f64,
262    semischedule_clearedmw: f64,
263    semischedule_compliancemw: f64,
264}
265
266impl FileKeyable for Regionsum {
267    fn key() -> crate::FileKey {
268        ("DISPATCH".into(), "REGIONSUM".into(), 4)
269    }
270}
271
272impl GetFromRawAemo for Regionsum {
273    type Output = Self;
274}
275
276#[derive(Deserialize, Serialize, Debug, Clone)]
277struct Interconnectorres {
278    #[serde(deserialize_with = "crate::au_datetime_deserialize")]
279    settlementdate: chrono::NaiveDateTime,
280    runno: i64,
281    interconnectorid: String,
282    dispatchinterval: i64,
283    intervention: i64,
284    meteredmwflow: Option<f64>,
285    mwflow: Option<f64>,
286    mwlosses: Option<f64>,
287    marginalvalue: Option<f64>,
288    violationdegree: Option<f64>,
289    #[serde(deserialize_with = "crate::au_datetime_deserialize")]
290    lastchanged: chrono::NaiveDateTime,
291    exportlimit: Option<f64>,
292    importlimit: Option<f64>,
293    marginalloss: Option<f64>,
294    exportgenconid: Option<String>,
295    importgenconid: Option<String>,
296    fcasexportlimit: Option<f64>,
297    fcasimportlimit: Option<f64>,
298    local_price_adjustment_export: Option<f64>,
299    locally_constrained_export: Option<i32>,
300    local_price_adjustment_import: Option<f64>,
301    locally_constrained_import: Option<i32>,
302}
303
304impl FileKeyable for Interconnectorres {
305    fn key() -> crate::FileKey {
306        ("DISPATCH".into(), "INTERCONNECTORRES".into(), 3)
307    }
308}
309
310impl GetFromRawAemo for Interconnectorres {
311    type Output = Self;
312}
313
314#[derive(Deserialize, Serialize, Debug, Clone)]
315struct Constraint {
316    #[serde(deserialize_with = "crate::au_datetime_deserialize")]
317    settlementdate: chrono::NaiveDateTime,
318    runno: i64,
319    constraintid: String,
320    dispatchinterval: i64,
321    intervention: i64,
322    rhs: f64,
323    marginalvalue: f64,
324    violationdegree: f64,
325    #[serde(deserialize_with = "crate::au_datetime_deserialize")]
326    lastchanged: chrono::NaiveDateTime,
327    duid: String,
328    #[serde(deserialize_with = "crate::au_datetime_deserialize")]
329    genconid_effectivedate: chrono::NaiveDateTime,
330    genconid_versionno: i64,
331    lhs: f64,
332}
333
334impl FileKeyable for Constraint {
335    fn key() -> crate::FileKey {
336        ("DISPATCH".into(), "CONSTRAINT".into(), 5)
337    }
338}
339
340impl GetFromRawAemo for Constraint {
341    type Output = Self;
342}
343
344#[derive(Deserialize, Serialize, Debug, Clone)]
345struct Interconnection {
346    #[serde(deserialize_with = "crate::au_datetime_deserialize")]
347    settlementdate: chrono::NaiveDateTime,
348    runno: i64,
349    intervention: i64,
350    from_regionid: String,
351    to_regionid: String,
352    dispatchinterval: i64,
353    irlf: f64,
354    mwflow: f64,
355    meteredmwflow: f64,
356    from_region_mw_losses: f64,
357    to_region_mw_losses: f64,
358    #[serde(deserialize_with = "crate::au_datetime_deserialize")]
359    lastchanged: chrono::NaiveDateTime,
360}
361
362impl FileKeyable for Interconnection {
363    fn key() -> crate::FileKey {
364        ("DISPATCH".into(), "INTERCONNECTION".into(), 1)
365    }
366}
367
368impl GetFromRawAemo for Interconnection {
369    type Output = Self;
370}