From 4e967ea57de504067a3fb11f93e924ab5a23632a Mon Sep 17 00:00:00 2001 From: anurosan <56799479+anurosan@users.noreply.github.com> Date: Sun, 15 Aug 2021 23:00:17 -0400 Subject: [PATCH 1/4] Create dataSource.py --- app/data/dataSource.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 app/data/dataSource.py diff --git a/app/data/dataSource.py b/app/data/dataSource.py new file mode 100644 index 00000000..0195e373 --- /dev/null +++ b/app/data/dataSource.py @@ -0,0 +1,15 @@ +from ..services.location.csbs import CSBSLocationService +from ..services.location.jhu import JhuLocationService +from ..services.location.nyt import NYTLocationService + +class DataSource(): + def getService(source): + if source.lower() == "csbs": + temp = CSBSLocationService() + return temp + elif source.lower() == "nyt": + temp = NYTLocationService() + return temp + else: + temp = JhuLocationService() + return temp From fab782bc46d9b92224f02af3c5d2bbf12bf9126f Mon Sep 17 00:00:00 2001 From: anurosan <56799479+anurosan@users.noreply.github.com> Date: Sun, 15 Aug 2021 23:13:54 -0400 Subject: [PATCH 2/4] Updated method data_source to go through DataSource class --- app/data/__init__.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/app/data/__init__.py b/app/data/__init__.py index 60a75dac..93dd1fea 100644 --- a/app/data/__init__.py +++ b/app/data/__init__.py @@ -2,14 +2,9 @@ from ..services.location.csbs import CSBSLocationService from ..services.location.jhu import JhuLocationService from ..services.location.nyt import NYTLocationService +from app.data.dataSource import DataSource -# Mapping of services to data-sources. -DATA_SOURCES = { - "jhu": JhuLocationService(), - "csbs": CSBSLocationService(), - "nyt": NYTLocationService(), -} - +DATA_SOURCES = ["jhu","csbs","nyt"] def data_source(source): """ @@ -17,5 +12,5 @@ def data_source(source): :returns: The service. :rtype: LocationService - """ - return DATA_SOURCES.get(source.lower()) + """ + return DataSource.getService(source) From c4edcfc8ffbfa15cc0d59b2a7510aa7636beb517 Mon Sep 17 00:00:00 2001 From: anurosan <56799479+anurosan@users.noreply.github.com> Date: Sun, 15 Aug 2021 23:21:29 -0400 Subject: [PATCH 3/4] Updated v2 so that DATA_SOURCES is no longer treated as a dictionary --- app/routers/v2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/routers/v2.py b/app/routers/v2.py index 31eb408c..b912fb88 100644 --- a/app/routers/v2.py +++ b/app/routers/v2.py @@ -107,4 +107,4 @@ async def sources(): """ Retrieves a list of data-sources that are availble to use. """ - return {"sources": list(DATA_SOURCES.keys())} + return {"sources": DATA_SOURCES} From 6109ac1071acf3c9c5db5989ebd6aa38f9fa6101 Mon Sep 17 00:00:00 2001 From: anurosan <56799479+anurosan@users.noreply.github.com> Date: Sun, 15 Aug 2021 23:25:04 -0400 Subject: [PATCH 4/4] Precondition has been implemented --- app/data/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/data/__init__.py b/app/data/__init__.py index 93dd1fea..149b9dbe 100644 --- a/app/data/__init__.py +++ b/app/data/__init__.py @@ -12,5 +12,15 @@ def data_source(source): :returns: The service. :rtype: LocationService - """ - return DataSource.getService(source) + """ + + exists = False + + for i in DATA_SOURCES: + if DATA_SOURCES.index[i] == source: + exists = True + + if exists == True: + return DataSource.getService(source) + else: + return DataSource.getService("jhu")