Search in sources :

Example 1 with UpstreamTree

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"));
        });
    });
}
Also used : StringPair(org.openlca.ipc.handlers.Upstream.StringPair) UpstreamTree(org.openlca.core.results.UpstreamTree) UpstreamNode(org.openlca.core.results.UpstreamNode) Rpc(org.openlca.ipc.Rpc)

Example 2 with UpstreamTree

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"));
        });
    });
}
Also used : StringPair(org.openlca.ipc.handlers.Upstream.StringPair) UpstreamTree(org.openlca.core.results.UpstreamTree) UpstreamNode(org.openlca.core.results.UpstreamNode) Rpc(org.openlca.ipc.Rpc)

Example 3 with UpstreamTree

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);
}
Also used : FullResult(org.openlca.core.results.FullResult) ProductSystem(org.openlca.core.model.ProductSystem) RootDescriptor(org.openlca.core.model.descriptors.RootDescriptor) Process(org.openlca.core.model.Process) TestProcess(org.openlca.core.TestProcess) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) UpstreamTree(org.openlca.core.results.UpstreamTree) UpstreamNode(org.openlca.core.results.UpstreamNode) Contribution(org.openlca.core.results.Contribution) Test(org.junit.Test)

Aggregations

UpstreamNode (org.openlca.core.results.UpstreamNode)3 UpstreamTree (org.openlca.core.results.UpstreamTree)3 Rpc (org.openlca.ipc.Rpc)2 StringPair (org.openlca.ipc.handlers.Upstream.StringPair)2 Test (org.junit.Test)1 TestProcess (org.openlca.core.TestProcess)1 Process (org.openlca.core.model.Process)1 ProductSystem (org.openlca.core.model.ProductSystem)1 ProcessDescriptor (org.openlca.core.model.descriptors.ProcessDescriptor)1 RootDescriptor (org.openlca.core.model.descriptors.RootDescriptor)1 Contribution (org.openlca.core.results.Contribution)1 FullResult (org.openlca.core.results.FullResult)1