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

Look up types defined only on parent templates #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 27 additions & 0 deletions hydra_pywr/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,33 @@ def __init__(self, client, network, network_id, scenario_id, attributes, templat
for tt in self.template.templatetypes:
self.type_id_map[tt.id] = tt

# Some types may be defined on parent templates
# Identify these and add to type_id_map

pending_types = {}
for tt in self.type_id_map.values():
parent_type = None
if hasattr(tt, "parent_id") and tt.parent_id is not None and tt.resource_type != "NETWORK":
parent_template_id = self.template.parent_id
while parent_template_id and not parent_type:
try:
parent_type = self.hydra.get_templatetype_by_name(
template_id=parent_template_id,
type_name=tt.name)
break
except RequestError:
# Type is not defined on immediate parent, so ascend
ptemp = self.hydra.get_template(template_id=parent_template_id)
parent_template_id = ptemp.parent_id

if parent_type:
pending_types[parent_type.id] = parent_type
else:
raise TypeError(f"Type '{tt.name}' with id {tt.id} not defined "
f"on template {self.template.id} or any parent template")

self.type_id_map.update(pending_types)

self.attr_unit_map = {}
self.hydra_node_by_id = {}

Expand Down