Skip to content

Commit

Permalink
v4.5.0: 🤓 Use the total of second doses (#13)
Browse files Browse the repository at this point in the history
* Refactor total-administration and perc-pop-vax calculation

* update fe version

* update translations

* update welcome modal
  • Loading branch information
fabriziomiano committed Feb 23, 2021
1 parent 308fbc0 commit cb84679
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 181 deletions.
56 changes: 38 additions & 18 deletions app/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,14 @@ def get_latest_vax_update():
return latest_update


def get_perc_pop_vax(tot_admins, population):
"""Return the ratio tot administrations / population rounded to 2 figs"""
def get_perc_pop_vax(population, area=None):
"""
Return the ratio tot administrations / population rounded to 2 figs
:param population: int
:param area: str
:return: float
"""
tot_admins = get_tot_admins(dtype='seconda_dose', area=area)
return round(((int(tot_admins) / population) * 100), 2)


Expand All @@ -273,23 +279,37 @@ def enrich_frontend_data(area=None, **data):
return data


def get_total_administrations(area=None):
"""Return the total administration performed"""
def get_tot_admins(dtype, area=None):
"""
Return the total of one of the three main vaccine data types
allowed_types ('totale', 'prima_dose', 'seconda_dose')
:param dtype: str: must be in allowed_types
:param area: str: region
:return: int: the total administrations of a given data type
if the data type is in allowed_types else 0
"""
allowed_types = ('totale', 'prima_dose', 'seconda_dose')
tot_adms = 0
if area:
pipe = [
{'$match': {VAX_AREA_KEY: area}},
{'$group': {'_id': f'${VAX_AREA_KEY}', 'tot': {'$sum': '$totale'}}}
]
else:
pipe = [
{'$group': {'_id': '{}', 'tot': {'$sum': '$totale'}}}
]
try:
cursor = VAX_SUMMARY_COLL.aggregate(pipeline=pipe)
tot_adms = next(cursor)['tot']
except Exception as e:
app.logger.error(f"While getting total admins: {e}")
if dtype in allowed_types:
if area:
pipe = [
{'$match': {VAX_AREA_KEY: area}},
{
'$group': {
'_id': f'${VAX_AREA_KEY}',
'tot': {
'$sum': f'${dtype}'
}
}
}
]
else:
pipe = [{'$group': {'_id': '{}', 'tot': {'$sum': f'${dtype}'}}}]
try:
cursor = VAX_SUMMARY_COLL.aggregate(pipeline=pipe)
tot_adms = next(cursor)['tot']
except Exception as e:
app.logger.error(f"While getting total admins: {e}")
return int(tot_adms)


Expand Down
8 changes: 5 additions & 3 deletions app/data/etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
VAX_DATE_FMT, VAX_AREA_KEY, VAX_TYPE_KEY, ITALY_POPULATION, OD_TO_PC_MAP,
POP_KEY
)

COLUMNS_TO_DROP = [STATE_KEY]


Expand Down Expand Up @@ -440,7 +441,8 @@ def augment_vax_df(df):
df[VAX_AGE_KEY] = df[VAX_AGE_KEY].apply(lambda x: x.strip())
df['totale'] = df[M_SEX_KEY] + df[F_SEX_KEY]
df['_id'] = (
df[VAX_DATE_KEY].apply(lambda x: x.strftime(VAX_DATE_FMT)) +
df[VAX_DATE_KEY].apply(
lambda x: x.strftime(VAX_DATE_FMT)) +
df[VAX_AREA_KEY] +
df[VAX_AGE_KEY] +
df[VAX_TYPE_KEY]
Expand All @@ -467,8 +469,8 @@ def augment_summary_vax_df(df):
out_df = out_df.append(reg_df)
out_df.reset_index(inplace=True)
out_df['_id'] = (
out_df[VAX_DATE_KEY].apply(lambda x: x.strftime(VAX_DATE_FMT)) +
out_df[VAX_AREA_KEY]
out_df[VAX_DATE_KEY].apply(
lambda x: x.strftime(VAX_DATE_FMT)) + out_df[VAX_AREA_KEY]
)
out_df[POP_KEY] = out_df[VAX_AREA_KEY].apply(
lambda x: ITALY_POPULATION[OD_TO_PC_MAP[x]])
Expand Down
10 changes: 7 additions & 3 deletions app/templates/base/modals/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<div class="modal-header">
<h5 class="modal-title">
{{ _('&#128075; Welcome to COVIDash') }}&#127470;&#127481;</h5>
{{ _('&#128075; Welcome to COVIDash') }} &#127470;&#127481;</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
Expand All @@ -17,8 +17,12 @@ <h5 class="modal-title">
{{ _("COVIDashIT is a dashboard that displays the official COVID-19 Italian outbreak data") }}
</p>
<p>
<span class="badge badge-pill bg-danger me-2">{{ _("New!") }}</span><i
class="fas fa-syringe me-2"></i>{{ _("Added vaccine data <a href='/vaccines'><strong>here</strong></a>;") }}
<span class="badge badge-pill bg-danger me-2">{{ _("New!") }}</span>
<i class="fas fa-user-shield me-2"></i>
{{ _("Percentage of people vaccinated based on the second dose") }}
</p>
<p>
<i class="fas fa-syringe me-2"></i>{{ _("Added vaccine data <a href='/vaccines'><strong>here</strong></a>;") }}
</p>
<p>
<i class="fas fa-mouse-pointer me-2"></i>{{ _("Use the navigation buttons on the navigation bar when in the regional/provincial views;") }}
Expand Down
14 changes: 11 additions & 3 deletions app/templates/vaccines.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,26 @@
<p class="small mb-0 text-primary">
<i class="fas fa-syringe me-2"></i>{{ _("Total administered:") }}
<strong>
{{ tot_admins_str }}
{{ tot_admins_str }} &nbsp; {{ admins_perc }}
<i class="fas fa-info-circle"
data-toggle="tooltip"
data-placement="auto"
title="{{ _("Percentage of administered doses wrt the delivered ones") }}"
></i> {{ admins_perc }}
></i>
</strong>
</p>

<!-- % people vaccinated -->
<p class="small mb-0 text-danger">
<i class="fas fa-user-shield me-2"></i>% {{ _("People Vaccinated: ") }}<strong>{{ perc_pop_vax }}</strong>
<i class="fas fa-user-shield me-2"></i>% {{ _("People Vaccinated: ") }}
<strong>
{{ perc_pop_vax }}
<i class="fas fa-info-circle"
data-toggle="tooltip"
data-placement="auto"
title="{{ _("Based on the second dose") }}">
</i>
</strong>
</p>
<div class="progress mb-1" style="height: 5px;">
<div class="progress-bar progress-bar-striped progress-bar-animated bg-danger"
Expand Down
Binary file modified app/translations/it_IT/LC_MESSAGES/messages.mo
Binary file not shown.
Loading

0 comments on commit cb84679

Please sign in to comment.