def get_hospital_text(district: DistrictData) -> str:
        text = "<b>­Ъцњ Hospitalisierungen in {name}</b>\n" \
               "In den letzten 7 Tagen wurden {count} Personen mit COVID-19 ins Krankenhaus eingewiesen. Die " \
               "Hospitalisierungsinzidenz, also die Krankenhauseinweisungen pro 100.000 Einwohner:innen in den letzten 7 Tagen, " \
               "betr├цgt somit {incidence}.\n\n".format(name=district.name, count=format_int(district.hospitalisation.cases),
                                                       incidence=format_float(district.hospitalisation.incidence))

        if district.hospitalisation.groups:
            text += "<b>Altersgruppen:</b>\n"
        for group in district.hospitalisation.groups:
            text += "Рђб {age} Jahre: {incidence} ({number} Einweisungen)\n".format(
                age=group.age_group,
                incidence=format_float(group.incidence),
                number=format_int(group.cases))

        return text
 def get_vacc_text(district: DistrictData, show_name: bool = False) -> str:
     name = ""
     if show_name:
         name = " (" + district.name + ")"
     return f"<b>­ЪњЅ Impfdaten{name}</b>\n" \
            "Am {date} wurden {doses} Dosen verimpft. So haben {vacc_partial} ({rate_partial}%) Personen in " \
            "{name} mindestens eine Impfdosis erhalten, {vacc_full} ({rate_full}%) Menschen sind bereits " \
            "vollst├цndig geimpft, {vacc_booster} ({rate_booster}%) Menschen haben eine Auffrischungsimpfung erhalten. " \
            "Bei dem Impftempo der letzten 7 Tage werden {vacc_speed} Dosen pro Tag verabreicht." \
            "\n\n" \
         .format(name=district.name, rate_full=format_float(district.vaccinations.full_rate * 100),
                 rate_partial=format_float(district.vaccinations.partial_rate * 100),
                 vacc_partial=format_int(district.vaccinations.vaccinated_partial),
                 rate_booster=format_float(district.vaccinations.booster_rate * 100),
                 vacc_booster=format_int(district.vaccinations.vaccinated_booster),
                 vacc_full=format_int(district.vaccinations.vaccinated_full),
                 date=district.vaccinations.date.strftime("%d.%m.%Y"),
                 doses=format_int(district.vaccinations.doses_diff),
                 vacc_speed=format_int(district.vaccinations.avg_speed))
    def get_district_vacc_summary(district: DistrictData) -> str:
        message = "<b>{name}</b>: {percent_partial}% min. Erstimpfung" \
            .format(name=district.name,
                    percent_partial=format_float(district.vaccinations.partial_rate * 100))

        message += "\nРђб {percent_full}% vollst├цndig erstimmunisiert" \
                   "\nРђб {percent_booster}% Auffrischungsimpfung erhalten" \
                   "\nРђб ├ў {vacc_per_day} Impfungen am Tag" \
            .format(percent_full=format_float(district.vaccinations.full_rate * 100),
                    percent_booster=format_float(district.vaccinations.booster_rate * 100),
                    vacc_per_day=format_int(district.vaccinations.avg_speed))
        return message
Beispiel #4
0
    def vaccination_speed_graph(self, district_id: int, duration: int = 49, quadratic=False) -> str:
        with self.connection.cursor(dictionary=True) as cursor:
            oldest_date = datetime.date.today() - datetime.timedelta(days=duration)
            cursor.execute('SELECT c.county_name as name, date, doses_diff FROM covid_vaccinations '
                           'LEFT JOIN counties c on c.rs = covid_vaccinations.district_id '
                           'WHERE district_id=%s AND date > %s ORDER BY date', [district_id, oldest_date])
            x_data = []
            y_data = []
            current_date = None
            district_name = None
            for row in cursor.fetchall():
                if row['doses_diff'] is None:
                    row['doses_diff'] = 0
                y_data.append(row['doses_diff'])
                x_data.append(row['date'])
                if not current_date or row['date'] > current_date:
                    current_date = row['date']
                    district_name = row['name']

        filepath = os.path.abspath(
            os.path.join(self.graphics_dir,
                         f"vaccination-speed-{current_date.isoformat()}-{district_id}-{duration}.jpg"))

        # Do not draw new graphic if its cached
        if not self.disable_cache and os.path.isfile(filepath):
            CACHED_GRAPHS.labels(type='vaccination-speed').inc()
            return filepath
        CREATED_GRAPHS.labels(type='vaccination-speed').inc()

        fig, ax1 = self.setup_plot(current_date, f"Impfungen {district_name}", "Verimpfte Dosen",
                                   quadratic=quadratic)
        # Plot data
        plt.xticks(x_data, rotation='30', ha='right')

        # Add a label every 7 days
        bars = plt.bar(x_data, y_data, color="#1fa2de", width=0.8, zorder=3)
        props = dict(boxstyle='round', facecolor='#ffffff', alpha=0.7, edgecolor='#ffffff')
        for i in range(len(bars) - 1, 0, -7):
            rect = bars[i]
            height = rect.get_height()
            ax1.annotate(format_int(int(height)),
                         xy=(rect.get_x() + rect.get_width() / 2., height),
                         xytext=(0, 30), textcoords='offset points',
                         arrowprops=dict(arrowstyle="-", facecolor='black'),
                         horizontalalignment='center', verticalalignment='top', bbox=props)

        self.set_weekday_formatter(ax1, current_date.weekday())

        # Save to file
        plt.savefig(filepath, format='JPEG')
        self.teardown_plt(fig)
        return filepath
Beispiel #5
0
    def infections_graph(self, district_id: int, duration: int = 49, quadratic=False) -> str:
        district_name, current_date, x_data, y_data = self._get_covid_data("new_cases", district_id, duration)

        filepath = os.path.abspath(
            os.path.join(self.graphics_dir, f"infections-{current_date.isoformat()}-{district_id}-{duration}.jpg"))

        # Do not draw new graphic if its cached
        if not self.disable_cache and os.path.isfile(filepath):
            CACHED_GRAPHS.labels(type='infections').inc()
            return filepath
        CREATED_GRAPHS.labels(type='infections').inc()

        fig, ax1 = self.setup_plot(current_date, f"Neuinfektionen {district_name}", "Neuinfektionen",
                                   quadratic=quadratic)
        # Plot data
        plt.xticks(x_data, rotation='30', ha='right')
        bars = plt.bar(x_data, y_data, color="#1fa2de", width=0.8, zorder=3)
        props = dict(boxstyle='round', facecolor='#ffffff', alpha=0.7, edgecolor='#ffffff')

        # Add a label every 7 days
        if duration < 70:
            for i in range(0, len(bars), 7):
                rect = bars[i]
                height = rect.get_height()
                ax1.annotate(format_int(int(height)),
                             xy=(rect.get_x() + rect.get_width() / 2., height),
                             xytext=(0, 30), textcoords='offset points',
                             arrowprops=dict(arrowstyle="-", facecolor='black'),
                             horizontalalignment='center', verticalalignment='top', bbox=props)

            self.set_weekday_formatter(ax1, current_date.weekday())
        else:
            self.set_monthly_formatter(ax1)

        # Save to file
        plt.savefig(filepath, format='JPEG')
        self.teardown_plt(fig)
        return filepath
    def get_district_summary(district: DistrictData, show_icu: bool,
                             show_vaccinations: bool) -> str:
        message = "<b>{name}</b>: {incidence}{incidence_trend}" \
            .format(name=district.name,
                    incidence=format_float(district.incidence),
                    incidence_trend=format_data_trend(district.incidence_trend))

        if district.incidence_interval_data:
            if district.incidence_interval_data.lower_threshold_days is not None:
                message += "\nРђб Seit {days} ({working_days}) ├╝ber {threshold}" \
                    .format(days=format_noun(district.incidence_interval_data.lower_threshold_days,
                                             FormattableNoun.DAYS),
                            working_days=format_noun(
                                district.incidence_interval_data.lower_threshold_working_days,
                                FormattableNoun.WORKING_DAYS),
                            threshold=format_int(district.incidence_interval_data.lower_threshold))

            if district.incidence_interval_data.upper_threshold_days is not None:
                if district.incidence_interval_data.lower_threshold_days is None:
                    message += "\nРђб Seit "
                else:
                    message += ", seit "
                message += "{days} ({working_days}) unter {threshold}" \
                    .format(days=format_noun(district.incidence_interval_data.upper_threshold_days,
                                             FormattableNoun.DAYS),
                            working_days=format_noun(
                                district.incidence_interval_data.upper_threshold_working_days,
                                FormattableNoun.WORKING_DAYS),
                            threshold=format_int(district.incidence_interval_data.upper_threshold))

        message += "\nРђб {new_cases}{cases_trend}, {new_deaths} seit gestern" \
            .format(new_cases=format_noun(district.new_cases, FormattableNoun.NEW_INFECTIONS),
                    cases_trend=format_data_trend(district.cases_trend),
                    new_deaths=format_noun(district.new_deaths, FormattableNoun.DEATHS))
        if district.hospitalisation:
            message += "\nРђб {cases} Krankenhauseinweisungen in den letzten 7 Tagen".format(
                cases=format_int(district.hospitalisation.cases))

        if (district.new_cases
                and district.new_cases < 0) or (district.new_deaths
                                                and district.new_deaths < 0):
            message += "\nРђб <i>Eine negative Differenz zum Vortag ist in der Regel auf eine Korrektur der Daten " \
                       "durch das Gesundheitsamt zur├╝ckzuf├╝hren</i>"
        if district.hospitalisation:
            message += "\nРђб Hospitalisierungsinzidenz: {incidence}".format(
                incidence=format_float(district.hospitalisation.incidence))

        if show_icu and district.icu_data:
            message += "\nРђб {percent_occupied}% ({beds_occupied}){occupied_trend} belegt, in " \
                       "{percent_covid}% ({beds_covid}){covid_trend} Covid19-Patient:innen, {clear_beds} frei (nur Erwachsene)" \
                .format(beds_occupied=format_noun(district.icu_data.occupied_beds, FormattableNoun.BEDS),
                        percent_occupied=format_float(district.icu_data.percent_occupied()),
                        occupied_trend=format_data_trend(district.icu_data.occupied_beds_trend),
                        beds_covid=format_noun(district.icu_data.occupied_covid, FormattableNoun.BEDS),
                        clear_beds=format_noun(district.icu_data.clear_beds, FormattableNoun.BEDS),
                        percent_covid=format_float(district.icu_data.percent_covid()),
                        covid_trend=format_data_trend(district.icu_data.occupied_covid_trend))

        if show_vaccinations and district.vaccinations:
            message += "\nРђб {no_doses} Neuimpfungen, {vacc_partial}% min. eine, {vacc_full}% beide Impfungen und " \
                       "{vacc_booster}% Auffrischungsimpfungen erhalten" \
                .format(no_doses=format_int(district.vaccinations.doses_diff),
                        vacc_partial=format_float(district.vaccinations.partial_rate * 100),
                        vacc_full=format_float(district.vaccinations.full_rate * 100),
                        vacc_booster=format_float(district.vaccinations.booster_rate * 100))
        return message
Beispiel #7
0
 def tick_formatter_german_numbers(tick_value, position) -> str:
     if tick_value > 999999:
         tick_value = float(tick_value / 1000000)
         return str(tick_value).replace(".", ",") + " Mio."
     return utils.format_int(int(tick_value))