Skip to main content

cimstructs/
EnergyArea.rs

1/// Describes an area having energy production or consumption. Specializations are intended to support the load allocation function as typically required in energy management systems or planning studies to allocate hypothesized load levels to individual load points for power flow analysis. Often the energy area can be linked to both measured and forecast load levels.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct EnergyArea {
4    #[serde(flatten)]
5    pub base: super::IdentifiedObject,
6}
7impl crate::base::CimElement for EnergyArea {
8    fn mrid(&self) -> &str { &self.base.id }
9    fn type_name(&self) -> &'static str { "EnergyArea" }
10    fn as_any(&self) -> &dyn std::any::Any { self }
11    fn to_json_value(&self) -> serde_json::Value {
12        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
13    }
14    fn to_block(&self) -> crate::base::RdfBlock {
15        let mut block = self.base.to_block();
16        block.type_name = "EnergyArea".to_string();
17        block
18    }
19}
20
21impl EnergyArea {
22    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
23        let mut obj = Self::default();
24        obj.base.id.clone_from(&b.mrid);
25        for (key, val) in &b.fields {
26            match key.as_str() {
27                "IdentifiedObject.description" => {
28                    match val {
29                        crate::base::FieldValue::Text(sv) => { obj.base.description = sv.clone(); }
30                        crate::base::FieldValue::TextList(svs) => {
31                            if let Some(sv) = svs.last() { obj.base.description = sv.clone(); }
32                        }
33                        _ => {}
34                    }
35                }
36                "IdentifiedObject.energyIdentCodeEic" => {
37                    match val {
38                        crate::base::FieldValue::Text(sv) => { obj.base.energy_ident_code_eic = sv.clone(); }
39                        crate::base::FieldValue::TextList(svs) => {
40                            if let Some(sv) = svs.last() { obj.base.energy_ident_code_eic = sv.clone(); }
41                        }
42                        _ => {}
43                    }
44                }
45                "IdentifiedObject.mRID" => {
46                    match val {
47                        crate::base::FieldValue::Text(sv) => { obj.base.m_rid = sv.clone(); }
48                        crate::base::FieldValue::TextList(svs) => {
49                            if let Some(sv) = svs.last() { obj.base.m_rid = sv.clone(); }
50                        }
51                        _ => {}
52                    }
53                }
54                "IdentifiedObject.name" => {
55                    match val {
56                        crate::base::FieldValue::Text(sv) => { obj.base.name = sv.clone(); }
57                        crate::base::FieldValue::TextList(svs) => {
58                            if let Some(sv) = svs.last() { obj.base.name = sv.clone(); }
59                        }
60                        _ => {}
61                    }
62                }
63                "IdentifiedObject.shortName" => {
64                    match val {
65                        crate::base::FieldValue::Text(sv) => { obj.base.short_name = sv.clone(); }
66                        crate::base::FieldValue::TextList(svs) => {
67                            if let Some(sv) = svs.last() { obj.base.short_name = sv.clone(); }
68                        }
69                        _ => {}
70                    }
71                }
72                _ => {}
73            }
74        }
75        obj
76    }
77}