Search in sources :

Example 6 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 7 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 8 with ImpactMethodDao

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

the class ImpactMethodExport method doIt.

@Override
protected void doIt(CSVPrinter printer, IDatabase db) throws IOException {
    log.trace("write impact methods");
    ImpactMethodDao dao = new ImpactMethodDao(db);
    CategoryDao categoryDao = new CategoryDao(db);
    List<ImpactMethodDescriptor> methods = dao.getDescriptors();
    for (ImpactMethodDescriptor method : methods) {
        Object[] line = createLine(method, categoryDao);
        printer.printRecord(line);
    }
    log.trace("{} impact methods written", methods.size());
}
Also used : CategoryDao(org.openlca.core.database.CategoryDao) ImpactMethodDescriptor(org.openlca.core.model.descriptors.ImpactMethodDescriptor) ImpactMethodDao(org.openlca.core.database.ImpactMethodDao)

Example 9 with ImpactMethodDao

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

the class TestData method method.

public static ImpactMethod method(String name, ImpactCategory... impacts) {
    ImpactMethod m = new ImpactMethod();
    m.refId = UUID.randomUUID().toString();
    m.name = name;
    for (ImpactCategory impact : impacts) {
        m.impactCategories.add(impact);
    }
    ImpactMethodDao dao = new ImpactMethodDao(Tests.getDb());
    return dao.insert(m);
}
Also used : ImpactMethodDao(org.openlca.core.database.ImpactMethodDao) ImpactCategory(org.openlca.core.model.ImpactCategory) ImpactMethod(org.openlca.core.model.ImpactMethod)

Example 10 with ImpactMethodDao

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

the class ImpactMethodImport method of.

@Override
public ImportStatus<ImpactMethod> of(String id) {
    var method = imp.get(ImpactMethod.class, id);
    // check if we are in update mode
    var update = false;
    if (method != null) {
        update = imp.shouldUpdate(method);
        if (!update) {
            return ImportStatus.skipped(method);
        }
    }
    // resolve the proto object
    var proto = imp.reader.getImpactMethod(id);
    if (proto == null)
        return method != null ? ImportStatus.skipped(method) : ImportStatus.error("Could not resolve ImpactMethod " + id);
    var wrap = ProtoWrap.of(proto);
    if (update) {
        if (imp.skipUpdate(method, wrap))
            return ImportStatus.skipped(method);
    }
    // map the data
    if (method == null) {
        method = new ImpactMethod();
        method.refId = id;
    }
    wrap.mapTo(method, imp);
    map(proto, method);
    // insert or update it
    var dao = new ImpactMethodDao(imp.db);
    method = update ? dao.update(method) : dao.insert(method);
    imp.putHandled(method);
    return update ? ImportStatus.updated(method) : ImportStatus.created(method);
}
Also used : ImpactMethodDao(org.openlca.core.database.ImpactMethodDao) ProtoImpactMethod(org.openlca.proto.ProtoImpactMethod) ImpactMethod(org.openlca.core.model.ImpactMethod)

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