def route_default(): today = database.get_stats(slug=SLUG["romania"]) if not today: return render_template("home.html", archive=[], stats_last_updated="N/A") incidence = today.get("Incidență", {}) infections = today.get("Judete", {}) today_date = datetime.strptime(today["Data"], DATE_FORMAT) today_keys = ["Confirmați", "Decedați", "Vindecați"] if not os.environ["DATELAZI_DATA_URL"].endswith("smallData.json"): today_keys.extend( ["Procent barbati", "Procent femei", "Procent copii"]) today = {key: today[key] for key in today_keys} archive_today = deepcopy(today) archive_today["Data"] = today_date archive = list(database.get_many(COLLECTION["archive"], "Data", how=1)) yesterday = today_date - timedelta(days=1) yesterday = [ x for x in archive if x["Data"] == yesterday.strftime(DATE_FORMAT) ] archive = [ DLZArchiveSerializer.deserialize( x, fields=["Confirmați", "Vindecați", "Decedați", "Data"]) for x in archive ] + [archive_today] return render_template( "home.html", stats_last_updated=today_date.strftime("%d.%m.%Y"), archive=archive, top_stats=[{ "name": key, "value": value, "icon": ICONS.get(key, "user"), "change": (today[key] - yesterday[0][key]) if yesterday else None, } for key, value in today.items()], incidence=[{ "county": c, "incidence": incidence[c] } for c in incidence.keys()], infections=[{ "county": c, "infections": infections[c] } for c in infections.keys()], )
def local_global_stats(): top_stats = database.get_stats( collection=COLLECTION["global"], slug=SLUG["global"] ) if not top_stats: return "Nu sunt statistici globale pentru ziua de azi" countries = list( database.get_many(COLLECTION["country"], order_by="total_cases")[:3] ) for item in countries: del item["_id"] last_updated = top_stats.pop("last_updated") return formatters.parse_global( title="🌎 Global Stats", stats=top_stats, items=prepare_items("country", countries), emoji="🦠", footer=f"\n`{last_updated}`\n[Source: worldometers.info](https://worldometers.info/)", )
def global_map(): countries = list(database.get_many(COLLECTION["country"], "total_cases")) if not countries: return render_template("global.html", countries=[], stats_last_updated="N/A") stats = [c for c in countries if c["country"].strip() == "World"][0] return render_template( "global.html", stats_last_updated=database.get_stats( COLLECTION["global"], slug=SLUG["global"])["last_updated"].replace("Last updated: ", ""), top_stats=[{ "name": key, "value": value, "icon": ICONS.get(key, "user"), "change": stats.get(CHANGES.get(key)), } for key, value in parse_top_stats(stats).items()], countries=parse_countries(countries), )
def test_get_many_order_by(self, collection_mock): collection_mock.return_value.find.return_value.sort.return_value = "fs" assert database.get_many("foo", order_by="foo_order", fo="bar") == "fs" collection_mock.assert_called_once_with("foo") collection_mock().find.assert_called_once_with({"fo": "bar"}) collection_mock().find().sort.assert_called_once_with("foo_order", -1)
def test_get_many_no_order(self, collection_mock): collection_mock.return_value.find.return_value = "find_foo" assert database.get_many("foo") == "find_foo" collection_mock.assert_called_once_with("foo") collection_mock().find.assert_called_once_with({})
def get_list(cls, chat_id): return database.get_many( cls.COLLECTION, order_by="name", how=1, chat_id=chat_id )