cimoxide-validation 0.3.1

SHACL validation of CGMES datasets against the ENTSO-E profile constraints
Documentation
// Generated by cimgen — do not edit by hand.
#![allow(clippy::all, dead_code, unused)]
use cimdecoder::CimDataset;
use crate::Violation;
use crate::helpers::*;

pub fn validate_p61970_301_steadystatehypothesis_ap_con_complex_notsolvedmas_shacl(dataset: &CimDataset) -> Vec<Violation> {
    let mut v = Vec::new();
    v.extend(check_p61970_301_steadystatehypothesis_ap_con_complex_notsolvedmas_shacl_battery_unit_battery_uni_etc(dataset));
    v.extend(check_p61970_301_steadystatehypothesis_ap_con_complex_notsolvedmas_shacl_cs_converter_cs_converte_etc(dataset));
    v.extend(check_p61970_301_steadystatehypothesis_ap_con_complex_notsolvedmas_shacl_cs_converter_cs_converte_etc_2(dataset));
    v.extend(check_p61970_301_steadystatehypothesis_ap_con_complex_notsolvedmas_shacl_phase_tap_changer_asymme_etc(dataset));
    v.extend(check_p61970_301_steadystatehypothesis_ap_con_complex_notsolvedmas_shacl_phase_tap_changer_linear_etc(dataset));
    v.extend(check_p61970_301_steadystatehypothesis_ap_con_complex_notsolvedmas_shacl_phase_tap_changer_symmet_etc(dataset));
    v.extend(check_p61970_301_steadystatehypothesis_ap_con_complex_notsolvedmas_shacl_phase_tap_changer_tabula_etc(dataset));
    v.extend(check_p61970_301_steadystatehypothesis_ap_con_complex_notsolvedmas_shacl_ratio_tap_changer_tap_ch_etc(dataset));
    v
}

pub fn check_p61970_301_steadystatehypothesis_ap_con_complex_notsolvedmas_shacl_battery_unit_battery_uni_etc(dataset: &CimDataset) -> Vec<Violation> {
    let mut violations = Vec::new();
    for mrid in dataset.by_type.get("BatteryUnit").into_iter().flatten() {
        let entry = &dataset.entries[mrid];
        let obj = match entry.element.as_any()
            .downcast_ref::<cimstructs::BatteryUnit>() {
            Some(o) => o, None => continue,
        };
        if obj.stored_e.is_none() || obj.rated_e.is_none() { continue; }
        if !((obj.stored_e.unwrap() as f64) < obj.rated_e.unwrap() as f64) {
            violations.push(Violation {
                object_id:   mrid.clone(),
                rule_id:     "sshn301:BatteryUnit.storedE-valueRangePair".to_string(),
                class:       "BatteryUnit".to_string(),
                property:    "BatteryUnit.storedE".to_string(),
                message:     "The value is either greater than or equal to BatteryUnit.ratedE.".to_string(),
                severity:    "sh:Violation".to_string(),
                name:        "C:301:SSH:BatteryUnit.storedE:valueRangePair".to_string(),
                description: "The attribute shall be a positive value or zero and lower than BatteryUnit.ratedE.".to_string(),
            });
        }
    }
    violations
}

pub fn check_p61970_301_steadystatehypothesis_ap_con_complex_notsolvedmas_shacl_cs_converter_cs_converte_etc(dataset: &CimDataset) -> Vec<Violation> {
    let mut violations = Vec::new();
    for mrid in dataset.by_type.get("CsConverter").into_iter().flatten() {
        let entry = &dataset.entries[mrid];
        let obj = match entry.element.as_any()
            .downcast_ref::<cimstructs::CsConverter>() {
            Some(o) => o, None => continue,
        };
        if obj.target_gamma.is_none() || obj.max_gamma.is_none() { continue; }
        if !((obj.target_gamma.unwrap() as f64) <= obj.max_gamma.unwrap() as f64) {
            violations.push(Violation {
                object_id:   mrid.clone(),
                rule_id:     "sshn301:CsConverter.targetGamma-valueRangePairTo".to_string(),
                class:       "CsConverter".to_string(),
                property:    "CsConverter.targetGamma".to_string(),
                message:     "The value is greater than CsConverter.maxGamma.".to_string(),
                severity:    "sh:Violation".to_string(),
                name:        "C:301:SSH:CsConverter.targetGamma:valueRangePairTo".to_string(),
                description: "Allowed values are within the range minGamma<=targetGamma<=maxGamma. ".to_string(),
            });
        }
    }
    violations
}

pub fn check_p61970_301_steadystatehypothesis_ap_con_complex_notsolvedmas_shacl_cs_converter_cs_converte_etc_2(dataset: &CimDataset) -> Vec<Violation> {
    let mut violations = Vec::new();
    for mrid in dataset.by_type.get("CsConverter").into_iter().flatten() {
        let entry = &dataset.entries[mrid];
        let obj = match entry.element.as_any()
            .downcast_ref::<cimstructs::CsConverter>() {
            Some(o) => o, None => continue,
        };
        if obj.target_alpha.is_none() || obj.max_alpha.is_none() { continue; }
        if !((obj.target_alpha.unwrap() as f64) <= obj.max_alpha.unwrap() as f64) {
            violations.push(Violation {
                object_id:   mrid.clone(),
                rule_id:     "sshn301:CsConverter.targetAlpha-valueRangePairTo".to_string(),
                class:       "CsConverter".to_string(),
                property:    "CsConverter.targetAlpha".to_string(),
                message:     "The value is greater than CsConverter.maxAlpha.".to_string(),
                severity:    "sh:Violation".to_string(),
                name:        "C:301:SSH:CsConverter.targetAlpha:valueRangePairTo".to_string(),
                description: "Allowed values are within the range minAlpha<=targetAlpha<=maxAlpha.".to_string(),
            });
        }
    }
    violations
}

pub fn check_p61970_301_steadystatehypothesis_ap_con_complex_notsolvedmas_shacl_phase_tap_changer_asymme_etc(dataset: &CimDataset) -> Vec<Violation> {
    let mut violations = Vec::new();
    for mrid in dataset.by_type.get("PhaseTapChangerAsymmetrical").into_iter().flatten() {
        let entry = &dataset.entries[mrid];
        let obj = match entry.element.as_any()
            .downcast_ref::<cimstructs::PhaseTapChangerAsymmetrical>() {
            Some(o) => o, None => continue,
        };
        if obj.base.base.base.step.is_none() || obj.base.base.base.high_step.is_none() { continue; }
        if !((obj.base.base.base.step.unwrap() as f64) <= obj.base.base.base.high_step.unwrap() as f64) {
            violations.push(Violation {
                object_id:   mrid.clone(),
                rule_id:     "sshn301:TapChanger.step-valueRangePairTo".to_string(),
                class:       "PhaseTapChangerAsymmetrical".to_string(),
                property:    "TapChanger.step".to_string(),
                message:     "The value is greater than TapChanger.highStep.".to_string(),
                severity:    "sh:Violation".to_string(),
                name:        "C:301:SSH:TapChanger.step:valueRangePairTo".to_string(),
                description: "The attribute shall be equal to or greater than lowStep and equal to or less than highStep.".to_string(),
            });
        }
    }
    violations
}

pub fn check_p61970_301_steadystatehypothesis_ap_con_complex_notsolvedmas_shacl_phase_tap_changer_linear_etc(dataset: &CimDataset) -> Vec<Violation> {
    let mut violations = Vec::new();
    for mrid in dataset.by_type.get("PhaseTapChangerLinear").into_iter().flatten() {
        let entry = &dataset.entries[mrid];
        let obj = match entry.element.as_any()
            .downcast_ref::<cimstructs::PhaseTapChangerLinear>() {
            Some(o) => o, None => continue,
        };
        if obj.base.base.step.is_none() || obj.base.base.high_step.is_none() { continue; }
        if !((obj.base.base.step.unwrap() as f64) <= obj.base.base.high_step.unwrap() as f64) {
            violations.push(Violation {
                object_id:   mrid.clone(),
                rule_id:     "sshn301:TapChanger.step-valueRangePairTo".to_string(),
                class:       "PhaseTapChangerLinear".to_string(),
                property:    "TapChanger.step".to_string(),
                message:     "The value is greater than TapChanger.highStep.".to_string(),
                severity:    "sh:Violation".to_string(),
                name:        "C:301:SSH:TapChanger.step:valueRangePairTo".to_string(),
                description: "The attribute shall be equal to or greater than lowStep and equal to or less than highStep.".to_string(),
            });
        }
    }
    violations
}

pub fn check_p61970_301_steadystatehypothesis_ap_con_complex_notsolvedmas_shacl_phase_tap_changer_symmet_etc(dataset: &CimDataset) -> Vec<Violation> {
    let mut violations = Vec::new();
    for mrid in dataset.by_type.get("PhaseTapChangerSymmetrical").into_iter().flatten() {
        let entry = &dataset.entries[mrid];
        let obj = match entry.element.as_any()
            .downcast_ref::<cimstructs::PhaseTapChangerSymmetrical>() {
            Some(o) => o, None => continue,
        };
        if obj.base.base.base.step.is_none() || obj.base.base.base.high_step.is_none() { continue; }
        if !((obj.base.base.base.step.unwrap() as f64) <= obj.base.base.base.high_step.unwrap() as f64) {
            violations.push(Violation {
                object_id:   mrid.clone(),
                rule_id:     "sshn301:TapChanger.step-valueRangePairTo".to_string(),
                class:       "PhaseTapChangerSymmetrical".to_string(),
                property:    "TapChanger.step".to_string(),
                message:     "The value is greater than TapChanger.highStep.".to_string(),
                severity:    "sh:Violation".to_string(),
                name:        "C:301:SSH:TapChanger.step:valueRangePairTo".to_string(),
                description: "The attribute shall be equal to or greater than lowStep and equal to or less than highStep.".to_string(),
            });
        }
    }
    violations
}

pub fn check_p61970_301_steadystatehypothesis_ap_con_complex_notsolvedmas_shacl_phase_tap_changer_tabula_etc(dataset: &CimDataset) -> Vec<Violation> {
    let mut violations = Vec::new();
    for mrid in dataset.by_type.get("PhaseTapChangerTabular").into_iter().flatten() {
        let entry = &dataset.entries[mrid];
        let obj = match entry.element.as_any()
            .downcast_ref::<cimstructs::PhaseTapChangerTabular>() {
            Some(o) => o, None => continue,
        };
        if obj.base.base.step.is_none() || obj.base.base.high_step.is_none() { continue; }
        if !((obj.base.base.step.unwrap() as f64) <= obj.base.base.high_step.unwrap() as f64) {
            violations.push(Violation {
                object_id:   mrid.clone(),
                rule_id:     "sshn301:TapChanger.step-valueRangePairTo".to_string(),
                class:       "PhaseTapChangerTabular".to_string(),
                property:    "TapChanger.step".to_string(),
                message:     "The value is greater than TapChanger.highStep.".to_string(),
                severity:    "sh:Violation".to_string(),
                name:        "C:301:SSH:TapChanger.step:valueRangePairTo".to_string(),
                description: "The attribute shall be equal to or greater than lowStep and equal to or less than highStep.".to_string(),
            });
        }
    }
    violations
}

pub fn check_p61970_301_steadystatehypothesis_ap_con_complex_notsolvedmas_shacl_ratio_tap_changer_tap_ch_etc(dataset: &CimDataset) -> Vec<Violation> {
    let mut violations = Vec::new();
    for mrid in dataset.by_type.get("RatioTapChanger").into_iter().flatten() {
        let entry = &dataset.entries[mrid];
        let obj = match entry.element.as_any()
            .downcast_ref::<cimstructs::RatioTapChanger>() {
            Some(o) => o, None => continue,
        };
        if obj.base.step.is_none() || obj.base.high_step.is_none() { continue; }
        if !((obj.base.step.unwrap() as f64) <= obj.base.high_step.unwrap() as f64) {
            violations.push(Violation {
                object_id:   mrid.clone(),
                rule_id:     "sshn301:TapChanger.step-valueRangePairTo".to_string(),
                class:       "RatioTapChanger".to_string(),
                property:    "TapChanger.step".to_string(),
                message:     "The value is greater than TapChanger.highStep.".to_string(),
                severity:    "sh:Violation".to_string(),
                name:        "C:301:SSH:TapChanger.step:valueRangePairTo".to_string(),
                description: "The attribute shall be equal to or greater than lowStep and equal to or less than highStep.".to_string(),
            });
        }
    }
    violations
}