def execute(self, args): try: # This call validates inputs. If a required arg isn't there # or an additional, unexpected, arg is present it will except. execute_args = super()._parse_execute_arguments(args) if IFunction.GLOBAL_HELP in execute_args.keys(): # Regardless of anything else, if help is there, show it and quit self.get_help(1) else: start_month = date_range(1, -1) end_month = date_range(50,-1) # Filter the files and get the data from the last one since # we are just going over global stats. region = execute_args['-r'] files = DataReader.get_dated_files(self.datasets, start_month, end_month) region_data = GlobalDataParser.parse_region_data([files[-1]], region) print("Province information for region : ", region) if len(region_data): columns = [6,30, 7, 8,11,11] headers = ['Rank','Province', 'Cases', 'Deaths', 'Recovered', 'Mortality'] PrintTable.print_banner(columns,headers) region = region_data[0] rows = [] for province in region.provinces.keys(): mortality = "%.2f" % (region.provinces[province].get_mortality()) row = [ province, region.provinces[province].confirmed_cases, region.provinces[province].deaths, region.provinces[province].recovered, mortality + " %" ] rows.append(row) # Sort them by mortality rows = sorted(rows, reverse=True, key=lambda x: x[1]) # Now print them rank = 1 for row in rows: row.insert(0,rank) PrintTable.print_row(columns, row) rank += 1 else: print("NO data found....") except Exception as ex: print(str(ex))
def execute(self, args): try: # This call validates inputs. If a required arg isn't there # or an additional, unexpected, arg is present it will except. execute_args = super()._parse_execute_arguments(args) if IFunction.GLOBAL_HELP in execute_args.keys(): # Regardless of anything else, if help is there, show it and quit self.get_help(1) else: start_month = date_range(1, -1) end_month = date_range(50, -1) # Filter the files and get the data from the last one since # we are just going over global stats. files = DataReader.get_dated_files(self.datasets, start_month, end_month) region_data = GlobalDataParser.parse_region_data([files[-1]]) # Accumulate province data for each region regional_details = {} for reg in region_data: regional_details[reg.region] = reg.condense_provinces() # Get the mortality for each region mortality_stats = [] for reg in regional_details.keys(): mortality = regional_details[reg].get_mortality() mortality_stats.append(mortality_overall(reg, mortality)) sorted_mortality_stats = sorted(mortality_stats, reverse=True, key=lambda x: x.rate) ''' Table 1: Prints out each region with it's rolled up stats across all provinces. ''' columns = [6, 35, 11] headers = ['Rank', 'Region', 'Mortality'] PrintTable.print_banner(columns, headers) entry = 1 for stat in sorted_mortality_stats: mortality_rate = "%.2f" % (stat.rate) row = [entry, stat.region, '{}%'.format(mortality_rate)] PrintTable.print_row(columns, row) entry += 1 except Exception as ex: print(str(ex)) raise ex
def execute(self, args): try: # This call validates inputs. If a required arg isn't there # or an additional, unexpected, arg is present it will except. execute_args = super()._parse_execute_arguments(args) if IFunction.GLOBAL_HELP in execute_args.keys(): # Regardless of anything else, if help is there, show it and quit self.get_help(1) else: start_month = date_range(1, -1) end_month = date_range(50, -1) # Filter the files and get the data from the last one since # we are just going over global stats. files = DataReader.get_dated_files(self.datasets, start_month, end_month) region_data = GlobalDataParser.parse_region_data([files[-1]]) # Accumulate province data for each region regional_details = {} for reg in region_data: regional_details[reg.region] = reg.condense_provinces() ''' Table 1: Prints out each region with it's rolled up stats across all provinces. ''' columns = [35, 11, 11, 11] headers = ['Region', 'Confirmed', 'Deaths', 'Mortality'] PrintTable.print_banner(columns, headers) overall_stats = OverallStats() data_rows = [] for region_key in regional_details.keys(): data_row = [region_key] data_row.append( regional_details[region_key].confirmed_cases) data_row.append(regional_details[region_key].deaths) #data_row.append(regional_details[region_key].recovered) mortality = '0.00' try: mortality = ( regional_details[region_key].deaths / regional_details[region_key].confirmed_cases) * 100 mortality = "%.2f" % (mortality) except: pass data_row.append(mortality) overall_stats.add_deaths( region_key, regional_details[region_key].deaths) overall_stats.add_mortality(region_key, float(mortality)) overall_stats.add_confirmed( region_key, regional_details[region_key].confirmed_cases) overall_stats.recovered_cases.append( regional_details[region_key].recovered) data_rows.append(data_row) sort_column = -1 if '-c' in execute_args: sort_column = 1 elif '-d' in execute_args: sort_column = 2 if sort_column != -1: sorted_rows = sorted(data_rows, reverse=True, key=lambda x: x[sort_column]) data_rows = sorted_rows for row in data_rows: PrintTable.print_row(columns, row) ''' Table 2: Global overall stats focusing on US vs World ''' print("") columns = [36, 26] headers = ['General Statistic', 'Value'] banner, cols = PrintTable.print_banner(columns, headers) total_cases = overall_stats.us_confirmed_cases + sum( overall_stats.non_us_confirmed_cases) total_deaths = overall_stats.us_deaths + sum( overall_stats.non_us_deaths) us_cases = "%d (%.3f)" % ( overall_stats.us_confirmed_cases, float(overall_stats.us_confirmed_cases / total_cases) * 100) non_us_case = "%d (%.3f)" % ( sum(overall_stats.non_us_confirmed_cases), float( sum(overall_stats.non_us_confirmed_cases) / total_cases) * 100) us_deaths = "%d (%.3f)" % ( overall_stats.us_deaths, float(overall_stats.us_deaths / total_deaths) * 100) non_us_deaths = "%d (%.3f)" % ( sum(overall_stats.non_us_deaths), float(sum(overall_stats.non_us_deaths) / total_deaths) * 100) PrintTable.print_row( columns, ["Total Global Confirmed Cases", total_cases]) PrintTable.print_row(columns, ["US Confirmed Cases", us_cases]) PrintTable.print_row(columns, ["Non-US Confirmed Cases", non_us_case]) PrintTable.print_row(columns, ["Total Global Deaths", total_deaths]) PrintTable.print_row(columns, ["US Deaths", us_deaths]) PrintTable.print_row(columns, ["Non-US Deaths", non_us_deaths]) #PrintTable.print_row(columns, ["Total Recovered", sum(overall_stats.recovered_cases)]) print(banner) PrintTable.print_row( columns, ["Highest Mortality", overall_stats.mortality_highest]) PrintTable.print_row(columns, [ "Highest Mortality Region", overall_stats.mortality_winner ]) print(banner) PrintTable.print_row(columns, [ "Highest Reported Deaths", overall_stats.total_cases_highest ]) PrintTable.print_row(columns, [ "Highest Reported Region", overall_stats.total_cases_winner ]) print(banner) print("") except Exception as ex: print(str(ex)) raise ex
def execute(self, args): try: # This call validates inputs. If a required arg isn't there # or an additional, unexpected, arg is present it will except. execute_args = super()._parse_execute_arguments(args) if IFunction.GLOBAL_HELP in execute_args.keys(): # Regardless of anything else, if help is there, show it and quit self.get_help(1) else: start_month = date_range(int(execute_args['-s']), -1) end_month = date_range(-1,-1) if '-e' in execute_args.keys(): end_month = date_range(int(execute_args['-e']),-1) files = DataReader.get_dated_files(self.datasets, start_month, end_month) # Get the region and then collect the data desired_region = execute_args['-r'] region_data = GlobalDataParser.parse_region_data(files, desired_region) # Output table header columns = [16, 19,19,19,11] headers = ['File', 'Confirmed', 'Deaths', 'Recovered', 'Mortality'] PrintTable.print_banner(columns,headers) last_confirmed = -1 last_death = -1 last_recovered = -1 # If -sum, then only first and last data_to_scan = region_data if '-sum' in execute_args.keys(): data_to_scan = [ region_data[0], region_data[-1] ] for rdata in data_to_scan: file_name = rdata.data_file.file_name mrate = '0.00' # Accumulate all of the province/state data condensed = rdata.condense_provinces() confirmed = condensed.confirmed_cases deaths = condensed.deaths recovered = condensed.recovered # Mortality rate mrate = '%.2f' %(condensed.get_mortality()) # If we have a last entry, get the diff to today if last_confirmed != -1: confirmed = "{} ({})".format(str(confirmed), str(confirmed - last_confirmed)) deaths = "{} ({})".format(str(deaths), str(deaths - last_death)) recovered = "{} ({})".format(str(recovered), str(recovered - last_recovered)) last_confirmed = condensed.confirmed_cases last_death = condensed.deaths last_recovered = condensed.recovered output_data = [ file_name, confirmed, deaths, recovered, mrate + ' %' ] PrintTable.print_row(columns, output_data) except Exception as ex: print(str(ex))