use of org.openlca.core.model.descriptors.FlowDescriptor in project olca-modules by GreenDelta.
the class StatusTest method testCsvIO.
@Test
public void testCsvIO() throws Exception {
var sourceFlow = new FlowRef();
sourceFlow.flow = new FlowDescriptor();
sourceFlow.flow.refId = "source";
sourceFlow.status = MappingStatus.warn("the source flow");
var targetFlow = new FlowRef();
targetFlow.flow = new FlowDescriptor();
targetFlow.flow.refId = "target";
targetFlow.status = MappingStatus.error("the target flow");
FlowMap map = new FlowMap();
map.entries.add(new FlowMapEntry(sourceFlow, targetFlow, 42));
File tmpFile = Files.createTempFile("_olca_" + getClass().getSimpleName(), ".csv").toFile();
FlowMap.toCsv(map, tmpFile);
map = FlowMap.fromCsv(tmpFile);
var e = map.entries.get(0);
assertTrue(tmpFile.delete());
assertEquals(MappingStatus.warn("the source flow"), e.sourceFlow().status);
assertEquals(MappingStatus.error("the target flow"), e.targetFlow().status);
}
use of org.openlca.core.model.descriptors.FlowDescriptor in project olca-modules by GreenDelta.
the class FlowInfo method getAll.
public static List<FlowInfo> getAll(SystemExportConfig conf, EnviIndex index) {
EntityCache cache = conf.getEntityCache();
Set<FlowDescriptor> flows = getFlowDescriptors(index);
List<FlowInfo> infos = new ArrayList<>();
for (FlowDescriptor flow : flows) {
CategoryPair catPair = CategoryPair.create(flow, cache);
FlowInfo info = new FlowInfo();
info.realId = flow.id;
info.id = flow.refId;
info.name = flow.name;
info.category = catPair.getCategory();
info.subCategory = catPair.getSubCategory();
if (flow.location != null) {
Location location = cache.get(Location.class, flow.location);
if (location != null)
info.location = location.code;
}
String unit = DisplayValues.referenceUnit(flow, cache);
info.unit = unit;
infos.add(info);
}
return infos;
}
use of org.openlca.core.model.descriptors.FlowDescriptor in project olca-modules by GreenDelta.
the class ProductInfo method getAll.
public static List<ProductInfo> getAll(SystemExportConfig conf, TechIndex index) {
EntityCache cache = conf.getEntityCache();
List<ProductInfo> infos = new ArrayList<>(index.size() + 2);
for (int i = 0; i < index.size(); i++) {
TechFlow pair = index.at(i);
RootDescriptor process = pair.provider();
FlowDescriptor product = pair.flow();
ProductInfo info = new ProductInfo();
info.provider = pair;
info.ref = pair.equals(index.getRefFlow());
info.process = process.name;
info.processId = process.refId;
info.product = product.name;
info.productId = product.refId;
if (process.category != null) {
Category cat = cache.get(Category.class, process.category);
CategoryPair catPair = new CategoryPair(cat);
info.processCategory = catPair.getCategory();
info.processSubCategory = catPair.getSubCategory();
}
if (process instanceof ProcessDescriptor) {
ProcessDescriptor p = (ProcessDescriptor) process;
if (p.location != null) {
Location loc = cache.get(Location.class, p.location);
if (loc != null)
info.processLocation = loc.code;
}
}
infos.add(info);
}
return infos;
}
use of org.openlca.core.model.descriptors.FlowDescriptor 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;
});
}
use of org.openlca.core.model.descriptors.FlowDescriptor in project olca-modules by GreenDelta.
the class SystemExport method mapLinks.
private void mapLinks(Model model) {
Technology tech = Models.forceTechnology(model);
Map<Long, ProcessInstance> instances = new HashMap<>();
for (Long id : system.processes) {
if (id == null)
continue;
ProcessInstance pi = initProcessInstance(id);
instances.put(id, pi);
tech.processes.add(pi);
}
for (ProcessLink link : system.processLinks) {
FlowDescriptor flow = flows.get(link.flowId);
if (flow == null)
continue;
if (flow.flowType == FlowType.PRODUCT_FLOW) {
ProcessInstance pi = instances.get(link.providerId);
addLink(pi, link, flow);
} else if (flow.flowType == FlowType.WASTE_FLOW) {
ProcessInstance pi = instances.get(link.processId);
addLink(pi, link, flow);
}
}
}
Aggregations