Search in sources :

Example 1 with ImpactCategory

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;
}
Also used : ImpactFactor(org.openlca.core.model.ImpactFactor) ImpactCategory(org.openlca.core.model.ImpactCategory) Category(org.openlca.core.model.Category) Parameter(org.openlca.core.model.Parameter) ImpactCategory(org.openlca.core.model.ImpactCategory) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) ImpactMethod(org.openlca.core.model.ImpactMethod)

Example 2 with ImpactCategory

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));
}
Also used : ImpactFactor(org.openlca.core.model.ImpactFactor) RootDescriptor(org.openlca.core.model.descriptors.RootDescriptor) Descriptor(org.openlca.core.model.descriptors.Descriptor) RootDescriptor(org.openlca.core.model.descriptors.RootDescriptor) ImpactCategory(org.openlca.core.model.ImpactCategory) ImpactCategoryDao(org.openlca.core.database.ImpactCategoryDao) Test(org.junit.Test)

Example 3 with ImpactCategory

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();
}
Also used : NwFactor(org.openlca.core.model.NwFactor) ImpactCategory(org.openlca.core.model.ImpactCategory) NwSet(org.openlca.core.model.NwSet) ImpactMethod(org.openlca.core.model.ImpactMethod) Before(org.junit.Before)

Example 4 with ImpactCategory

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);
}
Also used : ArrayList(java.util.ArrayList) ImpactCategory(org.openlca.core.model.ImpactCategory)

Example 5 with ImpactCategory

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);
}
Also used : Version(org.openlca.core.model.Version) ImpactCategory(org.openlca.core.model.ImpactCategory) ImpactMethod(org.openlca.core.model.ImpactMethod)

Aggregations

ImpactCategory (org.openlca.core.model.ImpactCategory)26 Test (org.junit.Test)8 ImpactMethod (org.openlca.core.model.ImpactMethod)8 ImpactFactor (org.openlca.core.model.ImpactFactor)7 Parameter (org.openlca.core.model.Parameter)6 ImpactCategoryDao (org.openlca.core.database.ImpactCategoryDao)5 AbstractZipTest (org.openlca.jsonld.AbstractZipTest)5 Flow (org.openlca.core.model.Flow)4 ImpactMethodDao (org.openlca.core.database.ImpactMethodDao)3 Date (java.util.Date)2 FlowDao (org.openlca.core.database.FlowDao)2 Category (org.openlca.core.model.Category)2 FlowProperty (org.openlca.core.model.FlowProperty)2 FlowPropertyFactor (org.openlca.core.model.FlowPropertyFactor)2 NwFactor (org.openlca.core.model.NwFactor)2 Process (org.openlca.core.model.Process)2 Uncertainty (org.openlca.core.model.Uncertainty)2 JsonArray (com.google.gson.JsonArray)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1