Skip to content
Snippets Groups Projects
Unverified Commit 3687be81 authored by AlexanderAlferov's avatar AlexanderAlferov Committed by GitHub
Browse files

Parse test JSON files and init unit tests with respective parameters (EXPOSUREAPP-3456) (#1575)


* Split and hide the protobuf config behind interfaces with individual mappers responsible for creating the desired formats.

* Merge branch 'release/1.7.x' into feature/3455-more-frequent-riskscore-updates-configs

# Conflicts:
#	Corona-Warn-App/src/deviceForTesters/java/de/rki/coronawarnapp/test/risklevel/ui/TestRiskLevelCalculationFragmentCWAViewModel.kt
#	Corona-Warn-App/src/main/java/de/rki/coronawarnapp/transaction/RiskLevelTransaction.kt
#	Corona-Warn-App/src/test/java/de/rki/coronawarnapp/transaction/RiskLevelTransactionTest.kt

* Make the AppConfig observable.
Provide the server time offset.
Offer a lastUpdatedAt timestamp.
Add an app config specific test screen.
Clean up test screens a bit and move debug options out of API test options.

* Fix test regression due to refactoring (moved code around).

* Store the server timestamp and offset at retrieval.
Switch to config storage via json to be able to store additional meta data fields (i.e. time).

* KLint and Me have a hate relationship based on both mutual admiration.

* Fix time offset parsing being locale dependent.

* Fix broken unit tests.

* Improve offset accuracy, move before unzipping.

* Fix overly long livedata subscription to results (viewmodel scope vs observer scope)

* Add mapping for the new protobuf configs + tests.

* For cached (retrofit) response, we need to check the cacheResponse and its timestamps
to determine an accurate time offset.

* Exposure a boolean property to tell us when a fallback config is being used.

* Hide the observable flow<ConfigData> behind a method that can automatically triggers refreshes.

* Use a common mapper interface.

* set old risklevelcalculation deprecated

* Created skeleton for new risk calculation and aggregation

* Initial

* Implementing steps to aggregate results form exposure windows - wip

* Address PR comments and KLints.

* Fix refactoring regression.

* ktlint

* Json parsing

* Added ExposureWindowRiskLevelConfig and ExposureWindowRiskLevelConfigMapper for new config api (not yet introduced)

Signed-off-by: default avatarKolya Opahle <k.opahle@sap.com>

* Added first Implementation of exposure window based calculateRisk function

Signed-off-by: default avatarKolya Opahle <k.opahle@sap.com>

* Added generics to Range.inRange

Signed-off-by: default avatarKolya Opahle <k.opahle@sap.com>

* Added Ugly Hack to RiskLevelTransaction to allow for compilation during testing

Signed-off-by: default avatarKolya Opahle <k.opahle@sap.com>

* Linting and injecting RiskLevelCalculation into TestRiskLevelCalculationFragmentCWAViewModel, currently wont build because ExposureWindowRiskLevelConfig has no Provider

Signed-off-by: default avatarKolya Opahle <k.opahle@sap.com>

* Linting extravaganza

Signed-off-by: default avatarKolya Opahle <k.opahle@sap.com>

* Lint Wars Episode VI: Return of the trailing Comma

* Improve config unzipping code.

* Add flag to forward exception thrown during HotDataFlow.kt initialization.

* Don't specify a default context via singleton.

* Move download and fallback logic into it's own class just responsible for sourcing the config: "AppConfigSource".
"AppConfigProvider" is now only responsible for making it available.

* Check test cases

* Simplify current concepts for making the app config observable until we have a default configuration.

* Implementing steps to aggregate results form exposure windows

* cleaned todo

* Adjusted default values

* Improve app config test screen, delete options, better feedback.
Show toast instead of crash on errors.

* Fixed GSON serialization not encoding/decoding the byte array correctly.
Added specific type adapters for instant and duration to get cleaner json.

* Remove type adapters from base gson due to conflict with CalculationTrackerStorage.

* refactored Windows aggregation

* We want to default to forced serialization of instant by our converters, instead of using the default serialization which will differ
between Java8.Instant and JodaTime.Instant, to prevent future headaches there, register explicit converters by default,
and overwrite them if necessary (currently only needed for CalculationTrackerStorage.kt).

* Improve AppConfigServer code readability by moving code into extensions.

* Fix merge conflicts

* removed example value

* Added missing import to WorkerBinderTest

* fixed unit tests

* Removed auto formatting on unrelated files (revert + cherry pick in other commit)

Signed-off-by: default avatarKolya Opahle <k.opahle@sap.com>

* Implementing steps to aggregate results form exposure windows

* Renamed ExposureWindowRiskLevelConfig to ExposureWindowRiskCalculationConfig

* adjusted & refactored Windows aggregation

* removed example Values

* satisfy lint

* make Aggregation work with Instant now

* Use long while calculation

* Added normalizedTimePerDayToRiskLevelMappingList to AppConfig

* normalizedTimePerDayToRiskLevelMappingList from AppConfig

* satisfy lint

* Get AppConfig on init and listen for updates

* exposureData to aggregatedRiskPerDateResult

* Corrected name in ConfigParserTest

* use instant for specific aggregation logs

* satisfy CI

* satisfy detekt

* Mock exposure windows

* Full test process

* Fix gitignore

* Improved logging

* Correct test cases dates handling

* Config fix and logs

* Small clean up

* fixed some naming and conversion issues with json test case parsing

Signed-off-by: default avatarKolya Opahle <k.opahle@sap.com>

* TRL Encodings in config did not match TRL Encodings used in js example

* Removing a return that broke the calculation

* Actual tests and formatting

* Formatting

Co-authored-by: default avatarMatthias Urhahn <matthias.urhahn@sap.com>
Co-authored-by: default avatarBMItter <Berndus@gmx.de>
Co-authored-by: default avatarKolya Opahle <k.opahle@sap.com>
Co-authored-by: default avatarharambasicluka <64483219+harambasicluka@users.noreply.github.com>
parent e51c8031
No related branches found
No related tags found
No related merge requests found
Showing
with 1580 additions and 1 deletion
......@@ -308,7 +308,7 @@ class DefaultRiskLevels @Inject constructor(
.filter { it.attenuationRange.inRange(scanInstance.typicalAttenuationDb) }
.map { it.weight }
.firstOrNull() ?: .0
return seconds + scanInstance.secondsSinceLastScan * weight
seconds + scanInstance.secondsSinceLastScan * weight
}
private fun determineRiskLevel(
......
package de.rki.coronawarnapp.nearby.windows.entities
import com.google.gson.annotations.SerializedName
import de.rki.coronawarnapp.nearby.windows.entities.cases.TestCase
import de.rki.coronawarnapp.nearby.windows.entities.configuration.DefaultRiskCalculationConfiguration
data class ExposureWindowsJsonInput(
@SerializedName("__comment__")
val comment: String,
@SerializedName("defaultRiskCalculationConfiguration")
val defaultRiskCalculationConfiguration: DefaultRiskCalculationConfiguration,
@SerializedName("testCases")
val testCases: List<TestCase>
)
package de.rki.coronawarnapp.nearby.windows.entities.cases
import com.google.gson.annotations.SerializedName
data class JsonScanInstance(
@SerializedName("minAttenuation")
val minAttenuation: Int,
@SerializedName("secondsSinceLastScan")
val secondsSinceLastScan: Int,
@SerializedName("typicalAttenuation")
val typicalAttenuation: Int
)
package de.rki.coronawarnapp.nearby.windows.entities.cases
import com.google.gson.annotations.SerializedName
data class JsonWindow(
@SerializedName("ageInDays")
val ageInDays: Int,
@SerializedName("calibrationConfidence")
val calibrationConfidence: Int,
@SerializedName("infectiousness")
val infectiousness: Int,
@SerializedName("reportType")
val reportType: Int,
@SerializedName("scanInstances")
val scanInstances: List<JsonScanInstance>
)
package de.rki.coronawarnapp.nearby.windows.entities.cases
import com.google.gson.annotations.SerializedName
data class TestCase(
@SerializedName("description")
val description: String,
@SerializedName("expAgeOfMostRecentDateWithHighRisk")
val expAgeOfMostRecentDateWithHighRisk: Long?,
@SerializedName("expAgeOfMostRecentDateWithLowRisk")
val expAgeOfMostRecentDateWithLowRisk: Long?,
@SerializedName("expTotalMinimumDistinctEncountersWithHighRisk")
val expTotalMinimumDistinctEncountersWithHighRisk: Int,
@SerializedName("expTotalMinimumDistinctEncountersWithLowRisk")
val expTotalMinimumDistinctEncountersWithLowRisk: Int,
@SerializedName("expTotalRiskLevel")
val expTotalRiskLevel: Int,
@SerializedName("exposureWindows")
val exposureWindows: List<JsonWindow>
)
package de.rki.coronawarnapp.nearby.windows.entities.configuration
import com.google.gson.annotations.SerializedName
data class DefaultRiskCalculationConfiguration(
@SerializedName("minutesAtAttenuationFilters")
val minutesAtAttenuationFilters: List<JsonMinutesAtAttenuationFilter>,
@SerializedName("minutesAtAttenuationWeights")
val minutesAtAttenuationWeights: List<JsonMinutesAtAttenuationWeight>,
@SerializedName("normalizedTimePerDayToRiskLevelMapping")
val normalizedTimePerDayToRiskLevelMapping: List<JsonNormalizedTimeToRiskLevelMapping>,
@SerializedName("normalizedTimePerEWToRiskLevelMapping")
val normalizedTimePerEWToRiskLevelMapping: List<JsonNormalizedTimeToRiskLevelMapping>,
@SerializedName("transmissionRiskLevelMultiplier")
val transmissionRiskLevelMultiplier: Double,
@SerializedName("trlEncoding")
val trlEncoding: JsonTrlEncoding,
@SerializedName("trlFilters")
val trlFilters: List<JsonTrlFilter>
)
package de.rki.coronawarnapp.nearby.windows.entities.configuration
import com.google.gson.annotations.SerializedName
data class JsonMinutesAtAttenuationFilter(
@SerializedName("attenuationRange")
val attenuationRange: Range,
@SerializedName("dropIfMinutesInRange")
val dropIfMinutesInRange: Range
)
package de.rki.coronawarnapp.nearby.windows.entities.configuration
import com.google.gson.annotations.SerializedName
data class JsonMinutesAtAttenuationWeight(
@SerializedName("attenuationRange")
val attenuationRange: Range,
@SerializedName("weight")
val weight: Double
)
package de.rki.coronawarnapp.nearby.windows.entities.configuration
import com.google.gson.annotations.SerializedName
data class JsonNormalizedTimeToRiskLevelMapping(
@SerializedName("normalizedTimeRange")
val normalizedTimeRange: Range,
@SerializedName("riskLevel")
val riskLevel: Int
)
package de.rki.coronawarnapp.nearby.windows.entities.configuration
import com.google.gson.annotations.SerializedName
data class JsonTrlEncoding(
@SerializedName("infectiousnessOffsetHigh")
val infectiousnessOffsetHigh: Int,
@SerializedName("infectiousnessOffsetStandard")
val infectiousnessOffsetStandard: Int,
@SerializedName("reportTypeOffsetConfirmedClinicalDiagnosis")
val reportTypeOffsetConfirmedClinicalDiagnosis: Int,
@SerializedName("reportTypeOffsetConfirmedTest")
val reportTypeOffsetConfirmedTest: Int,
@SerializedName("reportTypeOffsetRecursive")
val reportTypeOffsetRecursive: Int,
@SerializedName("reportTypeOffsetSelfReport")
val reportTypeOffsetSelfReport: Int
)
package de.rki.coronawarnapp.nearby.windows.entities.configuration
import com.google.gson.annotations.SerializedName
data class JsonTrlFilter(
@SerializedName("dropIfTrlInRange")
val dropIfTrlInRange: Range
)
package de.rki.coronawarnapp.nearby.windows.entities.configuration
import com.google.gson.annotations.SerializedName
data class Range(
@SerializedName("min")
val min: Double,
@SerializedName("minExclusive")
val minExclusive: Boolean,
@SerializedName("max")
val max: Double,
@SerializedName("maxExclusive")
val maxExclusive: Boolean
)
This diff is collapsed.
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