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

Commit

Permalink
Merge branch 'release/2.0.x' into feature/6015-Create-tracelocations-…
Browse files Browse the repository at this point in the history
…locally
  • Loading branch information
harambasicluka authored Mar 30, 2021
2 parents 8bcb824 + d8d2f5f commit 3cb7abf
Show file tree
Hide file tree
Showing 13 changed files with 255 additions and 204 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
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>
Loading

0 comments on commit 3cb7abf

Please sign in to comment.