Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridge Pattern #101

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/covidify/bridge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import abc


class Bridgeabstraction:

def __init__(self, imp):
self._imp = imp

def operation(self):
self._imp.operation_imp()


class Bridgeimplementer(metaclass=abc.ABCMeta):


@abc.abstractmethod
def operation_imp(self):
pass


class ConcretebridgeimplementerA(bridgeimplementer):

def operation_imp(self):
pass


class ConcretebridgeimplementerB(bridgeimplementer):

def operation_imp(self):
pass


def main():
concrete_bridgeimplementer_a = ConcretebridgeimplementerA()
Bridgeabstraction = Bridgeabstraction(concrete_bridgeimplementer_a)
Bridgeabstraction.operation()


if __name__ == "__main__":
main()
150 changes: 79 additions & 71 deletions src/covidify/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,76 +11,83 @@
#get the path of covidify in site-packages
env = covidify.__path__[0]

def check_output_folder(var, country_str, msg):
'''
Check if the output folder is valid, if not
just default to dekstop
'''

if not var:
print('%sMESSAGE: %s' % (' '*5, msg))
if country_str == 'Global':
return os.path.join('/Users', USER, 'Desktop', 'covidify-output')
else:
return os.path.join('/Users', USER, 'Desktop', 'covidify-output-{}'.format(country_str))
else:
return var

def check_forecast_days(var, msg):
'''
Default days for forecasting
'''
if not var:
return DAYS_IN_FUTURE
else:
return var
#Aggregate Pattern
class CheckOutputFolder:
def check_output_folder(var, country_str, msg):
'''
Check if the output folder is valid, if not
just default to dekstop
'''

if not var:
print('%sMESSAGE: %s' % (' '*5, msg))
if country_str == 'Global':
return os.path.join('/Users', USER, 'Desktop', 'covidify-output')
else:
return os.path.join('/Users', USER, 'Desktop', 'covidify-output-{}'.format(country_str))
else:
return var

def check_top_countries(var, msg):
'''
Check number of countries for the log plot
'''

if not var:
print('%sMESSAGE: %s' % (' '*5, msg))
return LOG_TOP_N_COUNTRIES
else:
return var

def check_source_arg(var, msg):
'''
Check if the datasource is valid, if not then just
default to the john hopkin github repo
'''
class CheckForcastDays:
def check_forecast_days(var, msg):
'''
Default days for forecasting
'''
if not var:
return DAYS_IN_FUTURE
else:
return var

if var is None:
print('%sMESSAGE: %s' % (' '*5, msg))
return 'JHU'
elif 'wiki' in var or 'JHU' in var:
return var
else:
print('%sMESSAGE: %s' % (' '*5, 'invalid source given'))
sys.exit()

def check_country(country, msg):
'''
Do some regex work on passed country string
because multi word args are not supported
'''

if not country:
print('%sMESSAGE: %s' % (' '*5, msg))
return 'Global'
else:
country_str = replace_arg_space(country[0])
return country_str
class CheckTopCountries:
def check_top_countries(var, msg):
'''
Check number of countries for the log plot
'''

if not var:
print('%sMESSAGE: %s' % (' '*5, msg))
return LOG_TOP_N_COUNTRIES
else:
return var

def check_list_flag(flag, msg):
class CheckSourceArg:
def check_source_arg(var, msg):
'''
Check if the datasource is valid, if not then just
default to the john hopkin github repo
'''

if not flag:
print('%sMESSAGE: %s' % (' '*5, msg))
sys.exit(1)
else:
return flag
if var is None:
print('%sMESSAGE: %s' % (' '*5, msg))
return 'JHU'
elif 'wiki' in var or 'JHU' in var:
return var
else:
print('%sMESSAGE: %s' % (' '*5, 'invalid source given'))
sys.exit()

class CheckCountry:
def check_country(country, msg):
'''
Do some regex work on passed country string
because multi word args are not supported
'''

if not country:
print('%sMESSAGE: %s' % (' '*5, msg))
return 'Global'
else:
country_str = replace_arg_space(country[0])
return country_str

class CheckListFlag:
def check_list_flag(flag, msg):

if not flag:
print('%sMESSAGE: %s' % (' '*5, msg))
sys.exit(1)
else:
return flag

############################################################

Expand Down Expand Up @@ -115,11 +122,12 @@ def run(output, source, country, top, forecast):

@click.option('--countries', help='List countries that have had confirmed cases.', is_flag=True)
@cli.command()
def list(countries):
'''
List all the countries that have confirmed cases.
'''
countries = check_list_flag(countries, '\033[1;31m Invalid flag passed. Make sure to use --countries\033[0;0m')
class List:
def list(countries):
'''
List all the countries that have confirmed cases.
'''
countries = check_list_flag(countries, '\033[1;31m Invalid flag passed. Make sure to use --countries\033[0;0m')

if countries:
get_countries()
Loading