Search in sources :

Example 1 with NwSet

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);
}
Also used : NwSet(org.openlca.core.model.NwSet)

Example 2 with NwSet

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();
}
Also used : NwFactor(org.openlca.core.model.NwFactor) ImpactCategory(org.openlca.core.model.ImpactCategory) NwSet(org.openlca.core.model.NwSet) ImpactMethod(org.openlca.core.model.ImpactMethod) Before(org.junit.Before)

Example 3 with NwSet

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);
        }
    }
}
Also used : NwSet(org.openlca.core.model.NwSet) Test(org.junit.Test)

Example 4 with NwSet

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);
    }
}
Also used : Objects(java.util.Objects) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) ImpactMethod(org.openlca.core.model.ImpactMethod) Strings(org.openlca.util.Strings) Json(org.openlca.jsonld.Json) NwFactor(org.openlca.core.model.NwFactor) NwSet(org.openlca.core.model.NwSet) ModelType(org.openlca.core.model.ModelType) JsonElement(com.google.gson.JsonElement) NwSet(org.openlca.core.model.NwSet)

Example 5 with NwSet

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);
    }
}
Also used : NwSet(org.openlca.core.model.NwSet) ImpactMethod(org.openlca.core.model.ImpactMethod)

Aggregations

NwSet (org.openlca.core.model.NwSet)10 ImpactMethod (org.openlca.core.model.ImpactMethod)6 NwFactor (org.openlca.core.model.NwFactor)3 Before (org.junit.Before)2 Test (org.junit.Test)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 Objects (java.util.Objects)1 ImpactCategory (org.openlca.core.model.ImpactCategory)1 ModelType (org.openlca.core.model.ModelType)1 Json (org.openlca.jsonld.Json)1 Strings (org.openlca.util.Strings)1