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

Statistics for boosters (EXPOSUREAPP-10765) #4680

Merged
merged 15 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ sealed class GlobalStatsItem(val cardType: Type) : GenericStatsItem() {
PERSONS_VACCINATED_COMPLETELY(6),
APPLIED_VACCINATION_RATES(7),
OCCUPIED_INTENSIVE_CARE_BEDS(9),
INCIDENCE_AND_HOSPITALIZATION(10)
INCIDENCE_AND_HOSPITALIZATION(10),
PERSONS_VACCINATED_WITH_BOOSTER(11)
}

abstract fun requireValidity()
Expand Down Expand Up @@ -238,6 +239,28 @@ data class PersonsVaccinatedCompletelyStats(
}
}

data class PersonsVaccinatedWithBoosterStats(
override val updatedAt: Instant,
override val keyFigures: List<KeyFigure>
) : GlobalStatsItem(cardType = Type.PERSONS_VACCINATED_WITH_BOOSTER) {

val boosterDoses: KeyFigure
get() = keyFigures.single { it.rank == KeyFigure.Rank.PRIMARY }

val total: KeyFigure
get() = keyFigures.single { it.rank == KeyFigure.Rank.TERTIARY }

override fun requireValidity() {
require(keyFigures.size == 2)
requireNotNull(keyFigures.singleOrNull { it.rank == KeyFigure.Rank.PRIMARY }) {
Timber.w("PersonsVaccinatesWithBoostersStats is missing primary value")
SamuraiKek marked this conversation as resolved.
Show resolved Hide resolved
}
requireNotNull(keyFigures.singleOrNull { it.rank == KeyFigure.Rank.TERTIARY }) {
Timber.w("PersonsVaccinatedWithBoosterStats is missing tertiary value")
}
}
}

data class AppliedVaccinationRatesStats(
override val updatedAt: Instant,
override val keyFigures: List<KeyFigure>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import de.rki.coronawarnapp.statistics.KeySubmissionsStats
import de.rki.coronawarnapp.statistics.OccupiedIntensiveCareStats
import de.rki.coronawarnapp.statistics.PersonsVaccinatedCompletelyStats
import de.rki.coronawarnapp.statistics.PersonsVaccinatedOnceStats
import de.rki.coronawarnapp.statistics.PersonsVaccinatedWithBoosterStats
import de.rki.coronawarnapp.statistics.SevenDayRValue
import de.rki.coronawarnapp.statistics.StatisticsData
import org.joda.time.Instant
Expand Down Expand Up @@ -64,6 +65,10 @@ class StatisticsParser @Inject constructor() {
updatedAt = updatedAt,
keyFigures = keyFigures
)
GlobalStatsItem.Type.PERSONS_VACCINATED_WITH_BOOSTER -> PersonsVaccinatedWithBoosterStats(
updatedAt = updatedAt,
keyFigures = keyFigures
)
null -> null.also { Timber.tag(TAG).e("Unknown statistics type: %s", rawCard) }
}.also {
Timber.tag(TAG).v("Parsed %s", it.toString().replace("\n", ", "))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import de.rki.coronawarnapp.statistics.KeySubmissionsStats
import de.rki.coronawarnapp.statistics.OccupiedIntensiveCareStats
import de.rki.coronawarnapp.statistics.PersonsVaccinatedCompletelyStats
import de.rki.coronawarnapp.statistics.PersonsVaccinatedOnceStats
import de.rki.coronawarnapp.statistics.PersonsVaccinatedWithBoosterStats
import de.rki.coronawarnapp.statistics.SevenDayRValue
import de.rki.coronawarnapp.statistics.ui.homecards.StatisticsCardAdapter.ItemVH
import de.rki.coronawarnapp.statistics.ui.homecards.cards.AddCard
Expand All @@ -24,6 +25,7 @@ import de.rki.coronawarnapp.statistics.ui.homecards.cards.LocalStatisticsCardIte
import de.rki.coronawarnapp.statistics.ui.homecards.cards.OccupiedIntensiveCareCard
import de.rki.coronawarnapp.statistics.ui.homecards.cards.PersonsVaccinatedCompletelyCard
import de.rki.coronawarnapp.statistics.ui.homecards.cards.PersonsVaccinatedOnceCard
import de.rki.coronawarnapp.statistics.ui.homecards.cards.PersonsVaccinatedWithBoosterCard
import de.rki.coronawarnapp.statistics.ui.homecards.cards.SevenDayRValueCard
import de.rki.coronawarnapp.statistics.ui.homecards.cards.StatisticsCardItem
import de.rki.coronawarnapp.util.lists.BindableVH
Expand Down Expand Up @@ -76,6 +78,10 @@ class StatisticsCardAdapter :
val item = data[it]
item is GlobalStatisticsCardItem && item.stats is PersonsVaccinatedCompletelyStats
}) { PersonsVaccinatedCompletelyCard(it) },
TypedVHCreatorMod({
val item = data[it]
item is GlobalStatisticsCardItem && item.stats is PersonsVaccinatedWithBoosterStats
}) { PersonsVaccinatedWithBoosterCard(it) },
TypedVHCreatorMod({
val item = data[it]
item is GlobalStatisticsCardItem && item.stats is AppliedVaccinationRatesStats
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package de.rki.coronawarnapp.statistics.ui.homecards.cards

import android.view.ViewGroup
import androidx.core.os.ConfigurationCompat
import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.databinding.HomeStatisticsCardsVaccinatedWithBoosterLayoutBinding
import de.rki.coronawarnapp.server.protocols.internal.stats.KeyFigureCardOuterClass
import de.rki.coronawarnapp.statistics.GlobalStatsItem
import de.rki.coronawarnapp.statistics.PersonsVaccinatedWithBoosterStats
import de.rki.coronawarnapp.statistics.ui.homecards.StatisticsCardAdapter
import de.rki.coronawarnapp.statistics.util.formatPercentageValue
import de.rki.coronawarnapp.statistics.util.formatStatisticalValue
import de.rki.coronawarnapp.util.StringBuilderExtension.appendWithLineBreak
import de.rki.coronawarnapp.util.StringBuilderExtension.appendWithTrailingSpace
import de.rki.coronawarnapp.util.formatter.getPrimaryLabel

class PersonsVaccinatedWithBoosterCard(parent: ViewGroup) :
StatisticsCardAdapter.ItemVH<GlobalStatisticsCardItem, HomeStatisticsCardsVaccinatedWithBoosterLayoutBinding>(
R.layout.home_statistics_cards_basecard_layout,
parent
) {
override val viewBinding = lazy {
HomeStatisticsCardsVaccinatedWithBoosterLayoutBinding.inflate(
layoutInflater,
itemView.findViewById(R.id.card_container),
true
)
}

private val currentSelectedLocale = ConfigurationCompat.getLocales(resources.configuration).get(0)

override val onBindData: HomeStatisticsCardsVaccinatedWithBoosterLayoutBinding.(
item: GlobalStatisticsCardItem,
payloads: List<Any>
) -> Unit = { orig, payloads ->
val item = payloads.filterIsInstance<GlobalStatisticsCardItem>().firstOrNull() ?: orig

infoStatistics.setOnClickListener {
item.onClickListener(item.stats)
}

with(item.stats as PersonsVaccinatedWithBoosterStats) {
personsVaccinatedWithBoosterContainer.contentDescription =
buildAccessibilityStringForPersonsVaccinatedWithBoosterCard(item.stats, boosterDoses, total)

primaryLabel.text = getPrimaryLabel(context)
primaryValue.text = formatPercentageValue(boosterDoses.value, currentSelectedLocale)
primaryValue.contentDescription = StringBuilder()
.appendWithTrailingSpace(getPrimaryLabel(context))
.appendWithTrailingSpace(formatPercentageValue(boosterDoses.value, currentSelectedLocale))
.append(context.getString(R.string.statistics_vaccinated_with_booster_card_title))

secondaryValue.text = formatStatisticalValue(context, total.value, total.decimals)
secondaryValue.contentDescription = StringBuilder()
.appendWithTrailingSpace(context.getString(R.string.statistics_card_infections_tertiary_label))
.appendWithTrailingSpace(formatStatisticalValue(context, total.value, total.decimals))
.append(context.getString(R.string.statistics_vaccinated_with_booster_card_title))
}
}

private fun buildAccessibilityStringForPersonsVaccinatedWithBoosterCard(
item: GlobalStatsItem,
firstDose: KeyFigureCardOuterClass.KeyFigure,
total: KeyFigureCardOuterClass.KeyFigure
): StringBuilder {

return StringBuilder()
.appendWithTrailingSpace(context.getString(R.string.accessibility_statistics_card_announcement))
.appendWithLineBreak(context.getString(R.string.statistics_vaccinated_with_booster_card_title))
.appendWithLineBreak(context.getString(R.string.statistics_nationwide_text))
.appendWithTrailingSpace(item.getPrimaryLabel(context))
.appendWithLineBreak(formatPercentageValue(firstDose.value, currentSelectedLocale))
.appendWithTrailingSpace(context.getString(R.string.statistics_card_infections_tertiary_label))
.appendWithTrailingSpace(formatStatisticalValue(context, total.value, total.decimals))
.append(context.getString(R.string.accessibility_statistics_card_navigation_information))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import de.rki.coronawarnapp.statistics.LocalStatsItem
import de.rki.coronawarnapp.statistics.OccupiedIntensiveCareStats
import de.rki.coronawarnapp.statistics.PersonsVaccinatedCompletelyStats
import de.rki.coronawarnapp.statistics.PersonsVaccinatedOnceStats
import de.rki.coronawarnapp.statistics.PersonsVaccinatedWithBoosterStats
import de.rki.coronawarnapp.statistics.SevenDayRValue
import de.rki.coronawarnapp.statistics.local.storage.SelectedStatisticsLocation
import de.rki.coronawarnapp.util.TimeAndDateExtensions.toUserTimeZone
Expand All @@ -38,7 +39,8 @@ fun GlobalStatsItem.getPrimaryLabel(context: Context): String {
}
is PersonsVaccinatedOnceStats,
is IncidenceAndHospitalizationStats,
is PersonsVaccinatedCompletelyStats -> when (updatedAtDate) {
is PersonsVaccinatedCompletelyStats,
is PersonsVaccinatedWithBoosterStats -> when (updatedAtDate) {
today -> context.getString(R.string.statistics_primary_value_until_today)
yesterday -> context.getString(R.string.statistics_primary_value_until_yesterday)
else -> context.getString(R.string.statistics_primary_value_until, dateTimeFormatter.print(updatedAtDate))
Expand Down
Loading