Search in sources :

Example 11 with FlowPropertyFactor

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);
}
Also used : FlowDao(org.openlca.core.database.FlowDao) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) Flow(org.openlca.core.model.Flow)

Example 12 with FlowPropertyFactor

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);
    }
}
Also used : FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) FlowProperty(org.openlca.core.model.FlowProperty)

Example 13 with FlowPropertyFactor

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;
}
Also used : UnitGroup(org.openlca.core.model.UnitGroup) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor)

Example 14 with FlowPropertyFactor

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);
    }
}
Also used : FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor)

Example 15 with FlowPropertyFactor

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);
}
Also used : FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) Flow(org.openlca.core.model.Flow)

Aggregations

FlowPropertyFactor (org.openlca.core.model.FlowPropertyFactor)36 Flow (org.openlca.core.model.Flow)21 FlowProperty (org.openlca.core.model.FlowProperty)17 Unit (org.openlca.core.model.Unit)11 FlowDao (org.openlca.core.database.FlowDao)9 UnitGroup (org.openlca.core.model.UnitGroup)6 ArrayList (java.util.ArrayList)4 ImpactFactor (org.openlca.core.model.ImpactFactor)3 Collections (java.util.Collections)2 List (java.util.List)2 Objects (java.util.Objects)2 Before (org.junit.Before)2 Test (org.junit.Test)2 M (org.openlca.app.M)2 Category (org.openlca.core.model.Category)2 Exchange (org.openlca.core.model.Exchange)2 Uncertainty (org.openlca.core.model.Uncertainty)2 UnitMappingEntry (org.openlca.io.UnitMappingEntry)2 Strings (org.openlca.util.Strings)2 SQLException (java.sql.SQLException)1