use of org.openlca.core.database.FlowDao in project olca-modules by GreenDelta.
the class DbLibrarySwap method techFlowsOf.
private List<TechFlow> techFlowsOf(IDatabase db) {
var processes = new ProcessDao(db).getDescriptors().stream().collect(map());
var flows = new FlowDao(db).getDescriptors().stream().filter(d -> d.flowType != FlowType.ELEMENTARY_FLOW).collect(map());
var protoIndex = library.getProductIndex();
var list = new ArrayList<TechFlow>();
for (int i = 0; i < protoIndex.getProductCount(); i++) {
var protoEntry = protoIndex.getProduct(i);
var process = processes.get(protoEntry.getProcess().getId());
var flow = flows.get(protoEntry.getProduct().getId());
if (process != null && flow != null) {
list.add(TechFlow.of(process, flow));
}
}
return list;
}
use of org.openlca.core.database.FlowDao in project olca-modules by GreenDelta.
the class TechIndex method eachProviderOf.
private static void eachProviderOf(IDatabase db, Consumer<TechFlow> fn) {
var processes = new ProcessDao(db).descriptorMap();
var flows = new FlowDao(db).descriptorMap();
String sql = "select f_owner, f_flow, is_input from tbl_exchanges";
NativeSql.on(db).query(sql, r -> {
long flowID = r.getLong(2);
var flow = flows.get(flowID);
if (flow == null || flow.flowType == null || flow.flowType == FlowType.ELEMENTARY_FLOW)
return true;
var type = flow.flowType;
boolean isInput = r.getBoolean(3);
if (isInput && type == FlowType.PRODUCT_FLOW)
return true;
if (!isInput && type == FlowType.WASTE_FLOW)
return true;
long procID = r.getLong(1);
var process = processes.get(procID);
if (process == null) {
// case the process would be null.
return true;
}
fn.accept(TechFlow.of(process, flow));
return true;
});
}
use of org.openlca.core.database.FlowDao in project olca-modules by GreenDelta.
the class ProcessTest method createCyclicModel.
private Process[] createCyclicModel(IDatabase db) {
UnitGroup ug = createUnitGroup(new UnitGroupDao(db));
FlowProperty fp = createFlowProperty(ug, new FlowPropertyDao(db));
Flow product1 = createProduct(fp, new FlowDao(db));
Flow product2 = createProduct(fp, new FlowDao(db));
ProcessDao dao = new ProcessDao(db);
Process p1 = createProcess(product1, dao);
Process p2 = createProcess(product2, dao);
p1 = addProvider(p1, p2, dao);
p2 = addProvider(p2, p1, dao);
return new Process[] { p1, p2 };
}
use of org.openlca.core.database.FlowDao in project olca-modules by GreenDelta.
the class RegionalizedCalculationTest method flow.
private Flow flow(String name, String unit, FlowType type) {
FlowDao dao = new FlowDao(db);
List<Flow> flows = dao.getForName(name);
if (!flows.isEmpty())
return flows.get(0);
var property = property(unit);
Flow flow = Flow.of(name, type, property);
return dao.insert(flow);
}
use of org.openlca.core.database.FlowDao in project olca-modules by GreenDelta.
the class ParameterUsageTreeTest method testImpactFactor.
@Test
public void testImpactFactor() {
var global = db.insert(Parameter.global("param", 42));
var flow = new Flow();
flow.name = "CH4";
new FlowDao(db).insert(flow);
var impact = new ImpactCategory();
impact.name = "GWP";
var factor = new ImpactFactor();
factor.flow = flow;
factor.value = 24.0;
factor.formula = "2 * param";
impact.impactFactors.add(factor);
new ImpactCategoryDao(db).insert(impact);
// find the factor node
var tree = ParameterUsageTree.of("param", db);
var node = find(tree, "GWP", "CH4");
assertNotNull(node);
assertEquals(Descriptor.of(flow), node.model);
assertEquals(UsageType.FORMULA, node.usageType);
assertEquals("2 * param", node.usage);
// find the global parameter definition
node = find(tree, "param");
assertNotNull(node);
assertEquals(Descriptor.of(global), node.model);
assertEquals(UsageType.DEFINITION, node.usageType);
}
Aggregations