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

Feature/TASK 3483 risk calculation v2 #1457

Merged
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c76432c
Set ENAPIVersion to 2
nickguendling Oct 29, 2020
e8ba2c7
Set deployment target to 13.7
nickguendling Oct 29, 2020
839bd01
added model classes to pars json
KaiTeuber Oct 31, 2020
a447151
added loading and parsing of json risk calculation test cases
KaiTeuber Oct 31, 2020
5e703c6
move test model to test target
KaiTeuber Oct 31, 2020
84a77ab
ExposureWindow uses real properties, added RiskHelper ExposureWindow
KaiTeuber Oct 31, 2020
39f4db7
cleanup
KaiTeuber Oct 31, 2020
288aa7c
Refine json test data parsing
nickguendling Nov 2, 2020
cb5a027
Implement json based unit test
nickguendling Nov 2, 2020
c6c56cc
Determine risk level per exposure window
nickguendling Nov 2, 2020
6204fed
Implement result aggregation
nickguendling Nov 2, 2020
21d59f4
added test for a single testcase to make calculation chankes work
KaiTeuber Nov 2, 2020
9098f6f
ENA no longer needed and removed
KaiTeuber Nov 2, 2020
03a1038
only check result if exp value is not nil
KaiTeuber Nov 2, 2020
2e9e02b
Update test case json to use proper report type raw values
nickguendling Nov 3, 2020
0dc9ec7
Use start of day for dates generated from test case json
nickguendling Nov 3, 2020
e91fca2
Remove obsolete test case properties
nickguendling Nov 3, 2020
29dcd1f
Update test cases json
nickguendling Nov 3, 2020
89dad9e
Clean up some test code
nickguendling Nov 3, 2020
04f6bf1
Remove number of exposure windows from calculation
nickguendling Nov 3, 2020
d50239f
Improve documentation
nickguendling Nov 3, 2020
69f2ad8
Move new calculation to service section
nickguendling Nov 3, 2020
a4a22a0
Add initializers from protobuf types
nickguendling Nov 3, 2020
50c38b0
Remove unused files
nickguendling Nov 4, 2020
ac2fe4d
Merge branch 'feature/2582-risk-calculation-v2' into feature/3544-tes…
nickguendling Nov 4, 2020
adf26cd
Make range properties private
nickguendling Nov 4, 2020
6ca03ef
Add unit tests for range
nickguendling Nov 4, 2020
e3f0e2d
Rename to risk calculation result
nickguendling Nov 4, 2020
fbfa53e
Remove properties that are only for tests and move functionality to a…
nickguendling Nov 4, 2020
f1b6899
Move decodable conformance for exposure window to test target
nickguendling Nov 4, 2020
c27d390
Rename detection date to calculation date
nickguendling Nov 4, 2020
9c014f2
Revert "Set deployment target to 13.7"
nickguendling Nov 4, 2020
c2375e2
Set deployment target only on the project
nickguendling Nov 4, 2020
aeaebd5
Rename to RiskCalculationExposureWindow and make it a window
nickguendling Nov 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 137 additions & 6 deletions src/xcode/ENA/ENA.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/xcode/ENA/ENA/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>ENDeveloperRegion</key>
<string>DE</string>
<key>ENAPIVersion</key>
<integer>1</integer>
<integer>2</integer>
<key>CFBundleName</key>
<string>ENA</string>
<key>CFBundlePackageType</key>
Expand Down
2 changes: 1 addition & 1 deletion src/xcode/ENA/ENA/Resources/Info_Debug.plist
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>ENAPIVersion</key>
<integer>1</integer>
<integer>2</integer>
<key>ENDeveloperRegion</key>
<string>TEST_DE_0</string>
<key>ITSAppUsesNonExemptEncryption</key>
Expand Down
2 changes: 1 addition & 1 deletion src/xcode/ENA/ENA/Resources/Info_Testflight.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>ENDeveloperRegion</key>
<string>TEST_DE_0</string>
<key>ENAPIVersion</key>
<integer>1</integer>
<integer>2</integer>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// Corona-Warn-App
//
// SAP SE and all other contributors
// copyright owners license this file to you under the Apache
// License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//

import Foundation

enum CWARiskLevel: Int, Decodable {

// MARK: - Init

init(from riskLevel: SAP_Internal_V2_NormalizedTimeToRiskLevelMapping.RiskLevel) {
switch riskLevel {
case .low:
self = .low
case .high:
self = .high
default:
fatalError("Only low and high risk levels are supported")
}
}

// MARK: - Internal

case low = 1
case high = 2

var eitherLowOrIncreasedRiskLevel: EitherLowOrIncreasedRiskLevel {
mlenkeit marked this conversation as resolved.
Show resolved Hide resolved
switch self {
case .low:
return .low
case .high:
return .increased
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// Corona-Warn-App
//
// SAP SE and all other contributors
// copyright owners license this file to you under the Apache
// License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//

import Foundation

struct ENARange: Decodable {

// MARK: - Init

init(from range: SAP_Internal_V2_Range) {
self.min = range.min
self.max = range.max
self.minExclusive = range.minExclusive
self.maxExclusive = range.maxExclusive
}

// MARK: - Internal

func contains(_ value: Double) -> Bool {
let minExclusive = self.minExclusive ?? false
let maxExclusive = self.maxExclusive ?? false

if minExclusive && value <= min { return false }
if !minExclusive && value < min { return false }
if maxExclusive && value >= max { return false }
if !maxExclusive && value > max { return false }

return true
}

func contains(_ value: Int) -> Bool {
contains(Double(value))
}

func contains(_ value: UInt8) -> Bool {
contains(Double(value))
}

// MARK: - Private

private let min: Double
private let max: Double

private let minExclusive: Bool?
private let maxExclusive: Bool?

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// Corona-Warn-App
//
// SAP SE and all other contributors
// copyright owners license this file to you under the Apache
// License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//

import Foundation
import ExposureNotification

struct ExposureWindow {

// MARK: - Init

init(
calibrationConfidence: ENCalibrationConfidence,
date: Date,
reportType: ENDiagnosisReportType,
infectiousness: ENInfectiousness,
scanInstances: [ScanInstance]
) {
self.calibrationConfidence = calibrationConfidence
self.date = date
self.reportType = reportType
self.infectiousness = infectiousness
self.scanInstances = scanInstances
}

init(from exposureWindow: ENExposureWindow) {
self.calibrationConfidence = exposureWindow.calibrationConfidence
self.date = exposureWindow.date
self.reportType = exposureWindow.diagnosisReportType
self.infectiousness = exposureWindow.infectiousness
self.scanInstances = exposureWindow.scanInstances.map { ScanInstance(from: $0) }
}

// MARK: - Internal

let calibrationConfidence: ENCalibrationConfidence
let date: Date
let reportType: ENDiagnosisReportType
let infectiousness: ENInfectiousness
let scanInstances: [ScanInstance]

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Corona-Warn-App
//
// SAP SE and all other contributors
// copyright owners license this file to you under the Apache
// License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//

import Foundation

struct MinutesAtAttenuationFilter: Decodable {

// MARK: - Init

init(from minutesAtAttenuationFilter: SAP_Internal_V2_MinutesAtAttenuationFilter) {
self.attenuationRange = ENARange(from: minutesAtAttenuationFilter.attenuationRange)
self.dropIfMinutesInRange = ENARange(from: minutesAtAttenuationFilter.dropIfMinutesInRange)
}

// MARK: - Internal

let attenuationRange: ENARange
let dropIfMinutesInRange: ENARange

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Corona-Warn-App
//
// SAP SE and all other contributors
// copyright owners license this file to you under the Apache
// License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//

import Foundation

struct MinutesAtAttenuationWeight: Decodable {

// MARK: - Init

init(from minutesAtAttenuationWeight: SAP_Internal_V2_MinutesAtAttenuationWeight) {
self.attenuationRange = ENARange(from: minutesAtAttenuationWeight.attenuationRange)
self.weight = minutesAtAttenuationWeight.weight
}

// MARK: - Internal

let attenuationRange: ENARange
let weight: Double

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Corona-Warn-App
//
// SAP SE and all other contributors
// copyright owners license this file to you under the Apache
// License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//

import Foundation

struct NormalizedTimeToRiskLevelMapping: Decodable {

// MARK: - Init

init(from normalizedTimeToRiskLevelMapping: SAP_Internal_V2_NormalizedTimeToRiskLevelMapping) {
self.normalizedTimeRange = ENARange(from: normalizedTimeToRiskLevelMapping.normalizedTimeRange)
self.riskLevel = CWARiskLevel(from: normalizedTimeToRiskLevelMapping.riskLevel)
}

// MARK: - Internal

let normalizedTimeRange: ENARange
let riskLevel: CWARiskLevel

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Corona-Warn-App
//
// SAP SE and all other contributors
// copyright owners license this file to you under the Apache
// License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//

import Foundation

struct RiskCalculationConfiguration: Decodable {

// MARK: - Init

init(from riskCalculationParameters: SAP_Internal_V2_RiskCalculationParameters) {
self.minutesAtAttenuationFilters = riskCalculationParameters.minutesAtAttenuationFilters.map { MinutesAtAttenuationFilter(from: $0) }
self.trlFilters = riskCalculationParameters.trlFilters.map { TrlFilter(from: $0) }
self.minutesAtAttenuationWeights = riskCalculationParameters.minutesAtAttenuationWeights.map { MinutesAtAttenuationWeight(from: $0) }
self.normalizedTimePerEWToRiskLevelMapping = riskCalculationParameters.normalizedTimePerEwtoRiskLevelMapping.map { NormalizedTimeToRiskLevelMapping(from: $0) }
self.normalizedTimePerDayToRiskLevelMapping = riskCalculationParameters.normalizedTimePerDayToRiskLevelMapping.map { NormalizedTimeToRiskLevelMapping(from: $0) }
self.trlEncoding = TrlEncoding(from: riskCalculationParameters.trlEncoding)
self.transmissionRiskLevelMultiplier = riskCalculationParameters.transmissionRiskLevelMultiplier
}

// MARK: - Internal

let minutesAtAttenuationFilters: [MinutesAtAttenuationFilter]
let trlFilters: [TrlFilter]
let minutesAtAttenuationWeights: [MinutesAtAttenuationWeight]
let normalizedTimePerEWToRiskLevelMapping: [NormalizedTimeToRiskLevelMapping]
let normalizedTimePerDayToRiskLevelMapping: [NormalizedTimeToRiskLevelMapping]
let trlEncoding: TrlEncoding
let transmissionRiskLevelMultiplier: Double

}
Loading