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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations