EN: Correctly report multiple exposures to same key

This commit is contained in:
Marvin W 2020-10-17 19:18:59 +02:00
parent ff79a670e5
commit 15fb118bbd
No known key found for this signature in database
GPG Key ID: 072E9235DB996F2A

View File

@ -25,10 +25,13 @@ fun List<MeasuredExposure>.merge(): List<MergedExposure> {
for (key in keys) { for (key in keys) {
var merged: MergedExposure? = null var merged: MergedExposure? = null
for (exposure in filter { it.key == key }.sortedBy { it.timestamp }) { for (exposure in filter { it.key == key }.sortedBy { it.timestamp }) {
if (merged == null) { if (merged != null && merged.timestamp + MergedExposure.MAXIMUM_DURATION + ROLLING_WINDOW_LENGTH_MS > exposure.timestamp) {
merged = MergedExposure(key, exposure.timestamp, listOf(MergedSubExposure(exposure.attenuation, exposure.duration)))
} else if (merged.timestamp + MergedExposure.MAXIMUM_DURATION + ROLLING_WINDOW_LENGTH_MS > exposure.timestamp) {
merged += exposure merged += exposure
} else {
if (merged != null) {
result.add(merged)
}
merged = MergedExposure(key, exposure.timestamp, listOf(MergedSubExposure(exposure.attenuation, exposure.duration)))
} }
if (merged.durationInMinutes > 30) { if (merged.durationInMinutes > 30) {
result.add(merged) result.add(merged)
@ -114,6 +117,7 @@ data class MergedExposure internal constructor(val key: TemporaryExposureKey, va
fun getRiskScore(configuration: ExposureConfiguration): Int { fun getRiskScore(configuration: ExposureConfiguration): Int {
val risk = getAttenuationRiskScore(configuration) * getDaysSinceLastExposureRiskScore(configuration) * getDurationRiskScore(configuration) * getTransmissionRiskScore(configuration) val risk = getAttenuationRiskScore(configuration) * getDaysSinceLastExposureRiskScore(configuration) * getDurationRiskScore(configuration) * getTransmissionRiskScore(configuration)
Log.d(TAG, "Risk score calculation: ${getAttenuationRiskScore(configuration)} * ${getDaysSinceLastExposureRiskScore(configuration)} * ${getDurationRiskScore(configuration)} * ${getTransmissionRiskScore(configuration)} = $risk") Log.d(TAG, "Risk score calculation: ${getAttenuationRiskScore(configuration)} * ${getDaysSinceLastExposureRiskScore(configuration)} * ${getDurationRiskScore(configuration)} * ${getTransmissionRiskScore(configuration)} = $risk")
if (risk < configuration.minimumRiskScore) return 0
return risk return risk
} }