use of org.openlca.core.database.ImpactCategoryDao in project olca-modules by GreenDelta.
the class FlowPropertyFactorUseSearchTest method testFindInImpactCategory.
@Test
public void testFindInImpactCategory() {
ImpactFactor iFactor = new ImpactFactor();
iFactor.flow = flow;
iFactor.flowPropertyFactor = factor;
ImpactCategory category = new ImpactCategory();
category.impactFactors.add(iFactor);
ImpactCategoryDao dao = new ImpactCategoryDao(database);
dao.insert(category);
List<RootDescriptor> results = search.findUses(factor);
dao.delete(category);
Assert.assertEquals(1, results.size());
Descriptor expected = Descriptor.of(category);
Assert.assertEquals(expected, results.get(0));
}
use of org.openlca.core.database.ImpactCategoryDao in project olca-modules by GreenDelta.
the class Sequence method init.
private void init(IDatabase db) {
index(CATEGORY, new CategoryDao(db));
index(LOCATION, new LocationDao(db));
index(ACTOR, new ActorDao(db));
index(SOURCE, new SourceDao(db));
index(UNIT, new UnitDao(db));
index(UNIT_GROUP, new UnitGroupDao(db));
index(FLOW_PROPERTY, new FlowPropertyDao(db));
index(FLOW, new FlowDao(db));
index(CURRENCY, new CurrencyDao(db));
index(PROCESS, new ProcessDao(db));
index(PRODUCT_SYSTEM, new ProductSystemDao(db));
index(IMPACT_CATEGORY, new ImpactCategoryDao(db));
index(IMPACT_METHOD, new ImpactMethodDao(db));
index(NW_SET, new NwSetDao(db));
index(PROJECT, new ProjectDao(db));
index(DQ_SYSTEM, new DQSystemDao(db));
index(SOCIAL_INDICATOR, new SocialIndicatorDao(db));
}
use of org.openlca.core.database.ImpactCategoryDao in project olca-modules by GreenDelta.
the class RegionalizedCalculationTest method testRegionalizedCalculation.
@Test
public void testRegionalizedCalculation() {
Flow nox = flow("NOx", "mg", FlowType.ELEMENTARY_FLOW);
// create the process
Process p = new Process();
p.name = "transport, bus";
p.quantitativeReference = p.output(flow("transport, bus", "p*km", FlowType.PRODUCT_FLOW), 1);
Exchange e1 = p.output(nox, 5);
e1.location = loc1;
Exchange e2 = p.output(nox, 10);
e2.location = loc2;
p = new ProcessDao(db).insert(p);
// create the LCIA category & method
var impact = new ImpactCategory();
impact.name = "human tox";
impact.factor(nox, 0.5);
impact.factor(nox, 0.1).location = loc1;
impact.factor(nox, 0.9).location = loc2;
impact = new ImpactCategoryDao(db).insert(impact);
var method = new ImpactMethod();
method.impactCategories.add(impact);
method = new ImpactMethodDao(db).insert(method);
// create the product system and calculation setup
var setup = CalculationSetup.fullAnalysis(ProductSystem.of(p)).withImpactMethod(method).withRegionalization(true);
var calculator = new SystemCalculator(db);
FullResult r = calculator.calculateFull(setup);
Assert.assertTrue(r.enviIndex().isRegionalized());
checkRegTotalFlowResults(r, new Object[][] { { nox, loc1, 5.0 }, { nox, loc2, 10.0 } });
}
use of org.openlca.core.database.ImpactCategoryDao in project olca-modules by GreenDelta.
the class Library method syncImpacts.
/**
* Returns the impact categories of the library in matrix order. If this
* information is not present or something went wrong while synchronizing
* the impact index with the database, an empty option is returned.
*/
public Optional<ImpactIndex> syncImpacts(IDatabase db) {
var proto = getImpactIndex();
int size = proto.getImpactCount();
if (size == 0)
return Optional.empty();
var index = new ImpactIndex();
var impacts = descriptors(new ImpactCategoryDao(db));
for (int i = 0; i < size; i++) {
var entry = proto.getImpact(i);
var impact = impacts.get(entry.getImpact().getId());
if (impact == null)
return Optional.empty();
index.add(impact);
}
return Optional.of(index);
}
use of org.openlca.core.database.ImpactCategoryDao in project olca-modules by GreenDelta.
the class ParameterTest method testImpactCategory.
@Test
public void testImpactCategory() {
var impact = new ImpactCategory();
impact.refId = UUID.randomUUID().toString();
var param = impact.parameter("param", 42);
var dao = new ImpactCategoryDao(Tests.getDb());
dao.insert(impact);
with(zip -> {
JsonExport export = new JsonExport(Tests.getDb(), zip);
export.write(impact);
});
dao.delete(impact);
with(zip -> {
JsonImport jImport = new JsonImport(zip, Tests.getDb());
jImport.run();
});
ImpactCategory clone = dao.getForRefId(impact.refId);
Assert.assertEquals(param.refId, clone.parameters.get(0).refId);
}
Aggregations