Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
improvements from reviewers
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-cwa committed Oct 30, 2020
1 parent 3c5de43 commit 965e966
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class DefaultRiskLevels @Inject constructor(
override suspend fun isIncreasedRisk(lastExposureSummary: ExposureSummary): Boolean {
val appConfiguration = appConfigProvider.getAppConfig()
Timber.tag(TAG).v("Retrieved configuration from backend")
// custom attenuation parameters to weight the attenuation
// custom attenuation parameters to weigh the attenuation
// values provided by the Google API
val attenuationParameters = appConfiguration.attenuationDuration
// these are the defined risk classes. They will divide the calculated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ import de.rki.coronawarnapp.exception.RiskLevelCalculationException
import de.rki.coronawarnapp.exception.reporting.report
import de.rki.coronawarnapp.nearby.ENFClient
import de.rki.coronawarnapp.nearby.InternalExposureNotificationClient
import de.rki.coronawarnapp.risk.RiskLevel.INCREASED_RISK
import de.rki.coronawarnapp.risk.RiskLevel.LOW_LEVEL_RISK
import de.rki.coronawarnapp.risk.RiskLevel.NO_CALCULATION_POSSIBLE_TRACING_OFF
import de.rki.coronawarnapp.risk.RiskLevel.UNDETERMINED
import de.rki.coronawarnapp.risk.RiskLevel.UNKNOWN_RISK_INITIAL
import de.rki.coronawarnapp.risk.RiskLevel.UNKNOWN_RISK_OUTDATED_RESULTS
import de.rki.coronawarnapp.risk.RiskLevel.UNKNOWN_RISK_OUTDATED_RESULTS_MANUAL
import de.rki.coronawarnapp.risk.RiskLevel.*
import de.rki.coronawarnapp.storage.LocalData
import de.rki.coronawarnapp.storage.RiskLevelRepository
import de.rki.coronawarnapp.task.Task
Expand All @@ -23,6 +17,7 @@ import de.rki.coronawarnapp.task.TaskFactory
import de.rki.coronawarnapp.task.common.DefaultProgress
import de.rki.coronawarnapp.util.ConnectivityHelper
import de.rki.coronawarnapp.util.ConnectivityHelper.isNetworkEnabled
import de.rki.coronawarnapp.util.TimeStamper
import de.rki.coronawarnapp.util.di.AppContext
import kotlinx.coroutines.channels.ConflatedBroadcastChannel
import kotlinx.coroutines.flow.Flow
Expand All @@ -36,7 +31,8 @@ import javax.inject.Provider
class RiskLevelTask @Inject constructor(
private val riskLevels: RiskLevels,
@AppContext private val context: Context,
private val enfClient: ENFClient
private val enfClient: ENFClient,
private val timeStamper: TimeStamper
) : Task<DefaultProgress, RiskLevelTask.Result> {

private val internalProgress = ConflatedBroadcastChannel<DefaultProgress>()
Expand All @@ -53,23 +49,25 @@ class RiskLevelTask @Inject constructor(
RiskLevelRepository.setLastCalculatedRiskLevelAsCurrent()
return Result(UNDETERMINED)
}

if (!enfClient.isTracingEnabled.first()) {
return Result(NO_CALCULATION_POSSIBLE_TRACING_OFF)
}

with(riskLevels) {
return Result(
when {
!enfClient.isTracingEnabled.first().also {
checkCancel()
} -> NO_CALCULATION_POSSIBLE_TRACING_OFF

calculationNotPossibleBecauseOfNoKeys().also {
checkCancel()
} -> UNKNOWN_RISK_INITIAL

calculationNotPossibleBecauseOfOutdatedResults().also {
checkCancel()
} -> if (backgroundJobsEnabled)
} -> if (backgroundJobsEnabled) {
UNKNOWN_RISK_OUTDATED_RESULTS
else
} else {
UNKNOWN_RISK_OUTDATED_RESULTS_MANUAL
}

isIncreasedRisk(getNewExposureSummary()).also {
checkCancel()
Expand All @@ -82,7 +80,7 @@ class RiskLevelTask @Inject constructor(
else -> LOW_LEVEL_RISK
}.also {
checkCancel()
updateRepository(it, System.currentTimeMillis())
updateRepository(it, timeStamper.nowUTC.millis)
}
)
}
Expand Down

0 comments on commit 965e966

Please sign in to comment.