Search in sources :

Example 26 with Unit

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

the class UnitMappingSync method updateUnitGroup.

/**
 * Add a new unit created from the given entry to the unit group.
 */
private UnitGroup updateUnitGroup(UnitMappingEntry entry, UnitGroup unitGroup) {
    log.trace("add new unit {} to group {}", entry.unitName, unitGroup);
    Unit unit = new Unit();
    unit.name = entry.unitName;
    unit.refId = UUID.randomUUID().toString();
    double factor = entry.factor == null ? 1d : entry.factor;
    unit.conversionFactor = factor;
    unitGroup.units.add(unit);
    unitGroup.lastChange = Calendar.getInstance().getTimeInMillis();
    Version.incUpdate(unitGroup);
    unitGroup = new UnitGroupDao(database).update(unitGroup);
    entry.factor = factor;
    entry.unitGroup = unitGroup;
    entry.unit = unitGroup.getUnit(entry.unitName);
    return unitGroup;
}
Also used : Unit(org.openlca.core.model.Unit) UnitGroupDao(org.openlca.core.database.UnitGroupDao)

Example 27 with Unit

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

the class UnitMappingSync method syncEntries.

/**
 * Replace the unit group and units in the entries with the last updated
 * versions. This ensures that all units and unit groups are synchronous
 * with the persistence layer.
 */
private void syncEntries(UnitGroup updatedGroup, List<UnitMappingEntry> entries) {
    for (UnitMappingEntry entry : entries) {
        if (!Objects.equals(updatedGroup, entry.unitGroup))
            continue;
        Unit unit = updatedGroup.getUnit(entry.unitName);
        entry.unit = unit;
        entry.unitGroup = updatedGroup;
    }
}
Also used : Unit(org.openlca.core.model.Unit)

Example 28 with Unit

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

the class DisplayValues method referenceUnit.

/**
 * Returns the name of the reference unit of the given flow.
 */
public static String referenceUnit(FlowDescriptor flow, EntityCache cache) {
    FlowPropertyDescriptor descriptor = cache.get(FlowPropertyDescriptor.class, flow.refFlowPropertyId);
    if (descriptor == null) {
        log.warn("no reference flow property for flow {}", flow);
        return "";
    }
    try {
        FlowProperty property = cache.get(FlowProperty.class, descriptor.id);
        Unit refUnit = property.unitGroup.referenceUnit;
        return refUnit.name;
    } catch (Exception e) {
        log.error("failed to get reference unit for flow " + flow.id, e);
        return "";
    }
}
Also used : FlowPropertyDescriptor(org.openlca.core.model.descriptors.FlowPropertyDescriptor) Unit(org.openlca.core.model.Unit) FlowProperty(org.openlca.core.model.FlowProperty)

Example 29 with Unit

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

the class ProcessTest method createUnitGroup.

private UnitGroup createUnitGroup(UnitGroupDao dao) {
    UnitGroup ug = new UnitGroup();
    ug.name = "unit group";
    ug.refId = UUID.randomUUID().toString();
    Unit u = new Unit();
    u.name = "unit";
    u.refId = UUID.randomUUID().toString();
    ug.units.add(u);
    ug.referenceUnit = u;
    return dao.insert(ug);
}
Also used : UnitGroup(org.openlca.core.model.UnitGroup) Unit(org.openlca.core.model.Unit)

Example 30 with Unit

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

the class ImpactMethodExport method getRefAmount.

private double getRefAmount(ImpactFactor factor) {
    double val = factor.value;
    Unit unit = factor.unit;
    if (unit != null)
        val = val / unit.conversionFactor;
    FlowPropertyFactor propFactor = factor.flowPropertyFactor;
    if (propFactor != null)
        val = val * propFactor.conversionFactor;
    return val;
}
Also used : Unit(org.openlca.core.model.Unit) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor)

Aggregations

Unit (org.openlca.core.model.Unit)50 UnitGroup (org.openlca.core.model.UnitGroup)18 Flow (org.openlca.core.model.Flow)13 FlowProperty (org.openlca.core.model.FlowProperty)13 FlowPropertyFactor (org.openlca.core.model.FlowPropertyFactor)11 UnitGroupDao (org.openlca.core.database.UnitGroupDao)9 ArrayList (java.util.ArrayList)6 FlowDao (org.openlca.core.database.FlowDao)4 FlowPropertyDao (org.openlca.core.database.FlowPropertyDao)4 List (java.util.List)3 IDatabase (org.openlca.core.database.IDatabase)3 Collections (java.util.Collections)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Objects (java.util.Objects)2 Test (org.junit.Test)2 M (org.openlca.app.M)2 ProcessDao (org.openlca.core.database.ProcessDao)2 UnitDao (org.openlca.core.database.UnitDao)2 ImpactFactor (org.openlca.core.model.ImpactFactor)2