use of org.openlca.core.model.FlowPropertyFactor in project olca-modules by GreenDelta.
the class FlowSheets method write.
private void write() {
Excel.trackSize(flowSheet, 0, 10);
Excel.trackSize(factorSheet, 0, 4);
writeFlowHeader();
writeFactorHeader();
var flows = new FlowDao(config.database).getAll();
flows.sort(new EntitySorter());
for (Flow flow : flows) {
flowRow++;
write(flow);
for (FlowPropertyFactor factor : flow.flowPropertyFactors) {
factorRow++;
writeFactor(flow, factor);
}
}
Excel.autoSize(flowSheet, 0, 10);
Excel.autoSize(factorSheet, 0, 4);
}
use of org.openlca.core.model.FlowPropertyFactor in project olca-modules by GreenDelta.
the class RefDataImport method createFlow.
private void createFlow(Exchange exchange, Flow flow) {
flow.name = exchange.name;
FlowProperty prop = index.getFlowProperty(exchange.unitId);
if (prop == null) {
prop = syncUnit(exchange.unitId, exchange.unit);
if (prop == null) {
log.warn("failed to create unit: " + exchange.unit);
return;
}
}
FlowPropertyFactor fac = new FlowPropertyFactor();
fac.flowProperty = prop;
fac.conversionFactor = 1.0;
flow.flowPropertyFactors.add(fac);
flow.referenceFlowProperty = prop;
try {
flow = flowDao.insert(flow);
index.putFlow(flow.refId, flow);
} catch (Exception e) {
log.error("Failed to store flow", e);
}
}
use of org.openlca.core.model.FlowPropertyFactor in project olca-modules by GreenDelta.
the class ModelImport method getRefUnit.
private Unit getRefUnit(Flow flow) {
if (flow == null)
return null;
FlowPropertyFactor fpf = flow.getReferenceFactor();
if (fpf == null || fpf.flowProperty == null)
return null;
UnitGroup ug = fpf.flowProperty.unitGroup;
if (ug == null)
return null;
return ug.referenceUnit;
}
use of org.openlca.core.model.FlowPropertyFactor in project olca-modules by GreenDelta.
the class FlowImport method map.
private void map(ProtoFlow proto, Flow flow, boolean inUpdateMode) {
flow.flowType = In.flowTypeOf(proto.getFlowType());
flow.casNumber = proto.getCas();
flow.synonyms = proto.getSynonyms();
flow.synonyms = proto.getFormula();
flow.infrastructureFlow = proto.getInfrastructureFlow();
var locID = proto.getLocation().getId();
if (Strings.notEmpty(locID)) {
flow.location = new LocationImport(imp).of(locID).model();
}
// sync existing flow property factors if we are in update
// mode to avoid ID changes of possibly used flow property
// factors
Map<String, FlowPropertyFactor> oldFactors = null;
if (inUpdateMode) {
oldFactors = new HashMap<>();
for (var factor : flow.flowPropertyFactors) {
var prop = factor.flowProperty;
if (prop == null || prop.refId == null)
continue;
oldFactors.put(prop.refId, factor);
}
flow.flowPropertyFactors.clear();
flow.referenceFlowProperty = null;
}
// flow property factors
for (var protoFactor : proto.getFlowPropertiesList()) {
var propID = protoFactor.getFlowProperty().getId();
FlowPropertyFactor factor = null;
if (oldFactors != null) {
factor = oldFactors.get(propID);
}
if (factor == null) {
factor = new FlowPropertyFactor();
}
if (Strings.notEmpty(propID)) {
factor.flowProperty = new FlowPropertyImport(imp).of(propID).model();
}
factor.conversionFactor = protoFactor.getConversionFactor();
if (protoFactor.getReferenceFlowProperty()) {
flow.referenceFlowProperty = factor.flowProperty;
}
flow.flowPropertyFactors.add(factor);
}
}
use of org.openlca.core.model.FlowPropertyFactor in project olca-modules by GreenDelta.
the class ProcessTest method createProduct.
private Flow createProduct(FlowProperty fp, FlowDao dao) {
Flow product = new Flow();
product.name = "product";
product.flowType = FlowType.PRODUCT_FLOW;
FlowPropertyFactor factor = new FlowPropertyFactor();
factor.flowProperty = fp;
product.flowPropertyFactors.add(factor);
product.referenceFlowProperty = factor.flowProperty;
return dao.insert(product);
}
Aggregations