Skip to main content

cimstructs/
LimitSet.rs

1/// Specifies a set of Limits that are associated with a Measurement. A Measurement may have several LimitSets corresponding to seasonal or other changing conditions. The condition is captured in the name and description attributes. The same LimitSet may be used for several Measurements. In particular percentage limits are used this way.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct LimitSet {
4    #[serde(flatten)]
5    pub base: super::IdentifiedObject,
6    /// Tells if the limit values are in percentage of normalValue or the specified Unit for Measurements and Controls.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub is_percentage_limits: Option<bool>,
9}
10impl crate::base::CimElement for LimitSet {
11    fn mrid(&self) -> &str { &self.base.id }
12    fn type_name(&self) -> &'static str { "LimitSet" }
13    fn as_any(&self) -> &dyn std::any::Any { self }
14    fn to_json_value(&self) -> serde_json::Value {
15        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
16    }
17    fn to_block(&self) -> crate::base::RdfBlock {
18        let mut block = self.base.to_block();
19        block.type_name = "LimitSet".to_string();
20        if let Some(v) = self.is_percentage_limits {
21            block.fields.insert("LimitSet.isPercentageLimits".into(), crate::base::FieldValue::Text(v.to_string()));
22        }
23        block
24    }
25}
26
27impl LimitSet {
28    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
29        let mut obj = Self::default();
30        obj.base.id.clone_from(&b.mrid);
31        for (key, val) in &b.fields {
32            match key.as_str() {
33                "LimitSet.isPercentageLimits" => {
34                    match val {
35                        crate::base::FieldValue::Text(sv) => { obj.is_percentage_limits = Some(sv.trim() == "true"); }
36                        crate::base::FieldValue::TextList(svs) => {
37                            if let Some(sv) = svs.last() { obj.is_percentage_limits = Some(sv.trim() == "true"); }
38                        }
39                        _ => {}
40                    }
41                }
42                "IdentifiedObject.description" => {
43                    match val {
44                        crate::base::FieldValue::Text(sv) => { obj.base.description = sv.clone(); }
45                        crate::base::FieldValue::TextList(svs) => {
46                            if let Some(sv) = svs.last() { obj.base.description = sv.clone(); }
47                        }
48                        _ => {}
49                    }
50                }
51                "IdentifiedObject.energyIdentCodeEic" => {
52                    match val {
53                        crate::base::FieldValue::Text(sv) => { obj.base.energy_ident_code_eic = sv.clone(); }
54                        crate::base::FieldValue::TextList(svs) => {
55                            if let Some(sv) = svs.last() { obj.base.energy_ident_code_eic = sv.clone(); }
56                        }
57                        _ => {}
58                    }
59                }
60                "IdentifiedObject.mRID" => {
61                    match val {
62                        crate::base::FieldValue::Text(sv) => { obj.base.m_rid = sv.clone(); }
63                        crate::base::FieldValue::TextList(svs) => {
64                            if let Some(sv) = svs.last() { obj.base.m_rid = sv.clone(); }
65                        }
66                        _ => {}
67                    }
68                }
69                "IdentifiedObject.name" => {
70                    match val {
71                        crate::base::FieldValue::Text(sv) => { obj.base.name = sv.clone(); }
72                        crate::base::FieldValue::TextList(svs) => {
73                            if let Some(sv) = svs.last() { obj.base.name = sv.clone(); }
74                        }
75                        _ => {}
76                    }
77                }
78                "IdentifiedObject.shortName" => {
79                    match val {
80                        crate::base::FieldValue::Text(sv) => { obj.base.short_name = sv.clone(); }
81                        crate::base::FieldValue::TextList(svs) => {
82                            if let Some(sv) = svs.last() { obj.base.short_name = sv.clone(); }
83                        }
84                        _ => {}
85                    }
86                }
87                _ => {}
88            }
89        }
90        obj
91    }
92}