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);
}
}
}
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);
}
}
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;
}
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());
}
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);
}
Aggregations