def test_get_population(): world = c.get_population() assert world.index.name == 'Country_Region' assert 'population' in world.columns # Check that the case regions and population regions match try: assert set(c.fetch_cases().index) == set(world.index) except AssertionError: failing_states = {'Palau', 'Western Sahara'} if set(c.fetch_cases().index).symmetric_difference(set( world.index)) == failing_states: pass else: raise AssertionError # Tests will have to be updated in 20+ years when the populations increase # more than the 'sensible' lower bound placed here # The lower bound exists in case the summing over regions fails somehow # and includes areas multiple times assert 140_000_000 * 1.5 > world.loc['Russia'].population > 140_000_000 assert 120_000_000 * 1.5 > world.loc['Japan'].population > 120_000_000 assert 320_000_000 * 1.5 > world.loc['US'].population > 320_000_000 assert 80_000_000 * 1.5 > world.loc['Germany'].population > 80_000_000
def generate_reports_countries( *, workers, kernel_name, wwwroot, force, disable_pbar, debug ): d = oscovida.fetch_deaths() c = oscovida.fetch_cases() countries = d.index countries2 = c.index assert (countries2 == countries).all() # TODO: The get_x_list methods should be part of Reporter class countries = get_country_list() cre = ReportExecutor( Reporter=CountryReport, kernel_name=kernel_name, wwwroot=wwwroot, expiry_hours=2, attempts=3, workers=workers, force=force, disable_pbar=disable_pbar, debug=debug, ) if debug: countries = countries[:10] cre.create_html_reports(countries) cre.create_markdown_index_page()
def get_country_list(): d, c = fetch_deaths(), fetch_cases() countries = d.index countries2 = c.index assert (countries2 == countries).all() # Here we should identify regions in countries, and process those. # Instead, as a quick hack to get started, we'll just take one country # and the current "get_country" method will sum over all regions of one country if only # the country name is given. return sorted(countries.drop_duplicates())
def test_get_population(): world = c.get_population() assert world.index.name == 'Country_Region' assert 'population' in world.columns # Check that the case regions and population regions match try: assert set(c.fetch_cases().index) == set(world.index) except AssertionError: # occasionally, population data is missing for case data: known_missing_states = {'Western Sahara', 'Antarctica'} msg = "Deviations are: " deviation = set( (c.fetch_cases().index).symmetric_difference(set(world.index))) msg += str(deviation) print(msg) print(f"Expect these to deviate: {known_missing_states}.") # difference between missing population data, and our expectation should_be_emtpy_set = deviation.symmetric_difference( known_missing_states) print(f"should_be_empty_set={should_be_emtpy_set}") # check that the deviation are only those regions for which we expect it assert deviation == known_missing_states # Tests will have to be updated in 20+ years when the populations increase # more than the 'sensible' lower bound placed here # The lower bound exists in case the summing over regions fails somehow # and includes areas multiple times assert 140_000_000 * 1.5 > world.loc['Russia'].population > 140_000_000 assert 120_000_000 * 1.5 > world.loc['Japan'].population > 120_000_000 assert 320_000_000 * 1.5 > world.loc['US'].population > 320_000_000 assert 80_000_000 * 1.5 > world.loc['Germany'].population > 80_000_000
def test_get_population(): world = c.get_population() assert world.index.name == 'Country_Region' assert 'population' in world.columns # Check that the case regions and population regions match assert set(c.fetch_cases().index) == set(world.index) # Tests will have to be updated in 20+ years when the populations increase # more than the 'sensible' lower bound placed here # The lower bound exists in case the summing over regions fails somehow # and includes areas multiple times assert 140_000_000 * 1.5 > world.loc['Russia'].population > 140_000_000 assert 120_000_000 * 1.5 > world.loc['Japan'].population > 120_000_000 assert 320_000_000 * 1.5 > world.loc['US'].population > 320_000_000 assert 80_000_000 * 1.5 > world.loc['Germany'].population > 80_000_000