covid-19-analysis/Analyser.py

66 lines
1.6 KiB
Python
Raw Normal View History

2020-03-28 11:37:54 +00:00
# -*- coding: utf-8 -*-
"""
Project: Analyse worldwide COVID-19 Data and provide graphs etc.
@author Patrick Müller
"""
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import tkinter as tk
"""
Fields in csv:
dateRep
day
month
year
cases
deaths
countriesAndTerritories
geoId
countryterritoryCode
popData2018
"""
2020-03-28 15:55:34 +00:00
from datetime import datetime, timedelta
2020-03-28 11:37:54 +00:00
class Analyser:
# Pandas Settings
2020-03-28 15:55:34 +00:00
pd.set_option('display.max_row', 50)
2020-03-28 11:37:54 +00:00
pd.set_option('display.max_column', 10)
df = pd.read_csv('2020-03-28_11-00.csv', encoding='windows-1252')
df['dateRep'] = pd.to_datetime(df['dateRep'])
2020-03-28 15:55:34 +00:00
print(df['dateRep'].head())
2020-03-28 11:37:54 +00:00
def getAvailableCountries(self):
return self.df['countriesAndTerritories'].unique()
2020-03-28 15:55:34 +00:00
def getCasesGraph(self, country) -> str:
"""
Get a graph with the absolute number of cases by day for the entered country
:param country: The country you wish to get the graph for
:return: The path for the picture of the graph
"""
2020-03-28 11:37:54 +00:00
fig = plt.figure()
ax = fig.add_subplot(111)
2020-03-28 15:55:34 +00:00
countryData = self.df[self.df['countriesAndTerritories'].isin([country])]
print(countryData['cases'].sum())
return 'abc'
def getTotalCases(self, country, date=datetime.now().strftime('%Y-%m-%d')) -> int:
"""
Get the current total cases for the entered country
:param country: The country you want the case number for
:param date: The date for which the case number is returned. Standard is the current date.
:return: The case number
"""
countryData = self.df[self.df['countriesAndTerritories'].isin([country])]
finalData = pd.DataFrame
countryData.filter(datetime.strptime(country))
print(finalData)
return countryData['cases'].sum()