This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce dagger 2, first risk level unit tests (EXPOSUREAPP-2207) (#…
…1069) * - add hilt for dependency injection - enable application & activities for hilt * updated dependency versions * test get risk level * renamed binding * -hilt +dagger 2 * satisfying klint * satisfying klint * satisfying klint * satisfying klint * satisfying klint for tests * additional module stubs, explicit android injector * additional module stubs, explicit android injector * renamed implementations * fixed compiler error for device for tester Co-authored-by: Fabian Kajzar <[email protected]> Co-authored-by: Jakob Möller <[email protected]>
- Loading branch information
1 parent
0d26afb
commit 5240f1b
Showing
23 changed files
with
387 additions
and
92 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
6 changes: 6 additions & 0 deletions
6
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/receiver/ReceiverBinder.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,6 @@ | ||
package de.rki.coronawarnapp.receiver | ||
|
||
import dagger.Module | ||
|
||
@Module | ||
internal abstract class ReceiverBinder |
66 changes: 66 additions & 0 deletions
66
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/risk/DefaultRiskLevelCalculation.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,66 @@ | ||
package de.rki.coronawarnapp.risk | ||
|
||
import com.google.android.gms.nearby.exposurenotification.ExposureSummary | ||
import de.rki.coronawarnapp.server.protocols.ApplicationConfigurationOuterClass | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
import kotlin.math.round | ||
|
||
@Singleton | ||
class DefaultRiskLevelCalculation @Inject constructor() : RiskLevelCalculation { | ||
|
||
companion object { | ||
|
||
private var TAG = DefaultRiskLevelCalculation::class.simpleName | ||
|
||
private const val DECIMAL_MULTIPLIER = 100 | ||
} | ||
|
||
override fun calculateRiskScore( | ||
attenuationParameters: ApplicationConfigurationOuterClass.AttenuationDuration, | ||
exposureSummary: ExposureSummary | ||
): Double { | ||
|
||
/** all attenuation values are capped to [TimeVariables.MAX_ATTENUATION_DURATION] */ | ||
val weightedAttenuationLow = | ||
attenuationParameters.weights.low | ||
.times(exposureSummary.attenuationDurationsInMinutes[0].capped()) | ||
val weightedAttenuationMid = | ||
attenuationParameters.weights.mid | ||
.times(exposureSummary.attenuationDurationsInMinutes[1].capped()) | ||
val weightedAttenuationHigh = | ||
attenuationParameters.weights.high | ||
.times(exposureSummary.attenuationDurationsInMinutes[2].capped()) | ||
|
||
val maximumRiskScore = exposureSummary.maximumRiskScore.toDouble() | ||
|
||
val defaultBucketOffset = attenuationParameters.defaultBucketOffset.toDouble() | ||
val normalizationDivisor = attenuationParameters.riskScoreNormalizationDivisor.toDouble() | ||
|
||
val attenuationStrings = | ||
"Weighted Attenuation: ($weightedAttenuationLow + $weightedAttenuationMid + " + | ||
"$weightedAttenuationHigh + $defaultBucketOffset)" | ||
Timber.v(attenuationStrings) | ||
|
||
val weightedAttenuationDuration = | ||
weightedAttenuationLow | ||
.plus(weightedAttenuationMid) | ||
.plus(weightedAttenuationHigh) | ||
.plus(defaultBucketOffset) | ||
|
||
Timber.v("Formula used: ($maximumRiskScore / $normalizationDivisor) * $weightedAttenuationDuration") | ||
|
||
val riskScore = (maximumRiskScore / normalizationDivisor) * weightedAttenuationDuration | ||
|
||
return round(riskScore.times(DECIMAL_MULTIPLIER)).div(DECIMAL_MULTIPLIER) | ||
} | ||
|
||
private fun Int.capped(): Int { | ||
return if (this > TimeVariables.getMaxAttenuationDuration()) { | ||
TimeVariables.getMaxAttenuationDuration() | ||
} else { | ||
this | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/risk/DefaultRiskScoreAnalysis.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,11 @@ | ||
package de.rki.coronawarnapp.risk | ||
|
||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class DefaultRiskScoreAnalysis @Inject constructor() : RiskScoreAnalysis { | ||
|
||
override fun withinDefinedLevelThreshold(riskScore: Double, min: Int, max: Int) = | ||
riskScore >= min && riskScore <= max | ||
} |
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
21 changes: 21 additions & 0 deletions
21
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/risk/RiskModule.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,21 @@ | ||
package de.rki.coronawarnapp.risk | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
abstract class RiskModule { | ||
|
||
@Binds | ||
@Singleton | ||
abstract fun bindRiskLevelCalculation( | ||
riskLevelCalculation: DefaultRiskLevelCalculation | ||
): RiskLevelCalculation | ||
|
||
@Binds | ||
@Singleton | ||
abstract fun bindRiskScoreAnalysis( | ||
riskScoreAnalysis: DefaultRiskScoreAnalysis | ||
): RiskScoreAnalysis | ||
} |
10 changes: 10 additions & 0 deletions
10
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/risk/RiskScoreAnalysis.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,10 @@ | ||
package de.rki.coronawarnapp.risk | ||
|
||
interface RiskScoreAnalysis { | ||
|
||
fun withinDefinedLevelThreshold( | ||
riskScore: Double, | ||
min: Int, | ||
max: Int | ||
): Boolean | ||
} |
6 changes: 6 additions & 0 deletions
6
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/service/ServiceBinder.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,6 @@ | ||
package de.rki.coronawarnapp.service | ||
|
||
import dagger.Module | ||
|
||
@Module | ||
internal abstract class ServiceBinder |
Oops, something went wrong.