Skip to content

Commit

Permalink
Merge pull request #185 from msrocka/master
Browse files Browse the repository at this point in the history
fix openLCA schema mapping export
  • Loading branch information
bl-young authored Nov 20, 2023
2 parents 8aa0b10 + 8b6fb7a commit 94c2e03
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions fedelemflowlist/jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import Path
from typing import Optional
import pandas as pd
import json

try:
import olca_schema as o
Expand Down Expand Up @@ -61,23 +62,21 @@ def to_json(self) -> dict:
flow_ref = o.Ref()
flow_ref.name = self.name
if self.category is not None:
flow_ref.category_path = self.category.split('/')
flow_ref.category = self.category

# set the UUID or generate it from the attributes
if self.uid is None:
flow_ref.id = make_uuid("Flow",
self.category, self.name)
flow_ref.id = make_uuid("Flow", self.category, self.name)
else:
flow_ref.id = self.uid

json = {
'flow': flow_ref.to_json()
'flow': flow_ref.to_dict()
}
if self.unit is not None:
unit_ref = units.unit_ref(self.unit)
if unit_ref is not None:
json['unit'] = unit_ref.to_json()

json['unit'] = unit_ref.to_dict()
return json


Expand Down Expand Up @@ -210,15 +209,21 @@ def _write_mappings(self, zw: zipio.ZipWriter):

for source_list, entries in maps.items():
list_ref = o.Ref()
list_ref.o_type = 'FlowMap'
list_ref.ref_type = o.RefType.FlowMap
list_ref.name = source_list
mappings = []
flow_map = {
'@id': str(uuid.uuid4()),
'name': '%s -> Fed.LCA Commons' % source_list,
'source': list_ref.to_json(),
'source': list_ref.to_dict(),
'mappings': mappings
}
for e in entries:
mappings.append(e.to_json())
zw.write_json(flow_map, 'flow_mappings')

# an ugly hack to write the flow maps directly to the zip-file
# as there are currenty only methods for writing RootEntity
# objects in the ZipWriter
zw._ZipWriter__zip.writestr(
"flow_mappings/" + flow_map["@id"] + ".json",
json.dumps(flow_map))

0 comments on commit 94c2e03

Please sign in to comment.