-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added (Weighted)MinimumKpiCalculationStrategy, renamed AggregationKpiCalculationStrategy to WeightedAverageKPICalculationStrategy, added in range check for KPI scores - we now calculate the weighted max as score * weight, but propagate the score - renamed AggregationKPICalculationStrategy.kt to WeightedAverageKPICalculationStrategy.kt - renamed RatioKPICalculationStrategy.kt to WeightedRatioKPICalculationStrategy.kt - feat: added WeightedMinimumKPICalculationStrategy * fix: min and max strategies return Empty() if edges are empty * feat: check the score of all KpiCalculationResults to guarantee that they are in the range of 0...100 * test: added rangeCheck test for KpiCalculationResults without a score * chore: renamed validity check function and added javadoc * fix: use PkgIdentifier and PURL to support non-OS targets * chore: fixed naming issues and explicitly return Empty() for max and min strategy
- Loading branch information
Showing
19 changed files
with
363 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
core/src/main/kotlin/de/fraunhofer/iem/spha/core/strategy/MinimumKPICalculationStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2024 Fraunhofer IEM. All rights reserved. | ||
* | ||
* Licensed under the MIT license. See LICENSE file in the project root for details. | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* License-Filename: LICENSE | ||
*/ | ||
|
||
package de.fraunhofer.iem.spha.core.strategy | ||
|
||
import de.fraunhofer.iem.spha.core.hierarchy.KpiHierarchyEdge | ||
import de.fraunhofer.iem.spha.model.kpi.KpiStrategyId | ||
import de.fraunhofer.iem.spha.model.kpi.hierarchy.KpiCalculationResult | ||
import de.fraunhofer.iem.spha.model.kpi.hierarchy.KpiNode | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
|
||
private val logger = KotlinLogging.logger {} | ||
|
||
internal object MinimumKPICalculationStrategy : BaseKpiCalculationStrategy() { | ||
|
||
override val kpiStrategyId: KpiStrategyId | ||
get() = KpiStrategyId.MINIMUM_STRATEGY | ||
|
||
override fun internalCalculateKpi(edges: Collection<KpiHierarchyEdge>): KpiCalculationResult { | ||
|
||
val min = edges.minOfOrNull { it.to.score } | ||
|
||
if (min == null) { | ||
return KpiCalculationResult.Empty() | ||
} | ||
|
||
return KpiCalculationResult.Success(score = min) | ||
} | ||
|
||
/** There is no validity requirement for this strategy. */ | ||
override fun internalIsValid(node: KpiNode, strict: Boolean): Boolean { | ||
|
||
if (node.edges.size == 1) { | ||
logger.warn { | ||
"Minimum KPI calculation strategy for node $node is planned " + | ||
"for a single child." | ||
} | ||
} | ||
|
||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...main/kotlin/de/fraunhofer/iem/spha/core/strategy/WeightedMinimumKPICalculationStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2024 Fraunhofer IEM. All rights reserved. | ||
* | ||
* Licensed under the MIT license. See LICENSE file in the project root for details. | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* License-Filename: LICENSE | ||
*/ | ||
|
||
package de.fraunhofer.iem.spha.core.strategy | ||
|
||
import de.fraunhofer.iem.spha.core.hierarchy.KpiHierarchyEdge | ||
import de.fraunhofer.iem.spha.model.kpi.KpiStrategyId | ||
import de.fraunhofer.iem.spha.model.kpi.hierarchy.KpiCalculationResult | ||
import de.fraunhofer.iem.spha.model.kpi.hierarchy.KpiNode | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
|
||
private val logger = KotlinLogging.logger {} | ||
|
||
internal object WeightedMinimumKPICalculationStrategy : BaseKpiCalculationStrategy() { | ||
|
||
override val kpiStrategyId: KpiStrategyId | ||
get() = KpiStrategyId.WEIGHTED_MINIMUM_STRATEGY | ||
|
||
override fun internalCalculateKpi(edges: Collection<KpiHierarchyEdge>): KpiCalculationResult { | ||
|
||
val min = edges.minByOrNull { it.to.score * it.actualWeight }?.to?.score | ||
|
||
if (min == null) { | ||
return KpiCalculationResult.Empty() | ||
} | ||
|
||
return KpiCalculationResult.Success(score = min) | ||
} | ||
|
||
/** There is no validity requirement for this strategy. */ | ||
override fun internalIsValid(node: KpiNode, strict: Boolean): Boolean { | ||
|
||
if (node.edges.size == 1) { | ||
logger.warn { | ||
"Maximum KPI calculation strategy for node $node is planned " + | ||
"for a single child." | ||
} | ||
} | ||
|
||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.