Search in sources :

Example 1 with SubCompartment

use of org.openlca.simapro.csv.enums.SubCompartment in project olca-modules by GreenDelta.

the class ImpactFactors method expand.

static void expand(ImpactCategoryBlock block) {
    if (block == null)
        return;
    // build a reverse index: flow -> type -> sub-compartment -> factor row
    var idx = new HashMap<String, EnumMap<ElementaryFlowType, EnumMap<SubCompartment, ImpactFactorRow>>>();
    for (var row : block.factors()) {
        var top = ElementaryFlowType.of(row.compartment());
        var sub = SubCompartment.of(row.subCompartment());
        if (top == null || sub == null || row.flow() == null)
            continue;
        var key = row.flow().trim().toLowerCase();
        if (key.isEmpty())
            continue;
        idx.computeIfAbsent(key, _key -> new EnumMap<>(ElementaryFlowType.class)).computeIfAbsent(top, _top -> new EnumMap<>(SubCompartment.class)).put(sub, row);
    }
    // generate factors
    for (var flowEntry : idx.entrySet()) {
        var map = flowEntry.getValue();
        for (var typeEntry : map.entrySet()) {
            var type = typeEntry.getKey();
            var rows = typeEntry.getValue();
            var unspecified = rows.get(SubCompartment.UNSPECIFIED);
            if (unspecified == null)
                continue;
            for (var sub : SubCompartment.values()) {
                if (sub == SubCompartment.UNSPECIFIED || sub.flowType() != type || rows.containsKey(sub))
                    continue;
                block.factors().add(new ImpactFactorRow().compartment(unspecified.compartment()).subCompartment(sub.toString()).flow(unspecified.flow()).casNumber(unspecified.casNumber()).factor(unspecified.factor()).unit(unspecified.unit()));
            }
        }
    }
}
Also used : SubCompartment(org.openlca.simapro.csv.enums.SubCompartment) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) ElementaryFlowType(org.openlca.simapro.csv.enums.ElementaryFlowType) ImpactCategoryBlock(org.openlca.simapro.csv.method.ImpactCategoryBlock) ImpactFactorRow(org.openlca.simapro.csv.method.ImpactFactorRow) ElementaryFlowType(org.openlca.simapro.csv.enums.ElementaryFlowType) HashMap(java.util.HashMap) ImpactFactorRow(org.openlca.simapro.csv.method.ImpactFactorRow) EnumMap(java.util.EnumMap)

Aggregations

EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 ElementaryFlowType (org.openlca.simapro.csv.enums.ElementaryFlowType)1 SubCompartment (org.openlca.simapro.csv.enums.SubCompartment)1 ImpactCategoryBlock (org.openlca.simapro.csv.method.ImpactCategoryBlock)1 ImpactFactorRow (org.openlca.simapro.csv.method.ImpactFactorRow)1