use of org.openlca.core.database.ImpactMethodDao 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.ImpactMethodDao 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.ImpactMethodDao in project olca-modules by GreenDelta.
the class ImpactMethodExport method doIt.
@Override
protected void doIt(CSVPrinter printer, IDatabase db) throws IOException {
log.trace("write impact methods");
ImpactMethodDao dao = new ImpactMethodDao(db);
CategoryDao categoryDao = new CategoryDao(db);
List<ImpactMethodDescriptor> methods = dao.getDescriptors();
for (ImpactMethodDescriptor method : methods) {
Object[] line = createLine(method, categoryDao);
printer.printRecord(line);
}
log.trace("{} impact methods written", methods.size());
}
use of org.openlca.core.database.ImpactMethodDao in project olca-modules by GreenDelta.
the class TestData method method.
public static ImpactMethod method(String name, ImpactCategory... impacts) {
ImpactMethod m = new ImpactMethod();
m.refId = UUID.randomUUID().toString();
m.name = name;
for (ImpactCategory impact : impacts) {
m.impactCategories.add(impact);
}
ImpactMethodDao dao = new ImpactMethodDao(Tests.getDb());
return dao.insert(m);
}
use of org.openlca.core.database.ImpactMethodDao in project olca-modules by GreenDelta.
the class ImpactMethodImport method of.
@Override
public ImportStatus<ImpactMethod> of(String id) {
var method = imp.get(ImpactMethod.class, id);
// check if we are in update mode
var update = false;
if (method != null) {
update = imp.shouldUpdate(method);
if (!update) {
return ImportStatus.skipped(method);
}
}
// resolve the proto object
var proto = imp.reader.getImpactMethod(id);
if (proto == null)
return method != null ? ImportStatus.skipped(method) : ImportStatus.error("Could not resolve ImpactMethod " + id);
var wrap = ProtoWrap.of(proto);
if (update) {
if (imp.skipUpdate(method, wrap))
return ImportStatus.skipped(method);
}
// map the data
if (method == null) {
method = new ImpactMethod();
method.refId = id;
}
wrap.mapTo(method, imp);
map(proto, method);
// insert or update it
var dao = new ImpactMethodDao(imp.db);
method = update ? dao.update(method) : dao.insert(method);
imp.putHandled(method);
return update ? ImportStatus.updated(method) : ImportStatus.created(method);
}
Aggregations