use of org.openlca.core.matrix.index.EnviFlow in project olca-modules by GreenDelta.
the class SankeyExample method main.
public static void main(String[] args) {
Julia.load();
var db = Derby.fromDataDir("ei37-apos");
var system = db.get(ProductSystem.class, "2bc48e5d-7a6c-4655-8477-42d2e53fa171");
var start = System.currentTimeMillis();
var result = FullResult.of(db, system);
var end = System.currentTimeMillis();
System.out.println("Computed result in: " + ((double) (end - start) / 1000d));
EnviFlow flow = result.enviIndex().at(42);
start = System.currentTimeMillis();
var sankey = Sankey.of(flow, result).withMaximumNodeCount(50).withMinimumShare(0.00).build();
end = System.currentTimeMillis();
System.out.println("Computed sankey in: " + ((double) (end - start) / 1000d));
System.out.println(sankey.toDot());
db.close();
}
use of org.openlca.core.matrix.index.EnviFlow in project olca-modules by GreenDelta.
the class ProjectInventorySheet method writeRows.
private int writeRows(int row, boolean inputs) {
var variants = export.variants;
header(sheet, row, 1, inputs ? "Inputs" : "Outputs");
for (int i = 0; i < variants.length; i++) {
int col = i + 6;
header(sheet, row, col, variants[i].name);
}
row++;
writeHeader(row++);
for (EnviFlow flow : export.resultItems.enviFlows()) {
if (flow.isInput())
continue;
writeInfo(flow.flow(), row);
var contributions = export.result.getContributions(flow);
for (int i = 0; i < variants.length; i++) {
int col = i + 6;
ProjectVariant variant = variants[i];
Contribution<?> c = Contributions.get(contributions, variant);
if (c == null)
continue;
Excel.cell(sheet, row, col, c.amount);
}
row++;
}
return row;
}
use of org.openlca.core.matrix.index.EnviFlow in project olca-modules by GreenDelta.
the class SimulationResultExport method writeInventorySheet.
private void writeInventorySheet(Workbook wb) {
Sheet sheet = wb.createSheet("Inventory");
Excel.trackSize(sheet, 0, FLOW_HEADER.length + 6);
row = 0;
List<EnviFlow> flows = result.getFlows();
writeInventorySection(flows, true, sheet);
writeInventorySection(flows, false, sheet);
Excel.autoSize(sheet, 0, FLOW_HEADER.length + 6);
flushSheet(sheet);
}
use of org.openlca.core.matrix.index.EnviFlow 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.matrix.index.EnviFlow in project olca-modules by GreenDelta.
the class RegionalizedCalculationTest method checkTotalFlowResults.
/**
* Checks a sequence of (Flow, Double) values.
*/
private void checkTotalFlowResults(FullResult r, Object[][] defs) {
for (Object[] row : defs) {
Flow flow = (Flow) row[0];
int flowIdx = r.enviIndex().of(flow.id);
EnviFlow iFlow = r.enviIndex().at(flowIdx);
double v = r.getTotalFlowResult(iFlow);
Assert.assertEquals((Double) row[1], v, 1e-10);
}
}
Aggregations