Skip to content

Commit

Permalink
Functional, no mapping done. Tests to be added and fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
jedesroches committed Jul 24, 2023
1 parent c4aa798 commit 5dd9ff5
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AssessProcessAction(

override fun run(indicator: ProgressIndicator) {
val trace = traceSystemWithIndicator(indicator, file, processName, matchLabels)
val order = trace.getProductOrder()
val order = trace.getObservableOrder()
val inventory = Assessment(trace.getSystemValue(), trace.getEntryPoint()).inventory()
this.data = Pair(inventory, order)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ class EvaluationTrace {
private var currentStage = HashSet<MatrixRowIndex>()
private val processes = HashSet<ProcessValue>()
private val substanceCharacterizations = HashSet<SubstanceCharacterizationValue>()
private val productDepthMap = HashMap<MatrixColumnIndex, Int>()
private val observableDepthMap = HashMap<MatrixColumnIndex, Int>()

companion object {
fun empty(): EvaluationTrace {
return EvaluationTrace()
}
}

fun getProductOrder(): Comparator<MatrixColumnIndex> {
fun getObservableOrder(): Comparator<MatrixColumnIndex> {
return object : Comparator<MatrixColumnIndex> {
override fun compare(o1: MatrixColumnIndex, o2: MatrixColumnIndex): Int {
val d1 = productDepthMap[o1] ?: throw EvaluatorException("unknown ${o1}")
val d2 = productDepthMap[o2] ?: throw EvaluatorException("unknown ${o2}")
val d1 = observableDepthMap[o1] ?: throw EvaluatorException("unknown ${o1}")
val d2 = observableDepthMap[o2] ?: throw EvaluatorException("unknown ${o2}")
if (d1 < d2) {
return -1
}
Expand Down Expand Up @@ -94,13 +94,13 @@ class EvaluationTrace {
.filterIsInstance<ProcessValue>()
.forEach { process ->
process.products.forEach { exchange ->
productDepthMap[exchange.product] = currentDepth
observableDepthMap[exchange.product] = currentDepth
}
}
currentStage
.filterIsInstance<SubstanceCharacterizationValue>()
.forEach { sc ->
productDepthMap[sc.referenceExchange.substance] = currentDepth
observableDepthMap[sc.referenceExchange.substance] = currentDepth
}

stages.add(currentStage)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package ch.kleis.lcaplugin.imports.ecospold

import ch.kleis.lcaplugin.core.lang.expression.SubstanceType
import ch.kleis.lcaplugin.imports.ModelWriter
import ch.kleis.lcaplugin.imports.ecospold.lcia.EcospoldImporter.Companion.unitToStr
import ch.kleis.lcaplugin.imports.ecospold.model.ActivityDataset
import ch.kleis.lcaplugin.imports.ecospold.model.ElementaryExchange
import ch.kleis.lcaplugin.imports.ecospold.model.IntermediateExchange
import ch.kleis.lcaplugin.imports.ecospold.model.Uncertainty
import ch.kleis.lcaplugin.imports.model.ExchangeBlock
import ch.kleis.lcaplugin.imports.model.ImportedBioExchange
import ch.kleis.lcaplugin.imports.model.ImportedProcess
import ch.kleis.lcaplugin.imports.model.ImportedProductExchange
import ch.kleis.lcaplugin.imports.simapro.sanitizeSymbol
Expand Down Expand Up @@ -36,7 +39,7 @@ open class EcoSpold2ProcessMapper(val process: ActivityDataset) {
mapInputs()
mapLandUse()
mapResources()
mapEmission()
mapEmissions()

return result
}
Expand All @@ -48,11 +51,46 @@ open class EcoSpold2ProcessMapper(val process: ActivityDataset) {
result.productBlocks = mutableListOf(ExchangeBlock("Products", products))
}

open fun mapEmission() {}
open fun mapInputs() {}
open fun mapLandUse() {}
open fun mapResources() {}
private fun mapEmissions() {
result.emissionBlocks += ExchangeBlock("FIXME",
process.flowData.elementaryExchanges
.filter { it.substanceType == SubstanceType.EMISSION }
.map(::elementaryExchangeToImportedBioExchange).toMutableList()
)

// TODO: Remove when closing #261
val bio = ImportedBioExchange(listOf(), "1.0", "u", pUid, "")
result.emissionBlocks += ExchangeBlock("Virtual Substance for Impact Factors", mutableListOf(bio))

}

private fun mapLandUse() {
result.landUseBlocks = mutableListOf(ExchangeBlock("FIXME",
process.flowData.elementaryExchanges
.filter { it.substanceType == SubstanceType.LAND_USE }
.map(::elementaryExchangeToImportedBioExchange).toMutableList()
))
}

private fun mapResources() {
result.resourceBlocks = mutableListOf(ExchangeBlock("FIXME",
process.flowData.elementaryExchanges
.filter { it.substanceType == SubstanceType.RESOURCE }
.map(::elementaryExchangeToImportedBioExchange).toMutableList()
))
}

private fun elementaryExchangeToImportedBioExchange(elementaryExchange: ElementaryExchange): ImportedBioExchange =
ImportedBioExchange(
comments = elementaryExchange.comment?.let { listOf(it) } ?: listOf(),
qty = elementaryExchange.amount.toString(),
unit = elementaryExchange.unit,
uid = ModelWriter.sanitizeAndCompact(elementaryExchange.name),
compartment = elementaryExchange.compartment,
subCompartment = elementaryExchange.subCompartment,
)

open fun mapInputs() {}

open fun mapMetas() {
val metas = result.meta
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.kleis.lcaplugin.imports.ecospold.lcia

import ch.kleis.lcaplugin.imports.ModelWriter
import ch.kleis.lcaplugin.imports.ecospold.EcoSpold2ProcessMapper
import ch.kleis.lcaplugin.imports.ecospold.lcia.EcospoldImporter.ProcessDictRecord
import ch.kleis.lcaplugin.imports.ecospold.model.ActivityDataset
import ch.kleis.lcaplugin.imports.shared.serializer.ProcessSerializer
Expand All @@ -19,28 +20,28 @@ class Ecospold2ProcessRenderer {
val category = category(data)

val subFolder = if (category == null) "" else "${category}${File.separatorChar}"
val process = LciaProcessMapper(data).map()
val process = EcoSpold2ProcessMapper(data).map()
process.comments.add(processComment)
val strProcess = ProcessSerializer.serialize(process)

w.write(
"processes${File.separatorChar}$subFolder${process.uid}.lca",
strProcess, index = false, closeAfterWrite = false
"processes${File.separatorChar}$subFolder${process.uid}.lca",
strProcess, index = false, closeAfterWrite = false
)
val substance = EcoSpold2SubstanceMapper.map(data, methodName)
val strSubstance = SubstanceSerializer.serialize(substance)
w.write(
"processes${File.separatorChar}$subFolder${process.uid}.lca",
strSubstance, index = false, closeAfterWrite = true
"processes${File.separatorChar}$subFolder${process.uid}.lca",
strSubstance, index = false, closeAfterWrite = true
)


}

private fun category(data: ActivityDataset): String? {
val desc = data.description.classifications
.firstOrNull { it.system == "EcoSpold01Categories" }
?.value
.firstOrNull { it.system == "EcoSpold01Categories" }
?.value
return desc?.let { ModelWriter.sanitizeAndCompact(it) }
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ch.kleis.lcaplugin.imports.ecospold.model


data class FlowData(
val intermediateExchanges: List<IntermediateExchange> = ArrayList(),
val impactIndicators: List<ImpactIndicator>
val intermediateExchanges: List<IntermediateExchange> = ArrayList(),
val impactIndicators: List<ImpactIndicator>,
val elementaryExchanges: Sequence<ElementaryExchange>,
)
Loading

0 comments on commit 5dd9ff5

Please sign in to comment.