Search in sources :

Example 1 with ProcessDescriptor

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

the class ExchangeConversion method setProvider.

private void setProvider(Exchange oExchange, ExchangeExtension ext) {
    long provider = oExchange.defaultProviderId;
    if (provider == 0)
        return;
    try {
        ProcessDao dao = new ProcessDao(config.db);
        ProcessDescriptor d = dao.getDescriptor(provider);
        if (d != null) {
            ext.setDefaultProvider(d.refId);
        }
    } catch (Exception e) {
        Logger log = LoggerFactory.getLogger(getClass());
        log.warn("could not load default provider " + provider, e);
    }
}
Also used : ProcessDao(org.openlca.core.database.ProcessDao) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) Logger(org.slf4j.Logger)

Example 2 with ProcessDescriptor

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

the class SystemExport method loadMaps.

private void loadMaps() {
    ProcessDao pDao = new ProcessDao(config.db);
    for (ProcessDescriptor pd : pDao.getDescriptors()) {
        processes.put(pd.id, pd);
        processIDs.put(pd.id, processIDs.size());
    }
    FlowDao fDao = new FlowDao(config.db);
    for (FlowDescriptor fd : fDao.getDescriptors()) {
        flows.put(fd.id, fd);
    }
    Set<Long> exchanges = system.processLinks.stream().map(link -> link.exchangeId).collect(Collectors.toSet());
    String query = "SELECT id, internal_id FROM tbl_exchanges";
    try {
        NativeSql.on(config.db).query(query, r -> {
            long id = r.getLong(1);
            if (exchanges.contains(id)) {
                exchangeIDs.put(id, r.getInt(2));
            }
            return true;
        });
    } catch (Exception e) {
        log.error("Failed to get internal exchange IDs", e);
    }
}
Also used : DataSetType(org.openlca.ilcd.commons.DataSetType) Technology(org.openlca.ilcd.models.Technology) QuantitativeReference(org.openlca.ilcd.models.QuantitativeReference) ProcessDao(org.openlca.core.database.ProcessDao) LoggerFactory(org.slf4j.LoggerFactory) Connection(org.openlca.ilcd.models.Connection) HashMap(java.util.HashMap) Ref(org.openlca.ilcd.commons.Ref) ProductSystem(org.openlca.core.model.ProductSystem) ModelName(org.openlca.ilcd.models.ModelName) Modelling(org.openlca.ilcd.models.Modelling) Map(java.util.Map) FlowDao(org.openlca.core.database.FlowDao) Models(org.openlca.ilcd.util.Models) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) ProcessLink(org.openlca.core.model.ProcessLink) FlowType(org.openlca.core.model.FlowType) Version(org.openlca.core.model.Version) DownstreamLink(org.openlca.ilcd.models.DownstreamLink) Logger(org.slf4j.Logger) Process(org.openlca.ilcd.processes.Process) Set(java.util.Set) NativeSql(org.openlca.core.database.NativeSql) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Parameter(org.openlca.ilcd.models.Parameter) Model(org.openlca.ilcd.models.Model) ProcessInstance(org.openlca.ilcd.models.ProcessInstance) DataSetInfo(org.openlca.ilcd.models.DataSetInfo) Classification(org.openlca.ilcd.commons.Classification) LangString(org.openlca.ilcd.commons.LangString) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) FlowDao(org.openlca.core.database.FlowDao) ProcessDao(org.openlca.core.database.ProcessDao) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) LangString(org.openlca.ilcd.commons.LangString)

Example 3 with ProcessDescriptor

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

the class SimulationResultExport method fillContributions.

private void fillContributions(TechFlow pp, Sheet sheet) {
    row = 0;
    String label = "Contributions of: ";
    if (pp.provider() != null) {
        label += pp.provider().name;
        if (pp.provider() instanceof ProcessDescriptor) {
            ProcessDescriptor p = (ProcessDescriptor) pp.provider();
            if (p.location != null) {
                Location loc = cache.get(Location.class, p.location);
                if (loc != null) {
                    label += " - " + loc.code;
                }
            }
        }
    }
    if (pp.flow() != null) {
        label += " | " + pp.flow().name;
        if (pp.flow().location != null) {
            Location loc = cache.get(Location.class, pp.flow().location);
            if (loc != null) {
                label += " - " + loc.code;
            }
        }
    }
    writer.headerRow(sheet, row, 1, label);
    row++;
    row++;
    if (result.hasImpacts()) {
        writer.headerRow(sheet, row++, 1, "Direct LCIA contributions");
        writer.headerRow(sheet, row, 1, IMPACT_HEADER);
        int valCol = IMPACT_HEADER.length + 1;
        writeValueHeaders(sheet, row++, valCol);
        for (ImpactDescriptor impact : result.getImpacts()) {
            writer.impactRow(sheet, row, 1, impact);
            double[] values = result.getAllDirect(pp, impact);
            writeValues(sheet, row, IMPACT_HEADER.length + 1, values);
            row++;
        }
        row++;
        writer.headerRow(sheet, row++, 1, "Upstream LCIA contributions");
        writer.headerRow(sheet, row, 1, IMPACT_HEADER);
        writeValueHeaders(sheet, row++, valCol);
        for (ImpactDescriptor impact : result.getImpacts()) {
            writer.impactRow(sheet, row, 1, impact);
            double[] values = result.getAllUpstream(pp, impact);
            writeValues(sheet, row, IMPACT_HEADER.length + 1, values);
            row++;
        }
        row++;
    }
    List<EnviFlow> flows = result.getFlows();
    writer.headerRow(sheet, row++, 1, "Direct LCI contributions - Inputs");
    writeFlowContributions(flows, pp, true, result::getAllDirect, sheet);
    writer.headerRow(sheet, row++, 1, "Direct LCI contributions - Outputs");
    writeFlowContributions(flows, pp, false, result::getAllDirect, sheet);
    writer.headerRow(sheet, row++, 1, "Upstream LCI contributions - Inputs");
    writeFlowContributions(flows, pp, true, result::getAllUpstream, sheet);
    writer.headerRow(sheet, row++, 1, "Upstream LCI contributions - Outputs");
    writeFlowContributions(flows, pp, false, result::getAllUpstream, sheet);
}
Also used : ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) EnviFlow(org.openlca.core.matrix.index.EnviFlow) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) Location(org.openlca.core.model.Location)

Example 4 with ProcessDescriptor

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

the class MarketProcessCleanUp method run.

@Override
public void run() {
    log.trace("run market process clean up");
    try {
        List<ProcessDescriptor> marketProcesses = getMarketProcesses();
        int i = 0;
        for (ProcessDescriptor descriptor : marketProcesses) {
            Process marketProcess = dao.getForId(descriptor.id);
            log.trace("replace market process {}", descriptor);
            marketProcess = fixSelfLoop(marketProcess);
            replaceMarket(marketProcess);
            i++;
            log.trace("finished {} of {}", i, marketProcesses.size());
        }
    } catch (Exception e) {
        log.error("failed to remove market processes in supply chain", e);
    }
}
Also used : ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) Process(org.openlca.core.model.Process)

Example 5 with ProcessDescriptor

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

the class EcoSpold2Export method exportProcesses.

private void exportProcesses() {
    for (ProcessDescriptor descriptor : descriptors) {
        ProcessDao dao = new ProcessDao(db);
        Process process = dao.getForId(descriptor.id);
        ProcessDocumentation doc = process.documentation;
        if (doc == null) {
            log.warn("no process entity or documentation for {} found", descriptor);
            continue;
        }
        exportProcess(process);
    }
}
Also used : ProcessDao(org.openlca.core.database.ProcessDao) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) Process(org.openlca.core.model.Process) ProcessDocumentation(org.openlca.core.model.ProcessDocumentation)

Aggregations

ProcessDescriptor (org.openlca.core.model.descriptors.ProcessDescriptor)36 ProcessDao (org.openlca.core.database.ProcessDao)14 Process (org.openlca.core.model.Process)9 FlowDescriptor (org.openlca.core.model.descriptors.FlowDescriptor)7 ArrayList (java.util.ArrayList)6 Location (org.openlca.core.model.Location)5 File (java.io.File)4 EntityCache (org.openlca.core.database.EntityCache)4 JsonObject (com.google.gson.JsonObject)3 Test (org.junit.Test)3 FlowDao (org.openlca.core.database.FlowDao)3 IDatabase (org.openlca.core.database.IDatabase)3 LocationDao (org.openlca.core.database.LocationDao)3 ProductSystem (org.openlca.core.model.ProductSystem)3 Logger (org.slf4j.Logger)3 HashMap (java.util.HashMap)2 Collectors (java.util.stream.Collectors)2 TestProcess (org.openlca.core.TestProcess)2 NativeSql (org.openlca.core.database.NativeSql)2 TechFlow (org.openlca.core.matrix.index.TechFlow)2