Search in sources :

Example 16 with FlowDao

use of org.openlca.core.database.FlowDao in project olca-app by GreenDelta.

the class ProcessCreator method createFlow.

private Flow createFlow() {
    Flow flow = new Flow();
    flow.refId = UUID.randomUUID().toString();
    if (!Strings.isNullOrEmpty(flowName))
        flow.name = flowName;
    else
        flow.name = name;
    flow.description = description;
    flow.flowType = wasteProcess ? FlowType.WASTE_FLOW : FlowType.PRODUCT_FLOW;
    flow.referenceFlowProperty = flowProperty;
    var factor = new FlowPropertyFactor();
    factor.conversionFactor = 1;
    factor.flowProperty = flowProperty;
    flow.flowPropertyFactors.add(factor);
    new FlowDao(db).insert(flow);
    return flow;
}
Also used : FlowDao(org.openlca.core.database.FlowDao) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) Flow(org.openlca.core.model.Flow)

Example 17 with FlowDao

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

the class FlowDirectionCheck method run.

@Override
public void run() {
    try {
        var flows = new FlowDao(v.db).descriptorMap();
        // collect the IDs of quantitative references
        var qrefs = new TLongHashSet();
        var qrefQuery = "select f_quantitative_reference from tbl_processes";
        NativeSql.on(v.db).query(qrefQuery, r -> {
            qrefs.add(r.getLong(1));
            return true;
        });
        checkDirections(flows, qrefs);
        if (!foundErrors && !v.wasCanceled()) {
            v.ok("checked flow directions");
        }
    } catch (Exception e) {
        v.error("error in flow direction check", e);
    } finally {
        v.workerFinished();
    }
}
Also used : FlowDao(org.openlca.core.database.FlowDao) TLongHashSet(gnu.trove.set.hash.TLongHashSet)

Example 18 with FlowDao

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

the class CategoriesTest method testFindOrAddModel.

@Test
public void testFindOrAddModel() {
    IDatabase db = Tests.getDb();
    String[] path = { "A", "B", "C", "D", "E" };
    Category c = null;
    for (int i = 0; i < 10; i++) {
        Category next = Categories.findOrAdd(db, ModelType.FLOW, path);
        if (c != null) {
            assertEquals(c.id, next.id);
        } else {
            c = next;
        }
        Flow f = new Flow();
        f.category = c;
        FlowDao dao = new FlowDao(db);
        dao.insert(f);
        f = dao.getForId(f.id);
        checkCat(path, f.category);
    }
}
Also used : IDatabase(org.openlca.core.database.IDatabase) Category(org.openlca.core.model.Category) FlowDao(org.openlca.core.database.FlowDao) Flow(org.openlca.core.model.Flow) Test(org.junit.Test)

Example 19 with FlowDao

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

the class FlowPropertyFactorUseSearchTest method tearDown.

@After
public void tearDown() {
    new FlowDao(database).delete(flow);
    new FlowPropertyDao(database).delete(property);
}
Also used : FlowDao(org.openlca.core.database.FlowDao) FlowPropertyDao(org.openlca.core.database.FlowPropertyDao) After(org.junit.After)

Example 20 with FlowDao

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

the class FlowPropertyFactorExport method doIt.

@Override
protected void doIt(CSVPrinter printer, IDatabase db) throws IOException {
    log.trace("write flow property factors");
    FlowDao dao = new FlowDao(db);
    int count = 0;
    for (Flow flow : dao.getAll()) {
        for (FlowPropertyFactor factor : flow.flowPropertyFactors) {
            Object[] line = createLine(flow, factor);
            printer.printRecord(line);
            count++;
        }
    }
    log.trace("{} flow property factors written", count);
}
Also used : FlowDao(org.openlca.core.database.FlowDao) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) Flow(org.openlca.core.model.Flow)

Aggregations

FlowDao (org.openlca.core.database.FlowDao)38 Flow (org.openlca.core.model.Flow)21 ProcessDao (org.openlca.core.database.ProcessDao)13 FlowPropertyFactor (org.openlca.core.model.FlowPropertyFactor)10 ArrayList (java.util.ArrayList)7 Collectors (java.util.stream.Collectors)6 FlowPropertyDao (org.openlca.core.database.FlowPropertyDao)6 IDatabase (org.openlca.core.database.IDatabase)6 FlowProperty (org.openlca.core.model.FlowProperty)6 FlowDescriptor (org.openlca.core.model.descriptors.FlowDescriptor)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 Test (org.junit.Test)4 LocationDao (org.openlca.core.database.LocationDao)4 Process (org.openlca.core.model.Process)4 Unit (org.openlca.core.model.Unit)4 TLongHashSet (gnu.trove.set.hash.TLongHashSet)3 HashSet (java.util.HashSet)3 Objects (java.util.Objects)3