Ejemplo n.º 1
0
def get_infection_data() -> Infections:
    """
    Retrieve infections (confirmed cases, deaths and recoveries) by country and date.
    Data is cached for 24 hours
    :return: A dictionary of countries with a list of dates and counts
    """
    config = read_config()
    endpoint = config["endpoints"]["infections"]
    text = requests.get(endpoint).text
    infection_data = json.loads(text)
    logger.info(
        f"retrieved infection data with {len(infection_data)} countries")
    return infection_data
Ejemplo n.º 2
0
def test_read_config():
    config = read_config()
    config_has_content = bool(config)
    config_is_dict = isinstance(config, dict)
    assert config_has_content and config_is_dict, "malformed config"
Ejemplo n.º 3
0
"""Statistical models"""
from datetime import datetime
from typing import Tuple
from typing import Union, List

import numpy as np
from sklearn.linear_model import LinearRegression

from covid19 import types as t
from covid19.utils import read_config

config = read_config()


def fit_infection_trend(kind: t.InfectionStatus,
                        infection_data: t.Infections) -> Tuple[list, list]:
    """
    Fit a linear model to the log of infection data
    :param kind: Infection status (deaths, confirmed, recovered)
    :param infection_data: infection data
    :return: A tuple of unique days  (from zero) and predicted infections for that day
    """
    linear_model = LinearRegression()
    predictors, response = [], []
    for country, content in infection_data.items():
        if country not in config["exclude"]["trend"]:
            counts = [day[kind.value] for day in content]
            days = [day for day in range(len(counts))]
            predictors.extend(days)
            response.extend(np.log10(counts))
    trend_days = sorted(list(set(predictors)))
Ejemplo n.º 4
0
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objects as go
from decouple import config
from flask import Flask

from covid19 import callbacks as cb, plots as p
from covid19.data import get_infection_data, filter_infection_data
from covid19.stats import build_summary_stats
from covid19.types import InfectionStatus
from covid19.utils import get_app_dir, read_config

logger = getLogger(__name__)

default_infection_status = InfectionStatus.CONFIRMED.value
config_file = read_config()
app_dir = get_app_dir()

with open(str(app_dir / "assets" / "header.md")) as header_file:
    header_md = header_file.read()

raw_infection_data = get_infection_data()
infection_data = filter_infection_data(raw_infection_data)
summary_data = build_summary_stats(infection_data)
graphic = p.Graphic(infection_data)
plots = graphic.figures[default_infection_status]


def generate_stats_panel() -> list:
    """Build a div with top level statistics"""
    panel_list = []