Skip to content

Commit

Permalink
fix: fix bug in data model that assumed that the market_unit_mrid was…
Browse files Browse the repository at this point in the history
… unique. This is not the case for loads, since they are in a load group and the load group is associated with a schedule resource
  • Loading branch information
davidkleiven committed Jan 15, 2025
1 parent 93df033 commit 6f94a55
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/cimsparql/adaptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ def set_generation_type(self) -> None:
"""
)

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 @@ -427,7 +427,7 @@ class GenUnitAndSyncMachineMridSchema(CoercingSchema):

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:NonConformLoadGroup.LoadGroup ?created_group
}
}
where {
?load a cim:EnergyConsumer .
?created_group cim:IdentifiedObject.name "created-group" .
filter not exists{?load cim:NonConformLoadGroup.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-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

0 comments on commit 6f94a55

Please sign in to comment.