Search in sources :

Example 1 with ImpactMethod

use of org.openlca.core.model.ImpactMethod 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 ImpactMethod

use of org.openlca.core.model.ImpactMethod 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 3 with ImpactMethod

use of org.openlca.core.model.ImpactMethod 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)

Example 4 with ImpactMethod

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

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

the class ILCDExport method tryExport.

private void tryExport(RootEntity component) throws Exception {
    if (component instanceof ImpactMethod) {
        ImpactMethodExport export = new ImpactMethodExport(config);
        export.run((ImpactMethod) component);
    } else if (component instanceof ProductSystem) {
        SystemExport export = new SystemExport(config);
        export.run((ProductSystem) component);
    } else if (component instanceof Process) {
        ProcessExport export = new ProcessExport(config);
        export.run((Process) component);
    } else if (component instanceof Flow) {
        FlowExport flowExport = new FlowExport(config);
        flowExport.run((Flow) component);
    } else if (component instanceof FlowProperty) {
        FlowPropertyExport export = new FlowPropertyExport(config);
        export.run((FlowProperty) component);
    } else if (component instanceof UnitGroup) {
        UnitGroupExport export = new UnitGroupExport(config);
        export.run((UnitGroup) component);
    } else if (component instanceof Actor) {
        ActorExport export = new ActorExport(config);
        export.run((Actor) component);
    } else if (component instanceof Source) {
        SourceExport export = new SourceExport(config);
        export.run((Source) component);
    }
}
Also used : UnitGroup(org.openlca.core.model.UnitGroup) ProductSystem(org.openlca.core.model.ProductSystem) Process(org.openlca.core.model.Process) FlowExport(org.openlca.io.ilcd.output.FlowExport) UnitGroupExport(org.openlca.io.ilcd.output.UnitGroupExport) SourceExport(org.openlca.io.ilcd.output.SourceExport) ImpactMethod(org.openlca.core.model.ImpactMethod) Source(org.openlca.core.model.Source) Flow(org.openlca.core.model.Flow) FlowPropertyExport(org.openlca.io.ilcd.output.FlowPropertyExport) Actor(org.openlca.core.model.Actor) ActorExport(org.openlca.io.ilcd.output.ActorExport) ImpactMethodExport(org.openlca.io.ilcd.output.ImpactMethodExport) ProcessExport(org.openlca.io.ilcd.output.ProcessExport) FlowProperty(org.openlca.core.model.FlowProperty) SystemExport(org.openlca.io.ilcd.output.SystemExport)

Aggregations

ImpactMethod (org.openlca.core.model.ImpactMethod)21 ImpactCategory (org.openlca.core.model.ImpactCategory)8 ImpactMethodDao (org.openlca.core.database.ImpactMethodDao)6 NwSet (org.openlca.core.model.NwSet)6 Process (org.openlca.core.model.Process)5 Flow (org.openlca.core.model.Flow)4 ProductSystem (org.openlca.core.model.ProductSystem)4 Test (org.junit.Test)3 Category (org.openlca.core.model.Category)3 FlowProperty (org.openlca.core.model.FlowProperty)3 NwFactor (org.openlca.core.model.NwFactor)3 Parameter (org.openlca.core.model.Parameter)3 JsonObject (com.google.gson.JsonObject)2 Objects (java.util.Objects)2 ProcessDao (org.openlca.core.database.ProcessDao)2 Actor (org.openlca.core.model.Actor)2 FlowPropertyFactor (org.openlca.core.model.FlowPropertyFactor)2 ImpactFactor (org.openlca.core.model.ImpactFactor)2 ModelType (org.openlca.core.model.ModelType)2 Project (org.openlca.core.model.Project)2