Search in sources :

Example 21 with FlowPropertyFactor

use of org.openlca.core.model.FlowPropertyFactor in project olca-app by GreenDelta.

the class AllocationSync method calcFactors.

private List<F> calcFactors(AllocationMethod method, List<Exchange> products) {
    FlowProperty commonProp = getCommonProperty(products, method);
    if (commonProp == null && method != AllocationMethod.PHYSICAL)
        commonProp = getCommonProperty(products, AllocationMethod.PHYSICAL);
    List<F> factors = new ArrayList<>();
    double totalAmount = 0;
    for (Exchange product : products) {
        double refAmount = getRefAmount(product);
        double absAmount = 0;
        if (commonProp != null) {
            Flow flow = product.flow;
            FlowPropertyFactor factor = flow.getFactor(commonProp);
            if (factor != null)
                absAmount = Math.abs(refAmount * factor.conversionFactor);
        }
        totalAmount += absAmount;
        factors.add(new F(product, absAmount));
    }
    if (totalAmount == 0)
        return factors;
    for (F f : factors) f.value = f.value / totalAmount;
    return factors;
}
Also used : Exchange(org.openlca.core.model.Exchange) ArrayList(java.util.ArrayList) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) FlowProperty(org.openlca.core.model.FlowProperty) Flow(org.openlca.core.model.Flow)

Example 22 with FlowPropertyFactor

use of org.openlca.core.model.FlowPropertyFactor in project olca-app by GreenDelta.

the class UnitCell method getItems.

@Override
protected UnitItem[] getItems(ImpactFactor factor) {
    if (factor == null || factor.flow == null)
        return new UnitItem[0];
    Flow flow = factor.flow;
    List<UnitItem> items = new ArrayList<>();
    for (FlowPropertyFactor prop : flow.flowPropertyFactors) {
        if (prop.flowProperty == null)
            continue;
        UnitGroup group = prop.flowProperty.unitGroup;
        if (group == null)
            continue;
        for (Unit unit : group.units) {
            items.add(new UnitItem(factor, prop, unit));
        }
    }
    Collections.sort(items);
    return items.toArray(new UnitItem[0]);
}
Also used : UnitGroup(org.openlca.core.model.UnitGroup) UnitItem(org.openlca.app.editors.lcia.UnitCell.UnitItem) ArrayList(java.util.ArrayList) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) Unit(org.openlca.core.model.Unit) Flow(org.openlca.core.model.Flow)

Example 23 with FlowPropertyFactor

use of org.openlca.core.model.FlowPropertyFactor in project olca-modules by GreenDelta.

the class FlowImport method createFlow.

/**
 * Creates a new flow and inserts it in the database.
 */
private FlowBucket createFlow(String flowKey, Flow flow, String unit) {
    var entry = unitMapping.getEntry(unit);
    if (entry == null || !entry.isValid()) {
        // we have no valid unit mapping; we create
        // a new one here
        var _db = db.database;
        var units = _db.insert(UnitGroup.of("New: " + unit, unit));
        var prop = _db.insert(FlowProperty.of("New: " + unit, units));
        entry = new UnitMappingEntry();
        entry.factor = 1.0;
        entry.flowProperty = prop;
        entry.unit = units.referenceUnit;
        entry.unitGroup = units;
        entry.unitName = unit;
        unitMapping.put(unit, entry);
    }
    flow.referenceFlowProperty = entry.flowProperty;
    FlowPropertyFactor factor = new FlowPropertyFactor();
    factor.flowProperty = entry.flowProperty;
    factor.conversionFactor = 1.0;
    flow.flowPropertyFactors.add(factor);
    db.put(flow, flowKey);
    return createBucket(flow, unit);
}
Also used : UnitMappingEntry(org.openlca.io.UnitMappingEntry) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor)

Example 24 with FlowPropertyFactor

use of org.openlca.core.model.FlowPropertyFactor in project olca-modules by GreenDelta.

the class FlowReferenceSearchTest method createModel.

@Override
protected Flow createModel() {
    Flow flow = new Flow();
    flow.category = insertAndAddExpected("category", new Category());
    flow.location = insertAndAddExpected("location", new Location());
    flow.flowPropertyFactors.add(createFlowPropertyFactor());
    flow.flowPropertyFactors.add(createFlowPropertyFactor());
    flow = db.insert(flow);
    for (FlowPropertyFactor f : flow.flowPropertyFactors) addExpected("flowProperty", f.flowProperty, "flowPropertyFactors", FlowPropertyFactor.class, f.id);
    return flow;
}
Also used : Category(org.openlca.core.model.Category) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) Flow(org.openlca.core.model.Flow) Location(org.openlca.core.model.Location)

Example 25 with FlowPropertyFactor

use of org.openlca.core.model.FlowPropertyFactor in project olca-modules by GreenDelta.

the class ImpactMethodReferenceSearchTest method createImpactFactor.

private ImpactFactor createImpactFactor(Object value) {
    ImpactFactor iFactor = new ImpactFactor();
    Flow flow = createFlow();
    FlowPropertyFactor factor = flow.flowPropertyFactors.get(0);
    Unit unit = factor.flowProperty.unitGroup.units.get(0);
    iFactor.flow = flow;
    iFactor.flowPropertyFactor = factor;
    iFactor.unit = unit;
    boolean formula = value instanceof String;
    if (formula)
        iFactor.formula = value.toString();
    else
        iFactor.value = (double) value;
    return iFactor;
}
Also used : ImpactFactor(org.openlca.core.model.ImpactFactor) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) Unit(org.openlca.core.model.Unit) 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