Search in sources :

Example 1 with EnviFlow

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();
}
Also used : EnviFlow(org.openlca.core.matrix.index.EnviFlow)

Example 2 with EnviFlow

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;
}
Also used : ProjectVariant(org.openlca.core.model.ProjectVariant) EnviFlow(org.openlca.core.matrix.index.EnviFlow)

Example 3 with EnviFlow

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);
}
Also used : EnviFlow(org.openlca.core.matrix.index.EnviFlow) Sheet(org.apache.poi.ss.usermodel.Sheet) SXSSFSheet(org.apache.poi.xssf.streaming.SXSSFSheet)

Example 4 with EnviFlow

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);
}
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 5 with EnviFlow

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);
    }
}
Also used : EnviFlow(org.openlca.core.matrix.index.EnviFlow) Flow(org.openlca.core.model.Flow) EnviFlow(org.openlca.core.matrix.index.EnviFlow) TechFlow(org.openlca.core.matrix.index.TechFlow)

Aggregations

EnviFlow (org.openlca.core.matrix.index.EnviFlow)21 ImpactDescriptor (org.openlca.core.model.descriptors.ImpactDescriptor)5 JsonObject (com.google.gson.JsonObject)4 EntityCache (org.openlca.core.database.EntityCache)4 TechFlow (org.openlca.core.matrix.index.TechFlow)3 Descriptor (org.openlca.core.model.descriptors.Descriptor)3 ContributionResult (org.openlca.core.results.ContributionResult)3 Collectors (java.util.stream.Collectors)2 Action (org.eclipse.jface.action.Action)2 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)2 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2 FormToolkit (org.eclipse.ui.forms.widgets.FormToolkit)2 ScrolledForm (org.eclipse.ui.forms.widgets.ScrolledForm)2 Test (org.junit.Test)2 TechIndex (org.openlca.core.matrix.index.TechIndex)2 Location (org.openlca.core.model.Location)2 Contribution (org.openlca.core.results.Contribution)2 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)1