Search in sources :

Example 21 with Parameter

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

the class ProcessImport method handleParameters.

private void handleParameters(DataSet dataSet, Process process) {
    List<Parameter> list = Parameters.fetch(dataSet, config);
    List<Parameter> newGlobals = new ArrayList<>();
    for (Parameter p : list) {
        if (p.scope == ParameterScope.PROCESS)
            process.parameters.add(p);
        else if (p.scope == ParameterScope.GLOBAL)
            newGlobals.add(p);
    }
    ParameterDao dao = new ParameterDao(config.db);
    Map<String, Boolean> map = new HashMap<>();
    for (Parameter p : dao.getGlobalParameters()) map.put(p.name, Boolean.TRUE);
    for (Parameter newGlobal : newGlobals) {
        Boolean exists = map.get(newGlobal.name);
        if (exists == null) {
            dao.insert(newGlobal);
            map.put(newGlobal.name, Boolean.TRUE);
        }
    }
}
Also used : ParameterDao(org.openlca.core.database.ParameterDao) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Parameter(org.openlca.core.model.Parameter)

Example 22 with Parameter

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

the class ProcessParameterConversion method addOrInsert.

private void addOrInsert(Parameter param) {
    if (param.scope == ParameterScope.PROCESS) {
        olcaProcess.parameters.add(param);
        return;
    }
    try {
        List<Parameter> params = dao.getGlobalParameters();
        boolean contains = false;
        for (Parameter dbParam : params) {
            if (Strings.nullOrEqual(param.name, dbParam.name)) {
                contains = true;
                break;
            }
        }
        if (!contains)
            dao.insert(param);
    } catch (Exception e) {
        log.error("Failed to store parameter in database", e);
    }
}
Also used : Parameter(org.openlca.core.model.Parameter)

Example 23 with Parameter

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

the class ParameterTableTest method depParameter.

private Parameter depParameter(double factor) {
    Parameter depParam = new Parameter();
    depParam.name = "dep_param";
    depParam.isInputParameter = false;
    depParam.formula = factor + " * inp_param";
    return depParam;
}
Also used : Parameter(org.openlca.core.model.Parameter)

Example 24 with Parameter

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

the class FormulaInterpreterTest method setUp.

/**
 * sets the following parameters:
 *
 * fi_tests_global = 32
 *
 * fi_tests_local = fi_tests_global + 10
 */
@Before
public void setUp() {
    globalParam = new Parameter();
    globalParam.name = "fi_tests_global";
    globalParam.isInputParameter = true;
    globalParam.scope = ParameterScope.GLOBAL;
    globalParam.value = 32;
    new ParameterDao(db).insert(globalParam);
    process = new Process();
    var localParam = new Parameter();
    localParam.name = "fi_tests_local";
    localParam.formula = "fi_tests_global + 10";
    localParam.isInputParameter = false;
    localParam.scope = ParameterScope.PROCESS;
    process.parameters.add(localParam);
    process = new ProcessDao(db).insert(process);
    interpreter = ParameterTable.interpreter(db, Collections.singleton(process.id), Collections.emptySet());
}
Also used : ParameterDao(org.openlca.core.database.ParameterDao) ProcessDao(org.openlca.core.database.ProcessDao) Parameter(org.openlca.core.model.Parameter) Process(org.openlca.core.model.Process) Before(org.junit.Before)

Example 25 with Parameter

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

the class ParameterTableTest method setUp.

@Before
public void setUp() {
    IDatabase db = Tests.getDb();
    Parameter globalInp = inpParameter(42);
    globalInp.scope = ParameterScope.GLOBAL;
    Parameter globalDep = depParameter(2);
    globalDep.scope = ParameterScope.GLOBAL;
    ParameterDao paramDao = new ParameterDao(db);
    paramDao.insert(globalInp);
    paramDao.insert(globalDep);
    process = new Process();
    Parameter ppInp = inpParameter(84);
    ppInp.scope = ParameterScope.PROCESS;
    Parameter ppDep = depParameter(3);
    ppDep.scope = ParameterScope.PROCESS;
    process.parameters.add(ppInp);
    process.parameters.add(ppDep);
    new ProcessDao(db).insert(process);
}
Also used : ParameterDao(org.openlca.core.database.ParameterDao) IDatabase(org.openlca.core.database.IDatabase) ProcessDao(org.openlca.core.database.ProcessDao) Parameter(org.openlca.core.model.Parameter) Process(org.openlca.core.model.Process) Before(org.junit.Before)

Aggregations

Parameter (org.openlca.core.model.Parameter)74 Test (org.junit.Test)17 AbstractZipTest (org.openlca.jsonld.AbstractZipTest)14 Process (org.openlca.core.model.Process)12 ParameterDao (org.openlca.core.database.ParameterDao)11 Uncertainty (org.openlca.core.model.Uncertainty)8 ArrayList (java.util.ArrayList)7 Category (org.openlca.core.model.Category)6 ImpactCategory (org.openlca.core.model.ImpactCategory)6 ParameterRedef (org.openlca.core.model.ParameterRedef)6 Exchange (org.openlca.core.model.Exchange)5 ImpactFactor (org.openlca.core.model.ImpactFactor)5 ProductSystem (org.openlca.core.model.ProductSystem)5 Before (org.junit.Before)4 JsonArray (com.google.gson.JsonArray)3 JsonObject (com.google.gson.JsonObject)3 ImpactMethod (org.openlca.core.model.ImpactMethod)3 ProcessDao (org.openlca.core.database.ProcessDao)2 DQSystem (org.openlca.core.model.DQSystem)2 Flow (org.openlca.core.model.Flow)2