GreenDelta / olca-schema

Other
14 stars 7 forks source link

Exchange lost its @type property #7

Open dt-woods opened 7 months ago

dt-woods commented 7 months ago

In a side project of upgrading old olca-schema to the latest version, I found myself running into some errors with JSON-LD imports, so I began to dig around in the differences in the JSON syntax of the process that works and the new version of the process that seemingly doesn't. The two nearly identical processes contain a list of exchanges. The first thing that jumps out as a difference is the missing @type property in the Exchange dictionaries.

For example, where a and b are two versions of the same process and the difference in the first (internalID) exchange is the missing @type property in a (the one in the JSON-LD that's crashing upon import).

>>> a['exchanges'][0]
{'amount': 6.813212415538652e-11,
 'description': 'netl, 2016',
 'dqEntry': '(1;nan;1;1;2)',
 'flow': {'@type': 'Flow',
  '@id': '663b55b1-648c-348f-a79d-9d44bcdaeb64',
  'category': 'Elementary Flows/emission/air',
  'name': '1,1,1,2-Tetrachloroethane'},
 'flowProperty': {'@type': 'FlowProperty',
  '@id': '93a60a56-a3c8-11da-a746-0800200b9a66',
  'name': 'Mass'},
 'internalId': 1,
 'isAvoidedProduct': False,
 'isInput': False,
 'isQuantitativeReference': False,
 'unit': {'@type': 'Unit',
  '@id': '20aadc24-a391-41cf-b340-3e4529f44bde',
  'name': 'kg'}}
>>> b['exchanges'][568]
{'@type': 'Exchange',    # <- see, here it is in the working copy
 'isAvoidedProduct': False,
 'isInput': False,
 'amount': 6.813212415538652e-11,
 'dqEntry': '(1;nan;1;1;1)',
 'description': 'netl,ap42,eGRID - 2016',
 'internalId': 1,
 'flow': {'@type': 'Flow',
  '@id': '663b55b1-648c-348f-a79d-9d44bcdaeb64',
  'name': '1,1,1,2-Tetrachloroethane',
  'category': 'Elementary Flows/emission/air',
  'flowType': 'ELEMENTARY_FLOW',
  'refUnit': 'kg'},
 'unit': {'@type': 'Unit',
  '@id': '20aadc24-a391-41cf-b340-3e4529f44bde',
  'name': 'kg'},
 'flowProperty': {'@type': 'FlowProperty',
  '@id': '93a60a56-a3c8-11da-a746-0800200b9a66',
  'name': 'Mass',
  'category': 'Technical flow properties',
  'refUnit': 'kg'}}

I took a look at the documentation and, sure enough, the @type property for an Exchange is still a thing. See here.

Sometimes these hidden properties don't show themselves right away, so I took a look at the to_dict methods for a new exchange.

>>> import olca-schema as o
>>> o.Exchange.from_dict({'isInput': False, 'amount': 1.0, 'description': "Lorem ipsum"}).to_dict()
{'amount': 1.0, 'description': 'Lorem ipsum', 'isInput': False}

So no @type property. To make sure I am not crazy, I tested a random flow:

>>> o.Flow().to_dict()
{'@type': 'Flow',
 '@id': 'bd3e8209-2eea-4b06-946c-fa6d4a32f51b',
 'lastChange': '2023-11-21T22:36:17.329856Z',
 'version': '01.00.000'}

Here's that @type property for an olca-schema element.

My question is, how important is this type field? I know Exchange isn't a root entity, so it doesn't get its own folder, but I'm a little concerned that this might be what's giving me some trouble.

Thanks for your time and assistance!