Search in sources :

Example 16 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 17 with ImpactCategory

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

the class MethodImport method map.

private ImpactMethod map(spold2.ImpactMethod eMethod) {
    if (eMethod.id == null) {
        log.info("method {} has no id", eMethod.name);
        return null;
    }
    log.info("import LCIA method {}", eMethod.name);
    ImpactMethod method = new ImpactMethod();
    method.refId = eMethod.id;
    method.name = eMethod.name;
    method.lastChange = new Date().getTime();
    eMethod.categories.forEach(eCategory -> eCategory.indicators.forEach(eIndicator -> {
        ImpactCategory impact = map(eCategory, eIndicator);
        if (impact != null) {
            method.impactCategories.add(impact);
        }
    }));
    return method;
}
Also used : FlowType(org.openlca.core.model.FlowType) Logger(org.slf4j.Logger) ImpactIndicator(spold2.ImpactIndicator) UnitMapping(org.openlca.io.UnitMapping) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) ImpactMethodDao(org.openlca.core.database.ImpactMethodDao) HashMap(java.util.HashMap) UnitMappingEntry(org.openlca.io.UnitMappingEntry) Unit(org.openlca.core.model.Unit) ModelType(org.openlca.core.model.ModelType) File(java.io.File) Flow(org.openlca.core.model.Flow) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) ImpactFactor(org.openlca.core.model.ImpactFactor) Objects(java.util.Objects) ImpactCategory(org.openlca.core.model.ImpactCategory) ImpactMethod(org.openlca.core.model.ImpactMethod) CategoryDao(org.openlca.core.database.CategoryDao) IDatabase(org.openlca.core.database.IDatabase) FlowDao(org.openlca.core.database.FlowDao) FlowProperty(org.openlca.core.model.FlowProperty) KeyGen(org.openlca.util.KeyGen) ImpactCategory(org.openlca.core.model.ImpactCategory) ImpactMethod(org.openlca.core.model.ImpactMethod) Date(java.util.Date)

Example 18 with ImpactCategory

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

the class ParameterReferencesTest method testImpactMethodParameter.

@Test
public void testImpactMethodParameter() {
    Parameter p1Global = createParameter("p1", "2*2", null, null);
    Parameter p1 = createParameter("p1", "2*2", ParameterScope.PROCESS, null);
    Parameter p2 = createParameter("p2", "2*p1*p3", ParameterScope.PROCESS, null);
    Parameter p3Global = createParameter("p3", "2*p4", null, null);
    Parameter p4Global = createParameter("p4", "2", null, null);
    ImpactCategory impact = createImpactCategory(null, new Parameter[] { p1, p2 });
    with((store) -> {
        JsonExport export = new JsonExport(db, store);
        export.write(impact);
        assertNotNull(store.get(ModelType.IMPACT_CATEGORY, impact.refId));
        assertNull(store.get(ModelType.PARAMETER, p1.refId));
        assertNull(store.get(ModelType.PARAMETER, p1Global.refId));
        assertNull(store.get(ModelType.PARAMETER, p2.refId));
        assertNotNull(store.get(ModelType.PARAMETER, p3Global.refId));
        assertNotNull(store.get(ModelType.PARAMETER, p4Global.refId));
    });
}
Also used : Parameter(org.openlca.core.model.Parameter) ImpactCategory(org.openlca.core.model.ImpactCategory) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 19 with ImpactCategory

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

the class ImpactMethodExport method run.

public void run(ImpactMethod method) {
    if (method == null)
        return;
    if (config.store.contains(LCIAMethod.class, method.refId))
        return;
    for (ImpactCategory impact : method.impactCategories) {
        LCIAMethod lciaMethod = new LCIAMethod();
        putAttribute("olca_method_uuid", method.refId, lciaMethod.otherAttributes);
        addMethodInfo(method, impact, lciaMethod);
        addFactors(impact, lciaMethod);
        config.store.put(lciaMethod);
    }
}
Also used : ImpactCategory(org.openlca.core.model.ImpactCategory) LCIAMethod(org.openlca.ilcd.methods.LCIAMethod)

Example 20 with ImpactCategory

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

the class ImpactCategoryImport method run.

void run() {
    log.trace("import LCIA categories");
    for (ImpactDescriptor d : sourceDao.getDescriptors()) {
        if (seq.contains(seq.IMPACT_CATEGORY, d.refId))
            continue;
        ImpactCategory src = sourceDao.getForId(d.id);
        ImpactCategory dest = src.copy();
        dest.refId = src.refId;
        dest.category = refs.switchRef(src.category);
        switchFactorRefs(dest);
        dest = destDao.insert(dest);
        seq.put(seq.IMPACT_CATEGORY, src.refId, dest.id);
    }
}
Also used : ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) ImpactCategory(org.openlca.core.model.ImpactCategory)

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