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

Commit

Permalink
Merge remote-tracking branch 'origin/feature/6015-Create-tracelocatio…
Browse files Browse the repository at this point in the history
…ns-locally' into feature/6015-Create-tracelocations-locally
  • Loading branch information
LukasLechnerDev committed Mar 31, 2021
2 parents 81e41aa + 3cb7abf commit 62784d2
Show file tree
Hide file tree
Showing 29 changed files with 331 additions and 282 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import de.rki.coronawarnapp.eventregistration.checkins.derivetime.deriveTime
import de.rki.coronawarnapp.eventregistration.checkins.split.splitByMidnightUTC
import de.rki.coronawarnapp.server.protocols.internal.pt.CheckInOuterClass
import de.rki.coronawarnapp.server.protocols.internal.pt.TraceLocationOuterClass
import de.rki.coronawarnapp.server.protocols.internal.v2.RiskCalculationParametersOuterClass.TransmissionRiskValueMapping
import de.rki.coronawarnapp.submission.Symptoms
import de.rki.coronawarnapp.submission.task.TransmissionRiskVector
import de.rki.coronawarnapp.submission.task.TransmissionRiskVectorDeterminator
Expand Down Expand Up @@ -37,17 +38,17 @@ class CheckInsTransformer @Inject constructor(
* @param symptoms [Symptoms] symptoms to calculate transmission risk level
*/
suspend fun transform(checkIns: List<CheckIn>, symptoms: Symptoms): List<CheckInOuterClass.CheckIn> {

val submissionParamContainer = appConfigProvider
val presenceTracing = appConfigProvider
.getAppConfig()
.presenceTracing
.submissionParameters

val submissionParams = presenceTracing.submissionParameters
val trvMappings = presenceTracing.riskCalculationParameters.transmissionRiskValueMapping
val transmissionVector = transmissionDeterminator.determine(symptoms)

val now = timeStamper.nowUTC
return checkIns.flatMap { originalCheckIn ->
Timber.d("Transforming check-in=$originalCheckIn")
val derivedTimes = submissionParamContainer.deriveTime(
val derivedTimes = submissionParams.deriveTime(
originalCheckIn.checkInStart.seconds,
originalCheckIn.checkInEnd.seconds
)
Expand All @@ -61,16 +62,32 @@ class CheckInsTransformer @Inject constructor(
checkInStart = derivedTimes.startTimeSeconds.secondsToInstant(),
checkInEnd = derivedTimes.endTimeSeconds.secondsToInstant()
)
derivedCheckIn.splitByMidnightUTC().map { checkIn ->
checkIn.toOuterCheckIn(transmissionVector)

derivedCheckIn.splitByMidnightUTC().mapNotNull { checkIn ->
checkIn.toOuterCheckIn(now, transmissionVector, trvMappings)
}
}
}
}

private fun CheckIn.toOuterCheckIn(
transmissionVector: TransmissionRiskVector
): CheckInOuterClass.CheckIn {
now: Instant,
transmissionVector: TransmissionRiskVector,
trvMappings: List<TransmissionRiskValueMapping>
): CheckInOuterClass.CheckIn? {
val transmissionRiskLevel = determineRiskTransmission(now, transmissionVector)

// Find transmissionRiskValue for matched transmissionRiskLevel - default 0.0 if no match
val transmissionRiskValue = trvMappings.find {
it.transmissionRiskLevel == transmissionRiskLevel
}?.transmissionRiskValue ?: 0.0

// Exclude check-in with TRV = 0.0
if (transmissionRiskValue == 0.0) {
Timber.d("CheckIn has TRL=$transmissionRiskLevel is excluded from submission (TRV=0)")
return null // Not mapped
}

val signedTraceLocation = TraceLocationOuterClass.SignedTraceLocation.newBuilder()
.setLocation(traceLocationBytes.toProtoByteString())
.setSignature(signature.toProtoByteString())
Expand All @@ -80,9 +97,7 @@ class CheckInsTransformer @Inject constructor(
.setSignedLocation(signedTraceLocation)
.setStartIntervalNumber(checkInStart.derive10MinutesInterval().toInt())
.setEndIntervalNumber(checkInEnd.derive10MinutesInterval().toInt())
.setTransmissionRiskLevel(
determineRiskTransmission(timeStamper.nowUTC, transmissionVector)
)
.setTransmissionRiskLevel(transmissionRiskLevel)
.build()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ private fun Long.isLastDay(days: Long): Boolean {
}

private fun List<CheckIn>.print() = Timber.i(
"splitInto: %s",
joinToString(separator = "\n") { checkIn ->
"SplitCheckIns=[%s]",
joinToString(separator = ",\n") { checkIn ->
"{checkInStart=%s,checkOutEnd=%s}".format(
checkIn.checkInStart,
checkIn.checkInEnd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class ScanCheckInQrCodeFragment :
checkInQrCodeScanTorch.setOnCheckedChangeListener { _, isChecked ->
binding.checkInQrCodeScanPreview.setTorch(isChecked)
}
checkInQrCodeScanClose.setOnClickListener { viewModel.onNavigateUp() }

checkInQrCodeScanToolbar.setNavigationOnClickListener { viewModel.onNavigateUp() }
checkInQrCodeScanPreview.decoderFactory = DefaultDecoderFactory(listOf(BarcodeFormat.QR_CODE))
checkInQrCodeScanViewfinderView.setCameraPreview(binding.checkInQrCodeScanPreview)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,22 @@ class SubmissionQRCodeScanFragment :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.submissionQrCodeScanTorch.setOnCheckedChangeListener { _, isChecked ->
binding.submissionQrCodeScanPreview.setTorch(
isChecked
)
}
with(binding) {
submissionQrCodeScanTorch.setOnCheckedChangeListener { _, isChecked ->
binding.submissionQrCodeScanPreview.setTorch(
isChecked
)
}

binding.submissionQrCodeScanClose.setOnClickListener {
viewModel.onClosePressed()
}
submissionQrCodeScanToolbar.setNavigationOnClickListener {
viewModel.onClosePressed()
}

binding.submissionQrCodeScanPreview.decoderFactory =
DefaultDecoderFactory(listOf(BarcodeFormat.QR_CODE))
submissionQrCodeScanPreview.decoderFactory =
DefaultDecoderFactory(listOf(BarcodeFormat.QR_CODE))

binding.submissionQrCodeScanViewfinderView.setCameraPreview(binding.submissionQrCodeScanPreview)
submissionQrCodeScanViewfinderView.setCameraPreview(binding.submissionQrCodeScanPreview)
}

viewModel.scanStatusValue.observe2(this) {
if (ScanStatus.INVALID == it) {
Expand Down
9 changes: 9 additions & 0 deletions Corona-Warn-App/src/main/res/drawable/ic_qr_1x_test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="18.461538dp"
android:viewportWidth="13"
android:viewportHeight="10">
<path
android:fillColor="#007FAD"
android:pathData="M0.3335,0.833H3.6668V9.1663H2.0002V2.4997H0.3335V0.833ZM10.1918,4.7663L12.5502,0.833H10.6085L9.2252,3.1413L7.8335,0.833H5.8918L8.2502,4.7663L5.6085,9.1663H7.5502L9.2168,6.383L10.8835,9.1663H12.8335L10.1918,4.7663Z" />
</vector>
15 changes: 15 additions & 0 deletions Corona-Warn-App/src/main/res/drawable/ic_qr_code.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector android:height="24dp" android:tint="#007FAD"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M3,11h8V3H3V11zM5,5h4v4H5V5z"/>
<path android:fillColor="@android:color/white" android:pathData="M3,21h8v-8H3V21zM5,15h4v4H5V15z"/>
<path android:fillColor="@android:color/white" android:pathData="M13,3v8h8V3H13zM19,9h-4V5h4V9z"/>
<path android:fillColor="@android:color/white" android:pathData="M19,19h2v2h-2z"/>
<path android:fillColor="@android:color/white" android:pathData="M13,13h2v2h-2z"/>
<path android:fillColor="@android:color/white" android:pathData="M15,15h2v2h-2z"/>
<path android:fillColor="@android:color/white" android:pathData="M13,17h2v2h-2z"/>
<path android:fillColor="@android:color/white" android:pathData="M15,19h2v2h-2z"/>
<path android:fillColor="@android:color/white" android:pathData="M17,17h2v2h-2z"/>
<path android:fillColor="@android:color/white" android:pathData="M17,13h2v2h-2z"/>
<path android:fillColor="@android:color/white" android:pathData="M19,15h2v2h-2z"/>
</vector>

This file was deleted.

18 changes: 0 additions & 18 deletions Corona-Warn-App/src/main/res/drawable/ic_qr_icon_test_scan.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
android:id="@+id/check_in_qr_code_scan_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/submission_qr_code_scan_title"
android:contentDescription="@string/qr_code_scan_body"
android:transitionName="shared_element_container">

<com.journeyapps.barcodescanner.BarcodeView
Expand All @@ -15,8 +15,8 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:zxing_framing_rect_height="@dimen/submission_scan_qr_code_viewfinder_size"
app:zxing_framing_rect_width="@dimen/submission_scan_qr_code_viewfinder_size">
app:zxing_framing_rect_height="@dimen/scan_qr_code_viewfinder_size"
app:zxing_framing_rect_width="@dimen/scan_qr_code_viewfinder_size">

</com.journeyapps.barcodescanner.BarcodeView>

Expand All @@ -28,62 +28,45 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:zxing_viewfinder_mask="@color/colorQrCodeScanMask"
app:zxing_viewfinder_laser_visibility="false" />

<TextView
android:id="@+id/check_in_qr_code_scan_body"
style="@style/registrationQRCodeScanBody"
android:layout_width="@dimen/submission_scan_qr_code_viewfinder_size"
style="@style/qrCodeScanBody"
android:layout_width="@dimen/scan_qr_code_viewfinder_size"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/submission_scan_qr_code_viewfinder_center_offset"
android:text="@string/submission_qr_code_scan_body"
android:layout_marginTop="@dimen/scan_qr_code_viewfinder_center_offset"
android:text="@string/qr_code_scan_body"
app:layout_constraintEnd_toEndOf="@id/check_in_qr_code_scan_preview"
app:layout_constraintStart_toStartOf="@id/check_in_qr_code_scan_preview"
app:layout_constraintTop_toBottomOf="@id/check_in_qr_code_scan_guideline_center" />


<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/check_in_qr_code_scan_close"
style="@style/buttonIcon"
android:layout_width="@dimen/icon_size_button"
android:layout_height="@dimen/icon_size_button"
app:layout_constraintBottom_toTopOf="@id/check_in_qr_code_scan_guideline_top"
app:layout_constraintEnd_toStartOf="@id/guideline_start"
app:layout_constraintStart_toStartOf="@id/guideline_start"
app:layout_constraintTop_toTopOf="@id/check_in_qr_code_scan_guideline_top">

<androidx.appcompat.widget.AppCompatImageView
style="@style/iconStable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/accessibility_close"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_close" />
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/check_in_qr_code_scan_toolbar"
style="@style/CWAToolbar.BackArrow.Transparent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navigationIconTint="@color/colorQrCodeScanToolbar"
app:title="@string/qr_code_scan_title"
app:titleTextColor="@color/colorQrCodeScanToolbar">

</androidx.constraintlayout.widget.ConstraintLayout>
<ToggleButton
android:id="@+id/check_in_qr_code_scan_torch"
android:layout_width="@dimen/icon_size_button"
android:layout_height="@dimen/icon_size_button"
android:layout_gravity="end"
android:layout_marginEnd="@dimen/spacing_tiny"
android:background="@drawable/ic_registration_qr_code_scan_torch_toggle"
android:backgroundTint="@color/colorQrCodeScanToolbar"
android:textOff=""
android:textOn="" />

<ToggleButton
android:id="@+id/check_in_qr_code_scan_torch"
android:layout_width="@dimen/icon_size_button"
android:layout_height="@dimen/icon_size_button"
android:background="@drawable/ic_registration_qr_code_scan_torch_toggle"
android:backgroundTint="@color/colorStableLight"
android:textOff=""
android:textOn=""
app:layout_constraintBottom_toTopOf="@id/check_in_qr_code_scan_guideline_top"
app:layout_constraintEnd_toStartOf="@id/guideline_end"
app:layout_constraintStart_toStartOf="@id/guideline_end"
app:layout_constraintTop_toTopOf="@id/check_in_qr_code_scan_guideline_top" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/check_in_qr_code_scan_guideline_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="@dimen/spacing_normal" />
</com.google.android.material.appbar.MaterialToolbar>

<androidx.constraintlayout.widget.Guideline
android:id="@+id/check_in_qr_code_scan_guideline_center"
Expand All @@ -92,6 +75,4 @@
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />

<include layout="@layout/merge_guidelines_side" />

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@
app:layout_constraintStart_toStartOf="parent"
app:countryList="@{countries}"/>

<TextView
android:id="@+id/submission_consent_hint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_normal"
app:layout_constraintTop_toBottomOf="@id/countryList"
app:layout_constraintStart_toStartOf="@id/guideline_start"
app:layout_constraintEnd_toEndOf="@id/guideline_end"
android:text="@string/submission_consent_help_by_warning_others_body_event"
style="@style/subtitle" />

<include layout="@layout/include_submission_consent_body"
android:id="@+id/include_submission_consent_body"
android:layout_width="0dp"
Expand All @@ -81,7 +92,7 @@
android:layout_marginHorizontal="@dimen/guideline_card"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/countryList"/>
app:layout_constraintTop_toBottomOf="@id/submission_consent_hint"/>

<FrameLayout
android:id="@+id/divider"
Expand Down
Loading

0 comments on commit 62784d2

Please sign in to comment.