Search in sources :

Example 1 with CostResultDescriptor

use of org.openlca.app.util.CostResultDescriptor in project olca-app by GreenDelta.

the class Combo method on.

public static Builder on(IResult r) {
    Combo c = new Combo();
    c.flows = new ArrayList<>();
    TLongHashSet flowIDs = new TLongHashSet();
    for (var f : r.getFlows()) {
        if (f.flow() == null || flowIDs.contains(f.flow().id))
            continue;
        flowIDs.add(f.flow().id);
        c.flows.add(f.flow());
    }
    // add LCIA categories
    if (r.hasImpacts()) {
        c.impacts = r.getImpacts();
    }
    // add cost / added value selection
    if (r.hasCosts() && (r instanceof SimpleResult)) {
        SimpleResult sr = (SimpleResult) r;
        CostResultDescriptor d1 = new CostResultDescriptor();
        d1.forAddedValue = false;
        d1.name = M.Netcosts;
        CostResultDescriptor d2 = new CostResultDescriptor();
        d2.forAddedValue = true;
        d2.name = M.AddedValue;
        c.costs = sr.totalCosts() >= 0 ? Arrays.asList(d1, d2) : Arrays.asList(d2, d1);
    }
    return new Builder(c);
}
Also used : TLongHashSet(gnu.trove.set.hash.TLongHashSet) CostResultDescriptor(org.openlca.app.util.CostResultDescriptor) SimpleResult(org.openlca.core.results.SimpleResult)

Example 2 with CostResultDescriptor

use of org.openlca.app.util.CostResultDescriptor in project olca-app by GreenDelta.

the class ResultMap method addMetaData.

private void addMetaData(Location loc, Feature f, Object selection) {
    f.properties.put("location_code", loc.code);
    f.properties.put("location", loc.name);
    f.properties.put("location_id", loc.refId);
    if (selection instanceof FlowDescriptor) {
        FlowDescriptor flow = (FlowDescriptor) selection;
        f.properties.put("flow_id", flow.refId);
        f.properties.put("flow", Labels.name(flow));
        f.properties.put("flow_category", Labels.category(flow));
        f.properties.put("unit", Labels.refUnit(flow));
        return;
    }
    if (selection instanceof ImpactDescriptor) {
        var imp = (ImpactDescriptor) selection;
        f.properties.put("impact_id", imp.refId);
        f.properties.put("impact_name", imp.name);
        f.properties.put("unit", imp.referenceUnit);
        return;
    }
    if (selection instanceof CostResultDescriptor) {
        CostResultDescriptor c = (CostResultDescriptor) selection;
        f.properties.put("cost_type", c.forAddedValue ? "added value" : "net costs");
        f.properties.put("unit", Labels.getReferenceCurrencyCode());
    }
}
Also used : FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) CostResultDescriptor(org.openlca.app.util.CostResultDescriptor)

Example 3 with CostResultDescriptor

use of org.openlca.app.util.CostResultDescriptor in project olca-app by GreenDelta.

the class TreeContentProvider method getChildren.

@Override
public Object[] getChildren(Object obj) {
    if (!(obj instanceof Contribution))
        return null;
    Contribution<?> c = (Contribution<?>) obj;
    // calculated contributions are cached
    if (c.childs != null && !c.childs.isEmpty())
        return c.childs.toArray();
    // leaf of the contribution tree
    if (!(c.item instanceof Location))
        return null;
    Location loc = (Location) c.item;
    Object selection = page.getSelection();
    Stream<Contribution<?>> stream = null;
    if (selection instanceof FlowDescriptor) {
        stream = contributions(loc, (FlowDescriptor) selection);
    } else if (selection instanceof CostResultDescriptor) {
        stream = contributions(loc, (CostResultDescriptor) selection);
    } else if (selection instanceof ImpactDescriptor) {
        stream = contributions(loc, (ImpactDescriptor) selection);
    }
    if (stream == null)
        return null;
    // TODO apply cutoff
    c.childs = stream.filter(con -> con.amount != 0).sorted((c1, c2) -> Double.compare(c2.amount, c1.amount)).collect(Collectors.toList());
    return c.childs.toArray();
}
Also used : Viewer(org.eclipse.jface.viewers.Viewer) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Location(org.openlca.core.model.Location) ArrayList(java.util.ArrayList) List(java.util.List) Stream(java.util.stream.Stream) EnviFlow(org.openlca.core.matrix.index.EnviFlow) ContributionResult(org.openlca.core.results.ContributionResult) Contribution(org.openlca.core.results.Contribution) CostResultDescriptor(org.openlca.app.util.CostResultDescriptor) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) CostResultDescriptor(org.openlca.app.util.CostResultDescriptor) Contribution(org.openlca.core.results.Contribution) Location(org.openlca.core.model.Location)

Example 4 with CostResultDescriptor

use of org.openlca.app.util.CostResultDescriptor in project olca-app by GreenDelta.

the class ProductSystemFigure method selectionLabel.

private String selectionLabel(Object selection) {
    if (selection instanceof FlowDescriptor) {
        FlowDescriptor flow = (FlowDescriptor) selection;
        return M.Flow + ": " + flow.name;
    }
    if (selection instanceof ImpactDescriptor) {
        var impact = (ImpactDescriptor) selection;
        return M.ImpactCategory + ": " + impact.name;
    }
    if (selection instanceof CostResultDescriptor) {
        CostResultDescriptor cost = (CostResultDescriptor) selection;
        String m = M.CostResult;
        return m + ": " + cost.name;
    }
    return M.NoAnalysisOptionsSet;
}
Also used : FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) CostResultDescriptor(org.openlca.app.util.CostResultDescriptor)

Example 5 with CostResultDescriptor

use of org.openlca.app.util.CostResultDescriptor in project olca-app by GreenDelta.

the class LocationPage method onSelected.

private void onSelected(Object obj) {
    label.update(obj);
    if (obj instanceof FlowDescriptor) {
        FlowDescriptor f = (FlowDescriptor) obj;
        update(locations.getContributions(f));
        return;
    }
    if (obj instanceof ImpactDescriptor) {
        var i = (ImpactDescriptor) obj;
        update(locations.getContributions(i));
        return;
    }
    if (obj instanceof CostResultDescriptor) {
        var c = (CostResultDescriptor) obj;
        if (c.forAddedValue) {
            update(locations.getAddedValueContributions());
        } else {
            update(locations.getNetCostsContributions());
        }
    }
}
Also used : FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) CostResultDescriptor(org.openlca.app.util.CostResultDescriptor)

Aggregations

CostResultDescriptor (org.openlca.app.util.CostResultDescriptor)5 FlowDescriptor (org.openlca.core.model.descriptors.FlowDescriptor)4 ImpactDescriptor (org.openlca.core.model.descriptors.ImpactDescriptor)4 TLongHashSet (gnu.trove.set.hash.TLongHashSet)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)1 Viewer (org.eclipse.jface.viewers.Viewer)1 EnviFlow (org.openlca.core.matrix.index.EnviFlow)1 Location (org.openlca.core.model.Location)1 ProcessDescriptor (org.openlca.core.model.descriptors.ProcessDescriptor)1 Contribution (org.openlca.core.results.Contribution)1 ContributionResult (org.openlca.core.results.ContributionResult)1 SimpleResult (org.openlca.core.results.SimpleResult)1