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;
}
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;
}
}
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 "";
}
}
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);
}
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;
}
Aggregations