Search in sources :

Example 1 with Location

use of org.openlca.core.model.Location in project olca-modules by GreenDelta.

the class ProcessReferenceSearchTest method createModel.

@Override
protected Process createModel() {
    Process process = new Process();
    process.category = insertAndAddExpected("category", new Category());
    process.location = insertAndAddExpected("location", new Location());
    process.dqSystem = insertAndAddExpected("dqSystem", new DQSystem());
    process.exchangeDqSystem = insertAndAddExpected("exchangeDqSystem", new DQSystem());
    process.socialDqSystem = insertAndAddExpected("socialDqSystem", new DQSystem());
    String n1 = generateName();
    String n2 = generateName();
    String n3 = generateName();
    String n4 = generateName();
    String n5 = generateName();
    createExchange(process, 3d, true);
    createExchange(process, "2*" + n4, false);
    process.parameters.add(createParameter(n1, 3d, false));
    process.parameters.add(createParameter(n2, n1 + "*2*" + n3, false));
    process.socialAspects.add(createSocialAspect());
    process.socialAspects.add(createSocialAspect());
    process.documentation = createDocumentation();
    insertAndAddExpected(n3, createParameter(n3, "5*5", true));
    // formula with parameter to see if added as reference (unexpected)
    insertAndAddExpected(n4, createParameter(n4, "3*" + n5, true));
    Parameter globalUnreferenced = createParameter(n1, "3*3", true);
    Parameter globalUnreferenced2 = createParameter(n5, "3*3", true);
    // must be inserted manually
    globalUnreferenced = db.insert(globalUnreferenced);
    globalUnreferenced2 = db.insert(globalUnreferenced2);
    process = db.insert(process);
    for (Exchange e : process.exchanges) {
        addExpected("flow", e.flow, "exchanges", Exchange.class, e.id);
        addExpected("flowPropertyFactor", e.flowPropertyFactor, "exchanges", Exchange.class, e.id);
        addExpected("flowProperty", e.flowPropertyFactor.flowProperty, "flowPropertyFactor", FlowPropertyFactor.class, e.flowPropertyFactor.id);
        addExpected("unit", e.unit, "exchanges", Exchange.class, e.id);
        Process provider = processes.get(e.defaultProviderId);
        if (provider != null)
            addExpected("defaultProviderId", provider, "exchanges", Exchange.class, e.id);
    }
    for (SocialAspect a : process.socialAspects) {
        addExpected("indicator", a.indicator, "socialAspects", SocialAspect.class, a.id);
        addExpected("source", a.source, "socialAspects", SocialAspect.class, a.id);
    }
    ProcessDocumentation doc = process.documentation;
    addExpected("dataDocumentor", doc.dataDocumentor, "documentation", ProcessDocumentation.class, doc.id);
    addExpected("dataGenerator", doc.dataGenerator, "documentation", ProcessDocumentation.class, doc.id);
    addExpected("dataSetOwner", doc.dataSetOwner, "documentation", ProcessDocumentation.class, doc.id);
    addExpected("reviewer", doc.reviewer, "documentation", ProcessDocumentation.class, doc.id);
    addExpected("publication", doc.publication, "documentation", ProcessDocumentation.class, doc.id);
    for (Source s : process.documentation.sources) addExpected("sources", s, "documentation", ProcessDocumentation.class, doc.id);
    return process;
}
Also used : Exchange(org.openlca.core.model.Exchange) Category(org.openlca.core.model.Category) SocialAspect(org.openlca.core.model.SocialAspect) DQSystem(org.openlca.core.model.DQSystem) Parameter(org.openlca.core.model.Parameter) Process(org.openlca.core.model.Process) ProcessDocumentation(org.openlca.core.model.ProcessDocumentation) Source(org.openlca.core.model.Source) Location(org.openlca.core.model.Location)

Example 2 with Location

use of org.openlca.core.model.Location in project olca-modules by GreenDelta.

the class LocationExport method doIt.

@Override
protected void doIt(CSVPrinter printer, IDatabase db) throws IOException {
    log.trace("write locations");
    LocationDao dao = new LocationDao(db);
    List<Location> locations = dao.getAll();
    for (Location location : locations) {
        Object[] line = createLine(location);
        printer.printRecord(line);
    }
    log.trace("{} locations written", locations.size());
}
Also used : LocationDao(org.openlca.core.database.LocationDao) Location(org.openlca.core.model.Location)

Example 3 with Location

use of org.openlca.core.model.Location 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 4 with Location

use of org.openlca.core.model.Location in project olca-modules by GreenDelta.

the class GeoJsonImport method run.

@Override
public void run() {
    try {
        // parse GeoJSON
        log.trace("parse GeoJSON file {}", file);
        FeatureCollection coll = GeoJSON.read(file);
        if (coll == null || coll.features.isEmpty())
            return;
        // index locations
        LocationDao dao = new LocationDao(db);
        indexLocations(dao);
        // match and update the locations
        for (Feature f : coll.features) {
            if (f.geometry == null || f.properties == null)
                continue;
            Location loc = findMatch(f);
            if (loc == null)
                continue;
            loc.geodata = GeoJSON.pack(FeatureCollection.of(f.geometry));
            dao.update(loc);
        }
    } catch (Exception e) {
        log.error("Failed to import GeoJSON file " + file, e);
    }
}
Also used : FeatureCollection(org.openlca.geo.geojson.FeatureCollection) LocationDao(org.openlca.core.database.LocationDao) Feature(org.openlca.geo.geojson.Feature) Location(org.openlca.core.model.Location)

Example 5 with Location

use of org.openlca.core.model.Location in project olca-modules by GreenDelta.

the class LocationResult method getContributions.

/**
 * Calculates location contributions to the given LCIA category.
 */
public List<Contribution<Location>> getContributions(ImpactDescriptor impact) {
    if (impact == null || result == null || !result.hasImpacts())
        return Collections.emptyList();
    HashMap<Location, Double> cons = new HashMap<>();
    double total = result.getTotalImpactResult(impact);
    if (!result.enviIndex().isRegionalized()) {
        // non-regionalized calculation;
        // we take the locations from the processes
        // in the columns and the results from the
        // corresponding process contributions
        result.techIndex().each((i, product) -> {
            Location loc = getLocation(product);
            double v = result.getDirectImpactResult(product, impact);
            cons.compute(loc, (_loc, oldVal) -> oldVal == null ? v : oldVal + v);
        });
    } else {
        // regionalized calculation;
        // we take the location from the index flows
        // and the values from the direct contributions
        // of these flows to the LCIA category result
        result.enviIndex().each((i, iFlow) -> {
            Location loc = iFlow.location() == null ? null : getLocation(iFlow.location().id);
            double v = result.getDirectFlowImpact(iFlow, impact);
            cons.compute(loc, (_loc, oldVal) -> oldVal == null ? v : oldVal + v);
        });
    }
    return asContributions(cons, total);
}
Also used : HashMap(java.util.HashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) Location(org.openlca.core.model.Location)

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