Search in sources :

Example 1 with RpcRequest

use of org.openlca.ipc.RpcRequest in project olca-modules by GreenDelta.

the class ImpactHandler method getLocationContributions.

@Rpc("get/impacts/contributions/locations")
public RpcResponse getLocationContributions(RpcRequest req) {
    return utils.contributionImpact(req, (result, impact, cache) -> {
        LocationResult r = new LocationResult(result, cache.db);
        List<Contribution<LocationDescriptor>> contributions = utils.toDescriptors(r.getContributions(impact));
        contributions = utils.filter(contributions, contribution -> contribution.amount != 0);
        return JsonRpc.encode(contributions, cache, json -> json.addProperty("unit", impact.referenceUnit));
    });
}
Also used : UpstreamNode(org.openlca.core.results.UpstreamNode) RpcRequest(org.openlca.ipc.RpcRequest) ImpactValue(org.openlca.core.results.ImpactValue) UpstreamTree(org.openlca.core.results.UpstreamTree) LocationDescriptor(org.openlca.core.model.descriptors.LocationDescriptor) Rpc(org.openlca.ipc.Rpc) HashMap(java.util.HashMap) LocationResult(org.openlca.core.results.LocationResult) RpcResponse(org.openlca.ipc.RpcResponse) RootDescriptor(org.openlca.core.model.descriptors.RootDescriptor) ArrayList(java.util.ArrayList) StringPair(org.openlca.ipc.handlers.Upstream.StringPair) List(java.util.List) JsonArray(com.google.gson.JsonArray) EnviFlow(org.openlca.core.matrix.index.EnviFlow) ContributionResult(org.openlca.core.results.ContributionResult) Contribution(org.openlca.core.results.Contribution) Map(java.util.Map) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) Contribution(org.openlca.core.results.Contribution) LocationResult(org.openlca.core.results.LocationResult) Rpc(org.openlca.ipc.Rpc)

Example 2 with RpcRequest

use of org.openlca.ipc.RpcRequest in project olca-modules by GreenDelta.

the class ImpactHandler method getProcessResultsImpacts.

@Rpc("get/impacts/process_results")
public RpcResponse getProcessResultsImpacts(RpcRequest req) {
    return utils.fullProcess(req, (result, process, cache) -> {
        JsonArray contributions = new JsonArray();
        result.getImpacts().forEach(impact -> {
            double total = result.getTotalImpactResult(impact);
            if (total == 0)
                return;
            Contribution<ImpactDescriptor> c = new Contribution<>();
            c.item = impact;
            c.amount = result.getDirectImpactResult(process, impact);
            c.share = c.amount / total;
            if (c.amount == 0)
                return;
            contributions.add(JsonRpc.encode(c, cache, json -> {
                json.addProperty("unit", impact.referenceUnit);
                json.addProperty("upstream", result.getUpstreamImpactResult(process, impact));
            }));
        });
        return contributions;
    });
}
Also used : JsonArray(com.google.gson.JsonArray) UpstreamNode(org.openlca.core.results.UpstreamNode) RpcRequest(org.openlca.ipc.RpcRequest) ImpactValue(org.openlca.core.results.ImpactValue) UpstreamTree(org.openlca.core.results.UpstreamTree) LocationDescriptor(org.openlca.core.model.descriptors.LocationDescriptor) Rpc(org.openlca.ipc.Rpc) HashMap(java.util.HashMap) LocationResult(org.openlca.core.results.LocationResult) RpcResponse(org.openlca.ipc.RpcResponse) RootDescriptor(org.openlca.core.model.descriptors.RootDescriptor) ArrayList(java.util.ArrayList) StringPair(org.openlca.ipc.handlers.Upstream.StringPair) List(java.util.List) JsonArray(com.google.gson.JsonArray) EnviFlow(org.openlca.core.matrix.index.EnviFlow) ContributionResult(org.openlca.core.results.ContributionResult) Contribution(org.openlca.core.results.Contribution) Map(java.util.Map) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) Contribution(org.openlca.core.results.Contribution) Rpc(org.openlca.ipc.Rpc)

Example 3 with RpcRequest

use of org.openlca.ipc.RpcRequest in project olca-modules by GreenDelta.

the class InventoryHandler method getLocationContributions.

@Rpc("get/inventory/contributions/locations")
public RpcResponse getLocationContributions(RpcRequest req) {
    return utils.contributionFlow(req, (result, flow, cache) -> {
        LocationResult r = new LocationResult(result, cache.db);
        List<Contribution<LocationDescriptor>> cons = utils.toDescriptors(r.getContributions(flow.flow()));
        cons = utils.filter(cons, c -> c.amount != 0);
        String unit = utils.getUnit(flow, cache);
        return JsonRpc.encode(cons, cache, json -> json.addProperty("unit", unit));
    });
}
Also used : UpstreamNode(org.openlca.core.results.UpstreamNode) RpcRequest(org.openlca.ipc.RpcRequest) UpstreamTree(org.openlca.core.results.UpstreamTree) LocationDescriptor(org.openlca.core.model.descriptors.LocationDescriptor) FlowValue(org.openlca.core.results.FlowValue) Rpc(org.openlca.ipc.Rpc) LocationResult(org.openlca.core.results.LocationResult) RpcResponse(org.openlca.ipc.RpcResponse) RootDescriptor(org.openlca.core.model.descriptors.RootDescriptor) ArrayList(java.util.ArrayList) StringPair(org.openlca.ipc.handlers.Upstream.StringPair) List(java.util.List) JsonArray(com.google.gson.JsonArray) Contribution(org.openlca.core.results.Contribution) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) Contribution(org.openlca.core.results.Contribution) LocationResult(org.openlca.core.results.LocationResult) Rpc(org.openlca.ipc.Rpc)

Example 4 with RpcRequest

use of org.openlca.ipc.RpcRequest in project olca-modules by GreenDelta.

the class InventoryHandler method getProcessResults.

private RpcResponse getProcessResults(RpcRequest req, boolean input) {
    return utils.fullProcess(req, (result, process, cache) -> {
        JsonArray contributions = new JsonArray();
        result.enviIndex().each((i, f) -> {
            if (f.isInput() != input)
                return;
            double total = result.getTotalFlowResult(f);
            if (total == 0)
                return;
            Contribution<FlowDescriptor> c = new Contribution<>();
            c.item = f.flow();
            c.amount = result.getDirectFlowResult(process, f);
            c.share = c.amount / total;
            if (c.amount == 0)
                return;
            String unit = utils.getUnit(f, cache);
            contributions.add(JsonRpc.encode(c, cache, json -> {
                json.addProperty("unit", unit);
                json.addProperty("upstream", result.getUpstreamFlowResult(process, f));
            }));
        });
        return contributions;
    });
}
Also used : JsonArray(com.google.gson.JsonArray) UpstreamNode(org.openlca.core.results.UpstreamNode) RpcRequest(org.openlca.ipc.RpcRequest) UpstreamTree(org.openlca.core.results.UpstreamTree) LocationDescriptor(org.openlca.core.model.descriptors.LocationDescriptor) FlowValue(org.openlca.core.results.FlowValue) Rpc(org.openlca.ipc.Rpc) LocationResult(org.openlca.core.results.LocationResult) RpcResponse(org.openlca.ipc.RpcResponse) RootDescriptor(org.openlca.core.model.descriptors.RootDescriptor) ArrayList(java.util.ArrayList) StringPair(org.openlca.ipc.handlers.Upstream.StringPair) List(java.util.List) JsonArray(com.google.gson.JsonArray) Contribution(org.openlca.core.results.Contribution) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) Contribution(org.openlca.core.results.Contribution)

Aggregations

JsonArray (com.google.gson.JsonArray)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 FlowDescriptor (org.openlca.core.model.descriptors.FlowDescriptor)4 LocationDescriptor (org.openlca.core.model.descriptors.LocationDescriptor)4 ProcessDescriptor (org.openlca.core.model.descriptors.ProcessDescriptor)4 RootDescriptor (org.openlca.core.model.descriptors.RootDescriptor)4 Contribution (org.openlca.core.results.Contribution)4 LocationResult (org.openlca.core.results.LocationResult)4 UpstreamNode (org.openlca.core.results.UpstreamNode)4 UpstreamTree (org.openlca.core.results.UpstreamTree)4 Rpc (org.openlca.ipc.Rpc)4 RpcRequest (org.openlca.ipc.RpcRequest)4 RpcResponse (org.openlca.ipc.RpcResponse)4 StringPair (org.openlca.ipc.handlers.Upstream.StringPair)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 EnviFlow (org.openlca.core.matrix.index.EnviFlow)2 ImpactDescriptor (org.openlca.core.model.descriptors.ImpactDescriptor)2 ContributionResult (org.openlca.core.results.ContributionResult)2