From 12d0c7eea6e4eb4cbfefdfbacb32015b9be9b64e Mon Sep 17 00:00:00 2001 From: Daniel Hjertholm <8713259+danhje@users.noreply.github.com> Date: Thu, 9 Jan 2025 10:41:25 +0100 Subject: [PATCH] chore: autoformat sparql through pre-commit --- .flake8 | 17 --- .gitignore | 1 + .pre-commit-config.yaml | 10 ++ README.md | 13 ++ qlue-ls.toml | 2 + src/cimsparql/sparql/ac_lines.sparql | 138 ++++++++---------- src/cimsparql/sparql/add_mrid.sparql | 12 +- .../sparql/associated_switches.sparql | 34 ++--- src/cimsparql/sparql/base_voltage.sparql | 31 ++-- src/cimsparql/sparql/borders.sparql | 56 +++---- .../sparql/branch_node_withdraw.sparql | 59 ++++---- src/cimsparql/sparql/bus.sparql | 71 ++++----- src/cimsparql/sparql/connections.sparql | 37 +++-- .../sparql/connectivity_nodes.sparql | 104 +++++++------ .../sparql/converter_hvdc_bidzones.sparql | 24 ++- src/cimsparql/sparql/converters.sparql | 120 +++++++-------- src/cimsparql/sparql/coordinates.sparql | 29 ++-- .../sparql/dc_active_power_flow.sparql | 60 ++++---- src/cimsparql/sparql/disconnected.sparql | 18 +-- src/cimsparql/sparql/exchange.sparql | 70 +++++---- src/cimsparql/sparql/full_model.sparql | 46 +++--- .../gen_unit_and_sync_machine_mapping.sparql | 7 +- src/cimsparql/sparql/hvdc.sparql | 31 ++-- src/cimsparql/sparql/loads.sparql | 63 ++++---- src/cimsparql/sparql/market_dates.sparql | 12 +- src/cimsparql/sparql/phase_tap_changer.sparql | 36 ++--- src/cimsparql/sparql/power_flow.sparql | 20 +-- src/cimsparql/sparql/ras_equipment.sparql | 9 +- src/cimsparql/sparql/regions.sparql | 28 ++-- .../sparql/series_compensators.sparql | 111 +++++++------- .../station_group_code_and_names.sparql | 14 +- .../station_group_for_power_unit.sparql | 18 +-- .../sparql/substation_voltage_level.sparql | 28 ++-- src/cimsparql/sparql/sv_branch.sparql | 90 ++++++------ src/cimsparql/sparql/sv_injection.sparql | 11 +- .../sparql/sv_power_deviation.sparql | 75 +++++----- src/cimsparql/sparql/switches.sparql | 62 ++++---- .../sparql/synchronous_machines.sparql | 104 ++++++------- .../add_eic_bidding_area_code.sparql | 23 +-- .../add_gen_unit_mrid.sparql | 25 ++-- .../add_market_code_for_load_groups.sparql | 19 +-- .../add_network_analysis_enable.sparql | 17 ++- .../add_non_conform_load_group.sparql | 15 +- .../add_sv_injection.sparql | 23 +-- .../add_zero_sv_power.sparql | 23 +-- .../sparql/transformer_branches.sparql | 114 ++++++++------- .../sparql/transformer_center_nodes.sparql | 59 ++++---- .../sparql/transformer_winding_angle.sparql | 22 +-- .../sparql/transformer_windings.sparql | 12 +- src/cimsparql/sparql/transformers.sparql | 47 +++--- ...transformers_connected_to_converter.sparql | 52 +++---- src/cimsparql/sparql/type_mapper.sparql | 20 +-- .../sparql/wind_generating_units.sparql | 34 +++-- src/cimsparql/sparql/winding.sparql | 35 +++-- src/cimsparql/sparql/winding_loss.sparql | 41 +++--- 55 files changed, 1140 insertions(+), 1112 deletions(-) delete mode 100644 .flake8 create mode 100644 qlue-ls.toml diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 99a297da..00000000 --- a/.flake8 +++ /dev/null @@ -1,17 +0,0 @@ -[flake8] -jobs = auto -max-line-length = 100 -ignore = E266, W503, E203 -exclude = - .git, - pip_cache, - pipenv_cache, - .venv, - .tox, - __pycache__ - .venv -# F, B - pyflakes and flake8-bugbear -# B901 - return with value inside generator function. -select = E,F,B,B901,W -max-complexity = 15 -output-file = .flake8.log diff --git a/.gitignore b/.gitignore index 3acb1a31..805cbd96 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ pip-log.txt nosetests.xml coverage.xml htmlcov +**/pytest.log # Translations *.mo diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 99a96ddc..db811b89 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,9 +13,19 @@ repos: - id: check-toml - id: end-of-file-fixer - id: trailing-whitespace + exclude: \.sparql$ - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.8.6 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - id: ruff-format + - repo: local + hooks: + - id: sparql-formatter + name: sparql-formatter + entry: sh -c 'for file in "$@"; do uv run qlue-ls format "$file" -w; done' -- + language: python + types: [file] + files: \.sparql$ + additional_dependencies: [qlue-ls] diff --git a/README.md b/README.md index 07cf1063..d7c22112 100644 --- a/README.md +++ b/README.md @@ -125,3 +125,16 @@ This can be done when initializing the `ServiceCfg` class or by specifying the ` export SPARQL_REST_API=RDF4J # To use RDF4J export SPARQL_REST_API=BLAZEGRAPH # To use BlazeGraph ``` + +## Contributing + +Contributions are always welcome and encouraged! Whether it's reporting a bug, suggesting an enhancement, or submitting a pull request, your input helps improve the project. + +### Development + +Dependencies are managed through uv, install with `uv sync`. + +It's recommended to install the pre-commit hooks so checks are run automatically on every commit. +After installing pre-commit itself, install the hooks with `pre-commit install`. +Checks are normally only run on modified files when committing, but you can run all checks on all files with +`pre-commit run --all`. diff --git a/qlue-ls.toml b/qlue-ls.toml new file mode 100644 index 00000000..6a70c77f --- /dev/null +++ b/qlue-ls.toml @@ -0,0 +1,2 @@ +[format] +where_new_line = true diff --git a/src/cimsparql/sparql/ac_lines.sparql b/src/cimsparql/sparql/ac_lines.sparql index b707fb9e..df2bd293 100644 --- a/src/cimsparql/sparql/ac_lines.sparql +++ b/src/cimsparql/sparql/ac_lines.sparql @@ -2,95 +2,81 @@ PREFIX cim: <${cim}> PREFIX SN: <${SN}> PREFIX xsd: <${xsd}> -select -# Below a lot of max aggregation is performed. For variables without any suffix (_1 og _2) all values within the +# Above a lot of max aggregation is performed. For variables without any suffix (_1 og _2) all values within the # group are equal and we might as well just pick the maximum value. For variables with the suffix _1 og _2, the -# value we want to extract either exist as one entry in the group. The other entry is an empty string. Since -# all strings are greater than the empty string, max-aggregation will pick the value we want. For the boolan -# value ?connected_1 (or_2), the default value is False. By a similar argument True is larger than False, -# thus max-aggregation will pick True if it exists in the group -(max(?mrid) as ?mrid) -(max(?name) as ?name) -(max(?node_1) as ?node_1) -(max(?node_2) as ?node_2) - -# If SvPower at node 1 is smaller than SvPower at node 2, we assign the loss (sum of the two) to node_1. In case +# value we want to extract exist as one entry in the group. The other entry is an empty string. Since all strings +# are greater than the empty string, max-aggregation will pick the value we want. For the boolan value +# ?connected_1 (or_2), the default value is False. By a similar argument True is larger than False, thus +# max-aggregation will pick True if it exists in the group. +# +# If SvPower at node 1 is smaller than SvPower at node 2, we assign the loss (sum of the two) to node_1. In case # SvPower at node 1 is larger than on node 2, the loss is assigned to node_2 -(if (xsd:double(max(?p_1)) < xsd:double(max(?p_2)), xsd:double(max(?p_1)) + xsd:double(max(?p_2)), xsd:double(0.0)) as ?ploss_1) -(if (xsd:double(max(?p_1)) > xsd:double(max(?p_2)), xsd:double(max(?p_1)) + xsd:double(max(?p_2)), xsd:double(0.0)) as ?ploss_2) -(max(?r) as ?r) -(max(?rate) as ?rate) -(coalesce(max(?in_service), max(?connected_1) && max(?connected_2), True) as ?status) -(max(?un) as ?un) -(max(?x) as ?x) -(max(?b) as ?b) -(max(?g) as ?g) -(max(?length) as ?length) -(max(?connectivity_node_1) as ?connectivity_node_1) -(max(?connectivity_node_2) as ?connectivity_node_2) -where { - # TODO: Check if SN:Equipment.networkAnalysisEnable is on it's way into the standard - # Assume π equivalent with at least r,x and b shunt. - # Extract properties for ACLineSegments +SELECT (MAX(?mrid) AS ?mrid) (MAX(?name) AS ?name) (MAX(?node_1) AS ?node_1) (MAX(?node_2) AS ?node_2) (IF(xsd:double(MAX(?p_1)) < xsd:double(MAX(?p_2)),xsd:double(MAX(?p_1)) + xsd:double(MAX(?p_2)),xsd:double(0.0)) AS ?ploss_1) (IF(xsd:double(MAX(?p_1)) > xsd:double(MAX(?p_2)),xsd:double(MAX(?p_1)) + xsd:double(MAX(?p_2)),xsd:double(0.0)) AS ?ploss_2) (MAX(?r) AS ?r) (MAX(?rate) AS ?rate) (COALESCE(MAX(?in_service), MAX(?connected_1) && MAX(?connected_2), True) AS ?status) (MAX(?un) AS ?un) (MAX(?x) AS ?x) (MAX(?b) AS ?b) (MAX(?g) AS ?g) (MAX(?length) AS ?length) (MAX(?connectivity_node_1) AS ?connectivity_node_1) (MAX(?connectivity_node_2) AS ?connectivity_node_2) +WHERE { ?_eq_subject ?eq_repo - service ?eq_repo { - ?acline cim:ACLineSegment.r ?r; - cim:ACLineSegment.x ?x; - cim:ACLineSegment.bch ?b; - cim:IdentifiedObject.mRID ?mrid; - cim:IdentifiedObject.name ?name; - cim:ConductingEquipment.BaseVoltage/cim:BaseVoltage.nominalVoltage ?un; - cim:Conductor.length ?length . - - ?terminal cim:Terminal.ConductingEquipment ?acline; - cim:Terminal.ConnectivityNode ?con_node; - cim:Terminal.sequenceNumber|cim:ACDCTerminal.sequenceNumber ?nr . - - # Find substation of each connectivity node of the terminals above - ?con_node cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation ?substation ; - cim:IdentifiedObject.mRID ?connectivity_node . - - # Find area and optionally bidzone for each substation - ?substation cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area . - - optional {?acline cim:ACLineSegment.gch ?g .} - optional {?acline SN:Equipment.networkAnalysisEnable ?analysis_enabled .} - - # If exists, extract active power limit for acline - optional { - ?_lim cim:OperationalLimit.OperationalLimitSet/cim:OperationalLimitSet.Equipment ?acline; - a cim:ActivePowerLimit; - cim:IdentifiedObject.name '${rate}'; - cim:ActivePowerLimit.value ?rate . - }} . + SERVICE ?eq_repo { + ?acline cim:ACLineSegment.r ?r ; + cim:ACLineSegment.x ?x ; + cim:ACLineSegment.bch ?b ; + cim:IdentifiedObject.mRID ?mrid ; + cim:IdentifiedObject.name ?name ; + cim:ConductingEquipment.BaseVoltage/cim:BaseVoltage.nominalVoltage ?un ; + cim:Conductor.length ?length . + ?terminal cim:Terminal.ConductingEquipment ?acline ; + cim:Terminal.ConnectivityNode ?con_node ; + cim:Terminal.sequenceNumber | cim:ACDCTerminal.sequenceNumber ?nr . + # Find substation of each connectivity node of the terminals above + ?con_node cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation ?substation ; + cim:IdentifiedObject.mRID ?connectivity_node . + # Find area and optionally bidzone for each substation + ?substation cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area . + OPTIONAL { + ?acline cim:ACLineSegment.gch ?g . + } + OPTIONAL { + ?acline SN:Equipment.networkAnalysisEnable ?analysis_enabled . + } + # If exists, extract active power limit for acline + OPTIONAL { + ?_lim cim:OperationalLimit.OperationalLimitSet/cim:OperationalLimitSet.Equipment ?acline ; + a cim:ActivePowerLimit ; + cim:IdentifiedObject.name '${rate}' ; + cim:ActivePowerLimit.value ?rate . + } + } . # Search for acline SV status will be combined with SSH connected - optional {?acline ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?in_service . } - + OPTIONAL { + ?acline ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?in_service . + } { ?con_node cim:ConnectivityNode.TopologicalNode ?topological_node . - } union { - filter not exists {?con_node cim:ConnectivityNode.TopologicalNode ?topological_node} + } + UNION { + FILTER NOT EXISTS { + ?con_node cim:ConnectivityNode.TopologicalNode ?topological_node + } ?terminal cim:Terminal.TopologicalNode ?topological_node . } ?topological_node cim:IdentifiedObject.mRID ?node . - # Find properties in TP/SV/SSH profile for each terminal. ?terminal cim:ACDCTerminal.connected ?connected . - optional {?terminal ^cim:SvPowerFlow.Terminal/cim:SvPowerFlow.p ?p .} - + OPTIONAL { + ?terminal ^cim:SvPowerFlow.Terminal/cim:SvPowerFlow.p ?p . + } # Create variables for node 1 and node 2 - bind(if(?nr = 1, str(?p), '') as ?p_1) - bind(if(?nr = 1, ?node, '') as ?node_1) - bind(if(?nr = 1, ?connected, False) as ?connected_1) - bind(if(?nr = 2, str(?p), '') as ?p_2) - bind(if(?nr = 2, ?node, '') as ?node_2) - bind(if(?nr = 2, ?connected, False) as ?connected_2) - bind(if(?nr = 1, ?connectivity_node, '') as ?connectivity_node_1) - bind(if(?nr = 2, ?connectivity_node, '') as ?connectivity_node_2) - filter(regex(?area, '${region}')) -} group by ?acline + BIND (IF(?nr = 1,STR(?p),'') AS ?p_1) + BIND (IF(?nr = 1,?node,'') AS ?node_1) + BIND (IF(?nr = 1,?connected,False) AS ?connected_1) + BIND (IF(?nr = 2,STR(?p),'') AS ?p_2) + BIND (IF(?nr = 2,?node,'') AS ?node_2) + BIND (IF(?nr = 2,?connected,False) AS ?connected_2) + BIND (IF(?nr = 1,?connectivity_node,'') AS ?connectivity_node_1) + BIND (IF(?nr = 2,?connectivity_node,'') AS ?connectivity_node_2) + FILTER (REGEX(?area,'${region}')) +} +GROUP BY ?acline # Filtration rules # 1) We don't need lines connecting nodes to themselves # 2) Only extract lines where at least two nodes exist # 3) Only extract lines where SN:Equipment.networkAnalysisEnable is True (if the field exists) -having((max(?node_1) != max(?node_2)) && (max(?node_1) != "") && (max(?node_2) != "") && (count(*) > 1) && coalesce(max(?analysis_enabled), True)) +HAVING ((MAX(?node_1) != MAX(?node_2)) && (MAX(?node_1) != "") && (MAX(?node_2) != "") && (COUNT(*) > 1) && COALESCE(MAX(?analysis_enabled), True)) diff --git a/src/cimsparql/sparql/add_mrid.sparql b/src/cimsparql/sparql/add_mrid.sparql index 8935feb2..81efcce9 100644 --- a/src/cimsparql/sparql/add_mrid.sparql +++ b/src/cimsparql/sparql/add_mrid.sparql @@ -1,8 +1,10 @@ # Name: Add MRID PREFIX cim: <${cim}> -insert {graph ${g} {?s cim:IdentifiedObject.mRID ?mrid}} -where { - graph ${g} {?s a ${rdf_type}} - filter (not exists {?s cim:IdentifiedObject.mRID ?mrid}) - bind(str(?s) as ?mrid) +INSERT {GRAPH ${g} {?s cim:IdentifiedObject.mRID ?mrid} .} +WHERE { + GRAPH ${g} { ?s a $ {rdf_type}} + FILTER NOT EXISTS { + ?s cim:IdentifiedObject.mRID ?mrid . + } + BIND (STR(?s) AS ?mrid) } diff --git a/src/cimsparql/sparql/associated_switches.sparql b/src/cimsparql/sparql/associated_switches.sparql index 27d773bc..9c17dfce 100644 --- a/src/cimsparql/sparql/associated_switches.sparql +++ b/src/cimsparql/sparql/associated_switches.sparql @@ -1,19 +1,19 @@ # Name: Associated switches PREFIX cim: <${cim}> - -select (SAMPLE(?equipment_mrid) as ?mrid) (SAMPLE(?name) as ?name) (GROUP_CONCAT(?switch_mrid; SEPARATOR=',') as ?switch_mrids) (GROUP_CONCAT(?switch_name; SEPARATOR=',') as ?switch_names) where { - { - ?equipment ^cim:Terminal.ConductingEquipment/cim:Terminal.ConnectivityNode/^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment ?switch; - cim:IdentifiedObject.name ?name ; - cim:IdentifiedObject.mRID ?equipment_mrid . - ?switch cim:Switch.normalOpen ?_normalOpen; - cim:IdentifiedObject.mRID ?switch_mrid ; - cim:IdentifiedObject.name ?switch_name ; - # Only included switches that has a "second" terminal. There are switches - # that only have one terminal. These switches can not connect/disconnect anything - ^cim:Terminal.ConductingEquipment/cim:ACDCTerminal.sequenceNumber 2 . - } minus { - ?equipment cim:Switch.normalOpen ?_open - } - -} group by ?equipment +SELECT (SAMPLE(?equipment_mrid) AS ?mrid) (SAMPLE(?name) AS ?name) (GROUP_CONCAT(?switch_mrid;SEPARATOR=',') AS ?switch_mrids) (GROUP_CONCAT(?switch_name;SEPARATOR=',') AS ?switch_names) +WHERE { + { + ?equipment ^cim:Terminal.ConductingEquipment/cim:Terminal.ConnectivityNode/^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment ?switch ; + cim:IdentifiedObject.name ?name ; + cim:IdentifiedObject.mRID ?equipment_mrid . + ?switch cim:Switch.normalOpen ?_normalOpen ; + cim:IdentifiedObject.mRID ?switch_mrid ; + cim:IdentifiedObject.name ?switch_name ; + ^cim:Terminal.ConductingEquipment/cim:ACDCTerminal.sequenceNumber 2 . + # Only include switches that have a "second" terminal. There are switches that only have one terminal. These switches can not connect/disconnect anything + } + MINUS { + ?equipment cim:Switch.normalOpen ?_open + } +} +GROUP BY ?equipment diff --git a/src/cimsparql/sparql/base_voltage.sparql b/src/cimsparql/sparql/base_voltage.sparql index e5e5ea0a..fec225f5 100644 --- a/src/cimsparql/sparql/base_voltage.sparql +++ b/src/cimsparql/sparql/base_voltage.sparql @@ -1,20 +1,21 @@ # Name: Base voltage PREFIX cim: <${cim}> PREFIX xsd: <${xsd}> - -select ?mrid ?un ?operating_voltage { - { - select ?base_voltage (avg(xsd:double(str(?voltage))) as ?operating_voltage) { - ?top_node ^cim:SvVoltage.TopologicalNode/cim:SvVoltage.v ?voltage; - cim:TopologicalNode.BaseVoltage ?base_voltage . - filter(xsd:double(str(?voltage)) > 0.0) - } group by ?base_voltage +SELECT ?mrid ?un ?operating_voltage +WHERE { + { + SELECT ?base_voltage (AVG(xsd:double(STR(?voltage))) AS ?operating_voltage) + WHERE { + ?top_node ^cim:SvVoltage.TopologicalNode/cim:SvVoltage.v ?voltage ; + cim:TopologicalNode.BaseVoltage ?base_voltage . + FILTER (xsd:double(STR(?voltage)) > 0.0) } - - ?_eq_subject ?eq_repo . - service ?eq_repo { - # Find the nominal voltage from the base voltage associated with the topological node - ?base_voltage cim:BaseVoltage.nominalVoltage ?un ; - cim:IdentifiedObject.mRID ?mrid - } + GROUP BY ?base_voltage + } + ?_eq_subject ?eq_repo . + SERVICE ?eq_repo { + # Find the nominal voltage from the base voltage associated with the topological node + ?base_voltage cim:BaseVoltage.nominalVoltage ?un ; + cim:IdentifiedObject.mRID ?mrid . + } } diff --git a/src/cimsparql/sparql/borders.sparql b/src/cimsparql/sparql/borders.sparql index cd1f9dde..aae50f23 100644 --- a/src/cimsparql/sparql/borders.sparql +++ b/src/cimsparql/sparql/borders.sparql @@ -1,32 +1,34 @@ # Name: Borders -PREFIX cim:<${cim}> -PREFIX SN:<${SN}> -select ?mrid ?name ?market_code ?area_1 ?area_2 ?t_mrid_1 ?t_mrid_2 -where { +PREFIX cim: <${cim}> +PREFIX SN: <${SN}> +SELECT ?mrid ?name ?market_code ?area_1 ?area_2 ?t_mrid_1 ?t_mrid_2 +WHERE { # Extract mRID, name and optionally market_code for aclines - ?acline a cim:ACLineSegment; - cim:IdentifiedObject.mRID ?mrid; - cim:IdentifiedObject.name ?name. - optional {?acline cim:Equipment.EquipmentContainer/SN:Line.marketCode ?market_code} . - optional {?acline SN:Equipment.networkAnalysisEnable ?_analysis_enabled .} - + ?acline a cim:ACLineSegment ; + cim:IdentifiedObject.mRID ?mrid ; + cim:IdentifiedObject.name ?name . + OPTIONAL { + ?acline cim:Equipment.EquipmentContainer/SN:Line.marketCode ?market_code . + } + OPTIONAL { + ?acline SN:Equipment.networkAnalysisEnable ?_analysis_enabled . + } # Extract properties for the terminal connected to one end of the acline (sequenceNumber 1) - ?terminal1 a cim:Terminal; - cim:Terminal.ConductingEquipment ?acline; - cim:Terminal.sequenceNumber|cim:ACDCTerminal.sequenceNumber 1; - cim:Terminal.ConnectivityNode/cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation/cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area_1; - cim:IdentifiedObject.mRID ?t_mrid_1 . - + ?terminal1 a cim:Terminal ; + cim:Terminal.ConductingEquipment ?acline ; + cim:Terminal.sequenceNumber | cim:ACDCTerminal.sequenceNumber 1 ; + cim:Terminal.ConnectivityNode/cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation/cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area_1 ; + cim:IdentifiedObject.mRID ?t_mrid_1 . # Extract properties for the terminal connected to the other end of the acline (sequenceNumber 2) - ?terminal2 a cim:Terminal; - cim:Terminal.ConductingEquipment ?acline; - cim:Terminal.sequenceNumber|cim:ACDCTerminal.sequenceNumber 2; - cim:Terminal.ConnectivityNode/cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation/cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area_2 ; - cim:IdentifiedObject.mRID ?t_mrid_2 . - - filter (?area_1 != ?area_2) - filter (regex(?area_1, '${region}') || regex(?area_2, '${region}')) - filter (!regex(?name, 'HVDC')) # Ignore HVDC - bind(coalesce(?_analysis_enabled, True) as ?analysis_enabled) - filter(?analysis_enabled) + ?terminal2 a cim:Terminal ; + cim:Terminal.ConductingEquipment ?acline ; + cim:Terminal.sequenceNumber | cim:ACDCTerminal.sequenceNumber 2 ; + cim:Terminal.ConnectivityNode/cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation/cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area_2 ; + cim:IdentifiedObject.mRID ?t_mrid_2 . + FILTER (?area_1 != ?area_2) + FILTER (REGEX(?area_1,'${region}') || REGEX(?area_2,'${region}')) + FILTER (!regex(?name, 'HVDC')) + BIND (COALESCE(?_analysis_enabled, true) AS ?analysis_enabled) + # Ignore HVDC + FILTER (?analysis_enabled = true) } diff --git a/src/cimsparql/sparql/branch_node_withdraw.sparql b/src/cimsparql/sparql/branch_node_withdraw.sparql index 5bcb4c97..dd1a717d 100644 --- a/src/cimsparql/sparql/branch_node_withdraw.sparql +++ b/src/cimsparql/sparql/branch_node_withdraw.sparql @@ -1,44 +1,47 @@ # Name: Branch node withdraw -PREFIX cim:<${cim}> -PREFIX SN:<${SN}> -select ?mrid ?node ?p ?q ?connectivity_node -where { +PREFIX cim: <${cim}> +PREFIX SN: <${SN}> +SELECT ?mrid ?node ?p ?q ?connectivity_node +WHERE { { - select * where { - ?_eq_subject ?eq_repo . - service ?eq_repo { - # Specify components wer are interested in - values ?rdf_type {cim:ACLineSegment cim:SeriesCompensator cim:PowerTransformer} . - ?component a ?rdf_type . - optional {?component SN:Equipment.networkAnalysisEnable ?_analysis_enabled .} - ?terminal cim:Terminal.ConductingEquipment ?component; - cim:IdentifiedObject.mRID ?mrid; + SELECT * + WHERE { + ?_eq_subject ?eq_repo . + SERVICE ?eq_repo { + VALUES ?rdf_type { cim:ACLineSegment cim:SeriesCompensator cim:PowerTransformer } + # Specify components wer are interested in + ?component a ?rdf_type . + OPTIONAL { + ?component SN:Equipment.networkAnalysisEnable ?_analysis_enabled . + } + ?terminal cim:Terminal.ConductingEquipment ?component ; + cim:IdentifiedObject.mRID ?mrid ; cim:Terminal.ConnectivityNode ?con_node . - ?con_node cim:IdentifiedObject.mRID ?connectivity_node . - - # Find area for the connectivity node of the terminal - ?con_node cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation/cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area . - filter(regex(?area, '${region}')) + ?con_node cim:IdentifiedObject.mRID ?connectivity_node . + # Find area for the connectivity node of the terminal + ?con_node cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation/cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area . + FILTER REGEX(?area,'${region}') } } } - # Extract properties of each terminal from the SV/TP/SSH profile. # If exists, the mRID of the topological node associated with the terminal is etracted ?terminal cim:ACDCTerminal.connected ?connected . - ?_sv_t cim:SvPowerFlow.Terminal ?terminal; - cim:SvPowerFlow.p ?p; - cim:SvPowerFlow.q ?q . + ?_sv_t cim:SvPowerFlow.Terminal ?terminal ; + cim:SvPowerFlow.p ?p ; + cim:SvPowerFlow.q ?q . { ?con_node cim:ConnectivityNode.TopologicalNode ?topological_node . - } union { - filter not exists {?con_node cim:ConnectivityNode.TopologicalNode ?topological_node} + } + UNION { + FILTER NOT EXISTS { + ?con_node cim:ConnectivityNode.TopologicalNode ?topological_node . + } ?terminal cim:Terminal.TopologicalNode ?topological_node . } ?topological_node cim:IdentifiedObject.mRID ?node . - + BIND (COALESCE(?_analysis_enabled, true) AS ?analysis_enabled) # Assign analysis enabled (all True if not exist) - bind(coalesce(?_analysis_enabled, True) as ?analysis_enabled) - filter(?analysis_enabled) - filter(?connected) + FILTER (?analysis_enabled = true) + FILTER (?connected = true) } diff --git a/src/cimsparql/sparql/bus.sparql b/src/cimsparql/sparql/bus.sparql index 9556294f..66970431 100644 --- a/src/cimsparql/sparql/bus.sparql +++ b/src/cimsparql/sparql/bus.sparql @@ -1,52 +1,55 @@ # Name: Bus -PREFIX cim:<${cim}> -PREFIX SN:<${SN}> -PREFIX entsoeSecretariat:<${entsoeSecretariat}> -select (?mrid as ?node) ?busname (?substation_name as ?substation) ?un ?base_voltage_mrid ?substation_mrid ?bidzone ?sv_voltage ?island ?is_swing_bus -where { +PREFIX cim: <${cim}> +PREFIX SN: <${SN}> +PREFIX entsoeSecretariat: <${entsoeSecretariat}> +SELECT (?mrid AS ?node) ?busname (?substation_name AS ?substation) ?un ?base_voltage_mrid ?substation_mrid ?bidzone ?sv_voltage ?island ?is_swing_bus +WHERE { # Extract propertoes from the TP/SV/SSH profile for each topological node - ?top_node cim:TopologicalNode.BaseVoltage ?base_voltage; - cim:TopologicalNode.ConnectivityNodeContainer ?container; - cim:IdentifiedObject.mRID ?mrid; - cim:IdentifiedObject.name ?busname; + ?top_node cim:TopologicalNode.BaseVoltage ?base_voltage ; + cim:TopologicalNode.ConnectivityNodeContainer ?container ; + cim:IdentifiedObject.mRID ?mrid ; + cim:IdentifiedObject.name ?busname ; ^cim:SvVoltage.TopologicalNode/cim:SvVoltage.v ?sv_voltage . - optional{?top_node ^cim:TopologicalIsland.TopologicalNodes/cim:IdentifiedObject.name ?island_name .} - optional{?top_node ^cim:TopologicalIsland.AngleRefTopoligicalNode ?angle_ref .} - + OPTIONAL { + ?top_node ^cim:TopologicalIsland.TopologicalNodes/cim:IdentifiedObject.name ?island_name . + } + OPTIONAL { + ?top_node ^cim:TopologicalIsland.AngleRefTopoligicalNode ?angle_ref . + } ?_eq_subject ?eq_repo . - service ?eq_repo { + SERVICE ?eq_repo { # Find the nominal voltage from the base voltage associated with the topological node - ?base_voltage cim:BaseVoltage.nominalVoltage ?un; - cim:IdentifiedObject.mRID ?base_voltage_mrid . - + ?base_voltage cim:BaseVoltage.nominalVoltage ?un ; + cim:IdentifiedObject.mRID ?base_voltage_mrid . # Extract properties from the connectivity node container associated with each topoligical node ?container cim:VoltageLevel.Substation ?_substation . - # Extract information about the substation associated with the connectivity node container - ?_substation cim:IdentifiedObject.mRID ?substation_mrid; - cim:IdentifiedObject.name ?substation_name; - cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area . - + ?_substation cim:IdentifiedObject.mRID ?substation_mrid ; + cim:IdentifiedObject.name ?substation_name ; + cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area . # Extract the bidzone of each substation if it exists - optional { - ?_substation SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC ?direct_bidzone + OPTIONAL { + ?_substation SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC ?direct_bidzone . } - } . - optional { + } + OPTIONAL { # When an EIC code does not exist, look for an EIC code in neighbouring nodes - filter(!bound(?direct_bidzone)) + FILTER (!bound(?direct_bidzone)) { - select ?top_node (max(?connected_bidzone) as ?nearby_bidzone) { + SELECT ?top_node (MAX(?connected_bidzone) AS ?nearby_bidzone) + WHERE { ?con_node cim:ConnectivityNode.TopologicalNode ?top_node . ?_eq_subj2 ?eq_repo2 . - service ?eq_repo2 { + SERVICE ?eq_repo2 { # Collect bidzones from substations connected to the current substation via a ConductingEquipment ?con_node ^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment/^cim:Terminal.ConductingEquipment/cim:Terminal.ConnectivityNode/cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation/SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC ?connected_bidzone . - }} group by ?top_node} + } + } + GROUP BY ?top_node + } } - bind(coalesce(?direct_bidzone, ?nearby_bidzone) as ?bidzone) - - FILTER regex(?area, '${region}') - bind(if(bound(?angle_ref), True, False) as ?is_swing_bus) - bind(coalesce(?island_name, "Unknown") as ?island) + BIND (COALESCE(?direct_bidzone, ?nearby_bidzone) AS ?bidzone) + FILTER REGEX(?area,'${region}') + BIND (IF(BOUND(?angle_ref),true,false) AS ?is_swing_bus) + BIND (COALESCE(?island_name, "Unknown") AS ?island) } diff --git a/src/cimsparql/sparql/connections.sparql b/src/cimsparql/sparql/connections.sparql index 43f18575..93f3d277 100644 --- a/src/cimsparql/sparql/connections.sparql +++ b/src/cimsparql/sparql/connections.sparql @@ -1,25 +1,24 @@ # Name: Connections -PREFIX cim:<${cim}> -PREFIX SN:<${SN}> -select ?mrid ?t_mrid_1 ?t_mrid_2 -where { +PREFIX cim: <${cim}> +PREFIX SN: <${SN}> +SELECT ?mrid ?t_mrid_1 ?t_mrid_2 +WHERE { + VALUES ?connector_type { cim:Breaker cim:Disconnector } # Declare connector types - values ?connector_type {cim:Breaker cim:Disconnector} - # Extact mRID for each connector - ?connector a ?connector_type; - cim:IdentifiedObject.mRID ?mrid . - + ?connector a ?connector_type ; + cim:IdentifiedObject.mRID ?mrid . # Extract properties for the terminal connected to sequenceNumber 1 - ?terminal1 cim:Terminal.ConductingEquipment ?connector; - cim:Terminal.sequenceNumber|cim:ACDCTerminal.sequenceNumber 1; - cim:IdentifiedObject.mRID ?t_mrid_1 . - + ?terminal1 cim:Terminal.ConductingEquipment ?connector ; + cim:Terminal.sequenceNumber | cim:ACDCTerminal.sequenceNumber 1 ; + cim:IdentifiedObject.mRID ?t_mrid_1 . # Extract properties for the terminal conencted to sequenceNumber 2 - ?terminal2 cim:Terminal.ConductingEquipment ?connector; - cim:Terminal.sequenceNumber|cim:ACDCTerminal.sequenceNumber 2; - cim:IdentifiedObject.mRID ?t_mrid_2 - optional {?connector SN:Equipment.networkAnalysisEnable ?_analysis_enabled .} - bind(coalesce(?_analysis_enabled, True) as ?analysis_enabled) - filter(?analysis_enabled) + ?terminal2 cim:Terminal.ConductingEquipment ?connector ; + cim:Terminal.sequenceNumber | cim:ACDCTerminal.sequenceNumber 2 ; + cim:IdentifiedObject.mRID ?t_mrid_2 . + OPTIONAL { + ?connector SN:Equipment.networkAnalysisEnable ?_analysis_enabled . + } + BIND (COALESCE(?_analysis_enabled, true) AS ?analysis_enabled) + FILTER (?analysis_enabled = true) } diff --git a/src/cimsparql/sparql/connectivity_nodes.sparql b/src/cimsparql/sparql/connectivity_nodes.sparql index b9110596..b21c0cff 100644 --- a/src/cimsparql/sparql/connectivity_nodes.sparql +++ b/src/cimsparql/sparql/connectivity_nodes.sparql @@ -1,67 +1,65 @@ # Name: Connectivity nodes - -PREFIX cim:<${cim}> -PREFIX SN:<${SN}> -PREFIX entsoeSecretariat:<${entsoeSecretariat}> - -select ?mrid (?container_mrid as ?container) ?container_name ?un ?base_voltage_mrid ?bidzone ?container_type -where { - ?con_node cim:ConnectivityNode.ConnectivityNodeContainer ?con_node_container; - cim:IdentifiedObject.mRID ?mrid . - - { - select ?con_node (count(*) as ?num_active) { - # Support both typed and not typed networkAnalysisEnable flag - values ?true {True "true"} - ?con_node ^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment/SN:Equipment.networkAnalysisEnable ?true - } group by ?con_node +PREFIX cim: <${cim}> +PREFIX SN: <${SN}> +PREFIX entsoeSecretariat: <${entsoeSecretariat}> +SELECT ?mrid (?container_mrid AS ?container) ?container_name ?un ?base_voltage_mrid ?bidzone ?container_type +WHERE { + ?con_node cim:ConnectivityNode.ConnectivityNodeContainer ?con_node_container ; + cim:IdentifiedObject.mRID ?mrid . + { + SELECT ?con_node (COUNT(*) AS ?num_active) + WHERE { + VALUES ?true { true "true" } + # Support both typed and not typed networkAnalysisEnable flag + ?con_node ^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment/SN:Equipment.networkAnalysisEnable ?true . } - filter(?num_active > 0) - - # Extract properties from the connectivity node container associated with each topoligical node + GROUP BY ?con_node + } + FILTER (?num_active > 0) { - ?con_node_container cim:VoltageLevel.BaseVoltage ?base_voltage; - cim:VoltageLevel.Substation ?_substation . - - ?base_voltage cim:BaseVoltage.nominalVoltage ?un; - cim:IdentifiedObject.mRID ?base_voltage_mrid . - + # Extract properties from the connectivity node container associated with each topoligical node + ?con_node_container cim:VoltageLevel.BaseVoltage ?base_voltage ; + cim:VoltageLevel.Substation ?_substation . + ?base_voltage cim:BaseVoltage.nominalVoltage ?un ; + cim:IdentifiedObject.mRID ?base_voltage_mrid . # Extract information about the substation associated with the connectivity node container - ?_substation cim:IdentifiedObject.mRID ?container_mrid; - cim:IdentifiedObject.name ?container_name; - cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area . - # Extract the bidzone of each substation if it exists - optional { - ?_substation SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC ?direct_bidzone - } . + ?_substation cim:IdentifiedObject.mRID ?container_mrid ; + cim:IdentifiedObject.name ?container_name ; + cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area . + # Extract the bidzone of each substation if it exists + OPTIONAL { + ?_substation SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC ?direct_bidzone . + } { - filter(!bound(?bidzone)) - # When an EIC code does not exist, look for an EIC code in neighbouring nodes + FILTER (!bound(?bidzone)) { - select (max(?related_bidzone) as ?nearby_bidzone) where { + # When an EIC code does not exist, look for an EIC code in neighbouring nodes + SELECT (MAX(?related_bidzone) AS ?nearby_bidzone) + WHERE { # Collect bidzones from substations connected to the current substation via a ConductingEquipment - ?con_node ^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment/^cim:Terminal.ConductingEquipment/cim:Terminal.ConnectivityNode/cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation/SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC ?related_bidzone . - } + ?con_node ^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment/^cim:Terminal.ConductingEquipment/cim:Terminal.ConnectivityNode/cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation/SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC ?related_bidzone . + } } } - bind("Substation" as ?container_type) - bind(coalesce(?direct_bidzone, ?nearby_bidzone) as ?bidzone) - } union { - ?con_node_container cim:Line.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area; - cim:IdentifiedObject.name ?container_name; - cim:IdentifiedObject.mRID ?container_mrid - - # Extract voltage levels connectivity nodes related via a conducting equipment (cim:Line has no cim:VoltageLeve.BaseVoltage) + BIND ("Substation" AS ?container_type) + BIND (COALESCE(?direct_bidzone, ?nearby_bidzone) AS ?bidzone) + } + UNION { + ?con_node_container cim:Line.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area ; + cim:IdentifiedObject.name ?container_name ; + cim:IdentifiedObject.mRID ?container_mrid . { - select ?base_voltage_mrid ?un { + # Extract voltage levels connectivity nodes related via a conducting equipment (cim:Line has no cim:VoltageLeve.BaseVoltage) + SELECT ?base_voltage_mrid ?un + WHERE { ?con_node ^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment/^cim:Terminal.ConductingEquipment/cim:Terminal.ConnectivityNode/cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.BaseVoltage ?base_voltage . - ?base_voltage cim:IdentifiedObject.mRID ?base_voltage_mrid; - cim:BaseVoltage.nominalVoltage ?un - } order by desc (xsd:double(str(?un))) - limit 1 + ?base_voltage cim:IdentifiedObject.mRID ?base_voltage_mrid ; + cim:BaseVoltage.nominalVoltage ?un . + } + ORDER BY DESC((xsd:double(STR(?un)))) + LIMIT 1 } - - bind("Line" as ?container_type) + BIND ("Line" AS ?container_type) } - FILTER regex(?area, '.*') + FILTER REGEX(?area,'.*') } diff --git a/src/cimsparql/sparql/converter_hvdc_bidzones.sparql b/src/cimsparql/sparql/converter_hvdc_bidzones.sparql index b41f216c..3af14f3a 100644 --- a/src/cimsparql/sparql/converter_hvdc_bidzones.sparql +++ b/src/cimsparql/sparql/converter_hvdc_bidzones.sparql @@ -1,19 +1,15 @@ # Name: Converter HVDC bidzones -PREFIX cim:<${cim}> -PREFIX SN:<${SN}> -PREFIX ALG:<${ALG}> - -select distinct ?mrid ?bidzone_1 ?bidzone_2 -where -{ +PREFIX cim: <${cim}> +PREFIX SN: <${SN}> +PREFIX ALG: <${ALG}> +SELECT DISTINCT ?mrid ?bidzone_1 ?bidzone_2 +WHERE { ?converter ALG:DCConverter.DCPole | ALG:VoltageSourceConverter.DCPole ?pole ; - cim:IdentifiedObject.mRID ?mrid . - ?pole cim:Equipment.EquipmentContainer/SN:Substation.MarketDeliveryPoint ?delivery_point. - + cim:IdentifiedObject.mRID ?mrid . + ?pole cim:Equipment.EquipmentContainer/SN:Substation.MarketDeliveryPoint ?delivery_point . ?delivery_point SN:MarketDeliveryPoint.BiddingArea/SN:BiddingArea.marketCode ?bidzone_1 . - # Extract the destination point from the line that has one end matching bidzone_1 - ?line SN:Line.FromMarketDeliveryPoint ?delivery_point; - SN:Line.ToMarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/SN:BiddingArea.marketCode ?bidzone_2 - filter(?bidzone_1 != ?bidzone_2) + ?line SN:Line.FromMarketDeliveryPoint ?delivery_point ; + SN:Line.ToMarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/SN:BiddingArea.marketCode ?bidzone_2 . + FILTER (?bidzone_1 != ?bidzone_2) } diff --git a/src/cimsparql/sparql/converters.sparql b/src/cimsparql/sparql/converters.sparql index d8e67637..ed8a1e24 100644 --- a/src/cimsparql/sparql/converters.sparql +++ b/src/cimsparql/sparql/converters.sparql @@ -1,74 +1,80 @@ # Name: Converters -PREFIX cim:<${cim}> -PREFIX xsd:<${xsd}> -PREFIX SN:<${SN}> -PREFIX ALG:<${ALG}> -select ?mrid ?name ?alias ?p ?q ?substation_mrid ?status ?node ?connectivity_node ?controller ?controller_factor ?pole_loss ?loss0 ?loss1 ?loss2 ?vdcn ?un -where { +PREFIX cim: <${cim}> +PREFIX xsd: <${xsd}> +PREFIX SN: <${SN}> +PREFIX ALG: <${ALG}> +SELECT ?mrid ?name ?alias ?p ?q ?substation_mrid ?status ?node ?connectivity_node ?controller ?controller_factor ?pole_loss ?loss0 ?loss1 ?loss2 ?vdcn ?un +WHERE { { - select * where { + SELECT * + WHERE { ?_eq_subject ?eq_repo . - service ?eq_repo { + SERVICE ?eq_repo { # Extract mrid, name, substation and optionally aliasName of the converter - ?converter cim:IdentifiedObject.mRID ?mrid; - cim:IdentifiedObject.name ?name; - ALG:VoltageSourceConverter.DCPole|ALG:DCConverter.DCPole ?pole. - - ?pole ALG:DCPole.DCController/cim:IdentifiedObject.mRID ?controller. - { - select ?pole (max(xsd:float(str(?controller_factor))) / count(*) as ?controller_factor) - { - ?converter ALG:VoltageSourceConverter.DCPole|ALG:DCConverter.DCPole ?pole. - ?pole ALG:DCPole.participationFactor ?controller_factor. - } group by ?pole - } - - optional {?converter cim:IdentifiedObject.aliasName ?alias .} + ?converter cim:IdentifiedObject.mRID ?mrid ; + cim:IdentifiedObject.name ?name ; + ALG:VoltageSourceConverter.DCPole | ALG:DCConverter.DCPole ?pole . + ?pole ALG:DCPole.DCController/cim:IdentifiedObject.mRID ?controller . + { + SELECT ?pole (MAX(xsd:float(STR(?controller_factor))) / COUNT(*) AS ?controller_factor) + WHERE { + ?converter ALG:VoltageSourceConverter.DCPole | ALG:DCConverter.DCPole ?pole . + ?pole ALG:DCPole.participationFactor ?controller_factor . + } + GROUP BY ?pole + } + OPTIONAL { + ?converter cim:IdentifiedObject.aliasName ?alias . + } # Extract properties for the terminals for the converter - ?terminal cim:Terminal.ConductingEquipment ?converter; - cim:Terminal.ConnectivityNode ?con_node; - cim:Terminal.sequenceNumber|cim:ACDCTerminal.sequenceNumber 1 . - ?con_node cim:IdentifiedObject.mRID ?connectivity_node; - cim:ConnectivityNode.ConnectivityNodeContainer ?con_node_container. - ?con_node_container cim:VoltageLevel.Substation ?substation; - cim:VoltageLevel.BaseVoltage/cim:BaseVoltage.nominalVoltage ?un. - ?substation cim:IdentifiedObject.mRID ?substation_mrid; - cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area . - optional {?converter SN:Equipment.networkAnalysisEnable ?_analysis_enabled .} - optional { - ?converter ALG:VoltageSourceConverter.loss0 ?_loss0; - ALG:VoltageSourceConverter.loss1 ?_loss1; - ALG:VoltageSourceConverter.loss2 ?_loss2. - ?pole cim:ConductingEquipment.BaseVoltage/cim:BaseVoltage.nominalVoltage ?_vdcn; - } - bind(coalesce(?_analysis_enabled, True) as ?analysis_enabled) - bind(coalesce(?_loss0, 0.0) as ?loss0) - bind(coalesce(?_loss1, 0.0) as ?loss1) - bind(coalesce(?_loss2, 0.0) as ?loss2) - bind(coalesce(?_vdcn, 0.0) as ?vdcn) - filter(?analysis_enabled) + ?terminal cim:Terminal.ConductingEquipment ?converter ; + cim:Terminal.ConnectivityNode ?con_node ; + cim:Terminal.sequenceNumber | cim:ACDCTerminal.sequenceNumber 1 . + ?con_node cim:IdentifiedObject.mRID ?connectivity_node ; + cim:ConnectivityNode.ConnectivityNodeContainer ?con_node_container . + ?con_node_container cim:VoltageLevel.Substation ?substation ; + cim:VoltageLevel.BaseVoltage/cim:BaseVoltage.nominalVoltage ?un . + ?substation cim:IdentifiedObject.mRID ?substation_mrid ; + cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area . + OPTIONAL { + ?converter SN:Equipment.networkAnalysisEnable ?_analysis_enabled . + } + OPTIONAL { + ?converter ALG:VoltageSourceConverter.loss0 ?_loss0 ; + ALG:VoltageSourceConverter.loss1 ?_loss1 ; + ALG:VoltageSourceConverter.loss2 ?_loss2 . + ?pole cim:ConductingEquipment.BaseVoltage/cim:BaseVoltage.nominalVoltage ?_vdcn . + } + BIND (COALESCE(?_analysis_enabled, true) AS ?analysis_enabled) + BIND (COALESCE(?_loss0, 0.0) AS ?loss0) + BIND (COALESCE(?_loss1, 0.0) AS ?loss1) + BIND (COALESCE(?_loss2, 0.0) AS ?loss2) + BIND (COALESCE(?_vdcn, 0.0) AS ?vdcn) + FILTER (?analysis_enabled = true) } } } - # Extract active and reactive power for the converter - ?converter cim:ACDCConverter.p ?p; - cim:ACDCConverter.q ?q. - - optional {?converter cim:ACDCConverter.poleLossP ?_pole_loss.} - optional {?converter ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?in_service .} - + ?converter cim:ACDCConverter.p ?p ; + cim:ACDCConverter.q ?q . + OPTIONAL { + ?converter cim:ACDCConverter.poleLossP ?_pole_loss . + } + OPTIONAL { + ?converter ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?in_service . + } # Extract connected and optionally the mrid for the topological node associated with the terminal ?terminal cim:ACDCTerminal.connected ?connected . - { ?con_node cim:ConnectivityNode.TopologicalNode ?topological_node . - } union { - filter not exists {?con_node cim:ConnectivityNode.TopologicalNode ?topological_node} + } + UNION { + FILTER NOT EXISTS { + ?con_node cim:ConnectivityNode.TopologicalNode ?topological_node . + } ?terminal cim:Terminal.TopologicalNode ?topological_node . } ?topological_node cim:IdentifiedObject.mRID ?node . - - bind(coalesce(?in_service, ?connected) as ?status) - bind(coalesce(?_pole_loss, 0.0) as ?pole_loss) + BIND (COALESCE(?in_service, ?connected) AS ?status) + BIND (COALESCE(?_pole_loss, 0.0) AS ?pole_loss) } diff --git a/src/cimsparql/sparql/coordinates.sparql b/src/cimsparql/sparql/coordinates.sparql index 19398236..71f961b0 100644 --- a/src/cimsparql/sparql/coordinates.sparql +++ b/src/cimsparql/sparql/coordinates.sparql @@ -1,16 +1,17 @@ # Name: Coordinates PREFIX cim: <${cim}> -select ?mrid ?x ?y ?epsg (str(?resource_type) as ?rdf_type) -where { - ?s cim:PositionPoint.Location ?location; - cim:PositionPoint.sequenceNumber ?nr; - cim:PositionPoint.xPosition ?x; - cim:PositionPoint.yPosition ?y. - ?location cim:Location.PowerSystemResources ?resource; - cim:Location.CoordinateSystem/cim:CoordinateSystem.crsUrn ?co. - values ?resource_type {cim:Substation cim:ACLineSegment} - ?resource a ?resource_type; - cim:IdentifiedObject.mRID ?mrid. - bind(strafter(?co, 'EPSG::') as ?epsg) - bind(concat(str(?mrid), str(?nr)) as ?sequence) -} order by (?sequece) +SELECT ?mrid ?x ?y ?epsg (STR(?resource_type) AS ?rdf_type) +WHERE { + ?s cim:PositionPoint.Location ?location ; + cim:PositionPoint.sequenceNumber ?nr ; + cim:PositionPoint.xPosition ?x ; + cim:PositionPoint.yPosition ?y . + ?location cim:Location.PowerSystemResources ?resource ; + cim:Location.CoordinateSystem/cim:CoordinateSystem.crsUrn ?co . + VALUES ?resource_type { cim:Substation cim:ACLineSegment } + ?resource a ?resource_type ; + cim:IdentifiedObject.mRID ?mrid . + BIND (STRAFTER(?co,'EPSG::') AS ?epsg) + BIND (CONCAT(STR(?mrid), STR(?nr)) AS ?sequence) +} +ORDER BY ?sequece diff --git a/src/cimsparql/sparql/dc_active_power_flow.sparql b/src/cimsparql/sparql/dc_active_power_flow.sparql index 2969ff59..1bf68fa1 100644 --- a/src/cimsparql/sparql/dc_active_power_flow.sparql +++ b/src/cimsparql/sparql/dc_active_power_flow.sparql @@ -1,38 +1,34 @@ # Name: DC Active Power Flow -PREFIX cim:<${cim}> -PREFIX xsd:<${xsd}> -select ?mrid ?p ?direction -where { +PREFIX cim: <${cim}> +PREFIX xsd: <${xsd}> +SELECT ?mrid ?p ?direction +WHERE { ?terminal ^cim:SvPowerFlow.Terminal/cim:SvPowerFlow.p ?p . ?_eq_subject ?eq_repo . - service ?eq_repo { - {{ - # Declare components we are interested in - values ?rdf_type {cim:ACLineSegment cim:SeriesCompensator} . - ?component a ?rdf_type; - cim:Equipment.EquipmentContainer/(cim:Line.Region|cim:VoltageLevel.Substation/cim:Substation.Region) ?region . - - # Extract properties for the terminal associated with the component - ?terminal cim:Terminal.ConductingEquipment ?component; - cim:Terminal.sequenceNumber|cim:ACDCTerminal.sequenceNumber ?nr . - } - union - { - - # Extract the region for the transformer - ?p_transformer cim:Equipment.EquipmentContainer/cim:Substation.Region ?region . - - # For each power transformer extract all windngs and terminal - ?component cim:PowerTransformerEnd.PowerTransformer ?p_transformer; - cim:TransformerEnd.Terminal ?terminal . - bind (1 as ?nr) + SERVICE ?eq_repo { + { + { + VALUES ?rdf_type { cim:ACLineSegment cim:SeriesCompensator } + # Declare components we are interested in + ?component a ?rdf_type ; + cim:Equipment.EquipmentContainer/(cim:Line.Region | cim:VoltageLevel.Substation/cim:Substation.Region) ?region . + # Extract properties for the terminal associated with the component + ?terminal cim:Terminal.ConductingEquipment ?component ; + cim:Terminal.sequenceNumber | cim:ACDCTerminal.sequenceNumber ?nr . + } + UNION { + # Extract the region for the transformer + ?p_transformer cim:Equipment.EquipmentContainer/cim:Substation.Region ?region . + # For each power transformer extract all windngs and terminal + ?component cim:PowerTransformerEnd.PowerTransformer ?p_transformer ; + cim:TransformerEnd.Terminal ?terminal . + BIND (1 AS ?nr) + } } - } . - ?region cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?regionName . - - # Extract the mRID for the component - ?component cim:IdentifiedObject.mRID ?mrid . - filter(regex(?regionName, '${region}')) - bind(if (?nr = 1, 1, -1) as ?direction) + ?region cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?regionName . + # Extract the mRID for the component + ?component cim:IdentifiedObject.mRID ?mrid . + FILTER REGEX(?regionName,'${region}') + BIND (IF(?nr = 1,1,-1) AS ?direction) } } diff --git a/src/cimsparql/sparql/disconnected.sparql b/src/cimsparql/sparql/disconnected.sparql index dd445c1d..8eb929c1 100644 --- a/src/cimsparql/sparql/disconnected.sparql +++ b/src/cimsparql/sparql/disconnected.sparql @@ -1,13 +1,13 @@ # Name: Disconnected -PREFIX cim:<${cim}> -select ?mrid where -{ +PREFIX cim: <${cim}> +SELECT ?mrid +WHERE { { - ?mrid a cim:Disconnector; - cim:Switch.open True . - } union { - ?mrid a cim:Terminal; - cim:Terminal.connected|cim:ACDCTerminal.connected False . - + ?mrid a cim:Disconnector ; + cim:Switch.open true . + } + UNION { + ?mrid a cim:Terminal ; + cim:Terminal.connected | cim:ACDCTerminal.connected false . } } diff --git a/src/cimsparql/sparql/exchange.sparql b/src/cimsparql/sparql/exchange.sparql index 39c7429b..b06a8f6d 100644 --- a/src/cimsparql/sparql/exchange.sparql +++ b/src/cimsparql/sparql/exchange.sparql @@ -1,60 +1,58 @@ # Name: Exchange PREFIX cim: <${cim}> PREFIX SN: <${SN}> -select ?name ?node ?mrid ?status ?p ?market_code -where -{ - ?terminal1 ^cim:SvPowerFlow.Terminal/cim:SvPowerFlow.p ?p; - cim:ACDCTerminal.connected ?connected_1 . +SELECT ?name ?node ?mrid ?status ?p ?market_code +WHERE { + ?terminal1 ^cim:SvPowerFlow.Terminal/cim:SvPowerFlow.p ?p ; + cim:ACDCTerminal.connected ?connected_1 . ?terminal2 cim:ACDCTerminal.connected ?connected_2 . - { ?con_node cim:ConnectivityNode.TopologicalNode ?topological_node . - } union { - filter not exists {?con_node cim:ConnectivityNode.TopologicalNode ?topological_node} + } + UNION { + FILTER NOT EXISTS { + ?con_node cim:ConnectivityNode.TopologicalNode ?topological_node . + } ?terminal1 cim:Terminal.TopologicalNode ?topological_node . } ?topological_node cim:IdentifiedObject.mRID ?node . - # Extract a connection flag that is composed of the inService flag for all conducting equipment connected # to an acline. - optional{?acline ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?in_service } . - + OPTIONAL { + ?acline ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?in_service . + } ?_eq_subject ?eq_repo . - service ?eq_repo { + SERVICE ?eq_repo { # Extract name and mrid for aclines - ?acline a cim:ACLineSegment; - cim:IdentifiedObject.name ?name; - cim:IdentifiedObject.mRID ?mrid . - filter (!regex(?name, 'HVDC')) . - optional {?acline cim:Equipment.EquipmentContainer/SN:Line.marketCode ?market_code . } - + ?acline a cim:ACLineSegment ; + cim:IdentifiedObject.name ?name ; + cim:IdentifiedObject.mRID ?mrid . + FILTER (!regex(?name, 'HVDC')) + OPTIONAL { + ?acline cim:Equipment.EquipmentContainer/SN:Line.marketCode ?market_code . + } # Extract properties for the terminal at sequenceNumber 1 for the acline - ?terminal1 cim:Terminal.ConductingEquipment ?acline; - cim:ACDCTerminal.sequenceNumber 1; + ?terminal1 cim:Terminal.ConductingEquipment ?acline ; + cim:ACDCTerminal.sequenceNumber 1 ; cim:Terminal.ConnectivityNode ?con_node . - # Extract from the connectivity node of terminal1 ?con_node cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation/cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area_1 . - # Extract propertoes for the terminal at squenceNumber 2 for the acline - ?terminal2 cim:Terminal.ConductingEquipment ?acline; - cim:ACDCTerminal.sequenceNumber 2; - cim:Terminal.ConnectivityNode/cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation/cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area_2 . - + ?terminal2 cim:Terminal.ConductingEquipment ?acline ; + cim:ACDCTerminal.sequenceNumber 2 ; + cim:Terminal.ConnectivityNode/cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation/cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area_2 . # When a region is provided: only keep results that satisfy either # 1) area_1 = region and area_2 != region # 2) area_2 = region and area_1 != region - filter ((regex(?area_1, '${region}') && !regex(?area_2, '${region}')) || (regex(?area_1, '${region}') && !regex(?area_2, '${region}'))) - - optional {?acline SN:Equipment.networkAnalysisEnable ?_analysis_enabled .} + FILTER ((REGEX(?area_1,'${region}') && !regex(?area_2, '${region}')) || (REGEX(?area_1,'${region}') && !regex(?area_2, '${region}'))) + OPTIONAL { + ?acline SN:Equipment.networkAnalysisEnable ?_analysis_enabled . + } } - - bind(coalesce(?_analysis_enabled, True) as ?analysis_enabled) - filter(?analysis_enabled) - + BIND (COALESCE(?_analysis_enabled, true) AS ?analysis_enabled) + FILTER (?analysis_enabled = true) + BIND (COALESCE(?in_service, ?connected_1 && ?connected_2) AS ?status) # Assign an overall status. The status is derived from the first existing entry of - # 1) The computed in_service flag for each acline - # 2) The connected status for the terminals. If one of the terminals is off, the status is False - bind(coalesce(?in_service, ?connected_1 && ?connected_2) as ?status) } +# 1) The computed in_service flag for each acline +# 2) The connected status for the terminals. If one of the terminals is off, the status is False diff --git a/src/cimsparql/sparql/full_model.sparql b/src/cimsparql/sparql/full_model.sparql index 444e92fe..ea935292 100644 --- a/src/cimsparql/sparql/full_model.sparql +++ b/src/cimsparql/sparql/full_model.sparql @@ -1,22 +1,30 @@ # Name: Full model -PREFIX md:<${md}> - -select ?model ?time ?profile ?version ?description -where -{ - ?model md:Model.profile ?profile; - md:Model.scenarioTime ?time; - md:Model.version ?version; - md:Model.description ?description . - { - select ?model (min(?dependency_exists) as ?all_dependencies_exist) { - ?_eq_subject ?eq_repo . - ?model md:Model.DependentOn ?depend_on . - - # Extract created time from both tp/sv/ssh profile and eq. - optional{{?depend_on md:Model.created ?created} union {service ?eq_repo {?depend_on md:Model.created ?created}}} - bind(bound(?created) as ?dependency_exists) - } group by ?model +PREFIX md: <${md}> +SELECT ?model ?time ?profile ?version ?description +WHERE { + ?model md:Model.profile ?profile ; + md:Model.scenarioTime ?time ; + md:Model.version ?version ; + md:Model.description ?description . + { + SELECT ?model (MIN(?dependency_exists) AS ?all_dependencies_exist) + WHERE { + ?_eq_subject ?eq_repo . + ?model md:Model.DependentOn ?depend_on . + # Extract created time from both tp/sv/ssh profile and eq. + OPTIONAL { + { + ?depend_on md:Model.created ?created . + } + UNION { + SERVICE ?eq_repo { + ?depend_on md:Model.created ?created . + } + } + } + BIND (BOUND(?created) AS ?dependency_exists) } - filter(?all_dependencies_exist) + GROUP BY ?model + } + FILTER (?all_dependencies_exist = true) } diff --git a/src/cimsparql/sparql/gen_unit_and_sync_machine_mapping.sparql b/src/cimsparql/sparql/gen_unit_and_sync_machine_mapping.sparql index 1f1273a7..57f76096 100644 --- a/src/cimsparql/sparql/gen_unit_and_sync_machine_mapping.sparql +++ b/src/cimsparql/sparql/gen_unit_and_sync_machine_mapping.sparql @@ -1,6 +1,7 @@ # Name: GeneratingUnit mrid to physical equipment mrid PREFIX cim: <${cim}> -select ?gen_unit_mrid ?sync_machine_mrid where { - ?s cim:SynchronousMachine.GeneratingUnit/cim:IdentifiedObject.mRID ?gen_unit_mrid; - cim:IdentifiedObject.mRID ?sync_machine_mrid +SELECT ?gen_unit_mrid ?sync_machine_mrid +WHERE { + ?s cim:SynchronousMachine.GeneratingUnit/cim:IdentifiedObject.mRID ?gen_unit_mrid ; + cim:IdentifiedObject.mRID ?sync_machine_mrid . } diff --git a/src/cimsparql/sparql/hvdc.sparql b/src/cimsparql/sparql/hvdc.sparql index 2ae1e810..adea45e7 100644 --- a/src/cimsparql/sparql/hvdc.sparql +++ b/src/cimsparql/sparql/hvdc.sparql @@ -2,22 +2,21 @@ PREFIX cim: <${cim}> PREFIX ALG: <${ALG}> PREFIX xsd: <${xsd}> -select ?converter_mrid_1 ?converter_mrid_2 (group_concat(?name; separator="--") as ?name) (sum(xsd:float(str(?r))) as ?r) -where -{ - ?converter_1 a ALG:VoltageSourceConverter; - cim:IdentifiedObject.mRID ?converter_mrid_1. - ?converter_2 a ALG:VoltageSourceConverter; - cim:IdentifiedObject.mRID ?converter_mrid_2. - ?t_1 cim:Terminal.ConnectivityNode/^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment ?converter_1; - cim:Terminal.ConductingEquipment ?line; +SELECT ?converter_mrid_1 ?converter_mrid_2 (GROUP_CONCAT(?name;SEPARATOR="--") AS ?name) (SUM(xsd:float(STR(?r))) AS ?r) +WHERE { + ?converter_1 a ALG:VoltageSourceConverter ; + cim:IdentifiedObject.mRID ?converter_mrid_1 . + ?converter_2 a ALG:VoltageSourceConverter ; + cim:IdentifiedObject.mRID ?converter_mrid_2 . + ?t_1 cim:Terminal.ConnectivityNode/^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment ?converter_1 ; + cim:Terminal.ConductingEquipment ?line ; cim:ACDCTerminal.sequenceNumber 1 . - ?t_2 cim:Terminal.ConnectivityNode/^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment ?converter_2; - cim:Terminal.ConductingEquipment ?line; + ?t_2 cim:Terminal.ConnectivityNode/^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment ?converter_2 ; + cim:Terminal.ConductingEquipment ?line ; cim:ACDCTerminal.sequenceNumber 2 . - ?line a ALG:DCLineSegment; - ALG:DCLineSegment.dcSegmentResistance ?r; - cim:IdentifiedObject.name ?name. + ?line a ALG:DCLineSegment ; + ALG:DCLineSegment.dcSegmentResistance ?r ; + cim:IdentifiedObject.name ?name . } -group by ?converter_mrid_1 ?converter_mrid_2 -having (count(*) > 1) +GROUP BY ?converter_mrid_1 ?converter_mrid_2 +HAVING (COUNT(*) > 1) diff --git a/src/cimsparql/sparql/loads.sparql b/src/cimsparql/sparql/loads.sparql index c01542ec..10dba316 100644 --- a/src/cimsparql/sparql/loads.sparql +++ b/src/cimsparql/sparql/loads.sparql @@ -1,52 +1,57 @@ # Name: Loads PREFIX cim: <${cim}> PREFIX SN: <${SN}> -select ?mrid ?name ?node ?substation_mrid ?status ?p ?q ?station_group ?connectivity_node -where { +SELECT ?mrid ?name ?node ?substation_mrid ?status ?p ?q ?station_group ?connectivity_node +WHERE { { # Appears to be significantly faster to run the query if the EQ part is executed within its own sub-query - select * where { + SELECT * + WHERE { ?_eq_subject ?eq_repo . - service ?eq_repo { + SERVICE ?eq_repo { # Extract mRID, name and substation for each load - ?load cim:IdentifiedObject.mRID ?mrid; - cim:IdentifiedObject.name ?name; - cim:Equipment.EquipmentContainer/cim:VoltageLevel.Substation ?substation. - + ?load cim:IdentifiedObject.mRID ?mrid ; + cim:IdentifiedObject.name ?name ; + cim:Equipment.EquipmentContainer/cim:VoltageLevel.Substation ?substation . # Extract area and mRID (referred to as 'station') for the substation of each load - ?substation cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area; + ?substation cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area ; cim:IdentifiedObject.mRID ?substation_mrid . - filter regex(?area, '${region}') - - optional {?load cim:NonConformLoad.LoadGroup/SN:NonConformLoadGroup.ScheduleResource/SN:ScheduleResource.marketCode ?station_group} . - optional {?load SN:Equipment.networkAnalysisEnable ?_network_analysis} . - bind(coalesce(?_network_analysis, True) as ?network_analysis) - filter (?network_analysis) - + FILTER REGEX(?area,'${region}') + OPTIONAL { + ?load cim:NonConformLoad.LoadGroup/SN:NonConformLoadGroup.ScheduleResource/SN:ScheduleResource.marketCode ?station_group . + } + OPTIONAL { + ?load SN:Equipment.networkAnalysisEnable ?_network_analysis . + } + BIND (COALESCE(?_network_analysis, true) AS ?network_analysis) + FILTER (?network_analysis = true) # Extract mRID and connectivity node for each terminal associated with a load - ?terminal cim:Terminal.ConductingEquipment ?load; - cim:Terminal.ConnectivityNode ?con_node . + ?terminal cim:Terminal.ConductingEquipment ?load ; + cim:Terminal.ConnectivityNode ?con_node . ?con_node cim:IdentifiedObject.mRID ?connectivity_node . - } . + } } } - # Extrcact connected flag and optionally the mRID of the topological node associated with the terminal ?terminal cim:ACDCTerminal.connected ?connected . { ?con_node cim:ConnectivityNode.TopologicalNode ?topological_node . - } union { - filter not exists {?con_node cim:ConnectivityNode.TopologicalNode ?topological_node} + } + UNION { + FILTER NOT EXISTS { + ?con_node cim:ConnectivityNode.TopologicalNode ?topological_node . + } ?terminal cim:Terminal.TopologicalNode ?topological_node . } ?topological_node cim:IdentifiedObject.mRID ?node . - # Optionally extract in_service flag and active and reactive energy consumption for each load - optional {?load ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?in_service }. - ?load cim:EnergyConsumer.p ?p; cim:EnergyConsumer.q ?q . - + OPTIONAL { + ?load ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?in_service . + } + ?load cim:EnergyConsumer.p ?p ; + cim:EnergyConsumer.q ?q . + BIND (COALESCE(?in_service, ?connected) AS ?status) # Assign status flag for load. The status flag is set to the first existing of - # 1) in_service flag - # 2) connected flag the terminal - bind(coalesce(?in_service, ?connected) as ?status) } +# 1) in_service flag +# 2) connected flag the terminal diff --git a/src/cimsparql/sparql/market_dates.sparql b/src/cimsparql/sparql/market_dates.sparql index 25d831c0..f95b245c 100644 --- a/src/cimsparql/sparql/market_dates.sparql +++ b/src/cimsparql/sparql/market_dates.sparql @@ -1,10 +1,10 @@ # Name: Market dates PREFIX cim: <${cim}> PREFIX SN: <${SN}> -select ?mrid ?name ?activation_date -where { - ?_set a SN:MarketDefinitionSet; - cim:IdentifiedObject.mRID ?mrid; - cim:IdentifiedObject.name ?name; - SN:MarketDefinitionSet.activationDate ?activation_date +SELECT ?mrid ?name ?activation_date +WHERE { + ?_set a SN:MarketDefinitionSet ; + cim:IdentifiedObject.mRID ?mrid ; + cim:IdentifiedObject.name ?name ; + SN:MarketDefinitionSet.activationDate ?activation_date . } diff --git a/src/cimsparql/sparql/phase_tap_changer.sparql b/src/cimsparql/sparql/phase_tap_changer.sparql index 71bdf953..83768594 100644 --- a/src/cimsparql/sparql/phase_tap_changer.sparql +++ b/src/cimsparql/sparql/phase_tap_changer.sparql @@ -1,22 +1,22 @@ # Name: Phase tap changer PREFIX cim: <${cim}> -select ?mrid ?phase_shift_increment ?enabled ?neutral_step ?high_step ?low_step ?mode ?target_value ?monitored_winding -where { - ?tap_changer cim:TapChanger.controlEnabled ?enabled_1. - ?tap_changer_control cim:RegulatingControl.enabled ?enabled_2; - cim:RegulatingControl.targetValue ?target_value. - ?_eq_subject ?eq_repo. - service ?eq_repo { - ?tap_changer cim:PhaseTapChangerLinear.stepPhaseShiftIncrement ?phase_shift_increment; - cim:TapChanger.TapChangerControl ?tap_changer_control; - cim:TapChanger.neutralStep ?neutral_step; - cim:TapChanger.highStep ?high_step; - cim:TapChanger.lowStep ?low_step; - ^cim:TransformerEnd.PhaseTapChanger ?winding. - ?winding cim:IdentifiedObject.mRID ?mrid. - ?tap_changer_control cim:RegulatingControl.mode ?control_mode; - cim:RegulatingControl.Terminal/^cim:TransformerEnd.Terminal/cim:IdentifiedObject.mRID ?monitored_winding. +SELECT ?mrid ?phase_shift_increment ?enabled ?neutral_step ?high_step ?low_step ?mode ?target_value ?monitored_winding +WHERE { + ?tap_changer cim:TapChanger.controlEnabled ?enabled_1 . + ?tap_changer_control cim:RegulatingControl.enabled ?enabled_2 ; + cim:RegulatingControl.targetValue ?target_value . + ?_eq_subject ?eq_repo . + SERVICE ?eq_repo { + ?tap_changer cim:PhaseTapChangerLinear.stepPhaseShiftIncrement ?phase_shift_increment ; + cim:TapChanger.TapChangerControl ?tap_changer_control ; + cim:TapChanger.neutralStep ?neutral_step ; + cim:TapChanger.highStep ?high_step ; + cim:TapChanger.lowStep ?low_step ; + ^cim:TransformerEnd.PhaseTapChanger ?winding . + ?winding cim:IdentifiedObject.mRID ?mrid . + ?tap_changer_control cim:RegulatingControl.mode ?control_mode ; + cim:RegulatingControl.Terminal/^cim:TransformerEnd.Terminal/cim:IdentifiedObject.mRID ?monitored_winding . } - bind(replace(str(?control_mode), str(cim:), "") as ?mode) - bind(?enabled_1 && ?enabled_2 as ?enabled) + BIND (replace(str(?control_mode), str(cim:), "") AS ?mode) + BIND (?enabled_1 && ?enabled_2 AS ?enabled) } diff --git a/src/cimsparql/sparql/power_flow.sparql b/src/cimsparql/sparql/power_flow.sparql index 1e08169a..17cef2be 100644 --- a/src/cimsparql/sparql/power_flow.sparql +++ b/src/cimsparql/sparql/power_flow.sparql @@ -1,15 +1,17 @@ # Name: Power flow -PREFIX cim:<${cim}> -select ?mrid ?p ?q ?in_service -where { - ?_s a cim:SvPowerFlow; - cim:SvPowerFlow.Terminal ?terminal; - cim:SvPowerFlow.p ?p; +PREFIX cim: <${cim}> +SELECT ?mrid ?p ?q ?in_service +WHERE { + ?_s a cim:SvPowerFlow ; + cim:SvPowerFlow.Terminal ?terminal ; + cim:SvPowerFlow.p ?p ; cim:SvPowerFlow.q ?q . ?_eq_subject ?eq_repo . - service ?eq_repo { + SERVICE ?eq_repo { ?terminal cim:IdentifiedObject.mRID ?mrid . } - optional {?terminal cim:Terminal.ConductingEquipment/^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?_in_service} - bind(coalesce(?_in_service, True) as ?in_service) + OPTIONAL { + ?terminal cim:Terminal.ConductingEquipment/^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?_in_service . + } + BIND (COALESCE(?_in_service, true) AS ?in_service) } diff --git a/src/cimsparql/sparql/ras_equipment.sparql b/src/cimsparql/sparql/ras_equipment.sparql index f1849638..4e85202a 100644 --- a/src/cimsparql/sparql/ras_equipment.sparql +++ b/src/cimsparql/sparql/ras_equipment.sparql @@ -1,10 +1,9 @@ # Name: RAS Equipment PREFIX cim: <${cim}> PREFIX alg: <${ALG}> -select ?mrid ?equipment_mrid ?name -where -{ - ?rpact (alg:ProtectiveActionEquipment.Equipment|alg:ProtectiveActionAdjustmentAC.ConductingEquipment|alg:ProtectiveActionAdjustmentDCController.DCController)/cim:IdentifiedObject.mRID ?equipment_mrid; - cim:IdentifiedObject.mRID ?mrid; +SELECT ?mrid ?equipment_mrid ?name +WHERE { + ?rpact (alg:ProtectiveActionEquipment.Equipment | alg:ProtectiveActionAdjustmentAC.ConductingEquipment | alg:ProtectiveActionAdjustmentDCController.DCController)/cim:IdentifiedObject.mRID ?equipment_mrid ; + cim:IdentifiedObject.mRID ?mrid ; cim:IdentifiedObject.name ?name . } diff --git a/src/cimsparql/sparql/regions.sparql b/src/cimsparql/sparql/regions.sparql index 3d503742..a4ef950b 100644 --- a/src/cimsparql/sparql/regions.sparql +++ b/src/cimsparql/sparql/regions.sparql @@ -1,14 +1,20 @@ # Name: Regions -PREFIX cim:<${cim}> -PREFIX SN:<${SN}> -select ?mrid ?region ?short_name ?name ?alias_name ?region_name -where { - ?subGeoRegion a cim:SubGeographicalRegion; - cim:IdentifiedObject.mRID ?mrid; - cim:IdentifiedObject.name ?name; - cim:SubGeographicalRegion.Region ?subgeoreg . - optional {?subGeoRegion SN:IdentifiedObject.shortName ?short_name} . - optional {?subGeoRegion cim:IdentifiedObject.aliasName ?alias_name} . +PREFIX cim: <${cim}> +PREFIX SN: <${SN}> +SELECT ?mrid ?region ?short_name ?name ?alias_name ?region_name +WHERE { + ?subGeoRegion a cim:SubGeographicalRegion ; + cim:IdentifiedObject.mRID ?mrid ; + cim:IdentifiedObject.name ?name ; + cim:SubGeographicalRegion.Region ?subgeoreg . + OPTIONAL { + ?subGeoRegion SN:IdentifiedObject.shortName ?short_name . + } + OPTIONAL { + ?subGeoRegion cim:IdentifiedObject.aliasName ?alias_name . + } ?subgeoreg cim:IdentifiedObject.name ?region . - optional {?subgeoreg cim:IdentifiedObject.aliasName ?region_name} + OPTIONAL { + ?subgeoreg cim:IdentifiedObject.aliasName ?region_name . + } } diff --git a/src/cimsparql/sparql/series_compensators.sparql b/src/cimsparql/sparql/series_compensators.sparql index 712c4b05..f855ba50 100644 --- a/src/cimsparql/sparql/series_compensators.sparql +++ b/src/cimsparql/sparql/series_compensators.sparql @@ -2,71 +2,58 @@ PREFIX cim: <${cim}> PREFIX SN: <${SN}> PREFIX xsd: <${xsd}> -select - (max(?mrid) as ?mrid) - (max(?name) as ?name) - (max(?node_1) as ?node_1) - (max(?node_2) as ?node_2) - (if (xsd:double(max(?p_1)) < xsd:double(max(?p_2)), xsd:double(max(?p_1)) + xsd:double(max(?p_2)), xsd:double(0.0)) as ?ploss_1) - (if (xsd:double(max(?p_1)) > xsd:double(max(?p_2)), xsd:double(max(?p_1)) + xsd:double(max(?p_2)), xsd:double(0.0)) as ?ploss_2) - (max(?r) as ?r) - (max(?rate) as ?rate) - (coalesce(max(?in_service), max(?connected_1) && max(?connected_2)) as ?status) - (max(?un) as ?un) - (max(?x) as ?x) - (max(?connectivity_node_1) as ?connectivity_node_1) - (max(?connectivity_node_2) as ?connectivity_node_2) -where { - # Assume π equivalent with at least r,x and b shunt. - # Extract properties for series compensator +SELECT (MAX(?mrid) AS ?mrid) (MAX(?name) AS ?name) (MAX(?node_1) AS ?node_1) (MAX(?node_2) AS ?node_2) (IF(xsd:double(MAX(?p_1)) < xsd:double(MAX(?p_2)),xsd:double(MAX(?p_1)) + xsd:double(MAX(?p_2)),xsd:double(0.0)) AS ?ploss_1) (IF(xsd:double(MAX(?p_1)) > xsd:double(MAX(?p_2)),xsd:double(MAX(?p_1)) + xsd:double(MAX(?p_2)),xsd:double(0.0)) AS ?ploss_2) (MAX(?r) AS ?r) (MAX(?rate) AS ?rate) (COALESCE(MAX(?in_service), MAX(?connected_1) && MAX(?connected_2)) AS ?status) (MAX(?un) AS ?un) (MAX(?x) AS ?x) (MAX(?connectivity_node_1) AS ?connectivity_node_1) (MAX(?connectivity_node_2) AS ?connectivity_node_2) +WHERE { + # Assume π equivalent with at least r,x and b shunt. # Extract properties for series compensator ?_eq_subject ?eq_repo . - service ?eq_repo { - ?compensator cim:SeriesCompensator.r ?r; - cim:SeriesCompensator.x ?x; - cim:IdentifiedObject.mRID ?mrid; - cim:IdentifiedObject.name ?name; - cim:ConductingEquipment.BaseVoltage/cim:BaseVoltage.nominalVoltage ?un; - ^cim:Terminal.ConductingEquipment ?terminal . - - # Extract terminal properties - ?terminal cim:Terminal.ConnectivityNode ?con_node; - cim:ACDCTerminal.sequenceNumber ?nr . - ?con_node cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation ?substation ; - cim:IdentifiedObject.mRID ?connectivity_node . - ?substation cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area . - optional {?compensator SN:Equipment.networkAnalysisEnable ?network_analysis} - filter(regex(?area, '${region}')) - - - # Optionally extract current limits - optional { - ?_lim cim:OperationalLimit.OperationalLimitSet/cim:OperationalLimitSet.Equipment ?compensator; - a cim:CurrentLimit; - cim:IdentifiedObject.name '${rate}'; - cim:CurrentLimit.value ?_rate . - # Convert rate from current to power using √3 * U [kV] * I [A] / 1000.0 [MVA] - bind(1.7320508075688772 * xsd:double(xsd:string(?un)) * xsd:double(xsd:string(?_rate)) / 1000.0 as ?rate) - }.} - - - # Extract the mRID of the topological node of the connectivity node + SERVICE ?eq_repo { + ?compensator cim:SeriesCompensator.r ?r ; + cim:SeriesCompensator.x ?x ; + cim:IdentifiedObject.mRID ?mrid ; + cim:IdentifiedObject.name ?name ; + cim:ConductingEquipment.BaseVoltage/cim:BaseVoltage.nominalVoltage ?un ; + ^cim:Terminal.ConductingEquipment ?terminal . + # Extract terminal properties + ?terminal cim:Terminal.ConnectivityNode ?con_node ; + cim:ACDCTerminal.sequenceNumber ?nr . + ?con_node cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.Substation ?substation ; + cim:IdentifiedObject.mRID ?connectivity_node . + ?substation cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area . + OPTIONAL { + ?compensator SN:Equipment.networkAnalysisEnable ?network_analysis . + } + FILTER REGEX(?area,'${region}') + # Optionally extract current limits + OPTIONAL { + ?_lim cim:OperationalLimit.OperationalLimitSet/cim:OperationalLimitSet.Equipment ?compensator ; + a cim:CurrentLimit ; + cim:IdentifiedObject.name '${rate}' ; + cim:CurrentLimit.value ?_rate . + BIND (1.7320508075688772 * xsd:double(xsd:string(?un)) * xsd:double(xsd:string(?_rate)) / 1000.0 AS ?rate) + # Convert rate from current to power using √3 * U [kV] * I [A] / 1000.0 [MVA] + } + } + # Extract the mRID of the topological node of the connectivity node ?con_node cim:ConnectivityNode.TopologicalNode/cim:IdentifiedObject.mRID ?node_mrid . # Optionally extract in_service associated with compensator - optional {?compensator ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?in_service} . - + OPTIONAL { + ?compensator ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?in_service . + } # Extract connected flag and optionally power for each terminal ?terminal cim:ACDCTerminal.connected ?connected . - optional {?terminal ^cim:SvPowerFlow.Terminal/cim:SvPowerFlow.p ?p .} - bind(coalesce(?node_mrid, ?t_mrid) as ?node) - + OPTIONAL { + ?terminal ^cim:SvPowerFlow.Terminal/cim:SvPowerFlow.p ?p . + } + BIND (COALESCE(?node_mrid, ?t_mrid) AS ?node) + BIND (IF(?nr = 1,STR(?p),'') AS ?p_1) + BIND (IF(?nr = 1,?node,'') AS ?node_1) + BIND (IF(?nr = 1,?connected,false) AS ?connected_1) + BIND (IF(?nr = 2,STR(?p),'') AS ?p_2) + BIND (IF(?nr = 2,?node,'') AS ?node_2) + BIND (IF(?nr = 2,?connected,false) AS ?connected_2) + BIND (IF(?nr = 1,?connectivity_node,'') AS ?connectivity_node_1) + BIND (IF(?nr = 2,?connectivity_node,'') AS ?connectivity_node_2) # Create variables for node 1 and node 2 - bind(if(?nr = 1, str(?p), '') as ?p_1) - bind(if(?nr = 1, ?node, '') as ?node_1) - bind(if(?nr = 1, ?connected, False) as ?connected_1) - bind(if(?nr = 2, str(?p), '') as ?p_2) - bind(if(?nr = 2, ?node, '') as ?node_2) - bind(if(?nr = 2, ?connected, False) as ?connected_2) - bind(if(?nr = 1, ?connectivity_node, '') as ?connectivity_node_1) - bind(if(?nr = 2, ?connectivity_node, '') as ?connectivity_node_2) -} group by ?compensator -having ((count(*) > 1) && (max(?node_1) != max(?node_2)) && coalesce(max(?analysis_enabled), True)) +} +GROUP BY ?compensator +HAVING ((COUNT(*) > 1) && (MAX(?node_1) != MAX(?node_2)) && COALESCE(MAX(?analysis_enabled), true)) diff --git a/src/cimsparql/sparql/station_group_code_and_names.sparql b/src/cimsparql/sparql/station_group_code_and_names.sparql index d94003b3..252f087c 100644 --- a/src/cimsparql/sparql/station_group_code_and_names.sparql +++ b/src/cimsparql/sparql/station_group_code_and_names.sparql @@ -1,10 +1,12 @@ # Name: Station group code and names PREFIX cim: <${cim}> PREFIX SN: <${SN}> -select ?station_group ?name ?alias_name where { - # SN is not made optional here because then there is no filtering left. - # TODO: Is ScheduleResource available in a another namespace? - ?s SN:ScheduleResource.marketCode ?station_group; - cim:IdentifiedObject.name ?name; - optional{?s cim:IdentifiedObject.aliasName ?alias_name} +SELECT ?station_group ?name ?alias_name +WHERE { + # SN is not made optional here because then there is no filtering left. # TODO: Is ScheduleResource available in a another namespace? + ?s SN:ScheduleResource.marketCode ?station_group ; + cim:IdentifiedObject.name ?name . + OPTIONAL { + ?s cim:IdentifiedObject.aliasName ?alias_name . + } } diff --git a/src/cimsparql/sparql/station_group_for_power_unit.sparql b/src/cimsparql/sparql/station_group_for_power_unit.sparql index 704f5a11..58649926 100644 --- a/src/cimsparql/sparql/station_group_for_power_unit.sparql +++ b/src/cimsparql/sparql/station_group_for_power_unit.sparql @@ -1,13 +1,13 @@ # Name: station group for power resource PREFIX SN: <${SN}> PREFIX cim: <${cim}> - -select ?power_system_model_mrid ?market_unit_mrid ?resource_name ?market_code where { - ?resource SN:ScheduleResource.marketCode ?market_code . - ?unit ?p ?resource; - cim:IdentifiedObject.name ?resource_name; - cim:IdentifiedObject.mRID ?market_unit_mrid; - values ?physical_model_predicate {cim:SynchronousMachine.GeneratingUnit cim:NonConformLoad.LoadGroup} - ?physical_object ?physical_model_predicate ?unit; - cim:IdentifiedObject.mRID ?power_system_model_mrid . +SELECT ?power_system_model_mrid ?market_unit_mrid ?resource_name ?market_code +WHERE { + ?resource SN:ScheduleResource.marketCode ?market_code . + ?unit ?p ?resource ; + cim:IdentifiedObject.name ?resource_name ; + cim:IdentifiedObject.mRID ?market_unit_mrid ; + VALUES ?physical_model_predicate { cim:SynchronousMachine.GeneratingUnit cim:NonConformLoad.LoadGroup } + ?physical_object ?physical_model_predicate ?unit ; + cim:IdentifiedObject.mRID ?power_system_model_mrid . } diff --git a/src/cimsparql/sparql/substation_voltage_level.sparql b/src/cimsparql/sparql/substation_voltage_level.sparql index a244d872..e56b63b7 100644 --- a/src/cimsparql/sparql/substation_voltage_level.sparql +++ b/src/cimsparql/sparql/substation_voltage_level.sparql @@ -1,17 +1,19 @@ # Name: Substation voltage level -PREFIX cim:<${cim}> -select ?container ?substation ?v -where { - ?volt_level a cim:VoltageLevel; - cim:IdentifiedObject.mRID ?container; - cim:VoltageLevel.BaseVoltage/cim:BaseVoltage.nominalVoltage ?v; +PREFIX cim: <${cim}> +SELECT ?container ?substation ?v +WHERE { + ?volt_level a cim:VoltageLevel ; + cim:IdentifiedObject.mRID ?container ; + cim:VoltageLevel.BaseVoltage/cim:BaseVoltage.nominalVoltage ?v ; cim:VoltageLevel.Substation ?_substation . - { select (max(?volt) as ?v) ?_substation - where { - ?volt_level a cim:VoltageLevel; - cim:VoltageLevel.BaseVoltage/cim:BaseVoltage.nominalVoltage ?volt; + { + SELECT (MAX(?volt) AS ?v) ?_substation + WHERE { + ?volt_level a cim:VoltageLevel ; + cim:VoltageLevel.BaseVoltage/cim:BaseVoltage.nominalVoltage ?volt ; cim:VoltageLevel.Substation ?_substation . - } group by ?_substation - } . - ?_substation cim:IdentifiedObject.mRID ?substation + } + GROUP BY ?_substation + } + ?_substation cim:IdentifiedObject.mRID ?substation . } diff --git a/src/cimsparql/sparql/sv_branch.sparql b/src/cimsparql/sparql/sv_branch.sparql index 7e38c5d0..ab79bd67 100644 --- a/src/cimsparql/sparql/sv_branch.sparql +++ b/src/cimsparql/sparql/sv_branch.sparql @@ -6,68 +6,62 @@ # PREFIX cim: <${cim}> PREFIX SN: <${SN}> -select ?mrid ?name ?r ?x ?bch ?gch ?status ?length ?un ?p_1 ?q_1 ?p_2 ?q_2 ?v_1 ?angle_1 ?v_2 ?angle_2 -where { +SELECT ?mrid ?name ?r ?x ?bch ?gch ?status ?length ?un ?p_1 ?q_1 ?p_2 ?q_2 ?v_1 ?angle_1 ?v_2 ?angle_2 +WHERE { # Extract key properties for ACLineSegment ?_eq_subject ?eq_repo . - service ?eq_repo { - ?acline cim:ACLineSegment.r ?r; - cim:ACLineSegment.x ?x; - cim:ACLineSegment.bch ?bch; - cim:ACLineSegment.gch ?gch; - cim:IdentifiedObject.mRID ?mrid; - cim:IdentifiedObject.name ?name; + SERVICE ?eq_repo { + ?acline cim:ACLineSegment.r ?r ; + cim:ACLineSegment.x ?x ; + cim:ACLineSegment.bch ?bch ; + cim:ACLineSegment.gch ?gch ; + cim:IdentifiedObject.mRID ?mrid ; + cim:IdentifiedObject.name ?name ; cim:ConductingEquipment.BaseVoltage/cim:BaseVoltage.nominalVoltage ?un . - - ?terminal_1 a cim:Terminal; - cim:Terminal.ConductingEquipment ?acline; - cim:Terminal.ConnectivityNode ?con_node_1; - cim:Terminal.sequenceNumber|cim:ACDCTerminal.sequenceNumber 1 . - - ?terminal_2 a cim:Terminal; - cim:Terminal.ConductingEquipment ?acline; - cim:Terminal.ConnectivityNode ?con_node_2; - cim:Terminal.sequenceNumber|cim:ACDCTerminal.sequenceNumber 2 . + ?terminal_1 a cim:Terminal ; + cim:Terminal.ConductingEquipment ?acline ; + cim:Terminal.ConnectivityNode ?con_node_1 ; + cim:Terminal.sequenceNumber | cim:ACDCTerminal.sequenceNumber 1 . + ?terminal_2 a cim:Terminal ; + cim:Terminal.ConductingEquipment ?acline ; + cim:Terminal.ConnectivityNode ?con_node_2 ; + cim:Terminal.sequenceNumber | cim:ACDCTerminal.sequenceNumber 2 . } # Extract in_service flag for each acline ?acline ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?in_service . - # Extract connectivity node, topological node, voltage ang angle ?con_node_1 cim:ConnectivityNode.TopologicalNode ?node_1 . - optional { - ?_sv_n_1 cim:SvVoltage.TopologicalNode ?node_1; - cim:SvVoltage.v ?v_1; + OPTIONAL { + ?_sv_n_1 cim:SvVoltage.TopologicalNode ?node_1 ; + cim:SvVoltage.v ?v_1 ; cim:SvVoltage.angle ?angle_1 . } - # Extract conencted flag and active and reactive power for each terminal - ?terminal_1 cim:Terminal.connected|cim:ACDCTerminal.connected ?connected_1 . - optional - { - ?_sv_t_1 cim:SvPowerFlow.Terminal ?terminal_1; - cim:SvPowerFlow.p ?p_1; - cim:SvPowerFlow.q ?q_1. - }. - + ?terminal_1 cim:Terminal.connected | cim:ACDCTerminal.connected ?connected_1 . + OPTIONAL { + ?_sv_t_1 cim:SvPowerFlow.Terminal ?terminal_1 ; + cim:SvPowerFlow.p ?p_1 ; + cim:SvPowerFlow.q ?q_1 . + } ?con_node_2 cim:ConnectivityNode.TopologicalNode ?node_2 . - optional { - ?_sv_n_2 cim:SvVoltage.TopologicalNode ?node_2; - cim:SvVoltage.v ?v_2; + OPTIONAL { + ?_sv_n_2 cim:SvVoltage.TopologicalNode ?node_2 ; + cim:SvVoltage.v ?v_2 ; cim:SvVoltage.angle ?angle_2 . } - ?terminal_2 cim:Terminal.connected|cim:ACDCTerminal.connected ?connected_2 . - optional - { - ?_sv_t_2 cim:SvPowerFlow.Terminal ?terminal_2; - cim:SvPowerFlow.p ?p_2; - cim:SvPowerFlow.q ?q_2. + ?terminal_2 cim:Terminal.connected | cim:ACDCTerminal.connected ?connected_2 . + OPTIONAL { + ?_sv_t_2 cim:SvPowerFlow.Terminal ?terminal_2 ; + cim:SvPowerFlow.p ?p_2 ; + cim:SvPowerFlow.q ?q_2 . + } + OPTIONAL { + ?acline SN:Equipment.networkAnalysisEnable ?_network_analysis . } - optional {?acline SN:Equipment.networkAnalysisEnable ?_network_analysis} - filter(?network_analysis) - bind(coalesce(?_network_analysis, True) as ?network_analysis) - + FILTER (?network_analysis = true) + BIND (COALESCE(?_network_analysis, true) AS ?network_analysis) + BIND (COALESCE(?in_service, ?connected_1 && ?connected_2) AS ?status) # Assign status flag for each branch. It is set to the first that exist of - # 1) in_service flag for each acline - # 2) Connected flags of the two terminals. Status is set to False if at least one of the terminals are disconnected - bind(coalesce(?in_service, ?connected_1 && ?connected_2) as ?status) . } +# 1) in_service flag for each acline +# 2) Connected flags of the two terminals. Status is set to False if at least one of the terminals are disconnected diff --git a/src/cimsparql/sparql/sv_injection.sparql b/src/cimsparql/sparql/sv_injection.sparql index be747d53..624d51cc 100644 --- a/src/cimsparql/sparql/sv_injection.sparql +++ b/src/cimsparql/sparql/sv_injection.sparql @@ -1,9 +1,8 @@ # Name: SvInjection -PREFIX cim:<${cim}> -select ?node ?p ?q -where -{ - ?sv_injection cim:SvInjection.TopologicalNode/cim:IdentifiedObject.mRID ?node; - cim:SvInjection.pInjection ?p; +PREFIX cim: <${cim}> +SELECT ?node ?p ?q +WHERE { + ?sv_injection cim:SvInjection.TopologicalNode/cim:IdentifiedObject.mRID ?node ; + cim:SvInjection.pInjection ?p ; cim:SvInjection.qInjection ?q . } diff --git a/src/cimsparql/sparql/sv_power_deviation.sparql b/src/cimsparql/sparql/sv_power_deviation.sparql index 4a0ebfee..21afb054 100644 --- a/src/cimsparql/sparql/sv_power_deviation.sparql +++ b/src/cimsparql/sparql/sv_power_deviation.sparql @@ -1,42 +1,41 @@ # Name: Sv power deviation -PREFIX xsd:<${xsd}> -PREFIX cim:<${cim}> -select -?node -(sum(xsd:double(str(?p))) as ?sum_terminal_flow) -(max(xsd:double(str(?p_inj))) as ?reported_sv_injection) -(group_concat(distinct(?con_node_mrid); - SEPARATOR=",") as ?connectivity_nodes) -(group_concat(?terminal_name; - SEPARATOR=",") as ?terminal_names) -where { - { - select * { - ?_eq_subject ?eq_repo . - service ?eq_repo { - ?terminal cim:Terminal.ConnectivityNode ?con_node ; - cim:Terminal.ConductingEquipment ?equipment; - cim:IdentifiedObject.name ?terminal_name . - ?con_node cim:IdentifiedObject.mRID ?con_node_mrid - } - } +PREFIX xsd: <${xsd}> +PREFIX cim: <${cim}> +SELECT ?node (SUM(xsd:double(STR(?p))) AS ?sum_terminal_flow) (MAX(xsd:double(STR(?p_inj))) AS ?reported_sv_injection) (GROUP_CONCAT(DISTINCT?con_node_mrid;SEPARATOR=",") AS ?connectivity_nodes) (GROUP_CONCAT(?terminal_name;SEPARATOR=",") AS ?terminal_names) +WHERE { + { + SELECT * + WHERE { + ?_eq_subject ?eq_repo . + SERVICE ?eq_repo { + ?terminal cim:Terminal.ConnectivityNode ?con_node ; + cim:Terminal.ConductingEquipment ?equipment ; + cim:IdentifiedObject.name ?terminal_name . + ?con_node cim:IdentifiedObject.mRID ?con_node_mrid . + } } - { - ?sv_power_flow cim:SvPowerFlow.Terminal ?terminal ; - cim:SvPowerFlow.p ?p - } union { - ?equipment cim:ACDCConverter.p ?p - filter not exists {?sv_power_flow cim:SvPowerFlow.Terminal ?terminal} + } + { + ?sv_power_flow cim:SvPowerFlow.Terminal ?terminal ; + cim:SvPowerFlow.p ?p . + } + UNION { + ?equipment cim:ACDCConverter.p ?p . + FILTER NOT EXISTS { + ?sv_power_flow cim:SvPowerFlow.Terminal ?terminal . } - { - ?con_node cim:ConnectivityNode.TopologicalNode ?tp_node - } union { - filter not exists { - ?con_node cim:ConnectivityNode.TopologicalNode ?tp_node - } - ?terminal cim:Terminal.TopologicalNode ?tp_node + } + { + ?con_node cim:ConnectivityNode.TopologicalNode ?tp_node . + } + UNION { + FILTER NOT EXISTS { + ?con_node cim:ConnectivityNode.TopologicalNode ?tp_node . } - ?tp_node cim:IdentifiedObject.mRID ?node; - cim:IdentifiedObject.name ?name; - ^cim:SvInjection.TopologicalNode/cim:SvInjection.pInjection ?p_inj -} group by ?node + ?terminal cim:Terminal.TopologicalNode ?tp_node . + } + ?tp_node cim:IdentifiedObject.mRID ?node ; + cim:IdentifiedObject.name ?name ; + ^cim:SvInjection.TopologicalNode/cim:SvInjection.pInjection ?p_inj . +} +GROUP BY ?node diff --git a/src/cimsparql/sparql/switches.sparql b/src/cimsparql/sparql/switches.sparql index dc37f352..b1101a34 100644 --- a/src/cimsparql/sparql/switches.sparql +++ b/src/cimsparql/sparql/switches.sparql @@ -1,35 +1,37 @@ # Name: Switches PREFIX cim: <${cim}> -select ?mrid ?is_open (strafter(str(?type), "#") as ?equipment_type) ?connectivity_node_1 ?connectivity_node_2 ?name where { - { - select * { - ?_eq_subject ?eq_repo . - service ?eq_repo { - { - # Extract the maximum terminal number per switch. This number is used to deduce the second terminal - # Normally this equals 2, but occasionally it can be one. In that case it means that the switch - # has only one termainal. A switch with only one terminal can not connect or disconnect anything - # which is equivalent of setting terminal 2 equal to terminal 1 - select ?switch (max(?nr) as ?max_terminal_number) { - ?switch cim:Switch.normalOpen ?_unused_normal_open; - ^cim:Terminal.ConductingEquipment/cim:ACDCTerminal.sequenceNumber ?nr - } group by ?switch - } - - values ?type {cim:Breaker cim:Disconnector cim:GroundDisconnector cim:LoadBreakSwitch cim:Recloser cim:MktSwitch cim:Fuse cim:Sectionaliser cim:Cut cim:Jumper} - ?switch cim:IdentifiedObject.mRID ?mrid; - a ?type; - cim:Switch.normalOpen ?normal_open; - ^cim:Terminal.ConductingEquipment ?terminal1; - ^cim:Terminal.ConductingEquipment ?terminal2; - cim:IdentifiedObject.name ?name . - ?terminal1 cim:ACDCTerminal.sequenceNumber 1; - cim:Terminal.ConnectivityNode/cim:IdentifiedObject.mRID ?connectivity_node_1 . - ?terminal2 cim:ACDCTerminal.sequenceNumber ?max_terminal_number; - cim:Terminal.ConnectivityNode/cim:IdentifiedObject.mRID ?connectivity_node_2 . - } +SELECT ?mrid ?is_open (STRAFTER(STR(?type),"#") AS ?equipment_type) ?connectivity_node_1 ?connectivity_node_2 ?name +WHERE { + { + SELECT * + WHERE { + ?_eq_subject ?eq_repo . + SERVICE ?eq_repo { + { + # Extract the maximum terminal number per switch. This number is used to deduce the second terminal # Normally this equals 2, but occasionally it can be one. In that case it means that the switch # has only one termainal. A switch with only one terminal can not connect or disconnect anything # which is equivalent of setting terminal 2 equal to terminal 1 + SELECT ?switch (MAX(?nr) AS ?max_terminal_number) + WHERE { + ?switch cim:Switch.normalOpen ?_unused_normal_open ; + ^cim:Terminal.ConductingEquipment/cim:ACDCTerminal.sequenceNumber ?nr . + } + GROUP BY ?switch } + VALUES ?type { cim:Breaker cim:Disconnector cim:GroundDisconnector cim:LoadBreakSwitch cim:Recloser cim:MktSwitch cim:Fuse cim:Sectionaliser cim:Cut cim:Jumper } + ?switch cim:IdentifiedObject.mRID ?mrid ; + a ?type ; + cim:Switch.normalOpen ?normal_open ; + ^cim:Terminal.ConductingEquipment ?terminal1 ; + ^cim:Terminal.ConductingEquipment ?terminal2 ; + cim:IdentifiedObject.name ?name . + ?terminal1 cim:ACDCTerminal.sequenceNumber 1 ; + cim:Terminal.ConnectivityNode/cim:IdentifiedObject.mRID ?connectivity_node_1 . + ?terminal2 cim:ACDCTerminal.sequenceNumber ?max_terminal_number ; + cim:Terminal.ConnectivityNode/cim:IdentifiedObject.mRID ?connectivity_node_2 . + } } - optional{?switch cim:Switch.open ?ssh_is_open} - bind(coalesce(?ssh_is_open, ?normal_open) as ?is_open) + } + OPTIONAL { + ?switch cim:Switch.open ?ssh_is_open . + } + BIND (COALESCE(?ssh_is_open, ?normal_open) AS ?is_open) } diff --git a/src/cimsparql/sparql/synchronous_machines.sparql b/src/cimsparql/sparql/synchronous_machines.sparql index 3380f3ff..aa8645c6 100644 --- a/src/cimsparql/sparql/synchronous_machines.sparql +++ b/src/cimsparql/sparql/synchronous_machines.sparql @@ -2,75 +2,77 @@ PREFIX cim: <${cim}> PREFIX SN: <${SN}> PREFIX xsd: <${xsd}> -select ?mrid ?name ?market_code ?node ?status ?station_group ?station_group_name ?substation_mrid ?max_p ?min_p ?merit_order ?sn ?p ?q ?connectivity_node ?generator_type ?schedule_resource -where { - # Extract properties for synchronous machines. +SELECT ?mrid ?name ?market_code ?node ?status ?station_group ?station_group_name ?substation_mrid ?max_p ?min_p ?merit_order ?sn ?p ?q ?connectivity_node ?generator_type ?schedule_resource +WHERE { { - select * where { + # Extract properties for synchronous machines. + SELECT * + WHERE { ?_eq_subject ?eq_repo . - service ?eq_repo { - ?machine a cim:SynchronousMachine; - cim:IdentifiedObject.mRID ?machine_mrid; - cim:IdentifiedObject.name ?name; - cim:RotatingMachine.ratedS ?sn; - ^cim:Terminal.ConductingEquipment ?terminal; - cim:Equipment.EquipmentContainer/cim:VoltageLevel.Substation ?substation . - + SERVICE ?eq_repo { + ?machine a cim:SynchronousMachine ; + cim:IdentifiedObject.mRID ?machine_mrid ; + cim:IdentifiedObject.name ?name ; + cim:RotatingMachine.ratedS ?sn ; + ^cim:Terminal.ConductingEquipment ?terminal ; + cim:Equipment.EquipmentContainer/cim:VoltageLevel.Substation ?substation . # TODO: Seems like cim15 uses SynchronousMachine while cim16 uses RotatingMachine. Will fix this when we have a proper cim16 model - optional{ - values ?gen_type {cim:NuclearGeneratingUnit cim:MktGeneratingUnit cim:HydroGeneratingUnit cim:WindGeneratingUnit cim:ThermalGeneratingUnit cim:SolarGeneratingUnit} - ?machine cim:SynchronousMachine.GeneratingUnit|cim:RotatingMachine.GeneratingUnit ?nullable_gen_unit . - ?nullable_gen_unit a ?gen_type + OPTIONAL { + VALUES ?gen_type { cim:NuclearGeneratingUnit cim:MktGeneratingUnit cim:HydroGeneratingUnit cim:WindGeneratingUnit cim:ThermalGeneratingUnit cim:SolarGeneratingUnit } + ?machine cim:SynchronousMachine.GeneratingUnit | cim:RotatingMachine.GeneratingUnit ?nullable_gen_unit . + ?nullable_gen_unit a ?gen_type . } - bind(coalesce(?nullable_gen_unit, URI("http://no-gen-unit")) as ?gen_unit) - + BIND (COALESCE(?nullable_gen_unit, URI("http://no-gen-unit")) AS ?gen_unit) ?terminal cim:Terminal.ConnectivityNode ?con_node . ?con_node cim:IdentifiedObject.mRID ?connectivity_node . - # Extract area and mrid for the substation associated with a sync machine - ?substation cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area; + ?substation cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area ; cim:IdentifiedObject.mRID ?substation_mrid . - # Optionally extract min/max operating power for each machin - optional { - ?gen_unit cim:IdentifiedObject.mRID ?gen_unit_mrid; - cim:GeneratingUnit.minOperatingP ?nullable_minP; - cim:GeneratingUnit.maxOperatingP ?nullable_maxP. - - optional { - ?gen_unit SN:GeneratingUnit.marketCode ?market_code; - SN:GeneratingUnit.groupAllocationWeight ?merit_order; - SN:GeneratingUnit.ScheduleResource ?ScheduleResource . - ?ScheduleResource SN:ScheduleResource.marketCode ?station_group; - cim:IdentifiedObject.mRID ?schedule_resource; - cim:IdentifiedObject.name ?station_group_name . - } + OPTIONAL { + ?gen_unit cim:IdentifiedObject.mRID ?gen_unit_mrid ; + cim:GeneratingUnit.minOperatingP ?nullable_minP ; + cim:GeneratingUnit.maxOperatingP ?nullable_maxP . + OPTIONAL { + ?gen_unit SN:GeneratingUnit.marketCode ?market_code ; + SN:GeneratingUnit.groupAllocationWeight ?merit_order ; + SN:GeneratingUnit.ScheduleResource ?ScheduleResource . + ?ScheduleResource SN:ScheduleResource.marketCode ?station_group ; + cim:IdentifiedObject.mRID ?schedule_resource ; + cim:IdentifiedObject.name ?station_group_name . } - filter regex(?area, '${region}') - + } + FILTER REGEX(?area,'${region}') # Opionally extract non-CIM standard properties generating units - optional {?machine SN:Equipment.networkAnalysisEnable ?_network_analysis} - bind(if(bound(?gen_type), replace(str(?gen_type), str(cim:), ""), "unknown") as ?generator_type) - bind(coalesce(?gen_unit_mrid, ?machine_mrid) as ?mrid) + OPTIONAL { + ?machine SN:Equipment.networkAnalysisEnable ?_network_analysis . + } + BIND (IF(BOUND(?gen_type),replace(str(?gen_type), str(cim:), ""),"unknown") AS ?generator_type) + BIND (COALESCE(?gen_unit_mrid, ?machine_mrid) AS ?mrid) } } } - ?terminal cim:ACDCTerminal.connected ?connected . { ?con_node cim:ConnectivityNode.TopologicalNode ?topological_node . - } union { - filter not exists {?con_node cim:ConnectivityNode.TopologicalNode ?topological_node} + } + UNION { + FILTER NOT EXISTS { + ?con_node cim:ConnectivityNode.TopologicalNode ?topological_node . + } ?terminal cim:Terminal.TopologicalNode ?topological_node . } ?topological_node cim:IdentifiedObject.mRID ?node . - - optional {?machine ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?in_service} . - optional {?machine cim:RotatingMachine.p ?p;cim:RotatingMachine.q ?q .} - - bind(coalesce(?_network_analysis, True) as ?network_analysis) - bind(coalesce(?in_service, ?connected) as ?status) - bind(coalesce(?nullable_maxP, if(xsd:double(str(?p)) >= 0.0, ?p, 0.0), 0.0) as ?max_p) - bind(coalesce(?nullable_minP, if(xsd:double(str(?p)) < 0.0, ?p, 0.0), 0.0) as ?min_p) - filter(?network_analysis) + OPTIONAL { + ?machine ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?in_service . + } + OPTIONAL { + ?machine cim:RotatingMachine.p ?p ; + cim:RotatingMachine.q ?q . + } + BIND (COALESCE(?_network_analysis, true) AS ?network_analysis) + BIND (COALESCE(?in_service, ?connected) AS ?status) + BIND (COALESCE(?nullable_maxP, IF(xsd:double(STR(?p)) >= 0.0, ?p, 0.0), 0.0) AS ?max_p) + BIND (COALESCE(?nullable_minP, IF(xsd:double(STR(?p)) < 0.0, ?p, 0.0), 0.0) AS ?min_p) + FILTER (?network_analysis = true) } diff --git a/src/cimsparql/sparql/test_configuration_modifications/add_eic_bidding_area_code.sparql b/src/cimsparql/sparql/test_configuration_modifications/add_eic_bidding_area_code.sparql index e7b46c92..229ac5e9 100644 --- a/src/cimsparql/sparql/test_configuration_modifications/add_eic_bidding_area_code.sparql +++ b/src/cimsparql/sparql/test_configuration_modifications/add_eic_bidding_area_code.sparql @@ -1,12 +1,13 @@ -prefix cim:<${cim}> -prefix SN:<${SN}> -prefix entsoeSecretariat:<${entsoeSecretariat}> -insert { - graph { - ?substation SN:Substation.MarketDeliveryPoint _:b0 . - _:b0 SN:MarketDeliveryPoint.BiddingArea _:b1 . - _:b1 entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC "10Y1001A1001A48H" -}} -where { - ?substation a cim:Substation +PREFIX cim: <${cim}> +PREFIX SN: <${SN}> +PREFIX entsoeSecretariat: <${entsoeSecretariat}> +INSERT { + GRAPH { + ?substation SN:Substation.MarketDeliveryPoint _:b0 . + _:b0 SN:MarketDeliveryPoint.BiddingArea _:b1 . + _:b1 entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC "10Y1001A1001A48H" . + } +} +WHERE { + ?substation a cim:Substation . } diff --git a/src/cimsparql/sparql/test_configuration_modifications/add_gen_unit_mrid.sparql b/src/cimsparql/sparql/test_configuration_modifications/add_gen_unit_mrid.sparql index 8efc82d6..0fb8c104 100644 --- a/src/cimsparql/sparql/test_configuration_modifications/add_gen_unit_mrid.sparql +++ b/src/cimsparql/sparql/test_configuration_modifications/add_gen_unit_mrid.sparql @@ -1,14 +1,17 @@ prefix cim:<${cim}> prefix SN:<${SN}> -insert { - graph { - _:b0 a SN:GeneratingUnit; - cim:IdentifiedObject.name "GeneratingUnit" . - ?machine cim:SynchronousMachine.GeneratingUnit _:b0 . - _:b0 SN:GeneratingUnit.ScheduleResource _:b1 . - _:b1 SN:ScheduleResource.marketCode "market0001" - }} -where { - ?machine a cim:SynchronousMachine - filter not exists{?machine cim:SynchronousMachine.GeneratingUnit ?unit} +INSERT { + GRAPH { + _:b0 a SN:GeneratingUnit ; +cim:IdentifiedObject.name "GeneratingUnit" . + ?machine cim:SynchronousMachine.GeneratingUnit _:b0 . + _:b0 SN:GeneratingUnit.ScheduleResource _:b1 . + _:b1 SN:ScheduleResource.marketCode "market0001" + } +} +WHERE { + ?machine a cim:SynchronousMachine + FILTER NOT EXISTS { + ?machine cim:SynchronousMachine.GeneratingUnit ?unit + } } diff --git a/src/cimsparql/sparql/test_configuration_modifications/add_market_code_for_load_groups.sparql b/src/cimsparql/sparql/test_configuration_modifications/add_market_code_for_load_groups.sparql index d27a6060..2f185d52 100644 --- a/src/cimsparql/sparql/test_configuration_modifications/add_market_code_for_load_groups.sparql +++ b/src/cimsparql/sparql/test_configuration_modifications/add_market_code_for_load_groups.sparql @@ -1,14 +1,15 @@ prefix cim:<${cim}> prefix SN:<${SN}> - # Assign all loads that does not have a load group to the newly created load group -insert { - graph { - ?load cim:NonConformLoad.LoadGroup ?created_group - } +INSERT { + GRAPH { + ?load cim:NonConformLoad.LoadGroup ?created_group + } } -where { - ?load a cim:EnergyConsumer . - ?created_group cim:IdentifiedObject.name "created-group" . - filter not exists{?load cim:NonConformLoad.LoadGroup ?group} +WHERE { + ?load a cim:EnergyConsumer . + ?created_group cim:IdentifiedObject.name "created-group" . + FILTER NOT EXISTS { + ?load cim:NonConformLoad.LoadGroup ?group + } } diff --git a/src/cimsparql/sparql/test_configuration_modifications/add_network_analysis_enable.sparql b/src/cimsparql/sparql/test_configuration_modifications/add_network_analysis_enable.sparql index 6d6c7279..10a341f6 100644 --- a/src/cimsparql/sparql/test_configuration_modifications/add_network_analysis_enable.sparql +++ b/src/cimsparql/sparql/test_configuration_modifications/add_network_analysis_enable.sparql @@ -1,9 +1,10 @@ -prefix cim:<${cim}> -prefix SN:<${SN}> -insert { - graph { - ?equipment SN:Equipment.networkAnalysisEnable True -}} -where { - ?terminal cim:Terminal.ConductingEquipment ?equipment +PREFIX cim: <${cim}> +PREFIX SN: <${SN}> +INSERT { + GRAPH { + ?equipment SN:Equipment.networkAnalysisEnable true . + } +} +WHERE { + ?terminal cim:Terminal.ConductingEquipment ?equipment . } diff --git a/src/cimsparql/sparql/test_configuration_modifications/add_non_conform_load_group.sparql b/src/cimsparql/sparql/test_configuration_modifications/add_non_conform_load_group.sparql index 1de7b83d..cbdbc5da 100644 --- a/src/cimsparql/sparql/test_configuration_modifications/add_non_conform_load_group.sparql +++ b/src/cimsparql/sparql/test_configuration_modifications/add_non_conform_load_group.sparql @@ -1,12 +1,11 @@ prefix cim:<${cim}> prefix SN:<${SN}> - # Create a load group -insert data { - graph { - _:b0 a cim:NonConformLoadGroup; - cim:IdentifiedObject.name "created-group"; - SN:NonConformLoadGroup.ScheduleResource _:b1 . - _:b1 SN:ScheduleResource.marketCode "created-load-resource-mcode" - } +INSERT DATA { + GRAPH { + _:b0 a cim:NonConformLoadGroup ; +cim:IdentifiedObject.name "created-group" ; +SN:NonConformLoadGroup.ScheduleResource _:b1 . + _:b1 SN:ScheduleResource.marketCode "created-load-resource-mcode" + } } diff --git a/src/cimsparql/sparql/test_configuration_modifications/add_sv_injection.sparql b/src/cimsparql/sparql/test_configuration_modifications/add_sv_injection.sparql index 768f9ae5..de0b7a8c 100644 --- a/src/cimsparql/sparql/test_configuration_modifications/add_sv_injection.sparql +++ b/src/cimsparql/sparql/test_configuration_modifications/add_sv_injection.sparql @@ -1,11 +1,14 @@ -prefix cim:<${cim}> -insert { - graph { - _:b0 cim:SvInjection.TopologicalNode ?tp_node; - a cim:SvInjection; - cim:SvInjection.pInjection 0.0 -}} -where { - ?tp_node a cim:TopologicalNode - filter not exists {?s cim:SvInjection.TopologicalNode ?tp_node} +PREFIX cim: <${cim}> +INSERT { + GRAPH { + _:b0 cim:SvInjection.TopologicalNode ?tp_node ; +a cim:SvInjection ; +cim:SvInjection.pInjection 0.0 . + } +} +WHERE { + ?tp_node a cim:TopologicalNode . + FILTER NOT EXISTS { + ?s cim:SvInjection.TopologicalNode ?tp_node . + } } diff --git a/src/cimsparql/sparql/test_configuration_modifications/add_zero_sv_power.sparql b/src/cimsparql/sparql/test_configuration_modifications/add_zero_sv_power.sparql index 9b8b1374..24e70dcc 100644 --- a/src/cimsparql/sparql/test_configuration_modifications/add_zero_sv_power.sparql +++ b/src/cimsparql/sparql/test_configuration_modifications/add_zero_sv_power.sparql @@ -1,13 +1,14 @@ -prefix cim:<${cim}> - -insert { - graph { - _:b0 a cim:SvPowerFlow; - cim:SvPowerFlow.Terminal ?terminal; - cim:SvPowerFlow.p "0.0" - } +PREFIX cim: <${cim}> +INSERT { + GRAPH { + _:b0 a cim:SvPowerFlow ; +cim:SvPowerFlow.Terminal ?terminal ; +cim:SvPowerFlow.p "0.0" . + } } -where { - ?terminal a cim:Terminal - filter not exists{?s cim:SvPowerFlow.Terminal ?terminal} +WHERE { + ?terminal a cim:Terminal . + FILTER NOT EXISTS { + ?s cim:SvPowerFlow.Terminal ?terminal . + } } diff --git a/src/cimsparql/sparql/transformer_branches.sparql b/src/cimsparql/sparql/transformer_branches.sparql index 7ae10997..d3f46242 100644 --- a/src/cimsparql/sparql/transformer_branches.sparql +++ b/src/cimsparql/sparql/transformer_branches.sparql @@ -3,76 +3,82 @@ PREFIX cim: <${cim}> PREFIX SN: <${SN}> PREFIX xsd: <${xsd}> # Name: Transformer branches -select ?node_1 ?node_2 ?status ?name ?mrid ?un ?r ?x ?b ?g ?rate ?angle ?ratio ?connectivity_node_1 (?node_2 as ?connectivity_node_2) -where { +SELECT ?node_1 ?node_2 ?status ?name ?mrid ?un ?r ?x ?b ?g ?rate ?angle ?ratio ?connectivity_node_1 (?node_2 AS ?connectivity_node_2) +WHERE { { - select * where { + SELECT * + WHERE { ?_eq_subject ?eq_repo . - service ?eq_repo { + SERVICE ?eq_repo { # Use mrid of transformer as dummy node - ?p_transformer cim:IdentifiedObject.mRID ?node_2; - cim:Equipment.EquipmentContainer ?Substation . + ?p_transformer cim:IdentifiedObject.mRID ?node_2 ; + cim:Equipment.EquipmentContainer ?Substation . ?Substation cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area . - filter(regex(?area, '${region}')) - + FILTER REGEX(?area,'${region}') # Extract properties for the windings associated with p_transformer - ?winding cim:TransformerEnd.Terminal ?terminal; - cim:IdentifiedObject.mRID ?mrid; - cim:IdentifiedObject.name ?name; - cim:PowerTransformerEnd.PowerTransformer ?p_transformer; - cim:PowerTransformerEnd.ratedU ?ubase; - cim:PowerTransformerEnd.r ?r; - cim:PowerTransformerEnd.x ?x; - cim:PowerTransformerEnd.b ?b; - cim:PowerTransformerEnd.g ?g . - optional{?winding cim:PowerTransformerEnd.phaseAngleClock ?aclock .} - bind(coalesce(?aclock, 0.0) as ?angleclock) - + ?winding cim:TransformerEnd.Terminal ?terminal ; + cim:IdentifiedObject.mRID ?mrid ; + cim:IdentifiedObject.name ?name ; + cim:PowerTransformerEnd.PowerTransformer ?p_transformer ; + cim:PowerTransformerEnd.ratedU ?ubase ; + cim:PowerTransformerEnd.r ?r ; + cim:PowerTransformerEnd.x ?x ; + cim:PowerTransformerEnd.b ?b ; + cim:PowerTransformerEnd.g ?g . + OPTIONAL { + ?winding cim:PowerTransformerEnd.phaseAngleClock ?aclock . + } + BIND (COALESCE(?aclock, 0.0) AS ?angleclock) # Extract the connectivity node for each termina, and find the nominal voltage from the connectivity node ?terminal cim:Terminal.ConnectivityNode ?con_node . ?con_node cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.BaseVoltage/cim:BaseVoltage.nominalVoltage ?un ; - cim:IdentifiedObject.mRID ?connectivity_node_1 . + cim:IdentifiedObject.mRID ?connectivity_node_1 . # Optionally extract active power limits - optional { - ?_lim a cim:ActivePowerLimit; - cim:OperationalLimit.OperationalLimitSet/cim:OperationalLimitSet.Terminal ?terminal; - cim:IdentifiedObject.name '${rate}'; + OPTIONAL { + ?_lim a cim:ActivePowerLimit ; + cim:OperationalLimit.OperationalLimitSet/cim:OperationalLimitSet.Terminal ?terminal ; + cim:IdentifiedObject.name '${rate}' ; cim:ActivePowerLimit.value ?rate . } - optional {?p_transformer SN:Equipment.networkAnalysisEnable ?_network_analysis} . - optional { - ?tap_changer cim:RatioTapChanger.TransformerEnd ?winding ; - cim:RatioTapChanger.stepVoltageIncrement ?inc; - cim:TapChanger.neutralStep ?neutral_step; - cim:TapChanger.normalStep ?normal_step - } . - bind(coalesce(?tap_changer, ) as ?ratio_tap_changer) + OPTIONAL { + ?p_transformer SN:Equipment.networkAnalysisEnable ?_network_analysis . + } + OPTIONAL { + ?tap_changer cim:RatioTapChanger.TransformerEnd ?winding ; + cim:RatioTapChanger.stepVoltageIncrement ?inc ; + cim:TapChanger.neutralStep ?neutral_step ; + cim:TapChanger.normalStep ?normal_step . + } + BIND (COALESCE(?tap_changer, ) AS ?ratio_tap_changer) } } } - { - ?con_node cim:ConnectivityNode.TopologicalNode ?top_node - } union { - # Get topological node directly from the terminal when it does not - # exist via the connectivity node - filter not exists {?con_node cim:ConnectivityNode.TopologicalNode ?top_node } - ?terminal cim:Terminal.TopologicalNode ?top_node - }. - + ?con_node cim:ConnectivityNode.TopologicalNode ?top_node . + } + UNION { + FILTER NOT EXISTS { + # Get topological node directly from the terminal when it does not # exist via the connectivity node + ?con_node cim:ConnectivityNode.TopologicalNode ?top_node . + } + ?terminal cim:Terminal.TopologicalNode ?top_node . + } ?top_node cim:IdentifiedObject.mRID ?node_1 . ?terminal cim:ACDCTerminal.connected ?connected . - optional {?winding ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?in_service} . - optional {?ratio_tap_changer cim:TapChanger.step ?ssh_step }. - bind(coalesce(?ssh_step, ?normal_step) as ?step) - bind(if(bound(?inc), 1+(xsd:integer(str(?step)) - xsd:integer(str(?neutral_step)))*xsd:double(str(?inc))/100.0, 1.0) as ?tau) - bind(coalesce(?_network_analysis, True) as ?network_analysis) - filter(?network_analysis) - + OPTIONAL { + ?winding ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?in_service . + } + OPTIONAL { + ?ratio_tap_changer cim:TapChanger.step ?ssh_step . + } + BIND (COALESCE(?ssh_step, ?normal_step) AS ?step) + BIND (IF(BOUND(?inc),1 + (xsd:integer(STR(?step)) - xsd:integer(STR(?neutral_step))) * xsd:double(STR(?inc)) / 100.0,1.0) AS ?tau) + BIND (COALESCE(?_network_analysis, true) AS ?network_analysis) + FILTER (?network_analysis = true) + BIND (COALESCE(?in_service, ?connected) AS ?status) + BIND (xsd:double(STR(?un)) * ?tau / xsd:double(STR(?ubase)) AS ?ratio) + BIND (xsd:double(30.0) * ?angleclock AS ?angle) # Assign status flag to the transformer. The first that exists is used - # 1) in_service flag on the transformer - # 2) Connected flag for the terminal - bind(coalesce(?in_service, ?connected) as ?status) - bind(xsd:double(str(?un))*?tau / xsd:double(str(?ubase)) as ?ratio) - bind(xsd:double(30.0) * ?angleclock as ?angle) } +# 1) in_service flag on the transformer +# 2) Connected flag for the terminal diff --git a/src/cimsparql/sparql/transformer_center_nodes.sparql b/src/cimsparql/sparql/transformer_center_nodes.sparql index 07b8b8c0..f936b8a4 100644 --- a/src/cimsparql/sparql/transformer_center_nodes.sparql +++ b/src/cimsparql/sparql/transformer_center_nodes.sparql @@ -1,37 +1,34 @@ # Name: Transformer center nodes -PREFIX cim:<${cim}> -PREFIX SN:<${SN}> -PREFIX entsoeSecretariat:<${entsoeSecretariat}> -select ?node ?busname (?container_name as ?substation) ?un ?base_voltage_mrid (?container_mrid as ?substation_mrid) ?bidzone ?island (False as ?is_swing_bus) ?connectivity_node (?un as ?sv_voltage) -where -{ - optional { +PREFIX cim: <${cim}> +PREFIX SN: <${SN}> +PREFIX entsoeSecretariat: <${entsoeSecretariat}> +SELECT ?node ?busname (?container_name AS ?substation) ?un ?base_voltage_mrid (?container_mrid AS ?substation_mrid) ?bidzone ?island (false AS ?is_swing_bus) ?connectivity_node (?un AS ?sv_voltage) +WHERE { + OPTIONAL { ?con_node cim:ConnectivityNode.TopologicalNode ?top_node . - ?top_node ^cim:TopologicalIsland.TopologicalNodes/cim:IdentifiedObject.name ?island_name - }. - - - + ?top_node ^cim:TopologicalIsland.TopologicalNodes/cim:IdentifiedObject.name ?island_name . + } ?_eq_subject ?eq_repo . - service ?eq_repo { - ?p_transformer cim:IdentifiedObject.mRID ?node; - cim:IdentifiedObject.name ?busname; - cim:Equipment.EquipmentContainer ?container. - ?winding cim:TransformerEnd.endNumber 1; - cim:PowerTransformerEnd.PowerTransformer ?p_transformer; - cim:TransformerEnd.Terminal ?terminal . - ?terminal cim:Terminal.ConnectivityNode ?con_node. - ?con_node cim:IdentifiedObject.mRID ?connectivity_node; - cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.BaseVoltage ?base_voltage . - ?container cim:IdentifiedObject.mRID ?container_mrid; - cim:IdentifiedObject.name ?container_name. - ?container SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC ?bidzone - optional {?p_transformer SN:Equipment.networkAnalysisEnable ?_network_analysis} - + SERVICE ?eq_repo { + ?p_transformer cim:IdentifiedObject.mRID ?node ; + cim:IdentifiedObject.name ?busname ; + cim:Equipment.EquipmentContainer ?container . + ?winding cim:TransformerEnd.endNumber 1 ; + cim:PowerTransformerEnd.PowerTransformer ?p_transformer ; + cim:TransformerEnd.Terminal ?terminal . + ?terminal cim:Terminal.ConnectivityNode ?con_node . + ?con_node cim:IdentifiedObject.mRID ?connectivity_node ; + cim:ConnectivityNode.ConnectivityNodeContainer/cim:VoltageLevel.BaseVoltage ?base_voltage . + ?container cim:IdentifiedObject.mRID ?container_mrid ; + cim:IdentifiedObject.name ?container_name . + ?container SN:Substation.MarketDeliveryPoint/SN:MarketDeliveryPoint.BiddingArea/entsoeSecretariat:IdentifiedObject.energyIdentCodeEIC ?bidzone . + OPTIONAL { + ?p_transformer SN:Equipment.networkAnalysisEnable ?_network_analysis . + } ?base_voltage cim:IdentifiedObject.mRID ?base_voltage_mrid ; - cim:BaseVoltage.nominalVoltage ?un + cim:BaseVoltage.nominalVoltage ?un . } - filter(?network_analysis) - bind(coalesce(?_network_analysis, True) as ?network_analysis) - bind(coalesce(?island_name, "Unknown") as ?island) + FILTER (?network_analysis = true) + BIND (COALESCE(?_network_analysis, true) AS ?network_analysis) + BIND (COALESCE(?island_name, "Unknown") AS ?island) } diff --git a/src/cimsparql/sparql/transformer_winding_angle.sparql b/src/cimsparql/sparql/transformer_winding_angle.sparql index 15142f7a..865cfd3d 100644 --- a/src/cimsparql/sparql/transformer_winding_angle.sparql +++ b/src/cimsparql/sparql/transformer_winding_angle.sparql @@ -1,18 +1,18 @@ # Name: Winding transformer angle PREFIX cim: <${cim}> PREFIX xsd: <${xsd}> -select ?mrid ?angle -where { +SELECT ?mrid ?angle +WHERE { ?tap_changer cim:TapChanger.step ?ssh_position . - optional{ ?tap_changer ^cim:SvTapStep.TapChanger/cim:SvTapStep.position ?sv_position } . - + OPTIONAL { + ?tap_changer ^cim:SvTapStep.TapChanger/cim:SvTapStep.position ?sv_position . + } ?_eq_subject ?eq_repo . - service ?eq_repo { - ?tap_changer cim:PhaseTapChangerLinear.stepPhaseShiftIncrement ?inc; - cim:TapChanger.neutralStep ?neutralstep; - ^cim:TransformerEnd.PhaseTapChanger/cim:IdentifiedObject.mRID ?mrid . + SERVICE ?eq_repo { + ?tap_changer cim:PhaseTapChangerLinear.stepPhaseShiftIncrement ?inc ; + cim:TapChanger.neutralStep ?neutralstep ; + ^cim:TransformerEnd.PhaseTapChanger/cim:IdentifiedObject.mRID ?mrid . } - - bind(coalesce(?sv_position, ?ssh_position) as ?position) - bind((xsd:double(str(?position)) - xsd:double(str(?neutralstep))) * xsd:double(str(?inc)) as ?angle) + BIND (COALESCE(?sv_position, ?ssh_position) AS ?position) + BIND ((xsd:double(STR(?position)) - xsd:double(STR(?neutralstep))) * xsd:double(STR(?inc)) AS ?angle) } diff --git a/src/cimsparql/sparql/transformer_windings.sparql b/src/cimsparql/sparql/transformer_windings.sparql index c33f3b63..4b780957 100644 --- a/src/cimsparql/sparql/transformer_windings.sparql +++ b/src/cimsparql/sparql/transformer_windings.sparql @@ -1,10 +1,10 @@ # Name: Transformer Windings PREFIX cim: <${cim}> -select ?mrid ?end_number ?w_mrid -where { - ?power_transformer a cim:PowerTransformer; +SELECT ?mrid ?end_number ?w_mrid +WHERE { + ?power_transformer a cim:PowerTransformer ; cim:IdentifiedObject.mRID ?mrid . - ?winding cim:IdentifiedObject.mRID ?w_mrid; - cim:PowerTransformerEnd.PowerTransformer ?power_transformer; - cim:TransformerEnd.endNumber ?end_number + ?winding cim:IdentifiedObject.mRID ?w_mrid ; + cim:PowerTransformerEnd.PowerTransformer ?power_transformer ; + cim:TransformerEnd.endNumber ?end_number . } diff --git a/src/cimsparql/sparql/transformers.sparql b/src/cimsparql/sparql/transformers.sparql index 07762bef..05bd9298 100644 --- a/src/cimsparql/sparql/transformers.sparql +++ b/src/cimsparql/sparql/transformers.sparql @@ -1,29 +1,30 @@ # Name: Transformers PREFIX cim: <${cim}> PREFIX SN: <${SN}> -select ?name ?p_mrid ?w_mrid ?end_number ?un ?t_mrid ?r ?x ?rate -where { +SELECT ?name ?p_mrid ?w_mrid ?end_number ?un ?t_mrid ?r ?x ?rate +WHERE { # Extract mRID for each power transformer - ?p_transformer a cim:PowerTransformer; - cim:IdentifiedObject.mRID ?p_mrid; - cim:Equipment.EquipmentContainer/cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area . - ?winding cim:PowerTransformerEnd.PowerTransformer ?p_transformer; - cim:PowerTransformerEnd.ratedU ?un; - cim:PowerTransformerEnd.r ?r; - cim:PowerTransformerEnd.x ?x; - cim:IdentifiedObject.mRID ?w_mrid; - cim:IdentifiedObject.name ?name; - cim:TransformerEnd.endNumber ?end_number; - cim:TransformerEnd.Terminal/cim:IdentifiedObject.mRID ?t_mrid; - - filter regex(?area, '${region}') . - optional { - ?p_lim cim:OperationalLimit.OperationalLimitSet/cim:OperationalLimitSet.Equipment ?winding; - a cim:ActivePowerLimit; - cim:IdentifiedObject.name '${rate}'; - cim:ActivePowerLimit.value ?rate + ?p_transformer a cim:PowerTransformer ; + cim:IdentifiedObject.mRID ?p_mrid ; + cim:Equipment.EquipmentContainer/cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area . + ?winding cim:PowerTransformerEnd.PowerTransformer ?p_transformer ; + cim:PowerTransformerEnd.ratedU ?un ; + cim:PowerTransformerEnd.r ?r ; + cim:PowerTransformerEnd.x ?x ; + cim:IdentifiedObject.mRID ?w_mrid ; + cim:IdentifiedObject.name ?name ; + cim:TransformerEnd.endNumber ?end_number ; + cim:TransformerEnd.Terminal/cim:IdentifiedObject.mRID ?t_mrid . + FILTER REGEX(?area,'${region}') + OPTIONAL { + ?p_lim cim:OperationalLimit.OperationalLimitSet/cim:OperationalLimitSet.Equipment ?winding ; + a cim:ActivePowerLimit ; + cim:IdentifiedObject.name '${rate}' ; + cim:ActivePowerLimit.value ?rate . } - optional {?p_transformer SN:Equipment.networkAnalysisEnable ?_analysis_enabled .} - filter(?analysis_enabled) - bind(coalesce(?_analysis_enabled, True) as ?analysis_enabled) + OPTIONAL { + ?p_transformer SN:Equipment.networkAnalysisEnable ?_analysis_enabled . + } + FILTER (?analysis_enabled = true) + BIND (COALESCE(?_analysis_enabled, true) AS ?analysis_enabled) } diff --git a/src/cimsparql/sparql/transformers_connected_to_converter.sparql b/src/cimsparql/sparql/transformers_connected_to_converter.sparql index 16d99138..70d8343d 100644 --- a/src/cimsparql/sparql/transformers_connected_to_converter.sparql +++ b/src/cimsparql/sparql/transformers_connected_to_converter.sparql @@ -1,34 +1,34 @@ # Name: Transforers connected to converter -PREFIX ALG:<${ALG}> +PREFIX ALG: <${ALG}> PREFIX SN: <${SN}> -PREFIX cim:<${cim}> - +PREFIX cim: <${cim}> # TODO: We probably need distinct since we get a hit on cim:VsConverter in SSH-profile and ALG:VoltageSourceConverter # in EQ-repo. This was caused by correcting the ALG-namespace which lacked # at the end -select distinct ?mrid ?name ?t_mrid ?p_mrid -where { - values ?converter_type {cim:VsConverter cim:CsConverter cim:DCConvertUnit ALG:VoltageSourceConverter ALG:DCConverter } - +SELECT DISTINCT ?mrid ?name ?t_mrid ?p_mrid +WHERE { + VALUES ?converter_type { cim:VsConverter cim:CsConverter cim:DCConvertUnit ALG:VoltageSourceConverter ALG:DCConverter } # Extract mRID for the converters - ?converter a ?converter_type; - cim:IdentifiedObject.mRID ?mrid . - + ?converter a ?converter_type ; + cim:IdentifiedObject.mRID ?mrid . # Extract mRID name for the power transformer associated with the converter - ?p_transformer a cim:PowerTransformer; - cim:IdentifiedObject.mRID ?p_mrid; - cim:IdentifiedObject.aliasName ?name; - cim:Equipment.EquipmentContainer/cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area ; - ^cim:Terminal.ConductingEquipment/cim:Terminal.ConnectivityNode/^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment ?converter . - + ?p_transformer a cim:PowerTransformer ; + cim:IdentifiedObject.mRID ?p_mrid ; + cim:IdentifiedObject.aliasName ?name ; + cim:Equipment.EquipmentContainer/cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area ; + ^cim:Terminal.ConductingEquipment/cim:Terminal.ConnectivityNode/^cim:Terminal.ConnectivityNode/cim:Terminal.ConductingEquipment ?converter . # Extract the mRID of the terminal associated with the first winding on each power transformer - ?winding cim:PowerTransformerEnd.PowerTransformer ?p_transformer; - cim:TransformerEnd.endNumber 1; - cim:TransformerEnd.Terminal/cim:IdentifiedObject.mRID ?t_mrid . - FILTER regex(?area, '${region}') - optional {?p_transformer SN:Equipment.networkAnalysisEnable ?_transformer_analysis_enabled .} - optional {?converter SN:Equipment.networkAnalysisEnable ?_converter_analysis_enabled .} - bind(coalesce(?_transformer_analysis_enabled, True) as ?transformer_analysis_enabled) - bind(coalesce(?_converter_analysis_enabled, True) as ?converter_analysis_enabled) - filter(?transformer_analysis_enabled) - filter(?converter_analysis_enabled) + ?winding cim:PowerTransformerEnd.PowerTransformer ?p_transformer ; + cim:TransformerEnd.endNumber 1 ; + cim:TransformerEnd.Terminal/cim:IdentifiedObject.mRID ?t_mrid . + FILTER REGEX(?area,'${region}') + OPTIONAL { + ?p_transformer SN:Equipment.networkAnalysisEnable ?_transformer_analysis_enabled . + } + OPTIONAL { + ?converter SN:Equipment.networkAnalysisEnable ?_converter_analysis_enabled . + } + BIND (COALESCE(?_transformer_analysis_enabled, true) AS ?transformer_analysis_enabled) + BIND (COALESCE(?_converter_analysis_enabled, true) AS ?converter_analysis_enabled) + FILTER (?transformer_analysis_enabled = true) + FILTER (?converter_analysis_enabled = true) } diff --git a/src/cimsparql/sparql/type_mapper.sparql b/src/cimsparql/sparql/type_mapper.sparql index 0f3a13cd..4f7ac6bb 100644 --- a/src/cimsparql/sparql/type_mapper.sparql +++ b/src/cimsparql/sparql/type_mapper.sparql @@ -1,18 +1,18 @@ # Name: Type mapper -PREFIX rdf:<${rdf}> -PREFIX rdfs:<${rdfs}> -PREFIX cims:<${cims}> -select distinct ?sparql_type ?range -where { +PREFIX rdf: <${rdf}> +PREFIX rdfs: <${rdfs}> +PREFIX cims: <${cims}> +SELECT DISTINCT ?sparql_type ?range +WHERE { { ?sparql_type ^rdfs:domain/cims:dataType ?range . - ?range cims:stereotype "Primitive" + ?range cims:stereotype "Primitive" . } - union { + UNION { ?sparql_type ^rdfs:domain/cims:dataType ?_dtype . ?_dtype cims:stereotype "CIMDatatype" . - ?_dtype_value rdfs:domain ?_dtype; - rdfs:label "value"@en; - cims:dataType ?range + ?_dtype_value rdfs:domain ?_dtype ; + rdfs:label "value"@en ; + cims:dataType ?range . } } diff --git a/src/cimsparql/sparql/wind_generating_units.sparql b/src/cimsparql/sparql/wind_generating_units.sparql index 64057b6a..a8663e7c 100644 --- a/src/cimsparql/sparql/wind_generating_units.sparql +++ b/src/cimsparql/sparql/wind_generating_units.sparql @@ -1,19 +1,21 @@ # Name: Wind generating units -PREFIX cim:<${cim}> -PREFIX SN:<${SN}> -select ?mrid ?name ?market_code ?station_group ?min_p ?max_p ?plant_mrid -where { - ?wind_gen_unit a cim:WindGeneratingUnit; - cim:IdentifiedObject.mRID ?mrid; - cim:IdentifiedObject.name ?name; - cim:GeneratingUnit.maxOperatingP ?max_p; - cim:GeneratingUnit.minOperatingP ?min_p . - optional{ - ?wind_gen_unit SN:WindGeneratingUnit.WindPowerPlant/cim:IdentifiedObject.mRID ?plant_mrid; - SN:GeneratingUnit.marketCode ?market_code; - SN:GeneratingUnit.ScheduleResource/SN:ScheduleResource.marketCode ?station_group . +PREFIX cim: <${cim}> +PREFIX SN: <${SN}> +SELECT ?mrid ?name ?market_code ?station_group ?min_p ?max_p ?plant_mrid +WHERE { + ?wind_gen_unit a cim:WindGeneratingUnit ; + cim:IdentifiedObject.mRID ?mrid ; + cim:IdentifiedObject.name ?name ; + cim:GeneratingUnit.maxOperatingP ?max_p ; + cim:GeneratingUnit.minOperatingP ?min_p . + OPTIONAL { + ?wind_gen_unit SN:WindGeneratingUnit.WindPowerPlant/cim:IdentifiedObject.mRID ?plant_mrid ; + SN:GeneratingUnit.marketCode ?market_code ; + SN:GeneratingUnit.ScheduleResource/SN:ScheduleResource.marketCode ?station_group . } - optional {?wind_gen_unit SN:Equipment.networkAnalysisEnable ?_network_analysis} - filter(?network_analysis) - bind(coalesce(?_network_analysis, True) as ?network_analysis) + OPTIONAL { + ?wind_gen_unit SN:Equipment.networkAnalysisEnable ?_network_analysis . + } + FILTER (?network_analysis = true) + BIND (COALESCE(?_network_analysis, true) AS ?network_analysis) } diff --git a/src/cimsparql/sparql/winding.sparql b/src/cimsparql/sparql/winding.sparql index 1c9a7345..cfeaebd1 100644 --- a/src/cimsparql/sparql/winding.sparql +++ b/src/cimsparql/sparql/winding.sparql @@ -2,23 +2,26 @@ PREFIX cim: <${cim}> PREFIX SN: <${SN}> PREFIX xsd: <${xsd}> - -select ?p_transformer (sum(?_count) as ?count) (max(?_name) as ?name) (sum(?in_service) as ?nr_on) (sum(xsd:double(str(?sv_p))) as ?p) -where -{ - optional {?winding ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?_in_service .} . - optional {?terminal cim:ACDCTerminal.connected ?_connected .} - optional {?terminal ^cim:SvPowerFlow.Terminal/cim:SvPowerFlow.p ?_sv_p .} - +SELECT ?p_transformer (SUM(?_count) AS ?count) (MAX(?_name) AS ?name) (SUM(?in_service) AS ?nr_on) (SUM(xsd:double(STR(?sv_p))) AS ?p) +WHERE { + OPTIONAL { + ?winding ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?_in_service . + } . + OPTIONAL { + ?terminal cim:ACDCTerminal.connected ?_connected . + } + OPTIONAL { + ?terminal ^cim:SvPowerFlow.Terminal/cim:SvPowerFlow.p ?_sv_p . + } ?_eq_subject ?eq_repo . - service ?eq_repo { - ?winding cim:PowerTransformerEnd.PowerTransformer ?p_transformer; - cim:TransformerEnd.Terminal ?terminal . + SERVICE ?eq_repo { + ?winding cim:PowerTransformerEnd.PowerTransformer ?p_transformer ; + cim:TransformerEnd.Terminal ?terminal . ?p_transformer cim:IdentifiedObject.name ?_name . } - bind(coalesce(?_connected, 1) as ?connected) - bind(if(coalesce(?_in_service, ?connected), 1, 0) as ?in_service) . - bind(coalesce(?_sv_p, xsd:double(0.0)) as ?sv_p) - bind(1 as ?_count) + BIND (COALESCE(?_connected, 1) AS ?connected) + BIND (IF(COALESCE(?_in_service, ?connected),1,0) AS ?in_service) + BIND (COALESCE(?_sv_p, "0.0"^^xsd:double) AS ?sv_p) + BIND (1 AS ?_count) } -group by ?p_transformer +GROUP BY ?p_transformer diff --git a/src/cimsparql/sparql/winding_loss.sparql b/src/cimsparql/sparql/winding_loss.sparql index fb80a7a1..906ad064 100644 --- a/src/cimsparql/sparql/winding_loss.sparql +++ b/src/cimsparql/sparql/winding_loss.sparql @@ -2,27 +2,30 @@ PREFIX cim: <${cim}> PREFIX SN: <${SN}> PREFIX xsd: <${xsd}> - -select ?mrid (sum(xsd:double(str(?sv_p)))/sum(?in_service) as ?ploss_2) -where { +SELECT ?mrid (SUM(xsd:double(STR(?sv_p))) / SUM(?in_service) AS ?ploss_2) +WHERE { ?terminal cim:ACDCTerminal.connected ?connected . - optional {?terminal ^cim:SvPowerFlow.Terminal/cim:SvPowerFlow.p ?_sv_p .} - optional {?winding ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?_in_service}. - + OPTIONAL { + ?terminal ^cim:SvPowerFlow.Terminal/cim:SvPowerFlow.p ?_sv_p . + } + OPTIONAL { + ?winding ^cim:SvStatus.ConductingEquipment/cim:SvStatus.inService ?_in_service . + } ?_eq_subject ?eq_repo . - service ?eq_repo { + SERVICE ?eq_repo { # Extract mRID and area for each power transformer - - ?winding cim:PowerTransformerEnd.PowerTransformer ?p_transformer; - cim:TransformerEnd.Terminal ?terminal . + ?winding cim:PowerTransformerEnd.PowerTransformer ?p_transformer ; + cim:TransformerEnd.Terminal ?terminal . ?p_transformer cim:IdentifiedObject.mRID ?mrid ; - cim:Equipment.EquipmentContainer/cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area . - filter(regex(?area, '.*')) - optional {?p_transformer SN:Equipment.networkAnalysisEnable ?_network_analysis} + cim:Equipment.EquipmentContainer/cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area . + FILTER REGEX(?area,'.*') + OPTIONAL { + ?p_transformer SN:Equipment.networkAnalysisEnable ?_network_analysis . + } } - - bind(if(coalesce(?_in_service, ?connected), 1, 0) as ?in_service) . - bind(coalesce(?_sv_p, xsd:double(0.0)) as ?sv_p) - bind(coalesce(?_network_analysis, True) as ?network_analysis) - filter(?network_analysis) -} group by ?mrid + BIND (IF(COALESCE(?_in_service, ?connected),1,0) AS ?in_service) + BIND (COALESCE(?_sv_p, "0.0"^^xsd:double) AS ?sv_p) + BIND (COALESCE(?_network_analysis, true) AS ?network_analysis) + FILTER (?network_analysis = true) +} +GROUP BY ?mrid