use of org.openlca.io.maps.FlowMapEntry in project olca-modules by GreenDelta.
the class ProcessWriter method writeElemExchanges.
private void writeElemExchanges(Process p, ElementaryFlowType type) {
writeln(type.exchangeHeader());
for (Exchange e : p.exchanges) {
if (e.flow == null || e.flow.flowType != FlowType.ELEMENTARY_FLOW)
continue;
Compartment comp = flowCompartments.get(e.flow);
if (comp == null || comp.type() != type)
continue;
FlowMapEntry mapEntry = mappedFlow(e.flow);
if (mapEntry == null) {
// we have an unmapped flow
var ref = toReferenceAmount(e);
var u = uncertainty(ref.amount, ref.uncertainty);
writeln(e.flow.name, comp.sub().toString(), unit(ref.unit), ref.amount, u[0], u[1], u[2], u[3], e.description);
continue;
}
// handle a mapped flow
FlowRef target = mapEntry.targetFlow();
String unit = target.unit != null ? unit(target.unit.name) : SimaProUnit.kg.symbol;
var u = uncertainty(e.amount, e.uncertainty, mapEntry.factor());
writeln(target.flow.name, comp.sub().toString(), unit, e.amount * mapEntry.factor(), u[0], u[1], u[2], u[3], e.description);
}
writeln();
}
use of org.openlca.io.maps.FlowMapEntry in project olca-modules by GreenDelta.
the class ProcessWriter method writeReferenceFlows.
@SuppressWarnings("unchecked")
private void writeReferenceFlows() {
// order flows by their type
int n = ElementaryFlowType.values().length;
List<Flow>[] buckets = new List[n];
for (int i = 0; i < n; i++) {
buckets[i] = new ArrayList<>();
}
for (Map.Entry<Flow, Compartment> e : flowCompartments.entrySet()) {
ElementaryFlowType type = e.getValue().type();
buckets[type.ordinal()].add(e.getKey());
}
// write the flow information
for (var type : ElementaryFlowType.values()) {
writeln(type.blockHeader());
// duplicate names are not allowed here
HashSet<String> handledNames = new HashSet<>();
for (Flow flow : buckets[type.ordinal()]) {
String name;
String unit = null;
FlowMapEntry mapEntry = mappedFlow(flow);
if (mapEntry != null) {
// handle mapped flows
name = mapEntry.targetFlow().flow.name;
if (mapEntry.targetFlow().unit != null) {
unit = unit(mapEntry.targetFlow().unit.name);
}
} else {
// handle unmapped flows
name = flow.name;
Unit refUnit = null;
if (flow.referenceFlowProperty != null) {
if (flow.referenceFlowProperty.unitGroup != null) {
refUnit = flow.referenceFlowProperty.unitGroup.referenceUnit;
}
}
unit = unit(refUnit);
}
if (name == null || unit == null)
continue;
String id = name.trim().toLowerCase();
if (handledNames.contains(id))
continue;
handledNames.add(id);
writeln(name, unit, flow.casNumber, "");
}
writeln();
writeln("End");
writeln();
writeln();
}
}
use of org.openlca.io.maps.FlowMapEntry in project olca-modules by GreenDelta.
the class RefDataImport method loadElemDBFlow.
/**
* Tries to load an elementary flow from the database, which could also be a
* mapped flow.
*/
private Flow loadElemDBFlow(ElementaryExchange exchange) {
String extId = exchange.flowId;
Flow flow = flowDao.getForRefId(extId);
if (flow != null)
return flow;
FlowMapEntry entry = config.getFlowMap().get(extId);
if (entry == null)
return null;
flow = flowDao.getForRefId(entry.targetFlowId());
if (flow == null)
return null;
index.putMappedFlow(extId, entry.factor());
return flow;
}
use of org.openlca.io.maps.FlowMapEntry in project olca-modules by GreenDelta.
the class FlowMapService method toModel.
private FlowMap toModel(ProtoFlowMap proto) {
if (proto == null)
return FlowMap.empty();
var flowMap = new FlowMap();
flowMap.name = proto.getName();
flowMap.description = proto.getDescription();
flowMap.refId = proto.getId();
for (var protoEntry : proto.getMappingsList()) {
var source = toModelRef(protoEntry.getFrom());
var target = toModelRef(protoEntry.getTo());
var factor = protoEntry.getConversionFactor();
flowMap.entries.add(new FlowMapEntry(source, target, factor));
}
return flowMap;
}
use of org.openlca.io.maps.FlowMapEntry in project olca-app by GreenDelta.
the class MappingDialog method open.
/**
* Opens a dialog for editing the given entry. When the returned status code
* is `OK`, the entry was updated (maybe modified). Otherwise, it is
* unchanged.
*/
static int open(MappingTool tool, FlowMapEntry entry) {
if (tool == null || entry == null)
return CANCEL;
// the dialog works on a copy of the entry; only if
// the user clicks on OK, the changes are applied
var copy = entry.copy();
var dialog = new MappingDialog(tool, entry.copy());
int state = dialog.open();
if (state != OK)
return state;
Function<FlowRef, FlowRef> check = flowRef -> {
var r = flowRef == null ? new FlowRef() : flowRef;
r.status = r.flow == null ? MappingStatus.error("no flow set") : MappingStatus.ok("edited or checked manually");
return r;
};
entry.factor(copy.factor()).sourceFlow(check.apply(copy.sourceFlow())).targetFlow(check.apply(copy.targetFlow()));
return state;
}
Aggregations