Search in sources :

Example 26 with Location

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

the class EcoSpold01Import method locations.

private void locations(DataSet ds) {
    Set<String> codes = new HashSet<>();
    IGeography geo = ds.getGeography();
    if (geo != null && geo.getLocation() != null) {
        codes.add(geo.getLocation());
    }
    for (IExchange e : ds.getExchanges()) {
        if (e.getLocation() != null) {
            codes.add(e.getLocation());
        }
    }
    for (String code : codes) {
        String id = KeyGen.get(code);
        Location loc = db.findLocation(code, id);
        if (loc != null) {
            log.skipped(loc);
            continue;
        }
        loc = new Location();
        loc.refId = id;
        loc.name = code;
        loc.code = code;
        db.put(loc, id);
        log.imported(loc);
    }
}
Also used : IExchange(org.openlca.ecospold.IExchange) IGeography(org.openlca.ecospold.IGeography) HashSet(java.util.HashSet) Location(org.openlca.core.model.Location)

Example 27 with Location

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

the class FlowInfo method getAll.

public static List<FlowInfo> getAll(SystemExportConfig conf, EnviIndex index) {
    EntityCache cache = conf.getEntityCache();
    Set<FlowDescriptor> flows = getFlowDescriptors(index);
    List<FlowInfo> infos = new ArrayList<>();
    for (FlowDescriptor flow : flows) {
        CategoryPair catPair = CategoryPair.create(flow, cache);
        FlowInfo info = new FlowInfo();
        info.realId = flow.id;
        info.id = flow.refId;
        info.name = flow.name;
        info.category = catPair.getCategory();
        info.subCategory = catPair.getSubCategory();
        if (flow.location != null) {
            Location location = cache.get(Location.class, flow.location);
            if (location != null)
                info.location = location.code;
        }
        String unit = DisplayValues.referenceUnit(flow, cache);
        info.unit = unit;
        infos.add(info);
    }
    return infos;
}
Also used : EntityCache(org.openlca.core.database.EntityCache) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ArrayList(java.util.ArrayList) CategoryPair(org.openlca.io.CategoryPair) Location(org.openlca.core.model.Location)

Example 28 with Location

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

the class ProductInfo method getAll.

public static List<ProductInfo> getAll(SystemExportConfig conf, TechIndex index) {
    EntityCache cache = conf.getEntityCache();
    List<ProductInfo> infos = new ArrayList<>(index.size() + 2);
    for (int i = 0; i < index.size(); i++) {
        TechFlow pair = index.at(i);
        RootDescriptor process = pair.provider();
        FlowDescriptor product = pair.flow();
        ProductInfo info = new ProductInfo();
        info.provider = pair;
        info.ref = pair.equals(index.getRefFlow());
        info.process = process.name;
        info.processId = process.refId;
        info.product = product.name;
        info.productId = product.refId;
        if (process.category != null) {
            Category cat = cache.get(Category.class, process.category);
            CategoryPair catPair = new CategoryPair(cat);
            info.processCategory = catPair.getCategory();
            info.processSubCategory = catPair.getSubCategory();
        }
        if (process instanceof ProcessDescriptor) {
            ProcessDescriptor p = (ProcessDescriptor) process;
            if (p.location != null) {
                Location loc = cache.get(Location.class, p.location);
                if (loc != null)
                    info.processLocation = loc.code;
            }
        }
        infos.add(info);
    }
    return infos;
}
Also used : Category(org.openlca.core.model.Category) EntityCache(org.openlca.core.database.EntityCache) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) TechFlow(org.openlca.core.matrix.index.TechFlow) ArrayList(java.util.ArrayList) RootDescriptor(org.openlca.core.model.descriptors.RootDescriptor) CategoryPair(org.openlca.io.CategoryPair) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) Location(org.openlca.core.model.Location)

Example 29 with Location

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

the class FlowReferenceSearchTest method createModel.

@Override
protected Flow createModel() {
    Flow flow = new Flow();
    flow.category = insertAndAddExpected("category", new Category());
    flow.location = insertAndAddExpected("location", new Location());
    flow.flowPropertyFactors.add(createFlowPropertyFactor());
    flow.flowPropertyFactors.add(createFlowPropertyFactor());
    flow = db.insert(flow);
    for (FlowPropertyFactor f : flow.flowPropertyFactors) addExpected("flowProperty", f.flowProperty, "flowPropertyFactors", FlowPropertyFactor.class, f.id);
    return flow;
}
Also used : Category(org.openlca.core.model.Category) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) Flow(org.openlca.core.model.Flow) Location(org.openlca.core.model.Location)

Example 30 with Location

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

the class LocationDescriptorTest method test.

@Test
public void test() {
    Location loc = new Location();
    loc.name = "LOC";
    loc.refId = "LOC";
    loc.code = "LOC";
    LocationDao dao = new LocationDao(Tests.getDb());
    loc = dao.insert(loc);
    LocationDescriptor d = dao.descriptorMap().get(loc.id);
    dao.delete(loc);
    Assert.assertEquals(loc.name, d.name);
    Assert.assertEquals(loc.refId, d.refId);
    Assert.assertEquals(loc.code, d.code);
}
Also used : LocationDescriptor(org.openlca.core.model.descriptors.LocationDescriptor) LocationDao(org.openlca.core.database.LocationDao) Location(org.openlca.core.model.Location) 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