Skip to main content

cimstructs/
OperationalLimitType.rs

1/// The operational meaning of a category of limits.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct OperationalLimitType {
4    #[serde(flatten)]
5    pub base: super::IdentifiedObject,
6    /// The nominal acceptable duration of the limit. Limits are commonly expressed in terms of the time limit for which the limit is normally acceptable. The actual acceptable duration of a specific limit may depend on other local factors such as temperature or wind speed. The attribute has meaning only if the flag isInfiniteDuration is set to false, hence it shall not be exchanged when isInfiniteDuration is set to true.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub acceptable_duration: Option<f64>,
9    /// The direction of the limit.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub direction: Option<super::base::UriRef>,
12    /// Defines if the operational limit type has infinite duration. If true, the limit has infinite duration. If false, the limit has definite duration which is defined by the attribute acceptableDuration.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub is_infinite_duration: Option<bool>,
15    /// Types of limits defined in the ENTSO-E Operational Handbook Policy 3.
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub kind: Option<super::base::MridRef>,
18}
19impl crate::base::CimElement for OperationalLimitType {
20    fn mrid(&self) -> &str { &self.base.id }
21    fn type_name(&self) -> &'static str { "OperationalLimitType" }
22    fn as_any(&self) -> &dyn std::any::Any { self }
23    fn to_json_value(&self) -> serde_json::Value {
24        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
25    }
26    fn to_block(&self) -> crate::base::RdfBlock {
27        let mut block = self.base.to_block();
28        block.type_name = "OperationalLimitType".to_string();
29        if let Some(v) = self.acceptable_duration {
30            block.fields.insert("OperationalLimitType.acceptableDuration".into(), crate::base::FieldValue::Text(v.to_string()));
31        }
32        if let Some(ref v) = self.direction {
33            block.fields.insert("OperationalLimitType.direction".into(), crate::base::FieldValue::Resource(v.uri.clone()));
34        }
35        if let Some(v) = self.is_infinite_duration {
36            block.fields.insert("OperationalLimitType.isInfiniteDuration".into(), crate::base::FieldValue::Text(v.to_string()));
37        }
38        if let Some(ref v) = self.kind {
39            block.fields.insert("OperationalLimitType.kind".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
40        }
41        block
42    }
43}
44
45impl OperationalLimitType {
46    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
47        let mut obj = Self::default();
48        obj.base.id.clone_from(&b.mrid);
49        for (key, val) in &b.fields {
50            match key.as_str() {
51                "OperationalLimitType.acceptableDuration" => {
52                    match val {
53                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.acceptable_duration = Some(v); } }
54                        crate::base::FieldValue::TextList(svs) => {
55                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.acceptable_duration = Some(v); } }
56                        }
57                        _ => {}
58                    }
59                }
60                "OperationalLimitType.direction" => {
61                    if let crate::base::FieldValue::Resource(sv) = val {
62                        obj.direction = Some(crate::base::UriRef { uri: sv.clone() });
63                    }
64                }
65                "OperationalLimitType.isInfiniteDuration" => {
66                    match val {
67                        crate::base::FieldValue::Text(sv) => { obj.is_infinite_duration = Some(sv.trim() == "true"); }
68                        crate::base::FieldValue::TextList(svs) => {
69                            if let Some(sv) = svs.last() { obj.is_infinite_duration = Some(sv.trim() == "true"); }
70                        }
71                        _ => {}
72                    }
73                }
74                "OperationalLimitType.kind" => {
75                    if let crate::base::FieldValue::Resource(sv) = val {
76                        obj.kind = Some(crate::base::MridRef { mrid: sv.clone() });
77                    }
78                }
79                "IdentifiedObject.description" => {
80                    match val {
81                        crate::base::FieldValue::Text(sv) => { obj.base.description = sv.clone(); }
82                        crate::base::FieldValue::TextList(svs) => {
83                            if let Some(sv) = svs.last() { obj.base.description = sv.clone(); }
84                        }
85                        _ => {}
86                    }
87                }
88                "IdentifiedObject.energyIdentCodeEic" => {
89                    match val {
90                        crate::base::FieldValue::Text(sv) => { obj.base.energy_ident_code_eic = sv.clone(); }
91                        crate::base::FieldValue::TextList(svs) => {
92                            if let Some(sv) = svs.last() { obj.base.energy_ident_code_eic = sv.clone(); }
93                        }
94                        _ => {}
95                    }
96                }
97                "IdentifiedObject.mRID" => {
98                    match val {
99                        crate::base::FieldValue::Text(sv) => { obj.base.m_rid = sv.clone(); }
100                        crate::base::FieldValue::TextList(svs) => {
101                            if let Some(sv) = svs.last() { obj.base.m_rid = sv.clone(); }
102                        }
103                        _ => {}
104                    }
105                }
106                "IdentifiedObject.name" => {
107                    match val {
108                        crate::base::FieldValue::Text(sv) => { obj.base.name = sv.clone(); }
109                        crate::base::FieldValue::TextList(svs) => {
110                            if let Some(sv) = svs.last() { obj.base.name = sv.clone(); }
111                        }
112                        _ => {}
113                    }
114                }
115                "IdentifiedObject.shortName" => {
116                    match val {
117                        crate::base::FieldValue::Text(sv) => { obj.base.short_name = sv.clone(); }
118                        crate::base::FieldValue::TextList(svs) => {
119                            if let Some(sv) = svs.last() { obj.base.short_name = sv.clone(); }
120                        }
121                        _ => {}
122                    }
123                }
124                _ => {}
125            }
126        }
127        obj
128    }
129}