diff options
| author | Alex <90010930+ajschofield@users.noreply.github.com> | 2020-08-18 19:00:42 +0100 |
|---|---|---|
| committer | Alex <90010930+ajschofield@users.noreply.github.com> | 2020-08-18 19:00:42 +0100 |
| commit | c44a5ff542e6b85f49ec2bb0046ef7a37112abdb (patch) | |
| tree | 9a1a815ebfb0a131e4829af498e3a73385e1d96b /main.py | |
| parent | 9b99ec4a82e6f4ab4fa84cc06cc55b9600a3d257 (diff) | |
| download | covid-tracker-2-c44a5ff542e6b85f49ec2bb0046ef7a37112abdb.tar.gz covid-tracker-2-c44a5ff542e6b85f49ec2bb0046ef7a37112abdb.zip | |
Temporarily removed deaths plot - legacy deaths download is no longer available as the data series has been discontinued (will update to use API in the future)
Diffstat (limited to 'main.py')
| -rw-r--r-- | main.py | 40 |
1 files changed, 23 insertions, 17 deletions
@@ -11,7 +11,7 @@ import time # VARIABLES AND INITIALISATION error_count = 0 url_cases = 'https://coronavirus.data.gov.uk/downloads/csv/coronavirus-cases_latest.csv' -url_deaths = 'https://coronavirus.data.gov.uk/downloads/csv/coronavirus-deaths_latest.csv' +# url_deaths = 'https://coronavirus.data.gov.uk/downloads/csv/coronavirus-deaths_latest.csv' def getStats(): global error_count @@ -39,7 +39,7 @@ def getStats(): error_count += 1 else: spinner.ok("✔") - + """ with yaspin(text=" Downloading COVID-19 deaths...", color="yellow") as spinner: time.sleep(2) try: @@ -51,7 +51,7 @@ def getStats(): error_count += 1 else: spinner.ok("✔") - + """ def csv_parser(): # Get abs path @@ -61,34 +61,34 @@ def csv_parser(): # Get path to files covid_case_file_path = path_to_stats / "covid-cases.csv" - covid_death_file_path = path_to_stats / "covid-deaths.csv" + # covid_death_file_path = path_to_stats / "covid-deaths.csv" # Read CSV files cases = pd.read_csv(covid_case_file_path).dropna() - deaths = pd.read_csv(covid_death_file_path).dropna() + # deaths = pd.read_csv(covid_death_file_path).dropna() # Get England data cases_filtered_england = cases.loc[cases['Area name'] == "England"] - deaths_filtered_england = deaths.loc[deaths['Area name'] == "England"] + # deaths_filtered_england = deaths.loc[deaths['Area name'] == "England"] # Sort by date cases_sorted = cases_filtered_england.sort_values(by='Specimen date') - deaths_sorted = deaths_filtered_england.sort_values(by='Reporting date') + # deaths_sorted = deaths_filtered_england.sort_values(by='Reporting date') # Convert date strings to datetime objects cases_sorted['Specimen date'] = pd.to_datetime(cases_sorted['Specimen date']) - deaths_sorted['Reporting date'] = pd.to_datetime(deaths_sorted['Reporting date']) + # deaths_sorted['Reporting date'] = pd.to_datetime(deaths_sorted['Reporting date']) # Return data from function - return cases_sorted, deaths_sorted + return cases_sorted # ,deaths_sorted # First, get latest stats using getStats() getStats() # Then, parse the data: we only need the dates and their corresponding values. imported = csv_parser() -cases = imported[0] -deaths = imported[1] +cases = imported #[0] +# deaths = imported[1] # Temporary variables date_today = datetime.now().strftime('%d-%m-%Y') @@ -107,41 +107,47 @@ with yaspin(text=" Checking if 'graphs' folder is present...", color="yellow") a with yaspin(text=" Creating and saving the daily cases plot...", color="yellow") as spinner: try: - p1 = ggplot(cases, aes(x="Specimen date", y="Daily lab-confirmed cases", group = 1)) + geom_point() + geom_line() + labs(title = "Daily COVID-19 Cases") + scale_x_date(date_breaks = "3 days") + stat_smooth(method='mavg', method_args={'window': 3}, color='cyan', show_legend=True) + stat_smooth(method='mavg', method_args={'window': 7}, color='blue') + theme(axis_text_x=element_text(rotation=45, hjust=1)) - p1.save(filename=('cases_daily_' + str(date_today)),path=path_to_graphs,height=10, width=20, units = 'in', dpi=1000, verbose = False) + p1 = ggplot(cases, aes(x="Specimen date", y="Daily lab-confirmed cases", group = 1)) + geom_col() + labs(title = "Daily COVID-19 Cases") + scale_x_date(date_breaks = "3 days") + stat_smooth(method='mavg', method_args={'window': 3}, color='cyan', show_legend=True) + stat_smooth(method='mavg', method_args={'window': 7}, color='blue') + theme(axis_text_x=element_text(rotation=45, hjust=1)) + p1.save(filename=('cases_daily_' + str(date_today)),path=path_to_graphs,height=6, width=20, units = 'in', dpi=1000, verbose = False) except Exception: spinner.fail("✘") error_count += 1 else: spinner.ok("✔") +""" with yaspin(text=" Creating and saving the daily change in deaths plot... ", color="yellow") as spinner: try: - p2 = ggplot(deaths, aes(x="Reporting date", y="Daily change in deaths", group = 1)) + geom_point() + geom_line() + labs(title = "Daily Change in Deaths") + scale_x_date(date_breaks = "3 days") + stat_smooth(method='mavg', method_args={'window': 3}, color='cyan') + stat_smooth(method='mavg', method_args={'window': 7}, color='blue') + theme(axis_text_x=element_text(rotation=45, hjust=1)) - p2.save(filename = ('deaths_change_daily_' + str(date_today)),path=path_to_graphs,height=10, width=20, units = 'in', dpi=1000, verbose = False) + p2 = ggplot(deaths, aes(x="Reporting date", y="Daily change in deaths", group = 1)) + geom_col() + labs(title = "Daily Change in Deaths") + scale_x_date(date_breaks = "3 days") + stat_smooth(method='mavg', method_args={'window': 3}, color='cyan') + stat_smooth(method='mavg', method_args={'window': 7}, color='blue') + theme(axis_text_x=element_text(rotation=45, hjust=1)) + p2.save(filename = ('deaths_change_daily_' + str(date_today)),path=path_to_graphs,height=6, width=20, units = 'in', dpi=1000, verbose = False) except Exception: spinner.fail("✘") error_count += 1 else: spinner.ok("✔") +""" + with yaspin(text=" Creating and saving the cumulative cases plot...", color="yellow") as spinner: try: p3 = ggplot(cases, aes(x="Specimen date", y="Cumulative lab-confirmed cases", group = 1)) + geom_point() + geom_line() + labs(title = "Cumulative Cases") + scale_x_date(date_breaks = "3 days") + theme(axis_text_x=element_text(rotation=45, hjust=1)) - p3.save(filename = ('cumulative_cases_' + str(date_today)),path=path_to_graphs,height=10, width=20, units = 'in', dpi=1000, verbose = False) + p3.save(filename = ('cumulative_cases_' + str(date_today)),path=path_to_graphs,height=6, width=20, units = 'in', dpi=1000, verbose = False) except Exception: spinner.fail("✘") error_count += 1 else: spinner.ok("✔") + +""" with yaspin(text=" Creating and saving the cumulative deaths plot...", color="yellow") as spinner: try: p4 = ggplot(deaths, aes(x="Reporting date", y="Cumulative deaths", group = 1)) + geom_point() + geom_line() + labs(title = "Cumulative Deaths") + scale_x_date(date_breaks = "3 days") + theme(axis_text_x=element_text(rotation=45, hjust=1)) - p4.save(filename = ('cumulative_deaths_' + str(date_today)),path=path_to_graphs,height=10, width=20, units = 'in', dpi=1000, verbose = False) + p4.save(filename = ('cumulative_deaths_' + str(date_today)),path=path_to_graphs,height=6, width=20, units = 'in', dpi=1000, verbose = False) except Exception: spinner.fail("✘") error_count += 1 else: spinner.ok("✔") +""" if error_count > 1: print("⚠ {} errors were encountered during runtime. Check the logs...".format(error_count)) |
