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));
});
}
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;
});
}
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));
});
}
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;
});
}
Aggregations