Skip to content
Snippets Groups Projects
Unverified Commit 29a8f7e4 authored by BMItter's avatar BMItter Committed by GitHub
Browse files

Adjusted getting infos for additionalRiskCalcInfo (#1684)

parent af008947
No related branches found
No related tags found
No related merge requests found
...@@ -35,11 +35,13 @@ import de.rki.coronawarnapp.util.ui.SingleLiveEvent ...@@ -35,11 +35,13 @@ import de.rki.coronawarnapp.util.ui.SingleLiveEvent
import de.rki.coronawarnapp.util.viewmodel.CWAViewModel import de.rki.coronawarnapp.util.viewmodel.CWAViewModel
import de.rki.coronawarnapp.util.viewmodel.CWAViewModelFactory import de.rki.coronawarnapp.util.viewmodel.CWAViewModelFactory
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.sample import kotlinx.coroutines.flow.sample
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.joda.time.Instant import org.joda.time.Instant
import timber.log.Timber import timber.log.Timber
import java.util.Date
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
class TestRiskLevelCalculationFragmentCWAViewModel @AssistedInject constructor( class TestRiskLevelCalculationFragmentCWAViewModel @AssistedInject constructor(
...@@ -63,7 +65,6 @@ class TestRiskLevelCalculationFragmentCWAViewModel @AssistedInject constructor( ...@@ -63,7 +65,6 @@ class TestRiskLevelCalculationFragmentCWAViewModel @AssistedInject constructor(
Timber.d("Example arg: %s", exampleArg) Timber.d("Example arg: %s", exampleArg)
} }
val startLocalQRCodeScanEvent = SingleLiveEvent<Unit>()
val riskLevelResetEvent = SingleLiveEvent<Unit>() val riskLevelResetEvent = SingleLiveEvent<Unit>()
val showRiskStatusCard = SubmissionRepository.deviceUIStateFlow.map { val showRiskStatusCard = SubmissionRepository.deviceUIStateFlow.map {
...@@ -126,16 +127,38 @@ class TestRiskLevelCalculationFragmentCWAViewModel @AssistedInject constructor( ...@@ -126,16 +127,38 @@ class TestRiskLevelCalculationFragmentCWAViewModel @AssistedInject constructor(
.appendLine(normalizedTimePerDayToRiskLevelMappingList) .appendLine(normalizedTimePerDayToRiskLevelMappingList)
.toString() .toString()
// Only update when risk level gets updated val additionalRiskCalcInfo = combine(
val additionalRiskCalcInfo = RiskLevelRepository RiskLevelRepository.riskLevelScore,
.riskLevelScore RiskLevelRepository.riskLevelScoreLastSuccessfulCalculated,
.map { createAdditionalRiskCalcInfo(it) } exposureResultStore.matchedKeyCount,
.asLiveData() exposureResultStore.daysSinceLastExposure,
LocalData.lastTimeDiagnosisKeysFromServerFetchFlow()
private suspend fun createAdditionalRiskCalcInfo(riskLevelScore: Int): String = StringBuilder() ) { riskLevelScore,
riskLevelScoreLastSuccessfulCalculated,
matchedKeyCount,
daysSinceLastExposure,
lastTimeDiagnosisKeysFromServerFetch ->
createAdditionalRiskCalcInfo(
riskLevelScore = riskLevelScore,
riskLevelScoreLastSuccessfulCalculated = riskLevelScoreLastSuccessfulCalculated,
matchedKeyCount = matchedKeyCount,
daysSinceLastExposure = daysSinceLastExposure,
lastTimeDiagnosisKeysFromServerFetch = lastTimeDiagnosisKeysFromServerFetch
)
}.asLiveData()
private suspend fun createAdditionalRiskCalcInfo(
riskLevelScore: Int,
riskLevelScoreLastSuccessfulCalculated: Int,
matchedKeyCount: Int,
daysSinceLastExposure: Int,
lastTimeDiagnosisKeysFromServerFetch: Date?
): String = StringBuilder()
.appendLine("Risk Level: ${RiskLevel.forValue(riskLevelScore)}") .appendLine("Risk Level: ${RiskLevel.forValue(riskLevelScore)}")
.appendLine("Last successful Risk Level: ${RiskLevelRepository.getLastSuccessfullyCalculatedScore()}") .appendLine("Last successful Risk Level: ${RiskLevel.forValue(riskLevelScoreLastSuccessfulCalculated)}")
.appendLine("Last Time Server Fetch: ${LocalData.lastTimeDiagnosisKeysFromServerFetch()}") .appendLine("Matched key count: $matchedKeyCount")
.appendLine("Days since last Exposure: $daysSinceLastExposure days")
.appendLine("Last Time Server Fetch: ${lastTimeDiagnosisKeysFromServerFetch?.time?.let { Instant.ofEpochMilli(it) }}")
.appendLine("Tracing Duration: ${TimeUnit.MILLISECONDS.toDays(TimeVariables.getTimeActiveTracingDuration())} days") .appendLine("Tracing Duration: ${TimeUnit.MILLISECONDS.toDays(TimeVariables.getTimeActiveTracingDuration())} days")
.appendLine("Tracing Duration in last 14 days: ${TimeVariables.getActiveTracingDaysInRetentionPeriod()} days") .appendLine("Tracing Duration in last 14 days: ${TimeVariables.getActiveTracingDaysInRetentionPeriod()} days")
.appendLine( .appendLine(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment