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