use of org.openlca.core.results.UpstreamTree in project olca-modules by GreenDelta.
the class ImpactHandler method getUpstream.
@Rpc("get/impacts/upstream")
public RpcResponse getUpstream(RpcRequest req) {
return utils.fullImpact(req, (result, impact, cache) -> {
List<StringPair> products = utils.parseProducts(req);
UpstreamTree tree = result.getTree(impact);
List<UpstreamNode> results = Upstream.calculate(tree, products);
return JsonRpc.encode(results, tree, cache, json -> {
json.addProperty("unit", impact.referenceUnit);
json.add("upstream", json.remove("amount"));
});
});
}
use of org.openlca.core.results.UpstreamTree in project olca-modules by GreenDelta.
the class InventoryHandler method getUpstream.
@Rpc("get/inventory/upstream")
public RpcResponse getUpstream(RpcRequest req) {
return utils.fullFlow(req, (result, flow, cache) -> {
List<StringPair> products = utils.parseProducts(req);
UpstreamTree tree = result.getTree(flow);
List<UpstreamNode> results = Upstream.calculate(tree, products);
String unit = utils.getUnit(flow, cache);
return JsonRpc.encode(results, tree, cache, json -> {
json.addProperty("unit", unit);
json.add("upstream", json.remove("amount"));
});
});
}
use of org.openlca.core.results.UpstreamTree in project olca-modules by GreenDelta.
the class CostTests method testSingleProcess.
@Test
public void testSingleProcess() {
Process p1 = TestProcess.refProduct("p1", 1, "kg").addCosts("p1", 2, "EUR").elemIn("water", 1, "m3").addCosts("water", 5, "EUR").get();
ProductSystem system = TestSystem.of(p1).get();
FullResult r = TestSystem.calculate(system);
Assert.assertEquals(3, r.totalCosts(), 1e-10);
ProcessDescriptor d1 = Descriptor.of(p1);
Assert.assertEquals(3, r.getUpstreamCostResult(d1), 1e-10);
Assert.assertEquals(3, r.getDirectCostResult(d1), 1e-10);
UpstreamTree tree = r.getCostTree();
UpstreamNode root = tree.root;
Assert.assertTrue(tree.childs(root).isEmpty());
Assert.assertEquals(3, root.result(), 1e-10);
List<Contribution<RootDescriptor>> contributions = r.getProcessCostContributions();
Assert.assertEquals(1, contributions.size());
Contribution<RootDescriptor> item = contributions.get(0);
Assert.assertEquals(3, item.amount, 1e-10);
Assert.assertEquals(1, item.share, 1e-10);
}
Aggregations