use of org.openlca.core.model.ImpactCategory in project olca-modules by GreenDelta.
the class ImpactMethodReferenceSearchTest method createModel.
@Override
protected ImpactMethod createModel() {
ImpactMethod method = new ImpactMethod();
method.category = insertAndAddExpected("category", new Category());
String n1 = generateName();
// String n2 = generateName();
String n3 = generateName();
String n4 = generateName();
String n5 = generateName();
// method.parameters.add(createParameter(n1, 3d, false));
// method.parameters.add(createParameter(n2, n1 + "*2*" + n3, false));
insertAndAddExpected(n3, createParameter(n3, "5*5", true));
// formula with parameter to see if added as reference (unexpected)
insertAndAddExpected(n4, createParameter(n4, "3*" + n5, true));
Parameter globalUnreferenced = createParameter(n1, "3*3", true);
Parameter globalUnreferenced2 = createParameter(n5, "3*3", true);
// must be inserted manually
globalUnreferenced = db.insert(globalUnreferenced);
globalUnreferenced2 = db.insert(globalUnreferenced2);
method.impactCategories.add(createImpactCategory(n4));
method.impactCategories.add(createImpactCategory(n4));
method = db.insert(method);
for (ImpactCategory category : method.impactCategories) for (ImpactFactor f : category.impactFactors) {
addExpected("flow", f.flow, "impactFactors", ImpactFactor.class, f.id);
addExpected("flowPropertyFactor", f.flowPropertyFactor, "impactFactors", ImpactFactor.class, f.id);
addExpected("flowProperty", f.flowPropertyFactor.flowProperty, "flowPropertyFactor", FlowPropertyFactor.class, f.flowPropertyFactor.id);
addExpected("unit", f.unit, "impactFactors", ImpactFactor.class, f.id);
}
return method;
}
use of org.openlca.core.model.ImpactCategory in project olca-modules by GreenDelta.
the class FlowPropertyFactorUseSearchTest method testFindInImpactCategory.
@Test
public void testFindInImpactCategory() {
ImpactFactor iFactor = new ImpactFactor();
iFactor.flow = flow;
iFactor.flowPropertyFactor = factor;
ImpactCategory category = new ImpactCategory();
category.impactFactors.add(iFactor);
ImpactCategoryDao dao = new ImpactCategoryDao(database);
dao.insert(category);
List<RootDescriptor> results = search.findUses(factor);
dao.delete(category);
Assert.assertEquals(1, results.size());
Descriptor expected = Descriptor.of(category);
Assert.assertEquals(expected, results.get(0));
}
use of org.openlca.core.model.ImpactCategory in project olca-modules by GreenDelta.
the class NwSetIOTest method setUp.
@Before
public void setUp() {
ImpactMethod method = new ImpactMethod();
for (int i = 0; i < NWSET_COUNT; i++) {
NwSet set = new NwSet();
set.name = "nwset_" + i;
method.nwSets.add(set);
}
ImpactCategoryDao cdao = new ImpactCategoryDao(db);
for (int i = 0; i < CATEGORY_COUNT; i++) {
ImpactCategory category = new ImpactCategory();
category.name = "category_" + i;
category = cdao.insert(category);
method.impactCategories.add(category);
for (NwSet set : method.nwSets) {
NwFactor factor = new NwFactor();
factor.weightingFactor = FACTOR;
factor.impactCategory = category;
factor.normalisationFactor = FACTOR;
set.factors.add(factor);
}
}
this.method = new ImpactMethodDao(db).insert(method);
Tests.emptyCache();
}
use of org.openlca.core.model.ImpactCategory in project olca-modules by GreenDelta.
the class ImpactMethodImport method switchImpacts.
private void switchImpacts(ImpactMethod dest) {
List<ImpactCategory> switched = new ArrayList<>(dest.impactCategories.size());
for (ImpactCategory srcCat : dest.impactCategories) {
ImpactCategory destCat = refs.switchRef(srcCat);
if (destCat != null) {
switched.add(destCat);
}
}
dest.impactCategories.clear();
dest.impactCategories.addAll(switched);
}
use of org.openlca.core.model.ImpactCategory in project olca-modules by GreenDelta.
the class ImpactMethods method exec.
private void exec() {
var version = block.version() != null ? new Version(block.version().major(), block.version().minor(), 0) : new Version(0, 0, 0);
var refId = KeyGen.get("SimaPro CSV", block.name(), version.toString());
var method = context.db().get(ImpactMethod.class, refId);
if (method != null) {
log.warn("an LCIA method refId='" + refId + "' already exists; skipped");
return;
}
method = new ImpactMethod();
method.refId = refId;
method.name = block.name();
method.version = version.getValue();
method.description = block.comment();
for (var csvImpact : block.impactCategories()) {
if (csvImpact.info() == null)
continue;
var impactId = KeyGen.get("SimaPro CSV", block.name(), version.toString(), csvImpact.info().name());
var impact = new ImpactCategory();
impact.refId = impactId;
impact.name = csvImpact.info().name();
impact.referenceUnit = csvImpact.info().unit();
addFactors(csvImpact, impact);
impact = context.insert(impact);
method.impactCategories.add(impact);
}
context.insert(method);
}
Aggregations