Skip to content

Commit

Permalink
Merge pull request #30 from rl-institut/features/update-foreign-keys
Browse files Browse the repository at this point in the history
Features/update foreign keys
  • Loading branch information
jnnr authored Sep 14, 2021
2 parents a4e3fae + 5488156 commit b3b8da5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion oemoflex/model/datapackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ def setup_default(
components=components,
)

def infer_metadata(self):
def infer_metadata(self, foreign_keys_update=None):
infer(
select_components=self.components,
package_name=self.name,
path=self.basepath,
foreign_keys_update=foreign_keys_update,
)

def parametrize(self, frame, column, values):
Expand Down
3 changes: 3 additions & 0 deletions oemoflex/model/foreign_keys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
'electricity-liion_battery',
'hydro-reservoir',
'electricity-bev',
'hydro-ror',
'ch4-excess',
]

'profile': [
Expand All @@ -21,6 +23,7 @@
'solar-pv',
'electricity-demand',
'hydro-reservoir',
'hydro-ror',
'heat-demand',
]

Expand Down
9 changes: 8 additions & 1 deletion oemoflex/model/inferring.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
all_foreign_keys = load_yaml(os.path.join(module_path, FOREIGN_KEYS))


def infer(select_components, package_name, path):
def infer(select_components, package_name, path, foreign_keys_update=None):

if foreign_keys_update:
for key, value in all_foreign_keys.items():
if key in foreign_keys_update:
value.extend(foreign_keys_update[key])

print("Updated foreign keys.")

foreign_keys = {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name,bus,capacity,carrier,marginal_cost,output_parameters,region,tech,type
A-electricity-shortage,A-electricity,,electricity,,,A,shortage,shortage
B-electricity-shortage,B-electricity,,electricity,,,B,shortage,shortage
A-electricity-shortage,A-electricity,,electricity,,{},A,shortage,shortage
B-electricity-shortage,B-electricity,,electricity,,{},B,shortage,shortage
4 changes: 2 additions & 2 deletions tests/_files/default_edp/data/elements/heat-shortage.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name,bus,capacity,carrier,marginal_cost,output_parameters,region,tech,type
A-heat-shortage,A-heat,,heat,,,A,shortage,shortage
B-heat-shortage,B-heat,,heat,,,B,shortage,shortage
A-heat-shortage,A-heat,,heat,,{},A,shortage,shortage
B-heat-shortage,B-heat,,heat,,{},B,shortage,shortage

0 comments on commit b3b8da5

Please sign in to comment.