Skip to content
116 changes: 116 additions & 0 deletions src/covidify/builder_data_vis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
from abc import ABCMeta, abstractstaticmethod

class iBuilder(metaclass=ABCMeta):
"the Builder Interface"

@staticmethod
@abstractstaticmethod
def build_part_create_trend_line():
"build Part create_trend_line"

@staticmethod
@abstractstaticmethod
def build_part_create_bar():
"build Part create_bar"


@staticmethod
@abstractstaticmethod
def build_part_create_stacked_bar():
"build Part create_stacked_bar"



class VisualBuilder(iBuilder):
"The concrete builder"

def __init__(self):
self.dataVis = DataVisualization()

#Builder Part for create_trend_line
def build_part_create_trend_line(self):
self.dataVis.paramParts.append('tmp_df, date_col, col, col2, col3, fig_title, country')
return self

#Builder Part for create_bar
def build_part_create_bar(self):
self.dataVis.paramParts.append('tmp_df, col, rgb, country')
return self

#Builder Part for stacked_bar
def build_part_create_stacked_bar(self):
self.dataVis.paramParts.append('tmp_df, col1, col2, fig_title, country')
return self

def get_result_params(self):
return self.dataVis


class DataVisualization():
"The Data Visualizer Params"

def __init__(self):
self.paramParts = []





class Director:
"The Director, using chosen params builds complex data visualization"

@staticmethod
def construct_Vis():
"constructs the methods with chosen params"
return VisualBuilder()\
.build_part_create_trend_line()\
.build_part_create_bar()\
.build_part_create_stacked_bar()\
.get_result_params()




#Client Use Example
PARAMS = Director.construct_Vis()
print(PARAMS.paramParts)
#prints and shows the params to build visualization parts

#Index 0 - contains parameters to build create_trend_line
#Index 1 - contains parameters to build crreate_bar
#Index 2 - contains parameters to build create_stacked_bar
#print(PARAMS.paramParts[0])
#print(PARAMS.paramParts[1])
#print(PARAMS.paramParts[2])


#Class/Method in which builder will be used for
"""def create_trend_line(tmp_df, date_col, col, col2, col3, fig_title, country):
fig, ax = plt.subplots(figsize=(20,10))
tmp_df.groupby([date_col])[[col, col2, col3]].sum().plot(ax=ax, marker='o')
ax.set_title(create_title(fig_title, country))
fig = ax.get_figure()
fig.savefig(os.path.join(image_dir, create_save_file(col, country, 'trendline')))

def create_bar(tmp_df, col, rgb, country):
tmp_df = tmp_df.tail(120)
fig, ax = plt.subplots(figsize=(20,10))
tmp = tmp_df.groupby(['date'])[[col]].sum()
ax.set_title(create_title(col, country))
tmp.plot.bar(ax=ax, rot=90, color=rgb)
fig = ax.get_figure()
fig.savefig(os.path.join(image_dir, create_save_file(col, country, 'bar')))

def create_stacked_bar(tmp_df, col1, col2, fig_title, country):
tmp_df = tmp_df.tail(120)
tmp_df = tmp_df.set_index('date')
fig, ax = plt.subplots(figsize=(20,10))
ax.set_title(create_title(fig_title, country))
tmp_df[[col2, col1]].plot.bar(ax=ax,
rot=90,
stacked=True)
fig = ax.get_figure()
fig.savefig(os.path.join(image_dir, create_save_file(col2, country, 'stacked_bar')))"""



12 changes: 7 additions & 5 deletions src/covidify/data_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
from difflib import get_close_matches
from datetime import datetime, date, time

from covidify.sources import github, wiki
#import/use aggregate root instead of git and wiki itself
from covidify.sources import agg_data_sources as sourceData

from covidify.config import REPO, TMP_FOLDER, TMP_GIT, DATA
from covidify.utils.utils import replace_arg_score

Expand All @@ -40,13 +42,13 @@

if country == 'Global':
country = None

#use reference dataFetch to access root to fetch Git data
if source == 'JHU':
df = github.get()

dataFetch = sourceData.getDataGit()
#use reference dataFetch to access root to fetch Wiki data
elif source == 'wiki':
print('Apologies, the wikipedia source is not ready yet - getting github data')
df = github.get()
dataFetch = sourceData.getDataWiki()



Expand Down
19 changes: 16 additions & 3 deletions src/covidify/data_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ def create_report_name(country):
daily_df = pd.read_csv(os.path.join(data_dir, trend_file))
log_df = pd.read_csv(os.path.join(data_dir, log_file))

#Create place to save diagrams
image_dir = os.path.join(out,'reports', 'images')
reports_dir = os.path.join(out,'reports')

if not os.path.exists(image_dir):
print('Creating reports folder...')
Expand All @@ -91,13 +88,27 @@ def create_save_file(col, country, graph_type):
return '{}_{}.png'.format(col, graph_type)

# Plot and save trendline graph

#Using Builder to build and create paams to pass to
#create_trend_line
#create_bar
#create_stacked_bar

PARAMS = Director.construct_Vis()
createTrenLine = PARAMS.paramParts[0]
createBar = PARAMS.paramParts[1]
createStackedBar = PARAMS.paramParts[2]


#Inject createTrendLine into the parameters using a dictionary and parcing
def create_trend_line(tmp_df, date_col, col, col2, col3, fig_title, country):
fig, ax = plt.subplots(figsize=(20,10))
tmp_df.groupby([date_col])[[col, col2, col3]].sum().plot(ax=ax, marker='o')
ax.set_title(create_title(fig_title, country))
fig = ax.get_figure()
fig.savefig(os.path.join(image_dir, create_save_file(col, country, 'trendline')))

#Inject createBar into the parameters using a dictionary and parcing
def create_bar(tmp_df, col, rgb, country):
tmp_df = tmp_df.tail(120)
fig, ax = plt.subplots(figsize=(20,10))
Expand All @@ -107,6 +118,7 @@ def create_bar(tmp_df, col, rgb, country):
fig = ax.get_figure()
fig.savefig(os.path.join(image_dir, create_save_file(col, country, 'bar')))

#Inject createStackedBar into the parameters using a dictionary and parcing
def create_stacked_bar(tmp_df, col1, col2, fig_title, country):
tmp_df = tmp_df.tail(120)
tmp_df = tmp_df.set_index('date')
Expand Down Expand Up @@ -138,6 +150,7 @@ def log_plot(tmp, col, fig_title):
fig = ax.get_figure()
fig.savefig(os.path.join(image_dir, create_save_file(col, country=None, graph_type='log')))


##### Create Graphs #####
print('Creating graphs...')
print('... Time Series Trend Line')
Expand Down
70 changes: 70 additions & 0 deletions src/covidify/iDataResource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from abc import ABCMeta, abstractstaticmethod

#Bridge Pattern Connected to Views
#Abstract Data Resource Class

class iDataResource(metaclass=ABCMeta):

@abstractstaticmethod
def graph():
pass

@abstractstaticmethod
def snippet():
pass
@abstractstaticmethod
def getcreateGraph():
pass



# Concrete Classes of iDataResource


#concrete class of IDataResource that creates a Pie Graph using builder class
class PieGraph(iDataResource):

resource = Director.construct_Vis()

#grabs graph from builder that injects params to data_visualiazation to create graph
def graph(self):
self.resource.getcreateGraph()

#Grabs covid numbers and quickly gets formated string to display quickly
def quickLook(self):
self.resource.getDataCount().toFormatedString()



#concrete class of IDataResource that creates a Bar Graph using builder class
class BarGraph(iDataResource):

resource = Director.construct_Vis()

#grabs graph from builder that injects params to data_visualiazation to create graph
def graph(self):
self.resource.getcreateGraph()

#Grabs covid numbers and quickly gets formated string to display quickly
def quickLook(self):
self.resource.getDataCount().toFormatedString()




#concrete class of IDataResource that creates a Forcast Graph - in some format using builder class
class ForcastGraph(iDataResource):

resource = Director.construct_Vis()

#Grabs Graph from builder that injects params to data_visualiazation to create graph
def graph(self):
self.resource.getcreateGraph()

#Grabs covid numbers and quickly gets formated string to display quickly
def quickLook(self):
self.resource.getDataCount().toFormatedString()




11 changes: 7 additions & 4 deletions src/covidify/list_countries.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
import click
import covidify
import numpy as np
from covidify.sources import github
#import/use aggregate root instead of git itself
from covidify.sources import agg_data_sources as sourceData

from covidify.config import SCRIPT

def get_countries():
print('Getting available countries...')
df = github.get()
df = df[df.confirmed > 0]
#use reference dataFetch to access root to fetch data
dataFetch = sourceData.getData()
dataFetch = dataFetch[dataFetch.confirmed > 0]

countries = sorted(list(set(df.country.values)))
countries = sorted(list(set(dataFetch.country.values)))

for a,b,c in zip(countries[::3],countries[1::3],countries[2::3]):
print('{:<30}{:<30}{:<}'.format(a,b,c))
Expand Down
18 changes: 18 additions & 0 deletions src/covidify/sources/agg_data_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#use this as our aggregate root for wiki and github which have their own files in /sources
class agg_data:
import wiki
import github
import pandas as pd
#Pandas is an open source Python package that is most widely used for data science/data analysis and machine learning tasks
#so including it here will also help with aggregate pattern as its used in many of the python code in this project.


def github_data(self):
return github.getData()


def wiki_data(self):
return wiki.getData()
#wiki.py isempty no code.

43 changes: 43 additions & 0 deletions src/covidify/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from abc import ABCMeta, abstractstaticmethod

#Bridge Pattern connected to iDataResource
#Abstract View class

class View(metaclass=ABCMeta):

dataResource = iDataResource()

#Constructor needs an iDataResource r
def __init__(self, r):
self.dataResource = r


@abstractstaticmethod
def display():
"Displays data resourse visualization in different types ofviews"



#Concrete Classes of Abstraction class View

#Creates concrete View that shows any and all data from resource type -- formated windows and sections show details and forcasts
class CompleteView(View):

def display(self):
self.dataResource.graph()
#displays graph that is created by the concrete resource class

#Creates a concrete View that shows extended details and extra data from concrete resource type used -- formated windows are larger
class ExtendedView(View):

def display(self):
self.dataResource.createGraph()
#displays graph that is created by the concrete resource class

#Creates a concrete View that shows simple and quick data from concrete resource used -- formated windows are small with no graphics
class QuickView(View):

def display(self):
self.dataResource.createGraph()
#displays graph that is created by the concrete resource class