Open michaelweinold opened 2 months ago
...maybe there is a way propagate edits from the table back to the dict of dicts, which is returned by NewNodeEachVisitGraphTraversal.calculate(lca, cutoff=0.01)
. Would this make it easier to re-compute upstream Supply Amounts
and the overall score?
{'nodes': {-1: Node(unique_id=-1, activity_datapackage_id=-1, activity_index=-1, reference_product_datapackage_id=-1, reference_product_index=-1, reference_product_production_amount=1.0, depth=0, supply_amount=1.0, cumulative_score=0.3768834121437975, direct_emissions_score=0.0, direct_emissions_score_outside_specific_flows=0.0, remaining_cumulative_score_outside_specific_flows=0.0, terminal=False),
0: Node(unique_id=0, activity_datapackage_id=235, activity_index=234, reference_product_datapackage_id=542, reference_product_index=153, reference_product_production_amount=0.9988390803337097, depth=1, supply_amount=1.0011622689671917, cumulative_score=0.3768834121437976, direct_emissions_score=0.015464815391143152, direct_emissions_score_outside_specific_flows=1.0495129317330404e-05, remaining_cumulative_score_outside_specific_flows=0.3614290918819718, terminal=False),
1: Node(unique_id=1, activity_datapackage_id=79, activity_index=78, reference_product_datapackage_id=431, reference_product_index=42, reference_product_production_amount=0.9359190464019775, depth=2, supply_amount=0.013377550027867835, cumulative_score=0.004254062537767607, direct_emissions_score=0.00012451661922425745, direct_emissions_score_outside_specific_flows=3.694040387367938e-06, remaining_cumulative_score_outside_specific_flows=0.004133239958930717, terminal=True),
2: Node(unique_id=2, activity_datapackage_id=311, activity_index=310, reference_product_datapackage_id=435, reference_product_index=46, reference_product_production_amount=0.9928678274154663, depth=2, supply_amount=0.09230018343308832, cumulative_score=0.041779131103952524, direct_emissions_score=0.001482884746645427, direct_emissions_score_outside_specific_flows=4.342210964385475e-05, remaining_cumulative_score_outside_specific_flows=0.04033966846695095, terminal=False),
(...)
'edges': [Edge(consumer_index=-1, consumer_unique_id=-1, producer_index=234, producer_unique_id=0, product_index=153, amount=1),
Edge(consumer_index=234, consumer_unique_id=0, producer_index=78, producer_unique_id=1, product_index=42, amount=0.012520303865276812),
Edge(consumer_index=234, consumer_unique_id=0, producer_index=310, producer_unique_id=2,
(...)
'flows': [Flow(flow_datapackage_id=1726, flow_index=947, activity_unique_id=19, activity_id=374, activity_index=373, amount=0.016917697121138834, score=0.016917697121138834),
Flow(flow_datapackage_id=1726, flow_index=947, activity_unique_id=3, activity_id=301, activity_index=300, amount=0.013172648927940041, score=0.013172648927940041),
Flow(flow_datapackage_id=1726, flow_index=947, activity_unique_id=4, activity_id=53, activity_index=52, amount=0.007941925100944729, score=0.007941925100944729),
(...)
}
Any time you change the matrix you need to start graph traversal again. It will break the matrix factorization cache, and change all LCA results.
I would do this by keeping a separate datapackage in memory, following https://github.com/brightway-lca/from-the-ground-up/blob/main/2%20-%20Building%20and%20using%20matrices%20in%20bw2calc.ipynb, as then you don't need to touch the SQLite database.
Currently, the dashboard returns a list of nodes in the supply chain tree like so:
The user should be able to say:
and then edit this
Supply Amount
in the second row.Of course, this would mean that correspondingly less
Supply Amount
of all activities feeding intoPaper
would be required. Of course, all this would also affect the overall LCA score.