From 096598541d1052176148b892308a18c724c73049 Mon Sep 17 00:00:00 2001 From: Kolya Opahle <k.opahle@sap.com> Date: Thu, 19 Nov 2020 14:38:33 +0100 Subject: [PATCH] Adressed some of the new comments --- .../test/api/ui/TestForAPIFragment.kt | 2 +- ...iskLevelCalculationFragmentCWAViewModel.kt | 3 +- .../nearby/ExposureStateUpdateWorker.kt | 5 +- .../coronawarnapp/risk/DefaultRiskLevels.kt | 46 +++++++++++-------- .../coronawarnapp/risk/ExposureResultStore.kt | 12 ++++- .../coronawarnapp/risk/result/RiskResult.kt | 1 - .../rki/coronawarnapp/update/UpdateChecker.kt | 4 +- 7 files changed, 44 insertions(+), 29 deletions(-) diff --git a/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/api/ui/TestForAPIFragment.kt b/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/api/ui/TestForAPIFragment.kt index df78daec5..d4e224e12 100644 --- a/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/api/ui/TestForAPIFragment.kt +++ b/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/api/ui/TestForAPIFragment.kt @@ -166,7 +166,7 @@ class TestForAPIFragment : Fragment(R.layout.fragment_test_for_a_p_i), buttonRetrieveExposureSummary.setOnClickListener { vm.launch { - val summary = exposureSummaryRepository.entities.first().first.toString() + val summary = exposureSummaryRepository.entities.first().exposureWindows.toString() withContext(Dispatchers.Main) { showToast(summary) diff --git a/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/risklevel/ui/TestRiskLevelCalculationFragmentCWAViewModel.kt b/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/risklevel/ui/TestRiskLevelCalculationFragmentCWAViewModel.kt index 70aec69b8..67d68216e 100644 --- a/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/risklevel/ui/TestRiskLevelCalculationFragmentCWAViewModel.kt +++ b/Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/risklevel/ui/TestRiskLevelCalculationFragmentCWAViewModel.kt @@ -12,6 +12,7 @@ import de.rki.coronawarnapp.diagnosiskeys.storage.KeyCacheRepository import de.rki.coronawarnapp.exception.ExceptionCategory import de.rki.coronawarnapp.exception.reporting.report import de.rki.coronawarnapp.nearby.ENFClient +import de.rki.coronawarnapp.risk.ExposureResult import de.rki.coronawarnapp.risk.ExposureResultStore import de.rki.coronawarnapp.risk.RiskLevel import de.rki.coronawarnapp.risk.RiskLevelTask @@ -110,7 +111,7 @@ class TestRiskLevelCalculationFragmentCWAViewModel @AssistedInject constructor( // Export File Reset keyCacheRepository.clear() - exposureResultStore.entities.value = Pair(emptyList(), null) + exposureResultStore.entities.value = ExposureResult(emptyList(), null) LocalData.lastCalculatedRiskLevel(RiskLevel.UNDETERMINED.raw) LocalData.lastSuccessfullyCalculatedRiskLevel(RiskLevel.UNDETERMINED.raw) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/nearby/ExposureStateUpdateWorker.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/nearby/ExposureStateUpdateWorker.kt index 92fe1c965..f0f0ed5c5 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/nearby/ExposureStateUpdateWorker.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/nearby/ExposureStateUpdateWorker.kt @@ -8,6 +8,7 @@ import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import de.rki.coronawarnapp.exception.ExceptionCategory import de.rki.coronawarnapp.exception.reporting.report +import de.rki.coronawarnapp.risk.ExposureResult import de.rki.coronawarnapp.risk.ExposureResultStore import de.rki.coronawarnapp.risk.RiskLevelTask import de.rki.coronawarnapp.task.TaskController @@ -26,8 +27,8 @@ class ExposureStateUpdateWorker @AssistedInject constructor( override suspend fun doWork(): Result { try { Timber.v("worker to persist exposure summary started") - enfClient.exposureWindows().also { - exposureResultStore.entities.value = Pair(it, null) + enfClient.exposureWindows().let { + exposureResultStore.entities.value = ExposureResult(it, null) Timber.v("exposure summary state updated: $it") } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/risk/DefaultRiskLevels.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/risk/DefaultRiskLevels.kt index 9e542ee8e..e091c66cf 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/risk/DefaultRiskLevels.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/risk/DefaultRiskLevels.kt @@ -95,7 +95,7 @@ class DefaultRiskLevels @Inject constructor( val aggregatedResult = aggregateResults(appConfig, riskResultsPerWindow) - exposureResultStore.entities.value = Pair(exposureWindows, aggregatedResult) + exposureResultStore.entities.value = ExposureResult(exposureWindows, aggregatedResult) val highRisk = aggregatedResult.totalRiskLevel == ProtoRiskLevel.HIGH @@ -227,7 +227,7 @@ class DefaultRiskLevels @Inject constructor( private fun determineRiskLevel( normalizedTime: Double, timeToRiskLevelMapping: List<RiskCalculationParametersOuterClass.NormalizedTimeToRiskLevelMapping> - ) = + ): ProtoRiskLevel? = timeToRiskLevelMapping .filter { it.normalizedTimeRange.inRange(normalizedTime) } .map { it.riskLevel } @@ -285,7 +285,7 @@ class DefaultRiskLevels @Inject constructor( normalizedTime ) - val riskLevel = determineRiskLevel( + val riskLevel: ProtoRiskLevel? = determineRiskLevel( normalizedTime, appConfig.normalizedTimePerExposureWindowToRiskLevelMapping ) @@ -301,7 +301,11 @@ class DefaultRiskLevels @Inject constructor( riskLevel ) - return RiskResult(transmissionRiskLevel, normalizedTime, riskLevel) + return RiskResult( + transmissionRiskLevel = transmissionRiskLevel, + normalizedTime = normalizedTime, + riskLevel = riskLevel + ) } override fun aggregateResults( @@ -313,9 +317,7 @@ class DefaultRiskLevels @Inject constructor( .toSet() Timber.d( - "uniqueDates: ${ - TextUtils.join(System.lineSeparator(), uniqueDatesMillisSinceEpoch) - }" + "uniqueDates: %s", { TextUtils.join(System.lineSeparator(), uniqueDatesMillisSinceEpoch) } ) val exposureHistory = uniqueDatesMillisSinceEpoch.map { aggregateRiskPerDate(appConfig, it, exposureWindowsAndResult) @@ -375,13 +377,13 @@ class DefaultRiskLevels @Inject constructor( Timber.d("numberOfDaysWithHighRisk: $numberOfDaysWithHighRisk") return AggregatedRiskResult( - totalRiskLevel, - totalMinimumDistinctEncountersWithLowRisk, - totalMinimumDistinctEncountersWithHighRisk, - mostRecentDateWithLowRisk, - mostRecentDateWithHighRisk, - numberOfDaysWithLowRisk, - numberOfDaysWithHighRisk + totalRiskLevel = totalRiskLevel, + totalMinimumDistinctEncountersWithLowRisk = totalMinimumDistinctEncountersWithLowRisk, + totalMinimumDistinctEncountersWithHighRisk = totalMinimumDistinctEncountersWithHighRisk, + mostRecentDateWithLowRisk = mostRecentDateWithLowRisk, + mostRecentDateWithHighRisk = mostRecentDateWithHighRisk, + numberOfDaysWithLowRisk = numberOfDaysWithLowRisk, + numberOfDaysWithHighRisk = numberOfDaysWithHighRisk ) } @@ -437,10 +439,10 @@ class DefaultRiskLevels @Inject constructor( Timber.d("minimumDistinctEncountersWithHighRisk: $minimumDistinctEncountersWithHighRisk") return AggregatedRiskPerDateResult( - dateMillisSinceEpoch, - riskLevel, - minimumDistinctEncountersWithLowRisk, - minimumDistinctEncountersWithHighRisk + dateMillisSinceEpoch = dateMillisSinceEpoch, + riskLevel = riskLevel, + minimumDistinctEncountersWithLowRisk = minimumDistinctEncountersWithLowRisk, + minimumDistinctEncountersWithHighRisk = minimumDistinctEncountersWithHighRisk ) } @@ -454,8 +456,12 @@ class DefaultRiskLevels @Inject constructor( private val TAG = DefaultRiskLevels::class.java.simpleName private const val DECIMAL_MULTIPLIER = 100 - class NormalizedTimePerExposureWindowToRiskLevelMappingMissingException : Exception() - class UnknownReportTypeException : Exception() + class NormalizedTimePerExposureWindowToRiskLevelMappingMissingException : Exception( + "Failed to map the normalized Time to a Risk Level" + ) + class UnknownReportTypeException : Exception( + "The Report Type returned by the ENF is not known" + ) private fun <T : Number> RiskCalculationParametersOuterClass.Range.inRange(value: T): Boolean = when { diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/risk/ExposureResultStore.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/risk/ExposureResultStore.kt index 9e06e15d4..dd12361da 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/risk/ExposureResultStore.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/risk/ExposureResultStore.kt @@ -9,7 +9,15 @@ import javax.inject.Singleton @Singleton class ExposureResultStore @Inject constructor() { - val entities = MutableStateFlow<ExposureResult>(Pair(emptyList(), null)) + val entities = MutableStateFlow( + ExposureResult( + exposureWindows = emptyList(), + aggregatedRiskResult = null + ) + ) } -typealias ExposureResult = Pair<List<ExposureWindow>, AggregatedRiskResult?> +data class ExposureResult( + val exposureWindows: List<ExposureWindow>, + val aggregatedRiskResult: AggregatedRiskResult? +) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/risk/result/RiskResult.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/risk/result/RiskResult.kt index e2b5c582b..ee04a41ef 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/risk/result/RiskResult.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/risk/result/RiskResult.kt @@ -2,7 +2,6 @@ package de.rki.coronawarnapp.risk.result import de.rki.coronawarnapp.server.protocols.internal.v2.RiskCalculationParametersOuterClass -// TODO("Adjust Types") data class RiskResult( val transmissionRiskLevel: Int, val normalizedTime: Double, diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/update/UpdateChecker.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/update/UpdateChecker.kt index ce5c756b7..695e297a1 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/update/UpdateChecker.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/update/UpdateChecker.kt @@ -70,11 +70,11 @@ class UpdateChecker(private val activity: LauncherActivity) { val minVersionFromServer = cwaAppConfig.minVersionCode - Timber.e( + Timber.d( "minVersionFromServer:%s", minVersionFromServer ) - Timber.e("Current app version:%s", BuildConfig.VERSION_CODE) + Timber.d("Current app version:%s", BuildConfig.VERSION_CODE) val needsImmediateUpdate = VersionComparator.isVersionOlder( BuildConfig.VERSION_CODE.toLong(), -- GitLab