Search in sources :

Example 1 with ImpactMethodDao

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

the class RefSwitcher method getDestImpactMethodId.

Long getDestImpactMethodId(Long srcMethodId) {
    if (srcMethodId == null)
        return null;
    ImpactMethodDao srcDao = new ImpactMethodDao(source);
    ImpactMethodDescriptor srcDescriptor = srcDao.getDescriptor(srcMethodId);
    if (srcDescriptor == null)
        return null;
    return seq.get(seq.IMPACT_METHOD, srcDescriptor.refId);
}
Also used : ImpactMethodDescriptor(org.openlca.core.model.descriptors.ImpactMethodDescriptor) ImpactMethodDao(org.openlca.core.database.ImpactMethodDao)

Example 2 with ImpactMethodDao

use of org.openlca.core.database.ImpactMethodDao 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 ImpactMethodDao

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

the class MethodImport method run.

@Override
public void run() {
    ImpactMethodDao dao = new ImpactMethodDao(db);
    Spold2Files.parse(files, es2 -> {
        if (es2.impactMethod == null)
            return;
        ImpactMethod m = dao.getForRefId(es2.impactMethod.id);
        if (m != null) {
            log.warn("an LCIA method with id={} " + "already exisis; not imported", m.refId);
            return;
        }
        m = map(es2.impactMethod);
        if (m != null) {
            dao.insert(m);
            log.info("saved new LCIA method {}", m);
        }
    });
}
Also used : ImpactMethodDao(org.openlca.core.database.ImpactMethodDao) ImpactMethod(org.openlca.core.model.ImpactMethod)

Example 4 with ImpactMethodDao

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

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

the class CalculationExample method main.

public static void main(String[] args) {
    Julia.load();
    try (var db = Derby.fromDataDir("ei22")) {
        var system = db.get(ProductSystem.class, "7d1cbce0-b5b3-47ba-95b5-014ab3c7f569");
        var method = new ImpactMethodDao(db).getForRefId("207ffac9-aaa8-401d-ac90-874defd3751a");
        var setup = CalculationSetup.fullAnalysis(system).withImpactMethod(method);
        var calc = new SystemCalculator(db);
        var r = calc.calculateFull(setup);
        var f = r.enviIndex().at(0);
        System.out.println(f.flow().name + "  -> " + r.getTotalFlowResult(f));
        var impact = r.impactIndex().at(0);
        System.out.println(impact.name + "  -> " + r.getTotalImpactResult(impact));
    }
}
Also used : ImpactMethodDao(org.openlca.core.database.ImpactMethodDao) SystemCalculator(org.openlca.core.math.SystemCalculator)

Aggregations

ImpactMethodDao (org.openlca.core.database.ImpactMethodDao)13 ImpactMethod (org.openlca.core.model.ImpactMethod)5 Process (org.openlca.core.model.Process)4 ImpactMethodDescriptor (org.openlca.core.model.descriptors.ImpactMethodDescriptor)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Database (org.openlca.app.db.Database)3 Labels (org.openlca.app.util.Labels)3 Collections (java.util.Collections)2 Action (org.eclipse.jface.action.Action)2 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)2 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)2 ITableLabelProvider (org.eclipse.jface.viewers.ITableLabelProvider)2 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 SWT (org.eclipse.swt.SWT)2 Image (org.eclipse.swt.graphics.Image)2 Button (org.eclipse.swt.widgets.Button)2