Esempio n. 1
0
def finalize_record(check_expectations=False):
    # do nothing if record has already been finalized
    if not abbr:
        return
    global errs
    global warns
    data = {
        'ncumul_tested': tested,
        'ncumul_conf': cases,
        'ncumul_released': recovered,
        'ncumul_deceased': deaths,
        'current_hosp': hospitalized,
        'new_hosp': new_hosp,
        'current_icu': icu,
        'current_vent': vent,
        'current_isolated': isolated,
        'current_quarantined': quarantined,
        'ncumul_ICF': icf, # GE only
        'ncumul_confirmed_non_resident': confirmed_non_resident, # BS only
        'current_hosp_non_resident': hosp_non_resident, # BS only
    }
    # Remove Nones
    extras = {k: v for (k, v) in data.items() if not v is None}
    # Format k,v
    extras = [f"{k}={v}" for (k, v) in extras.items()]
    # Join into list.
    extras = ",".join(extras)

    urls = ", ".join(url_sources)

    # if expectations are not met, we treat this as an error
    if check_expectations:
        violated_expectations, warnings_exp = sm.check_expected(abbr, date, data)
        errs.extend(violated_expectations)
        warns.extend(warnings_exp)

    if date and not errs:
        print("{:2} {:<16} {:>7} {:>7} OK {}{}{}".format(
            abbr,
            date,
            cases if cases is not None else '-',
            deaths if deaths is not None else '-',
            scrape_time,
            f" # Extras: {extras}" if extras else "",
            f" # URLs: {urls}"))
    else:
        if not date:
            errs.append("Missing date")
        errs.extend(warns)
        errs = ". ".join(errs)
        print("{:2} {:<16} {:>7} {:>7} FAILED {} {}{}{}".format(
            abbr,
            date or "-",
            cases if cases is not None else '-',
            deaths if deaths is not None else '-',
            scrape_time or "-",
            f" # Extras: {extras}" if extras else "",
            f" # URLs: {urls}",
            f" # Errors: {errs}"))
        sys.exit(1)
Esempio n. 2
0
        'ncumul_deceased': deaths,
        'current_hosp': hospitalized,
        'current_icu': icu,
        'current_vent': vent,
    }
    # Remove Nones
    extras = {k: v for (k, v) in data.items() if not v is None}
    # Format k,v
    extras = [f"{k}={v}" for (k, v) in extras.items()]
    # Join into list.
    extras = ",".join(extras)

    urls = ", ".join(url_sources)

    # if expectations are not met, we treat this as an error
    violated_expectations, warnings_exp = sm.check_expected(abbr, date, data)
    errs.extend(violated_expectations)
    warns.extend(warnings_exp)

    if date and not errs:
        print("{:2} {:<16} {:>7} {:>7} OK {}{}{}".format(
            abbr, date, cases if cases is not None else '-',
            deaths if deaths is not None else '-', scrape_time,
            f" # Extras: {extras}" if extras else "", f" # URLs: {urls}"))
    else:
        if not date:
            errs.append("Missing date")
        errs.extend(warns)
        errs = ". ".join(errs)
        print("{:2} {:<16} {:>7} {:>7} FAILED {} {}{}{}".format(
            abbr, date or "-", cases if cases is not None else '-',
Esempio n. 3
0
        'ncumul_hosp': hospitalized,
        'ncumul_ICU': icu,
        'ncumul_vent': vent,
    }
    # Remove Nones
    extras = {k: v for (k, v) in extras_dict.items() if not v is None}
    # Format k,v
    extras = [f"{k}={v}" for (k, v) in extras.items()]
    # Join into list.
    extras = ",".join(extras)

    urls = ", ".join(url_sources)

    if date and cases and not errs:
        violated_expectations = sm.check_expected(abbr,
                                                  date=date,
                                                  deaths=deaths,
                                                  extras=extras_dict)
        # For now just print warnings on stderr.
        for violated_expectation in violated_expectations:
            print(f'WARNING: {violated_expectation}', file=sys.stderr)
        print("{:2} {:<16} {:>7} {:>7} OK {}{}{}".format(
            abbr, date, cases, deaths if not deaths is None else "-",
            scrape_time, f" # Extras: {extras}" if extras else "",
            f" # URLs: {urls}"))
    else:
        if not date:
            errs.append("Missing date")
        if not cases:
            errs.append("Missing cases")
        errs.extend(warns)
        errs = ". ".join(errs)
Esempio n. 4
0
        # See, README.md
        'ncumul_hosp': hospitalized,
        'ncumul_ICU': icu,
        'ncumul_vent': vent,
    }
    # Remove Nones
    extras = {k: v for (k, v) in extras.items() if not v is None}
    # Format k,v
    extras = [f"{k}={v}" for (k, v) in extras.items()]
    # Join into list.
    extras = ",".join(extras)

    urls = ", ".join(url_sources)

    if date and cases and not errs:
        violated_expectations = sm.check_expected(abbr, deaths=deaths, hospitalized=hospitalized, icu=icu, vent=vent, released=recovered)
        # For now just print warnings on stderr.
        for violated_expectation in violated_expectations:
          print(f'WARNING: {violated_expectation}', file=sys.stderr)
        print("{:2} {:<16} {:>7} {:>7} OK {}{}{}".format(
            abbr,
            date,
            cases,
            deaths if not deaths is None else "-",
            scrape_time,
            f" # Extras: {extras}" if extras else "",
            f" # URLs: {urls}"))
    else:
        if not date:
            errs.append("Missing date")
        if not cases:
        'ncumul_deceased': deaths,
        'current_hosp': hospitalized,
        'current_icu': icu,
        'current_vent': vent,
    }
    # Remove Nones
    extras = {k: v for (k, v) in data.items() if not v is None}
    # Format k,v
    extras = [f"{k}={v}" for (k, v) in extras.items()]
    # Join into list.
    extras = ",".join(extras)

    urls = ", ".join(url_sources)

    # if expectations are not met, we treat this as an error
    violated_expectations = sm.check_expected(abbr, date, data)
    errs.extend(violated_expectations)

    if date and not errs:
        print("{:2} {:<16} {:>7} {:>7} OK {}{}{}".format(
            abbr, date, cases if cases is not None else '-',
            deaths if deaths is not None else '-', scrape_time,
            f" # Extras: {extras}" if extras else "", f" # URLs: {urls}"))
    else:
        if not date:
            errs.append("Missing date")
        errs.extend(warns)
        errs = ". ".join(errs)
        print("{:2} {:<16} {:>7} {:>7} FAILED {} {}{}{}".format(
            abbr, date or "-", cases if cases is not None else '-',
            deaths if deaths is not None else '-', scrape_time or "-",