Search in sources :

Example 6 with Location

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

the class LocationResult method getNetCostsContributions.

/**
 * Calculates location contributions to the total net-costs.
 */
public List<Contribution<Location>> getNetCostsContributions() {
    if (result == null)
        return Collections.emptyList();
    HashMap<Location, Double> cons = new HashMap<>();
    result.techIndex().each((i, product) -> {
        Location loc = getLocation(product);
        double v = result.getDirectCostResult(product);
        cons.compute(loc, (_loc, oldVal) -> oldVal == null ? v : oldVal + v);
    });
    double total = result.totalCosts;
    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)

Example 7 with Location

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

the class LocationResult method getAddedValueContributions.

/**
 * Calculates location contributions to the total added value.
 */
public List<Contribution<Location>> getAddedValueContributions() {
    if (result == null)
        return Collections.emptyList();
    HashMap<Location, Double> cons = new HashMap<>();
    result.techIndex().each((i, product) -> {
        Location loc = getLocation(product);
        double costs = result.getDirectCostResult(product);
        double v = costs == 0 ? 0 : -costs;
        cons.compute(loc, (_loc, oldVal) -> oldVal == null ? v : oldVal + v);
    });
    double total = result.totalCosts;
    total = total == 0 ? 0 : -total;
    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)

Example 8 with Location

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

the class LocationResult method getLocation.

private Location getLocation(long id) {
    Location loc = cache.get(id);
    if (loc != null)
        return loc;
    loc = new LocationDao(db).getForId(id);
    cache.put(id, loc);
    return loc;
}
Also used : LocationDao(org.openlca.core.database.LocationDao) Location(org.openlca.core.model.Location)

Example 9 with Location

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

the class DataUtil method toDataSet.

static ProtoDataSet.Builder toDataSet(IDatabase db, RefEntity e) {
    var ds = ProtoDataSet.newBuilder();
    var conf = WriterConfig.of(db);
    if (e instanceof Actor)
        return ds.setActor(new ActorWriter(conf).write((Actor) e));
    if (e instanceof Category)
        return ds.setCategory(new CategoryWriter(conf).write((Category) e));
    if (e instanceof Currency)
        return ds.setCurrency(new CurrencyWriter(conf).write((Currency) e));
    if (e instanceof DQSystem)
        return ds.setDqSystem(new DQSystemWriter(conf).write((DQSystem) e));
    if (e instanceof Flow)
        return ds.setFlow(new FlowWriter(conf).write((Flow) e));
    if (e instanceof FlowProperty)
        return ds.setFlowProperty(new FlowPropertyWriter(conf).write((FlowProperty) e));
    if (e instanceof ImpactCategory)
        return ds.setImpactCategory(new ImpactCategoryWriter(conf).write((ImpactCategory) e));
    if (e instanceof ImpactMethod)
        return ds.setImpactMethod(new ImpactMethodWriter(conf).write((ImpactMethod) e));
    if (e instanceof Location)
        return ds.setLocation(new LocationWriter(conf).write((Location) e));
    if (e instanceof Parameter)
        return ds.setParameter(new ParameterWriter(conf).write((Parameter) e));
    if (e instanceof Process)
        return ds.setProcess(new ProcessWriter(conf).write((Process) e));
    if (e instanceof ProductSystem)
        return ds.setProductSystem(new ProductSystemWriter(conf).write((ProductSystem) e));
    if (e instanceof Project)
        return ds.setProject(new ProjectWriter(conf).write((Project) e));
    if (e instanceof SocialIndicator)
        return ds.setSocialIndicator(new SocialIndicatorWriter(conf).write((SocialIndicator) e));
    if (e instanceof Source)
        return ds.setSource(new SourceWriter(conf).write((Source) e));
    if (e instanceof UnitGroup)
        return ds.setUnitGroup(new UnitGroupWriter(conf).write((UnitGroup) e));
    return ds;
}
Also used : ImpactCategory(org.openlca.core.model.ImpactCategory) Category(org.openlca.core.model.Category) UnitGroup(org.openlca.core.model.UnitGroup) ImpactCategoryWriter(org.openlca.proto.io.output.ImpactCategoryWriter) ProductSystem(org.openlca.core.model.ProductSystem) Process(org.openlca.core.model.Process) UnitGroupWriter(org.openlca.proto.io.output.UnitGroupWriter) ImpactMethod(org.openlca.core.model.ImpactMethod) ProductSystemWriter(org.openlca.proto.io.output.ProductSystemWriter) Source(org.openlca.core.model.Source) CurrencyWriter(org.openlca.proto.io.output.CurrencyWriter) FlowPropertyWriter(org.openlca.proto.io.output.FlowPropertyWriter) Actor(org.openlca.core.model.Actor) Currency(org.openlca.core.model.Currency) CategoryWriter(org.openlca.proto.io.output.CategoryWriter) ImpactCategoryWriter(org.openlca.proto.io.output.ImpactCategoryWriter) FlowProperty(org.openlca.core.model.FlowProperty) FlowWriter(org.openlca.proto.io.output.FlowWriter) ImpactCategory(org.openlca.core.model.ImpactCategory) SourceWriter(org.openlca.proto.io.output.SourceWriter) Flow(org.openlca.core.model.Flow) LocationWriter(org.openlca.proto.io.output.LocationWriter) Project(org.openlca.core.model.Project) DQSystemWriter(org.openlca.proto.io.output.DQSystemWriter) ParameterWriter(org.openlca.proto.io.output.ParameterWriter) DQSystem(org.openlca.core.model.DQSystem) ActorWriter(org.openlca.proto.io.output.ActorWriter) ImpactMethodWriter(org.openlca.proto.io.output.ImpactMethodWriter) ProjectWriter(org.openlca.proto.io.output.ProjectWriter) Parameter(org.openlca.core.model.Parameter) SocialIndicator(org.openlca.core.model.SocialIndicator) ProcessWriter(org.openlca.proto.io.output.ProcessWriter) Location(org.openlca.core.model.Location) SocialIndicatorWriter(org.openlca.proto.io.output.SocialIndicatorWriter)

Example 10 with Location

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

the class FlowTest method testWithLocation.

@Test
public void testWithLocation() {
    Location loc = new Location();
    loc.code = "ABC";
    loc.refId = UUID.randomUUID().toString();
    LocationDao locDao = new LocationDao(Tests.getDb());
    loc = locDao.insert(loc);
    Flow flow = createModel();
    flow.location = loc;
    flow = dao.insert(flow);
    exportAndDelete(flow, dao);
    doImport(dao, flow);
    Flow clone = dao.getForRefId(flow.refId);
    Assert.assertEquals("ABC", clone.location.code);
    dao.delete(clone);
    locDao.delete(loc);
}
Also used : LocationDao(org.openlca.core.database.LocationDao) Location(org.openlca.core.model.Location) Flow(org.openlca.core.model.Flow) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

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