Skip to content
Snippets Groups Projects
Unverified Commit 4c0114e6 authored by chris-cwa's avatar chris-cwa Committed by GitHub
Browse files

Ignore negative secondsSinceLastScan (EXPOSUREAPP-3897) (#1694)

ignore negative secondsSinceLastScan
parent 395e3b2e
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ import org.joda.time.Instant ...@@ -14,6 +14,7 @@ import org.joda.time.Instant
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
import kotlin.math.max
@Singleton @Singleton
class DefaultRiskLevels @Inject constructor() : RiskLevels { class DefaultRiskLevels @Inject constructor() : RiskLevels {
...@@ -37,7 +38,7 @@ class DefaultRiskLevels @Inject constructor() : RiskLevels { ...@@ -37,7 +38,7 @@ class DefaultRiskLevels @Inject constructor() : RiskLevels {
// Get total seconds at attenuation in exposure window // Get total seconds at attenuation in exposure window
val secondsAtAttenuation: Double = scanInstances val secondsAtAttenuation: Double = scanInstances
.filter { attenuationFilter.attenuationRange.inRange(it.minAttenuationDb) } .filter { attenuationFilter.attenuationRange.inRange(it.minAttenuationDb) }
.fold(.0) { acc, scanInstance -> acc + scanInstance.secondsSinceLastScan } .fold(.0) { acc, scanInstance -> acc + max(scanInstance.secondsSinceLastScan, 0) }
val minutesAtAttenuation = secondsAtAttenuation / 60 val minutesAtAttenuation = secondsAtAttenuation / 60
return attenuationFilter.dropIfMinutesInRange.inRange(minutesAtAttenuation) return attenuationFilter.dropIfMinutesInRange.inRange(minutesAtAttenuation)
...@@ -86,7 +87,7 @@ class DefaultRiskLevels @Inject constructor() : RiskLevels { ...@@ -86,7 +87,7 @@ class DefaultRiskLevels @Inject constructor() : RiskLevels {
.filter { it.attenuationRange.inRange(scanInstance.minAttenuationDb) } .filter { it.attenuationRange.inRange(scanInstance.minAttenuationDb) }
.map { it.weight } .map { it.weight }
.firstOrNull() ?: .0 .firstOrNull() ?: .0
seconds + scanInstance.secondsSinceLastScan * weight seconds + max(scanInstance.secondsSinceLastScan, 0) * weight
} }
private fun determineRiskLevel( private fun determineRiskLevel(
......
...@@ -1060,6 +1060,46 @@ ...@@ -1060,6 +1060,46 @@
"expAgeOfMostRecentDateWithHighRisk": null, "expAgeOfMostRecentDateWithHighRisk": null,
"expNumberOfDaysWithLowRisk": 1, "expNumberOfDaysWithLowRisk": 1,
"expNumberOfDaysWithHighRisk": 0 "expNumberOfDaysWithHighRisk": 0
},
{
"description": "ignores negative secondsSinceLastScan (can happen when time-travelling, not officially supported)",
"exposureWindows": [
{
"ageInDays": 1,
"reportType": 3,
"infectiousness": 2,
"calibrationConfidence": 0,
"scanInstances": [
{
"minAttenuation": 25,
"typicalAttenuation": 25,
"secondsSinceLastScan": -86160
},
{
"minAttenuation": 25,
"typicalAttenuation": 25,
"secondsSinceLastScan": 300
},
{
"minAttenuation": 25,
"typicalAttenuation": 25,
"secondsSinceLastScan": 300
},
{
"minAttenuation": 25,
"typicalAttenuation": 25,
"secondsSinceLastScan": 300
}
]
}
],
"expTotalRiskLevel": 2,
"expTotalMinimumDistinctEncountersWithLowRisk": 0,
"expTotalMinimumDistinctEncountersWithHighRisk": 1,
"expAgeOfMostRecentDateWithLowRisk": null,
"expAgeOfMostRecentDateWithHighRisk": 1,
"expNumberOfDaysWithLowRisk": 0,
"expNumberOfDaysWithHighRisk": 1
} }
] ]
} }
\ No newline at end of file
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