+1 vote
38 views

Hello,

I'm trying to add ImpactFactors to LCIA methods via IPC (using the Python "olca" library).

What I'm doing is getting the method, then the ImpactCategories via IPC. I add an ImpactFactor to the impact_factor property of the ImpactCategory object, then update the ImpactCategory, but nothing happens : when I request the ImpactCategory back, it contains the same ImpactFactors as before (mine is not there).

The HTTP request log (below) shows that my ImpactFactor (the last one) is correctly sent. 

2019-03-25 07:02:14 DEBUG    http://openlca:8080 "POST / HTTP/1.1" 200 None
2019-03-25 07:02:14 DEBUG    Starting new HTTP connection (1): openlca:8080
send: b'POST / HTTP/1.1\r\nHost: openlca:8080\r\nUser-Agent: python-requests/2.20.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-Length: 14473\r\nContent-Type: application/json\r\n\r\n'
send: b'{"jsonrpc": "2.0", "id": 13, "method": "update/model", "params": {"@type": "ImpactCategory", "@id": "b5f6e767-96b3-3b60-b44f-213e6a659a99", "name": "Natural land transformation - ReCiPe Midpoint (H)", "version": "00.00.000", "referenceUnitName": "m2", "impactFactors": [{"@type": "ImpactFactor", "flow": {"@type": "FlowRef", "@id": "e3c1224d-1958-4fbb-b0e3-91943e5975c7", "name": "Transformation, to tropical rain forest", "categoryPath": ["Elementary flows", "Resource", "unspecified"], "refUnit": "m2", "flowType": "ELEMENTARY_FLOW"}, "flowProperty": {"@type": "Ref", "@id": "93a60a56-a3c8-19da-a746-0800200c9a66", "name": "Area", "categoryPath": ["Technical flow properties"]}, "unit": {"@type": "Ref", "@id": "3ce61faa-5716-41c1-aef6-b5920054acc9", "name": "m2"}, "value": -1.0}, ..., {"@type": "ImpactFactor", "flow": {"@type": "FlowRef", "@id": "2299398e-0846-4290-bcab-09bda2e61ee3", "name": "Transformation, to unknown", "categoryPath": ["Elementary flows", "Resource", "unspecified"], "refUnit": "m2", "flowType": "ELEMENTARY_FLOW"}, "flowProperty": {"@type": "Ref", "@id": "93a60a56-a3c8-19da-a746-0800200c9a66", "name": "Area", "categoryPath": ["Technical flow properties"]}, "unit": {"@type": "Ref", "@id": "3ce61faa-5716-41c1-aef6-b5920054acc9", "name": "m2"}, "value": -0.4}, {"@type": "ImpactFactor", "flow": {"@type": "Ref", "@id": "86cb7772-78ca-4b30-92e8-5976559846e5"}, "flowProperty": {"@type": "Ref", "@id": "01846770-4cfe-4a25-8ad9-919d8d378345", "name": "Number of items", "categoryPath": ["Technical flow properties"]}, "unit": {"@type": "Ref", "@id": "6dabe201-aaac-4509-92f0-d00c26cb72ab", "name": "Item(s)"}, "value": 1.0}]}}'
reply: 'HTTP/1.1 200 OK \r\n'

There is not much to see in the OpenLCA log (set to show "all"):

TRACE [07:04:32.743] @org.openlca.ipc.Server>serve>104 - handle request 25/update/model
TRACE [07:04:32.744] @org.openlca.ipc.Server>getResponse>118 - Call method update/model
TRACE [07:04:32.751] @org.openlca.ipc.Server>serve>104 - handle request 26/get/model
TRACE [07:04:32.753] @org.openlca.ipc.Server>getResponse>118 - Call method get/model
TRACE [07:04:32.754] @org.openlca.core.database.Query>getAll>61 - Get all class org.openlca.core.model.ImpactCategory with query select e from ImpactCategory e where e.refId = :refId
DEBUG [07:04:32.755] @org.openlca.core.database.Query>getAll>70 - 1 results
TRACE [07:04:32.756] @org.openlca.core.database.EntityCache$Loader>registerDescriptorDaos>159 - register descriptor DAOs
TRACE [07:04:32.756] @org.openlca.core.database.EntityCache$Loader>getDao>259 - register class class org.openlca.core.model.Category
TRACE [07:04:32.757] @org.openlca.core.database.BaseDao>getForId>173 - get class org.openlca.core.model.Category for id=1001
TRACE [07:04:32.758] @org.openlca.core.database.EntityCache$Loader>getDao>259 - register class class org.openlca.core.model.FlowProperty
TRACE [07:04:32.758] @org.openlca.core.database.BaseDao>getForId>173 - get class org.openlca.core.model.FlowProperty for id=1240
TRACE [07:04:32.758] @org.openlca.core.database.BaseDao>getForId>173 - get class org.openlca.core.model.Category for id=991
TRACE [07:04:32.759] @org.openlca.core.database.BaseDao>getForId>173 - get class org.openlca.core.model.Category for id=973

in openLCA by (170 points)
retagged by
by (170 points)
Thank you for answering. I tried that, and it removed all ImpactCategories on the method.
You can try it with this simple test :

import olca
client = olca.Client(8080)
client.url = 'http://%s:%i' % ('openlca', 8080)

# Get the 'TRACI' method, which at this point has the default ImpactCategories :
olca_method = client.get(olca.ImpactMethod, 'a36e90a3-5419-3b08-8244-d18d8b029226')

# Just save it as we got it
client.update(olca_method)

# Now the 'TRACI' method has no ImpactCategories anymore

1 Answer

+2 votes
by (2.6k points)
selected by
 
Best answer
this is an error in openLCA, I created this issue: https://github.com/GreenDelta/olca-app/issues/79

I will let you know when this is fixed
by (170 points)
Awesome, thank you very much.
...