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