Search in sources :

Example 1 with ImpactIndex

use of org.openlca.core.matrix.index.ImpactIndex 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);
}
Also used : ImpactIndex(org.openlca.core.matrix.index.ImpactIndex) ImpactCategoryDao(org.openlca.core.database.ImpactCategoryDao)

Example 2 with ImpactIndex

use of org.openlca.core.matrix.index.ImpactIndex in project olca-modules by GreenDelta.

the class SystemExport method mapImpactCategoryIndices.

private List<ImpactDescriptor> mapImpactCategoryIndices(ExcelHeader header, ImpactIndex impactIndex) {
    var sortedCategories = impactIndex.content().stream().sorted((i1, i2) -> Strings.compare(i1.name, i2.name)).collect(Collectors.toList());
    int counter = 0;
    for (ImpactDescriptor category : sortedCategories) {
        header.putIndexMapping(counter, impactIndex.of(category));
        counter++;
    }
    return sortedCategories;
}
Also used : CalculationSetup(org.openlca.core.model.CalculationSetup) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) MatrixReader(org.openlca.core.matrix.format.MatrixReader) TechIndex(org.openlca.core.matrix.index.TechIndex) EnviIndex(org.openlca.core.matrix.index.EnviIndex) Excel(org.openlca.io.xls.Excel) MatrixData(org.openlca.core.matrix.MatrixData) DateFormat(java.text.DateFormat) Sheet(org.apache.poi.ss.usermodel.Sheet) Matrix(org.openlca.core.matrix.format.Matrix) Logger(org.slf4j.Logger) GregorianCalendar(java.util.GregorianCalendar) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) Workbook(org.apache.poi.ss.usermodel.Workbook) Strings(org.openlca.util.Strings) DenseMatrix(org.openlca.core.matrix.format.DenseMatrix) AllocationMethod(org.openlca.core.model.AllocationMethod) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) ImpactIndex(org.openlca.core.matrix.index.ImpactIndex) Collections(java.util.Collections) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor)

Aggregations

ImpactIndex (org.openlca.core.matrix.index.ImpactIndex)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 DateFormat (java.text.DateFormat)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 GregorianCalendar (java.util.GregorianCalendar)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1 ImpactCategoryDao (org.openlca.core.database.ImpactCategoryDao)1 MatrixData (org.openlca.core.matrix.MatrixData)1 DenseMatrix (org.openlca.core.matrix.format.DenseMatrix)1 Matrix (org.openlca.core.matrix.format.Matrix)1 MatrixReader (org.openlca.core.matrix.format.MatrixReader)1 EnviIndex (org.openlca.core.matrix.index.EnviIndex)1 TechIndex (org.openlca.core.matrix.index.TechIndex)1