Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce valid KpiResult scores #30

Merged
merged 3 commits into from
Oct 28, 2024
Merged

Enforce valid KpiResult scores #30

merged 3 commits into from
Oct 28, 2024

Conversation

janniclas
Copy link
Contributor

feat: check the score of all KpiCalculationResults to guarantee that they are in the range of 0...100

@janniclas janniclas self-assigned this Oct 28, 2024
@janniclas janniclas added the enhancement New feature or request label Oct 28, 2024
@janniclas janniclas added this to the 0.0.3 milestone Oct 28, 2024
Copy link

github-actions bot commented Oct 28, 2024

TestsPassed ✅Skipped ⏭️Failed ❌
JUnit Test Report53 ran53 passed0 skipped0 failed

Copy link

github-actions bot commented Oct 28, 2024

Code Coverage

Overall Project 80.59% -0.06% 🍏
Files changed 97.7% 🍏

Module Coverage
core 89.69% -0.14% 🍏
Files
Module File Coverage
core KpiCalculationStrategy.kt 95.22% -0.64% 🍏

@@ -60,6 +61,8 @@ internal interface KpiCalculationStrategy {
fun isValid(node: KpiNode, strict: Boolean = false): Boolean
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intented to be on global scope? How does the private modifier work in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logging library says to use it this way, I didn't check why and trusted them.
private makes it accessible in the whole file and it should be initialized first.

}
}

private fun <T : KpiCalculationResult> validateScore(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the method not only validates but also coerces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair point, will rename

@@ -149,4 +152,38 @@ internal abstract class BaseKpiCalculationStrategy : KpiCalculationStrategy {
}

protected abstract fun internalIsValid(node: KpiNode, strict: Boolean): Boolean

companion object {
fun getResultInValidRange(result: KpiCalculationResult): KpiCalculationResult {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a point where we should throw in strict mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in strict mode we would fail even earlier as we then enforce the validity of the given KPI hierarchy and a valid hierarchy should not result in invalid values.
This function should mainly act as a failsafe if we somehow messed up and somewhere get invalid range results.

@janniclas janniclas merged commit e160dfa into main Oct 28, 2024
2 checks passed
@janniclas janniclas deleted the featu/inRangeCheck branch October 29, 2024 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants