Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Structural Design Pattern: Bridge Pattern
  • Loading branch information
DukeM23 committed Aug 16, 2021
commit 988bda17dcebc66e8f15d8fecf762a0add84946f
16 changes: 9 additions & 7 deletions app/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""app.data"""
from ..services.location.csbs import CSBSLocationService
from ..services.location.jhu import JhuLocationService
from ..services.location.nyt import NYTLocationService
from ..services.location.csbs import CSBSLocationServicee
from ..services.location.jhu import JhuLocationServicee
from ..services.location.nyt import NYTLocationServicee
from app.services.location.__init__ import LocationServicer

class DataSourceSingletonMeta(type):
"""
access point to the DataSourceSingleton
access point to the DataSource
"""

_instances = {}

def __call__(cls, *args, **kwargs):
Expand All @@ -22,9 +24,9 @@ def __call__(cls, *args, **kwargs):

class DataSourceSingleton(metaclass=DataSourceSingletonMeta):
DATA_SOURCES = {
"jhu": JhuLocationService(),
"csbs": CSBSLocationService(),
"nyt": NYTLocationService(),
"jhu": LocationServicer(JhuLocationServicee()),
"csbs": LocationServicer(CSBSLocationServicee()),
"nyt": LocationServicer(NYTLocationServicee()),
}
def get_data_source(self, dataSource):
return self.DATA_SOURCES.get(dataSource.lower())
Expand Down
45 changes: 26 additions & 19 deletions app/services/location/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,34 @@
from abc import ABC, abstractmethod


class LocationService(ABC):
class LocationServicer: # The 'Remote' of the Pattern
"""
Service for retrieving locations.
Abstraction class handling the 'Front End' portion of the project
"""

@abstractmethod
async def get_all(self):
"""
Gets and returns all of the locations.
def __init__(self, implementation):
self.implementation = implementation

@abstractmethod
def all_locations(self):
return self.implementation.get_all()

@abstractmethod
def locations(self):
return self.implementation.get()

class LocationServicee: # The 'Device' with the implmentation
"""
Implementation Interface
"""

def get_all(self):
# No implementation - interface method
pass

def get(self):
# No implementation - interface method
pass


:returns: The locations.
:rtype: List[Location]
"""
raise NotImplementedError

@abstractmethod
async def get(self, id): # pylint: disable=redefined-builtin,invalid-name
"""
Gets and returns location with the provided id.

:returns: The location.
:rtype: Location
"""
raise NotImplementedError
5 changes: 2 additions & 3 deletions app/services/location/csbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from ...coordinates import Coordinates
from ...location.csbs import CSBSLocation
from ...utils import httputils
from . import LocationService
from . import LocationServicee

LOGGER = logging.getLogger("services.location.csbs")


class CSBSLocationService(LocationService):
class CSBSLocationServicee(LocationServicee):
"""
Service for retrieving locations from csbs
"""
Expand All @@ -30,7 +30,6 @@ async def get(self, loc_id): # pylint: disable=arguments-differ
locations = await self.get_all()
return locations[loc_id]


# Base URL for fetching data
BASE_URL = "https://facts.csbs.org/covid-19/covid19_county.csv"

Expand Down
4 changes: 2 additions & 2 deletions app/services/location/jhu.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
from ...utils import countries
from ...utils import date as date_util
from ...utils import httputils
from . import LocationService
from . import LocationServicee

LOGGER = logging.getLogger("services.location.jhu")
PID = os.getpid()


class JhuLocationService(LocationService):
class JhuLocationServicee(LocationServicee):
"""
Service for retrieving locations from Johns Hopkins CSSE (https://github.com/CSSEGISandData/COVID-19).
"""
Expand Down
4 changes: 2 additions & 2 deletions app/services/location/nyt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
from ...location.nyt import NYTLocation
from ...models import Timeline
from ...utils import httputils
from . import LocationService
from . import LocationServicee

LOGGER = logging.getLogger("services.location.nyt")


class NYTLocationService(LocationService):
class NYTLocationServicee(LocationServicee):
"""
Service for retrieving locations from New York Times (https://github.com/nytimes/covid-19-data).
"""
Expand Down