Search in sources :

Example 41 with Location

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);
    }
}
Also used : ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Logger(org.slf4j.Logger) Location(org.openlca.core.model.Location)

Example 42 with Location

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;
}
Also used : RefEntity(org.openlca.core.model.RefEntity) EnviFlow(org.openlca.core.matrix.index.EnviFlow) Descriptor(org.openlca.core.model.descriptors.Descriptor) CostResultDescriptor(org.openlca.app.util.CostResultDescriptor) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) Location(org.openlca.core.model.Location)

Example 43 with Location

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);
            }
        }
    }
}
Also used : ImpactFactor(org.openlca.core.model.ImpactFactor) ArrayList(java.util.ArrayList) FormulaInterpreter(org.openlca.expressions.FormulaInterpreter) TLongByteHashMap(gnu.trove.map.hash.TLongByteHashMap) TLongHashSet(gnu.trove.set.hash.TLongHashSet) Location(org.openlca.core.model.Location) Pair(org.openlca.util.Pair)

Example 44 with Location

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;
}
Also used : Process(org.openlca.core.model.Process) Location(org.openlca.core.model.Location) Flow(org.openlca.core.model.Flow)

Aggregations

Location (org.openlca.core.model.Location)44 LocationDao (org.openlca.core.database.LocationDao)11 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 ProcessDescriptor (org.openlca.core.model.descriptors.ProcessDescriptor)6 Test (org.junit.Test)5 FlowDescriptor (org.openlca.core.model.descriptors.FlowDescriptor)5 FeatureCollection (org.openlca.geo.geojson.FeatureCollection)5 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)4 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)4 EnviFlow (org.openlca.core.matrix.index.EnviFlow)4 Category (org.openlca.core.model.Category)4 Flow (org.openlca.core.model.Flow)4 Process (org.openlca.core.model.Process)4 ImpactDescriptor (org.openlca.core.model.descriptors.ImpactDescriptor)4 List (java.util.List)3 CostResultDescriptor (org.openlca.app.util.CostResultDescriptor)3 Feature (org.openlca.geo.geojson.Feature)3 Pair (org.openlca.util.Pair)3 TLongByteHashMap (gnu.trove.map.hash.TLongByteHashMap)2