Search in sources :

Example 6 with FlowDao

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

the class FlowExport method doIt.

@Override
protected void doIt(CSVPrinter printer, IDatabase db) throws IOException {
    log.trace("write flows");
    FlowDao dao = new FlowDao(db);
    List<Flow> flows = dao.getAll();
    for (Flow flow : flows) {
        Object[] line = createLine(flow);
        printer.printRecord(line);
    }
    log.trace("{} flows written", flows.size());
}
Also used : FlowDao(org.openlca.core.database.FlowDao) Flow(org.openlca.core.model.Flow)

Example 7 with FlowDao

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

the class FlowSheets method write.

private void write() {
    Excel.trackSize(flowSheet, 0, 10);
    Excel.trackSize(factorSheet, 0, 4);
    writeFlowHeader();
    writeFactorHeader();
    var flows = new FlowDao(config.database).getAll();
    flows.sort(new EntitySorter());
    for (Flow flow : flows) {
        flowRow++;
        write(flow);
        for (FlowPropertyFactor factor : flow.flowPropertyFactors) {
            factorRow++;
            writeFactor(flow, factor);
        }
    }
    Excel.autoSize(flowSheet, 0, 10);
    Excel.autoSize(factorSheet, 0, 4);
}
Also used : FlowDao(org.openlca.core.database.FlowDao) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) Flow(org.openlca.core.model.Flow)

Example 8 with FlowDao

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

the class TechIndex method fillFrom.

private void fillFrom(IDatabase db, ProductSystem system) {
    var systems = new ProductSystemDao(db).descriptorMap();
    var processes = new ProcessDao(db).descriptorMap();
    var results = new ResultDao(db).descriptorMap();
    var flows = new FlowDao(db).descriptorMap();
    for (var link : system.processLinks) {
        RootDescriptor p = processes.get(link.providerId);
        if (p == null) {
            p = systems.get(link.providerId);
            if (p == null) {
                p = results.get(link.providerId);
            }
        }
        if (p == null)
            continue;
        var flow = flows.get(link.flowId);
        if (flow == null)
            continue;
        // the tech-index checks for duplicates of products and links
        var provider = TechFlow.of(p, flow);
        add(provider);
        var exchange = new LongPair(link.processId, link.exchangeId);
        putLink(exchange, provider);
    }
}
Also used : FlowDao(org.openlca.core.database.FlowDao) ProcessDao(org.openlca.core.database.ProcessDao) ResultDao(org.openlca.core.database.ResultDao) RootDescriptor(org.openlca.core.model.descriptors.RootDescriptor) ProductSystemDao(org.openlca.core.database.ProductSystemDao)

Example 9 with FlowDao

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

the class ModelImport method collectFlows.

/**
 * Collect the flows that are used in the process links. This function must
 * be called after all processes are imported.
 */
private Map<String, Flow> collectFlows(Technology tech) {
    Set<String> usedFlows = new HashSet<>();
    for (ProcessInstance pi : tech.processes) {
        for (Connection con : pi.connections) {
            usedFlows.add(con.outputFlow);
            for (DownstreamLink link : con.downstreamLinks) {
                usedFlows.add(link.inputFlow);
            }
        }
    }
    FlowDao dao = new FlowDao(config.db());
    Map<String, Flow> m = new HashMap<>();
    for (Flow f : dao.getForRefIds(usedFlows)) {
        m.put(f.refId, f);
    }
    return m;
}
Also used : HashMap(java.util.HashMap) FlowDao(org.openlca.core.database.FlowDao) Connection(org.openlca.ilcd.models.Connection) ProcessInstance(org.openlca.ilcd.models.ProcessInstance) DownstreamLink(org.openlca.ilcd.models.DownstreamLink) HashSet(java.util.HashSet) Flow(org.openlca.core.model.Flow)

Example 10 with FlowDao

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

the class SystemsInSystemsTests method testCalc.

@Test
public void testCalc() {
    IDatabase db = Tests.getDb();
    UnitGroupDao ugDao = new UnitGroupDao(db);
    FlowPropertyDao fpDao = new FlowPropertyDao(db);
    FlowDao flowDao = new FlowDao(db);
    ProcessDao processDao = new ProcessDao(db);
    ProductSystemDao systemDao = new ProductSystemDao(db);
    UnitGroup ug6939 = new UnitGroup();
    ug6939.refId = UUID.randomUUID().toString();
    ug6939.name = "Units of mass";
    Unit kg = new Unit();
    kg.name = "kg";
    kg.conversionFactor = 1.0;
    kg.refId = UUID.randomUUID().toString();
}
Also used : IDatabase(org.openlca.core.database.IDatabase) UnitGroup(org.openlca.core.model.UnitGroup) FlowDao(org.openlca.core.database.FlowDao) FlowPropertyDao(org.openlca.core.database.FlowPropertyDao) ProcessDao(org.openlca.core.database.ProcessDao) Unit(org.openlca.core.model.Unit) UnitGroupDao(org.openlca.core.database.UnitGroupDao) ProductSystemDao(org.openlca.core.database.ProductSystemDao) Test(org.junit.Test)

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