Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix bug in data model that assumed that the market_unit_mrid was… #330

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/cimsparql/adaptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
from string import Template
from typing import TYPE_CHECKING

from rdflib import ConjunctiveGraph

Check failure on line 13 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "rdflib" could not be resolved (reportMissingImports)

Check failure on line 13 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "rdflib" could not be resolved (reportMissingImports)

Check failure on line 13 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "rdflib" could not be resolved (reportMissingImports)

Check failure on line 13 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "rdflib" could not be resolved (reportMissingImports)
from rdflib.namespace import XSD

Check failure on line 14 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "rdflib.namespace" could not be resolved (reportMissingImports)

Check failure on line 14 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "rdflib.namespace" could not be resolved (reportMissingImports)

Check failure on line 14 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "rdflib.namespace" could not be resolved (reportMissingImports)

Check failure on line 14 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "rdflib.namespace" could not be resolved (reportMissingImports)
from rdflib.plugins.sparql import prepareUpdate

Check failure on line 15 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "rdflib.plugins.sparql" could not be resolved (reportMissingImports)

Check failure on line 15 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "rdflib.plugins.sparql" could not be resolved (reportMissingImports)

Check failure on line 15 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "rdflib.plugins.sparql" could not be resolved (reportMissingImports)

Check failure on line 15 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "rdflib.plugins.sparql" could not be resolved (reportMissingImports)
from rdflib.query import ResultRow

Check failure on line 16 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "rdflib.query" could not be resolved (reportMissingImports)

Check failure on line 16 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "rdflib.query" could not be resolved (reportMissingImports)

Check failure on line 16 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "rdflib.query" could not be resolved (reportMissingImports)

Check failure on line 16 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "rdflib.query" could not be resolved (reportMissingImports)
from rdflib.term import BNode, Literal, URIRef

Check failure on line 17 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "rdflib.term" could not be resolved (reportMissingImports)

Check failure on line 17 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "rdflib.term" could not be resolved (reportMissingImports)

Check failure on line 17 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "rdflib.term" could not be resolved (reportMissingImports)

Check failure on line 17 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "rdflib.term" could not be resolved (reportMissingImports)

from cimsparql.graphdb import default_namespaces

if TYPE_CHECKING:
from collections.abc import Iterable

from rdflib import Graph

Check failure on line 24 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "rdflib" could not be resolved (reportMissingImports)

Check failure on line 24 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "rdflib" could not be resolved (reportMissingImports)

Check failure on line 24 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "rdflib" could not be resolved (reportMissingImports)

Check failure on line 24 in src/cimsparql/adaptions.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "rdflib" could not be resolved (reportMissingImports)


class XmlModelAdaptor:
Expand Down Expand Up @@ -71,10 +71,15 @@
"""
)

def add_market_code_to_non_conform_load(self) -> None:
self.update_graph("add_non_conform_load_group.sparql")
self.update_graph("add_market_code_for_load_groups.sparql")

def adapt(self, eq_uri: str) -> None:
self.add_zero_sv_power_flow()
self.add_zero_sv_injection()
self.add_generating_unit()
self.add_market_code_to_non_conform_load()
self.add_mrid()
self.add_dtypes()
self.set_generation_type()
Expand Down
2 changes: 1 addition & 1 deletion src/cimsparql/data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import datetime as dt
from typing import Self

import pandera as pa

Check failure on line 6 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "pandera" could not be resolved (reportMissingImports)

Check failure on line 6 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "pandera" could not be resolved (reportMissingImports)

Check failure on line 6 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "pandera" could not be resolved (reportMissingImports)

Check failure on line 6 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "pandera" could not be resolved (reportMissingImports)
from pandera.api.pandas.model_config import BaseConfig

Check failure on line 7 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "pandera.api.pandas.model_config" could not be resolved (reportMissingImports)

Check failure on line 7 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "pandera.api.pandas.model_config" could not be resolved (reportMissingImports)

Check failure on line 7 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "pandera.api.pandas.model_config" could not be resolved (reportMissingImports)

Check failure on line 7 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "pandera.api.pandas.model_config" could not be resolved (reportMissingImports)
from pandera.typing import DataFrame, Index, Series

Check failure on line 8 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "pandera.typing" could not be resolved (reportMissingImports)

Check failure on line 8 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "pandera.typing" could not be resolved (reportMissingImports)

Check failure on line 8 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "pandera.typing" could not be resolved (reportMissingImports)

Check failure on line 8 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "pandera.typing" could not be resolved (reportMissingImports)


class CoercingSchema(pa.DataFrameModel):
Expand Down Expand Up @@ -427,7 +427,7 @@

class StationGroupForPowerUnitSchema(CoercingSchema):
power_system_model_mrid: str = pa.Field(unique=True)
market_unit_mrid: str = pa.Field(unique=True)
market_unit_mrid: str = pa.Field()
resource_name: str
market_code: str

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
prefix cim:<${cim}>
prefix SN:<${SN}>

# Assign all loads that does not have a load group to the newly created load group
insert {
graph <http://cimsparql/xml-adpator/EQ-modifications> {
?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}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix cim:<${cim}>
prefix SN:<${SN}>

# Create a load group
insert data {
graph <http://cimsparql/xml-adpator/EQ-modifications> {
_:b0 a cim:NonConformLoadGroup;
cim:IdentifiedObject.name "created-group";
SN:NonConformLoadGroup.ScheduleResource _:b1 .
_:b1 SN:ScheduleResource.marketCode "created-load-resource-mcode"
}
}
2 changes: 1 addition & 1 deletion tests/test_micro_t1_nl.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,4 @@ def test_station_group_for_power_unit(test_model: t_common.ModelTest) -> None:
assert test_model.model

group_for_units = test_model.model.station_group_for_power_unit()
assert len(group_for_units) == 4
assert len(group_for_units) == 10
8 changes: 8 additions & 0 deletions tests/test_xml_adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,11 @@ def test_add_generating_unit(xml_adaptor: XmlModelAdaptor) -> None:
xml_adaptor.add_generating_unit()
query = "select * {?machine cim:SynchronousMachine.GeneratingUnit ?unit}"
assert len(xml_adaptor.graph.query(query, initNs=xml_adaptor.namespaces())) > 0


def test_add_market_code_to_non_conform_load(xml_adaptor: XmlModelAdaptor) -> None:
query = "select * {?group SN:NonConformLoadGroup.ScheduleResource/SN:ScheduleResource.marketCode ?code}"
assert len(xml_adaptor.graph.query(query, initNs=xml_adaptor.namespaces())) == 0

xml_adaptor.add_market_code_to_non_conform_load()
assert len(xml_adaptor.graph.query(query, initNs=xml_adaptor.namespaces())) == 1
Loading