use of org.openlca.core.model.NwSet in project olca-app by GreenDelta.
the class ImpactNwPage method findNewNwSet.
private NwSet findNewNwSet() {
List<NwSet> list = getModel().nwSets;
if (list.isEmpty())
return null;
NwSet old = setViewer.getSelected();
if (old == null)
return list.get(0);
for (NwSet set : list) {
if (Objects.equals(old.refId, set.refId))
return set;
}
return list.get(0);
}
use of org.openlca.core.model.NwSet in project olca-modules by GreenDelta.
the class NwSetIOTest method setUp.
@Before
public void setUp() {
ImpactMethod method = new ImpactMethod();
for (int i = 0; i < NWSET_COUNT; i++) {
NwSet set = new NwSet();
set.name = "nwset_" + i;
method.nwSets.add(set);
}
ImpactCategoryDao cdao = new ImpactCategoryDao(db);
for (int i = 0; i < CATEGORY_COUNT; i++) {
ImpactCategory category = new ImpactCategory();
category.name = "category_" + i;
category = cdao.insert(category);
method.impactCategories.add(category);
for (NwSet set : method.nwSets) {
NwFactor factor = new NwFactor();
factor.weightingFactor = FACTOR;
factor.impactCategory = category;
factor.normalisationFactor = FACTOR;
set.factors.add(factor);
}
}
this.method = new ImpactMethodDao(db).insert(method);
Tests.emptyCache();
}
use of org.openlca.core.model.NwSet in project olca-modules by GreenDelta.
the class NwSetIOTest method testNwSetTable.
@Test
public void testNwSetTable() {
for (NwSet nwSet : method.nwSets) {
var table = NwSetTable.of(db, nwSet);
for (var impact : method.impactCategories) {
Assert.assertEquals(FACTOR, table.getNormalizationFactor(impact.id), 1e-20);
Assert.assertEquals(FACTOR, table.getWeightingFactor(impact.id), 1e-20);
}
}
}
use of org.openlca.core.model.NwSet in project olca-modules by GreenDelta.
the class ImpactMethodImport method mapNwSets.
private void mapNwSets(JsonObject json, ImpactMethod method) {
var array = Json.getArray(json, "nwSets");
if (array == null)
return;
for (JsonElement e : array) {
if (!e.isJsonObject())
continue;
var nwObj = e.getAsJsonObject();
var nwSet = new NwSet();
method.nwSets.add(nwSet);
In.mapAtts(nwObj, nwSet, 0L);
nwSet.weightedScoreUnit = Json.getString(json, "weightedScoreUnit");
Json.stream(Json.getArray(nwObj, "factors")).filter(JsonElement::isJsonObject).map(f -> nwFactor(f.getAsJsonObject(), method)).forEach(nwSet.factors::add);
}
}
use of org.openlca.core.model.NwSet in project olca-modules by GreenDelta.
the class ImpactMethodImport method createMethod.
private void createMethod(ImpactMethodDescriptor d) {
ImpactMethod src = srcDao.getForId(d.id);
ImpactMethod dest = src.copy();
dest.refId = src.refId;
dest.category = refs.switchRef(src.category);
switchImpacts(dest);
switchNwSets(src, dest);
dest = destDao.insert(dest);
seq.put(seq.IMPACT_METHOD, src.refId, dest.id);
for (NwSet nwSet : dest.nwSets) {
seq.put(seq.NW_SET, nwSet.refId, nwSet.id);
}
}
Aggregations