Search in sources :

Example 1 with ImpactCategoryDao

use of org.openlca.core.database.ImpactCategoryDao 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 2 with ImpactCategoryDao

use of org.openlca.core.database.ImpactCategoryDao in project olca-modules by GreenDelta.

the class Sequence method init.

private void init(IDatabase db) {
    index(CATEGORY, new CategoryDao(db));
    index(LOCATION, new LocationDao(db));
    index(ACTOR, new ActorDao(db));
    index(SOURCE, new SourceDao(db));
    index(UNIT, new UnitDao(db));
    index(UNIT_GROUP, new UnitGroupDao(db));
    index(FLOW_PROPERTY, new FlowPropertyDao(db));
    index(FLOW, new FlowDao(db));
    index(CURRENCY, new CurrencyDao(db));
    index(PROCESS, new ProcessDao(db));
    index(PRODUCT_SYSTEM, new ProductSystemDao(db));
    index(IMPACT_CATEGORY, new ImpactCategoryDao(db));
    index(IMPACT_METHOD, new ImpactMethodDao(db));
    index(NW_SET, new NwSetDao(db));
    index(PROJECT, new ProjectDao(db));
    index(DQ_SYSTEM, new DQSystemDao(db));
    index(SOCIAL_INDICATOR, new SocialIndicatorDao(db));
}
Also used : SourceDao(org.openlca.core.database.SourceDao) CurrencyDao(org.openlca.core.database.CurrencyDao) ImpactCategoryDao(org.openlca.core.database.ImpactCategoryDao) CategoryDao(org.openlca.core.database.CategoryDao) ActorDao(org.openlca.core.database.ActorDao) FlowPropertyDao(org.openlca.core.database.FlowPropertyDao) LocationDao(org.openlca.core.database.LocationDao) UnitDao(org.openlca.core.database.UnitDao) DQSystemDao(org.openlca.core.database.DQSystemDao) NwSetDao(org.openlca.core.database.NwSetDao) FlowDao(org.openlca.core.database.FlowDao) ImpactMethodDao(org.openlca.core.database.ImpactMethodDao) ProcessDao(org.openlca.core.database.ProcessDao) UnitGroupDao(org.openlca.core.database.UnitGroupDao) SocialIndicatorDao(org.openlca.core.database.SocialIndicatorDao) ImpactCategoryDao(org.openlca.core.database.ImpactCategoryDao) ProductSystemDao(org.openlca.core.database.ProductSystemDao) ProjectDao(org.openlca.core.database.ProjectDao)

Example 3 with ImpactCategoryDao

use of org.openlca.core.database.ImpactCategoryDao in project olca-modules by GreenDelta.

the class RegionalizedCalculationTest method testRegionalizedCalculation.

@Test
public void testRegionalizedCalculation() {
    Flow nox = flow("NOx", "mg", FlowType.ELEMENTARY_FLOW);
    // create the process
    Process p = new Process();
    p.name = "transport, bus";
    p.quantitativeReference = p.output(flow("transport, bus", "p*km", FlowType.PRODUCT_FLOW), 1);
    Exchange e1 = p.output(nox, 5);
    e1.location = loc1;
    Exchange e2 = p.output(nox, 10);
    e2.location = loc2;
    p = new ProcessDao(db).insert(p);
    // create the LCIA category & method
    var impact = new ImpactCategory();
    impact.name = "human tox";
    impact.factor(nox, 0.5);
    impact.factor(nox, 0.1).location = loc1;
    impact.factor(nox, 0.9).location = loc2;
    impact = new ImpactCategoryDao(db).insert(impact);
    var method = new ImpactMethod();
    method.impactCategories.add(impact);
    method = new ImpactMethodDao(db).insert(method);
    // create the product system and calculation setup
    var setup = CalculationSetup.fullAnalysis(ProductSystem.of(p)).withImpactMethod(method).withRegionalization(true);
    var calculator = new SystemCalculator(db);
    FullResult r = calculator.calculateFull(setup);
    Assert.assertTrue(r.enviIndex().isRegionalized());
    checkRegTotalFlowResults(r, new Object[][] { { nox, loc1, 5.0 }, { nox, loc2, 10.0 } });
}
Also used : Exchange(org.openlca.core.model.Exchange) FullResult(org.openlca.core.results.FullResult) ImpactMethodDao(org.openlca.core.database.ImpactMethodDao) ProcessDao(org.openlca.core.database.ProcessDao) Process(org.openlca.core.model.Process) ImpactCategory(org.openlca.core.model.ImpactCategory) ImpactCategoryDao(org.openlca.core.database.ImpactCategoryDao) ImpactMethod(org.openlca.core.model.ImpactMethod) Flow(org.openlca.core.model.Flow) EnviFlow(org.openlca.core.matrix.index.EnviFlow) TechFlow(org.openlca.core.matrix.index.TechFlow) Test(org.junit.Test)

Example 4 with ImpactCategoryDao

use of org.openlca.core.database.ImpactCategoryDao in project olca-modules by GreenDelta.

the class Library method syncImpacts.

/**
 * Returns the impact categories of the library in matrix order. If this
 * information is not present or something went wrong while synchronizing
 * the impact index with the database, an empty option is returned.
 */
public Optional<ImpactIndex> syncImpacts(IDatabase db) {
    var proto = getImpactIndex();
    int size = proto.getImpactCount();
    if (size == 0)
        return Optional.empty();
    var index = new ImpactIndex();
    var impacts = descriptors(new ImpactCategoryDao(db));
    for (int i = 0; i < size; i++) {
        var entry = proto.getImpact(i);
        var impact = impacts.get(entry.getImpact().getId());
        if (impact == null)
            return Optional.empty();
        index.add(impact);
    }
    return Optional.of(index);
}
Also used : ImpactIndex(org.openlca.core.matrix.index.ImpactIndex) ImpactCategoryDao(org.openlca.core.database.ImpactCategoryDao)

Example 5 with ImpactCategoryDao

use of org.openlca.core.database.ImpactCategoryDao in project olca-modules by GreenDelta.

the class ParameterTest method testImpactCategory.

@Test
public void testImpactCategory() {
    var impact = new ImpactCategory();
    impact.refId = UUID.randomUUID().toString();
    var param = impact.parameter("param", 42);
    var dao = new ImpactCategoryDao(Tests.getDb());
    dao.insert(impact);
    with(zip -> {
        JsonExport export = new JsonExport(Tests.getDb(), zip);
        export.write(impact);
    });
    dao.delete(impact);
    with(zip -> {
        JsonImport jImport = new JsonImport(zip, Tests.getDb());
        jImport.run();
    });
    ImpactCategory clone = dao.getForRefId(impact.refId);
    Assert.assertEquals(param.refId, clone.parameters.get(0).refId);
}
Also used : JsonImport(org.openlca.jsonld.input.JsonImport) ImpactCategory(org.openlca.core.model.ImpactCategory) JsonExport(org.openlca.jsonld.output.JsonExport) ImpactCategoryDao(org.openlca.core.database.ImpactCategoryDao) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Aggregations

ImpactCategoryDao (org.openlca.core.database.ImpactCategoryDao)8 ImpactCategory (org.openlca.core.model.ImpactCategory)5 Test (org.junit.Test)4 ProcessDao (org.openlca.core.database.ProcessDao)3 FlowDao (org.openlca.core.database.FlowDao)2 ImpactMethodDao (org.openlca.core.database.ImpactMethodDao)2 Flow (org.openlca.core.model.Flow)2 ImpactFactor (org.openlca.core.model.ImpactFactor)2 TLongLongHashMap (gnu.trove.map.hash.TLongLongHashMap)1 ActorDao (org.openlca.core.database.ActorDao)1 CategoryDao (org.openlca.core.database.CategoryDao)1 CurrencyDao (org.openlca.core.database.CurrencyDao)1 DQSystemDao (org.openlca.core.database.DQSystemDao)1 FlowPropertyDao (org.openlca.core.database.FlowPropertyDao)1 LocationDao (org.openlca.core.database.LocationDao)1 NwSetDao (org.openlca.core.database.NwSetDao)1 ParameterDao (org.openlca.core.database.ParameterDao)1 ProductSystemDao (org.openlca.core.database.ProductSystemDao)1 ProjectDao (org.openlca.core.database.ProjectDao)1 SocialIndicatorDao (org.openlca.core.database.SocialIndicatorDao)1