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