Search in sources :

Example 1 with LocationResult

use of org.openlca.core.results.LocationResult 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 LocationResult

use of org.openlca.core.results.LocationResult 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)

Aggregations

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