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

Event warning in representation does not work (EXPOSUREAPP-14233,EXPOSUREAPP-14230 ) #5664

Merged
merged 10 commits into from
Oct 28, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ class PresenceTracingTestViewModel @AssistedInject constructor(

val warningPackages = traceWarningRepository.allMetaData.first()
val overlaps = presenceTracingRiskRepository.allCheckInWarningOverlaps.first()
val lastResult = presenceTracingRiskRepository.allRiskLevelResults.first().singleOrNull()
val lastResult = presenceTracingRiskRepository.allRiskLevelResults.first().firstOrNull { it.wasSuccessfullyCalculated }

val infoText = when {
!lastResult!!.wasSuccessfullyCalculated -> "Last calculation failed"
lastResult?.wasSuccessfullyCalculated != true -> "Last calculation failed"
overlaps.isEmpty() -> "No matches found (${warningPackages.size} warning packages)."
overlaps.size > 100 -> "Output too large. ${overlaps.size} lines"
overlaps.isNotEmpty() -> overlaps.fold(StringBuilder()) { stringBuilder, checkInOverlap ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class CheckInWarningMatcher @Inject constructor(
checkInProtectedReport: List<CheckInOuterClass.CheckInProtectedReport>,
checkIns: List<CheckIn>
): List<TraceWarning.TraceTimeIntervalWarning> {
val hashCheckInMap = checkIns.map { it.traceLocationIdHash to it }.toMap()
val hashCheckInMap = checkIns.associateBy { it.traceLocationIdHash }
return checkInProtectedReport
.filter {
hashCheckInMap.containsKey(it.locationIdHash.toOkioByteString())
Expand Down Expand Up @@ -164,7 +164,15 @@ internal fun CheckIn.calculateOverlap(
warning: TraceWarning.TraceTimeIntervalWarning,
traceWarningPackageId: String
): CheckInWarningOverlap? {
if (warning.locationIdHash.toOkioByteString() != traceLocationIdHash) return null
val warningLocationId = warning.locationIdHash.toOkioByteString()
if (warningLocationId != traceLocationIdHash) return run {
Timber.tag(TAG).d(
"warningLocationId=%s does NOT match traceLocationId=%s", warningLocationId, traceLocationIdHash
)
null
}

Timber.tag(TAG).d("warningLocationId matches traceLocationIdHash both are =%s", traceLocationIdHash)

val warningStartMillis = warning.startIntervalNumber.tenMinIntervalToMillis()
val warningEndMillis = (warning.startIntervalNumber + warning.period).tenMinIntervalToMillis()
Expand All @@ -189,7 +197,9 @@ internal fun CheckIn.calculateOverlap(
traceWarningPackageId = traceWarningPackageId,
startTime = Instant.ofEpochMilli(overlapStartMillis),
endTime = Instant.ofEpochMilli(overlapEndMillis)
)
).also {
Timber.tag(TAG).d("CheckInWarningOverlap=%s", it)
}
}

// converts number of 10min intervals into milliseconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import de.rki.coronawarnapp.util.viewmodel.cwaViewModelsAssisted
import java.time.Instant
import java.time.LocalDate
import java.time.LocalTime
import java.time.ZoneOffset
import java.time.ZoneId
import javax.inject.Inject
import kotlin.math.abs

Expand Down Expand Up @@ -149,11 +149,11 @@ class EditCheckInFragment : Fragment(R.layout.fragment_edit_check_in), AutoInjec
MaterialDatePicker
.Builder
.datePicker()
.setSelection(defaultValue?.atStartOfDay(ZoneOffset.UTC)?.toInstant()?.toEpochMilli())
.setSelection(defaultValue?.atStartOfDay(ZoneId.systemDefault())?.toInstant()?.toEpochMilli())
.build()
.apply {
addOnPositiveButtonClickListener {
callback(Instant.ofEpochMilli(it).atZone(ZoneOffset.UTC).toLocalDate())
callback(Instant.ofEpochMilli(it).atZone(ZoneId.systemDefault()).toLocalDate())
}
}
.show(childFragmentManager, DATE_PICKER_TAG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import dagger.assisted.AssistedInject
import de.rki.coronawarnapp.presencetracing.checkins.CheckIn
import de.rki.coronawarnapp.presencetracing.checkins.CheckInRepository
import de.rki.coronawarnapp.ui.presencetracing.organizer.category.adapter.category.mapTraceLocationToTitleRes
import de.rki.coronawarnapp.util.toLocalDateTimeUtc
import de.rki.coronawarnapp.util.toLocalDateTimeUserTz
import de.rki.coronawarnapp.util.ui.SingleLiveEvent
import de.rki.coronawarnapp.util.viewmodel.CWAViewModel
Expand Down Expand Up @@ -69,46 +68,50 @@ class EditCheckInViewModel @AssistedInject constructor(
}

fun onStartDateClicked() {
val utcDateTime = checkInStartTime.value?.toLocalDateTimeUtc()
openStartPickerEvent.value = DateTimePickerEvent.DatePickerEvent(utcDateTime?.toLocalDate())
val dateTime = checkInStartTime.value?.toLocalDateTimeUserTz()
openStartPickerEvent.value = DateTimePickerEvent.DatePickerEvent(dateTime?.toLocalDate())
}

fun onStartTimeClicked() {
val utcDateTime = checkInStartTime.value?.toLocalDateTimeUtc()
openStartPickerEvent.value = DateTimePickerEvent.TimePickerEvent(utcDateTime?.toLocalTime())
val dateTime = checkInStartTime.value?.toLocalDateTimeUserTz()
openStartPickerEvent.value = DateTimePickerEvent.TimePickerEvent(dateTime?.toLocalTime())
}

fun onEndDateClicked() {
val utcDateTime = checkInEndTime.value?.toLocalDateTimeUtc()
openEndPickerEvent.value = DateTimePickerEvent.DatePickerEvent(utcDateTime?.toLocalDate())
val dateTime = checkInEndTime.value?.toLocalDateTimeUserTz()
openEndPickerEvent.value = DateTimePickerEvent.DatePickerEvent(dateTime?.toLocalDate())
}

fun onEndTimeClicked() {
val utcDateTime = checkInEndTime.value?.toLocalDateTimeUtc()
openEndPickerEvent.value = DateTimePickerEvent.TimePickerEvent(utcDateTime?.toLocalTime())
val dateTime = checkInEndTime.value?.toLocalDateTimeUserTz()
openEndPickerEvent.value = DateTimePickerEvent.TimePickerEvent(dateTime?.toLocalTime())
}

fun onStartTimeChanged(event: DateTimePickerEvent) {
val startDateTime = checkInStartTime.value?.toLocalDateTimeUtc()
val startDateTime = checkInStartTime.value?.toLocalDateTimeUserTz()

when (event) {
is DateTimePickerEvent.TimePickerEvent ->
checkInStartTime.value =
startDateTime?.toLocalDate()?.atTime(event.localTime)?.toInstant(ZoneOffset.UTC)
startDateTime?.toLocalDate()?.atTime(event.localTime)?.atZone(ZoneOffset.systemDefault())
?.toInstant()
is DateTimePickerEvent.DatePickerEvent ->
checkInStartTime.value =
startDateTime?.toLocalTime()?.atDate(event.localDate)?.toInstant(ZoneOffset.UTC)
startDateTime?.toLocalTime()?.atDate(event.localDate)?.atZone(ZoneOffset.systemDefault())
?.toInstant()
}
}

fun onEndTimeChanged(event: DateTimePickerEvent) {
val endDateTime = checkInEndTime.value?.toLocalDateTimeUtc()
val endDateTime = checkInEndTime.value?.toLocalDateTimeUserTz()

when (event) {
is DateTimePickerEvent.TimePickerEvent ->
checkInEndTime.value = endDateTime?.toLocalDate()?.atTime(event.localTime)?.toInstant(ZoneOffset.UTC)
checkInEndTime.value =
endDateTime?.toLocalDate()?.atTime(event.localTime)?.atZone(ZoneOffset.systemDefault())?.toInstant()
is DateTimePickerEvent.DatePickerEvent ->
checkInEndTime.value = endDateTime?.toLocalTime()?.atDate(event.localDate)?.toInstant(ZoneOffset.UTC)
checkInEndTime.value =
endDateTime?.toLocalTime()?.atDate(event.localDate)?.atZone(ZoneOffset.systemDefault())?.toInstant()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import java.time.Instant
import java.time.LocalDate
import java.time.LocalTime
import java.time.ZoneId
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import javax.inject.Inject
Expand Down Expand Up @@ -143,7 +142,7 @@ class TraceLocationWarnDurationFragment :
MaterialDatePicker
.Builder
.datePicker()
.setSelection(dateTime.toInstant(ZoneOffset.UTC).toEpochMilli())
.setSelection(dateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli())
.setCalendarConstraints(constraintsBuilder.build())
.build()
.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import java.time.Duration
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneOffset
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import kotlin.math.roundToInt
Expand Down Expand Up @@ -110,7 +110,7 @@ class TraceLocationWarnDurationViewModel @AssistedInject constructor(
}

fun getTraceLocationWarnDuration(traceLocation: TraceLocation): TraceLocationWarnDuration {
val startDate = localDateTime.toInstant(ZoneOffset.UTC)
val startDate = localDateTime.atZone(ZoneId.systemDefault()).toInstant()
return TraceLocationWarnDuration(
traceLocation = traceLocation,
startDate = startDate,
Expand Down