use of org.openlca.core.model.Location in project olca-app by GreenDelta.
the class LocationMap method setInput.
void setInput(List<Contribution<Location>> items) {
if (browser == null)
return;
List<HeatmapPoint> points = new ArrayList<>();
for (Contribution<Location> c : items) {
if (!showInMap(c))
continue;
Location location = c.item;
HeatmapPoint point = new HeatmapPoint();
point.latitude = location.latitude;
point.longitude = location.longitude;
point.weight = (int) (100d * c.share);
points.add(point);
}
if (points.size() == 1) {
points.get(0).weight = 1;
}
String json = new Gson().toJson(points);
try {
browser.execute("setData(" + json + ")");
} catch (Exception e) {
Logger log = LoggerFactory.getLogger(LocationMap.class);
log.warn("Error setting location data", e);
}
}
use of org.openlca.core.model.Location in project olca-app by GreenDelta.
the class TreeLabel method getLabel.
private String getLabel(Contribution<?> c) {
if (c == null || c.item == null)
return M.None;
if (c.item instanceof Location) {
Location loc = (Location) c.item;
String label = loc.name;
if (loc.code != null && !Strings.nullOrEqual(loc.code, label)) {
label += " - " + loc.code;
}
return label;
}
if (c.item instanceof EnviFlow)
return Labels.name((EnviFlow) c.item);
if (c.item instanceof Descriptor)
return Labels.name((Descriptor) c.item);
if (c.item instanceof RefEntity)
return Labels.name((RefEntity) c.item);
return null;
}
use of org.openlca.core.model.Location in project olca-app by GreenDelta.
the class GeoFactorCalculator method createFactors.
private void createFactors(Map<Location, List<Pair<GeoProperty, Double>>> locParams) {
// remove all LCIA factors with a flow and location
// that will be calculated
TLongHashSet setupFlows = new TLongHashSet();
for (GeoFlowBinding b : setup.bindings) {
if (b.flow == null)
continue;
setupFlows.add(b.flow.id);
}
TLongHashSet setupLocations = new TLongHashSet();
for (Location loc : locations) {
setupLocations.add(loc.id);
}
TLongByteHashMap isDefaultPresent = new TLongByteHashMap();
List<ImpactFactor> removals = new ArrayList<>();
for (ImpactFactor factor : impact.impactFactors) {
if (factor.flow == null)
return;
long flowID = factor.flow.id;
if (!setupFlows.contains(flowID))
continue;
if (factor.location == null) {
isDefaultPresent.put(flowID, (byte) 1);
} else if (setupLocations.contains(factor.location.id)) {
removals.add(factor);
}
}
impact.impactFactors.removeAll(removals);
// generate the non-regionalized default factors
// for setup flows that are not yet present
FormulaInterpreter fi = new FormulaInterpreter();
for (GeoProperty param : setup.properties) {
fi.bind(param.identifier, Double.toString(param.defaultValue));
}
for (GeoFlowBinding b : setup.bindings) {
if (b.flow == null)
continue;
byte present = isDefaultPresent.get(b.flow.id);
if (present == (byte) 1)
continue;
try {
double val = fi.eval(b.formula);
impact.factor(b.flow, val);
} catch (Exception e) {
log.error("failed to evaluate formula {} " + " of binding with flow {}", b.formula, b.flow);
}
}
// finally, generate regionalized factors
for (Location loc : locParams.keySet()) {
// bind the location specific parameter values
// to a formula interpreter
fi = new FormulaInterpreter();
List<Pair<GeoProperty, Double>> pairs = locParams.get(loc);
if (pairs == null)
continue;
for (Pair<GeoProperty, Double> pair : pairs) {
GeoProperty param = pair.first;
double val = pair.second == null ? param.defaultValue : pair.second;
fi.bind(param.identifier, Double.toString(val));
}
for (GeoFlowBinding b : setup.bindings) {
if (b.flow == null || b.formula == null)
continue;
try {
double val = fi.eval(b.formula);
var factor = impact.factor(b.flow, val);
factor.location = loc;
} catch (Exception e) {
log.error("Failed to calculate factor from formula " + b.formula + " in binding with flow " + b.flow, e);
}
}
}
}
use of org.openlca.core.model.Location in project olca-app by GreenDelta.
the class BaseLabelProvider method getModelLabel.
protected String getModelLabel(RefEntity o) {
if (o == null)
return "";
String label = Strings.cut(o.name, 75);
Location location = null;
if (o instanceof Flow)
location = ((Flow) o).location;
else if (o instanceof Process)
location = ((Process) o).location;
if (location != null && location.code != null)
label += " (" + location.code + ")";
return label;
}
Aggregations