From d5314b2bfeccd8d166e48a89f933b831414e81b1 Mon Sep 17 00:00:00 2001 From: DukeM23 Date: Mon, 12 Jul 2021 15:33:14 -0600 Subject: [PATCH 1/6] Adding something about the datasebase on the read.mb page --- CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4ecdd0b6..91b53c02 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,6 +15,10 @@ Please write new test cases for new code you create. * We will love you forever if you include unit tests. We can always use more test coverage * If you have updated [Pipefile](./Pipfile), you have to update `Pipfile.lock`, `requirements.txt` and `requirements-dev.txt`. See section [Update requirements files](./README.md#update-requirements-files). +## Some about the database + +* There is gonna be something that must be added into the database because blah blah this is a test. This is something in consideration about the database wanting to be added to add stability blah + ## Your First Code Contribution Unsure where to begin contributing to coronavirus-tracker-api ? You can start by looking through these issues labels: From 5f4fe871a8842cf62985c7016022b200ab4a3c7f Mon Sep 17 00:00:00 2001 From: DukeM23 Date: Sat, 24 Jul 2021 21:12:17 -0600 Subject: [PATCH 2/6] Lab 8: Aggregate Pattern 2 --- app/data/__init__.py | 20 ++++++++++++-------- app/main.py | 14 ++++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/data/__init__.py b/app/data/__init__.py index 60a75dac..c23c76c8 100644 --- a/app/data/__init__.py +++ b/app/data/__init__.py @@ -10,12 +10,16 @@ "nyt": NYTLocationService(), } +class DataSourceRequest: + def __init__(self, request): # request is of Obj reference of Reqeust from FastAPI + self.request = request + + def get_data_source(self): + """ + Retrieves the provided data-source service. -def data_source(source): - """ - Retrieves the provided data-source service. - - :returns: The service. - :rtype: LocationService - """ - return DATA_SOURCES.get(source.lower()) + :returns: The service. + :rtype: LocationService + """ + request_source = self.request.query_params.get("source", default="jhu") # gets source parameters + return DATA_SOURCES.get(request_source.lower()) diff --git a/app/main.py b/app/main.py index b9aff949..c9ff29da 100644 --- a/app/main.py +++ b/app/main.py @@ -14,7 +14,7 @@ from sentry_sdk.integrations.asgi import SentryAsgiMiddleware from .config import get_settings -from .data import data_source +from .data import DataSourceRequest from .routers import V1, V2 from .utils.httputils import setup_client_session, teardown_client_session @@ -74,17 +74,19 @@ async def add_datasource(request: Request, call_next): Attach the data source to the request.state. """ # Retrieve the datas ource from query param. - source = data_source(request.query_params.get("source", default="jhu")) + requested_data_source = DataSourceRequest(request) + data_source = requested_data_source.get_data_source() + - # Abort with 404 if source cannot be found. - if not source: + # Abort with 404 if data_source cannot be found. + if not data_source: return Response("The provided data-source was not found.", status_code=404) # Attach source to request. - request.state.source = source + request.state.data_source = data_source # Move on... - LOGGER.debug(f"source provided: {source.__class__.__name__}") + LOGGER.debug(f"source provided: {data_source.__class__.__name__}") response = await call_next(request) return response From a548ed217f1820b1fe3ab0dd091d19d4e056f78e Mon Sep 17 00:00:00 2001 From: DukeM23 Date: Sat, 24 Jul 2021 21:26:10 -0600 Subject: [PATCH 3/6] Lab 8 Aggregate Patterns 1: Countries aggregate --- app/location/__init__.py | 14 +- app/services/location/jhu.py | 9 +- app/utils/countries.py | 757 ++++++++++++++++++----------------- 3 files changed, 400 insertions(+), 380 deletions(-) diff --git a/app/location/__init__.py b/app/location/__init__.py index 1da5e9e5..9092c0c5 100644 --- a/app/location/__init__.py +++ b/app/location/__init__.py @@ -1,6 +1,7 @@ """app.location""" from ..coordinates import Coordinates -from ..utils import countries +from ..utils.countries import Country +# from ..utils import country from ..utils.populations import country_population @@ -10,12 +11,13 @@ class Location: # pylint: disable=too-many-instance-attributes A location in the world affected by the coronavirus. """ - def __init__( + def __init__( self, id, country, province, coordinates, last_updated, confirmed, deaths, recovered, ): # pylint: disable=too-many-arguments # General info. self.id = id - self.country = country.strip() + self.country_obj = country # country_obj should contain a reference to a Country Class that is being passed + self.country = self.country_obj.get_country().strip() self.province = province.strip() self.coordinates = coordinates @@ -27,6 +29,7 @@ def __init__( self.deaths = deaths self.recovered = recovered + @property def country_code(self): """ @@ -35,7 +38,8 @@ def country_code(self): :returns: The country code. :rtype: str """ - return (countries.country_code(self.country) or countries.DEFAULT_COUNTRY_CODE).upper() + country_code = (self.country.get_country_code() or self.country.get_default_country_code()).upper + return country_code @property def country_population(self): @@ -91,7 +95,7 @@ def __init__(self, id, country, province, coordinates, last_updated, timelines): # Statistics (retrieve latest from timelines). confirmed=timelines.get("confirmed").latest or 0, deaths=timelines.get("deaths").latest or 0, - recovered=timelines.get("recovered").latest or 0, + recovered=timelines.get("recovered").latest or 0 ) # Set timelines. diff --git a/app/services/location/jhu.py b/app/services/location/jhu.py index ebed3960..23355bd8 100644 --- a/app/services/location/jhu.py +++ b/app/services/location/jhu.py @@ -12,11 +12,12 @@ from ...coordinates import Coordinates from ...location import TimelinedLocation from ...models import Timeline -from ...utils import countries +from ...utils.countries import Country from ...utils import date as date_util from ...utils import httputils from . import LocationService + LOGGER = logging.getLogger("services.location.jhu") PID = os.getpid() @@ -94,11 +95,12 @@ async def get_category(category): latest = list(history.values())[-1] # Normalize the item and append to locations. + locations.append( { # General info. "country": country, - "country_code": countries.country_code(country), + "country_code": Country(country), "province": item["Province/State"], # Coordinates. "coordinates": {"lat": item["Lat"], "long": item["Long"],}, @@ -169,13 +171,14 @@ async def get_locations(): # Grab coordinates. coordinates = location["coordinates"] + # Creation of Country Class # Create location (supporting timelines) and append. locations.append( TimelinedLocation( # General info. index, - location["country"], + Country(location["country"]), location["province"], # Coordinates. Coordinates(latitude=coordinates["lat"], longitude=coordinates["long"]), diff --git a/app/utils/countries.py b/app/utils/countries.py index 9fb4f98a..19e9d222 100644 --- a/app/utils/countries.py +++ b/app/utils/countries.py @@ -1,380 +1,393 @@ """app.utils.countries.py""" import logging - -LOGGER = logging.getLogger(__name__) - -# Default country code. -DEFAULT_COUNTRY_CODE = "XX" - -# Mapping of country names to alpha-2 codes according to -# https://en.wikipedia.org/wiki/ISO_3166-1. -# As a reference see also https://github.com/TakahikoKawasaki/nv-i18n (in Java) -# fmt: off COUNTRY_NAME__COUNTRY_CODE = { - "Afghanistan" : "AF", - "Åland Islands" : "AX", - "Albania" : "AL", - "Algeria" : "DZ", - "American Samoa" : "AS", - "Andorra" : "AD", - "Angola" : "AO", - "Anguilla" : "AI", - "Antarctica" : "AQ", - "Antigua and Barbuda" : "AG", - "Argentina" : "AR", - "Armenia" : "AM", - "Aruba" : "AW", - "Australia" : "AU", - "Austria" : "AT", - "Azerbaijan" : "AZ", - " Azerbaijan" : "AZ", - "Bahamas" : "BS", - "The Bahamas" : "BS", - "Bahamas, The" : "BS", - "Bahrain" : "BH", - "Bangladesh" : "BD", - "Barbados" : "BB", - "Belarus" : "BY", - "Belgium" : "BE", - "Belize" : "BZ", - "Benin" : "BJ", - "Bermuda" : "BM", - "Bhutan" : "BT", - "Bolivia, Plurinational State of" : "BO", - "Bolivia" : "BO", - "Bonaire, Sint Eustatius and Saba" : "BQ", - "Caribbean Netherlands" : "BQ", - "Bosnia and Herzegovina" : "BA", - # "Bosnia–Herzegovina" : "BA", - "Bosnia" : "BA", - "Botswana" : "BW", - "Bouvet Island" : "BV", - "Brazil" : "BR", - "British Indian Ocean Territory" : "IO", - "Brunei Darussalam" : "BN", - "Brunei" : "BN", - "Bulgaria" : "BG", - "Burkina Faso" : "BF", - "Burundi" : "BI", - "Cambodia" : "KH", - "Cameroon" : "CM", - "Canada" : "CA", - "Cape Verde" : "CV", - "Cabo Verde" : "CV", - "Cayman Islands" : "KY", - "Central African Republic" : "CF", - "Chad" : "TD", - "Chile" : "CL", - "China" : "CN", - "Mainland China" : "CN", - "Christmas Island" : "CX", - "Cocos (Keeling) Islands" : "CC", - "Colombia" : "CO", - "Comoros" : "KM", - "Congo" : "CG", - "Congo (Brazzaville)" : "CG", - "Republic of the Congo" : "CG", - "Congo, the Democratic Republic of the" : "CD", - "Congo (Kinshasa)" : "CD", - "DR Congo" : "CD", - "Cook Islands" : "CK", - "Costa Rica" : "CR", - "Côte d'Ivoire" : "CI", - "Cote d'Ivoire" : "CI", - "Ivory Coast" : "CI", - "Croatia" : "HR", - "Cuba" : "CU", - "Curaçao" : "CW", - "Curacao" : "CW", - "Cyprus" : "CY", - "Czech Republic" : "CZ", - "Czechia" : "CZ", - "Denmark" : "DK", - "Djibouti" : "DJ", - "Dominica" : "DM", - "Dominican Republic" : "DO", - "Dominican Rep" : "DO", - "Ecuador" : "EC", - "Egypt" : "EG", - "El Salvador" : "SV", - "Equatorial Guinea" : "GQ", - "Eritrea" : "ER", - "Estonia" : "EE", - "Ethiopia" : "ET", - "Falkland Islands (Malvinas)" : "FK", - "Falkland Islands" : "FK", - "Faroe Islands" : "FO", - "Faeroe Islands" : "FO", - "Fiji" : "FJ", - "Finland" : "FI", - "France" : "FR", - "French Guiana" : "GF", - "French Polynesia" : "PF", - "French Southern Territories" : "TF", - "Gabon" : "GA", - "Gambia" : "GM", - "The Gambia" : "GM", - "Gambia, The" : "GM", - "Georgia" : "GE", - "Germany" : "DE", - "Deutschland" : "DE", - "Ghana" : "GH", - "Gibraltar" : "GI", - "Greece" : "GR", - "Greenland" : "GL", - "Grenada" : "GD", - "Guadeloupe" : "GP", - "Guam" : "GU", - "Guatemala" : "GT", - "Guernsey" : "GG", - "Guinea" : "GN", - "Guinea-Bissau" : "GW", - "Guyana" : "GY", - "Haiti" : "HT", - "Heard Island and McDonald Islands" : "HM", - "Holy See (Vatican City State)" : "VA", - "Holy See" : "VA", - "Vatican City" : "VA", - "Honduras" : "HN", - "Hong Kong" : "HK", - "Hong Kong SAR" : "HK", - "Hungary" : "HU", - "Iceland" : "IS", - "India" : "IN", - "Indonesia" : "ID", - "Iran, Islamic Republic of" : "IR", - "Iran" : "IR", - "Iran (Islamic Republic of)" : "IR", - "Iraq" : "IQ", - "Ireland" : "IE", - "Republic of Ireland" : "IE", - "Isle of Man" : "IM", - "Israel" : "IL", - "Italy" : "IT", - "Jamaica" : "JM", - "Japan" : "JP", - "Jersey" : "JE", - # Guernsey and Jersey form Channel Islands. Conjoin Guernsey on Jersey. - # Jersey has higher population. - # https://en.wikipedia.org/wiki/Channel_Islands - "Guernsey and Jersey" : "JE", - "Channel Islands" : "JE", - # "Channel Islands" : "GB", - "Jordan" : "JO", - "Kazakhstan" : "KZ", - "Kenya" : "KE", - "Kiribati" : "KI", - "Korea, Democratic People's Republic of" : "KP", - "North Korea" : "KP", - "Korea, Republic of" : "KR", - "Korea, South" : "KR", - "South Korea" : "KR", - "Republic of Korea" : "KR", - "Kosovo, Republic of" : "XK", - "Kosovo" : "XK", - "Kuwait" : "KW", - "Kyrgyzstan" : "KG", - "Lao People's Democratic Republic" : "LA", - "Laos" : "LA", - "Latvia" : "LV", - "Lebanon" : "LB", - "Lesotho" : "LS", - "Liberia" : "LR", - "Libya" : "LY", - "Liechtenstein" : "LI", - "Lithuania" : "LT", - "Luxembourg" : "LU", - "Macao" : "MO", - # TODO Macau is probably a typo. Report it to CSSEGISandData/COVID-19 - "Macau" : "MO", - "Macao SAR" : "MO", - "North Macedonia" : "MK", - "Macedonia" : "MK", - "Madagascar" : "MG", - "Malawi" : "MW", - "Malaysia" : "MY", - "Maldives" : "MV", - "Mali" : "ML", - "Malta" : "MT", - "Marshall Islands" : "MH", - "Martinique" : "MQ", - "Mauritania" : "MR", - "Mauritius" : "MU", - "Mayotte" : "YT", - "Mexico" : "MX", - "Micronesia, Federated States of" : "FM", - "F.S. Micronesia" : "FM", - "Micronesia" : "FM", - "Moldova, Republic of" : "MD", - "Republic of Moldova" : "MD", - "Moldova" : "MD", - "Monaco" : "MC", - "Mongolia" : "MN", - "Montenegro" : "ME", - "Montserrat" : "MS", - "Morocco" : "MA", - "Mozambique" : "MZ", - "Myanmar" : "MM", - "Burma" : "MM", - "Namibia" : "NA", - "Nauru" : "NR", - "Nepal" : "NP", - "Netherlands" : "NL", - "New Caledonia" : "NC", - "New Zealand" : "NZ", - "Nicaragua" : "NI", - "Niger" : "NE", - "Nigeria" : "NG", - "Niue" : "NU", - "Norfolk Island" : "NF", - "Northern Mariana Islands" : "MP", - "Norway" : "NO", - "Oman" : "OM", - "Pakistan" : "PK", - "Palau" : "PW", - "Palestine, State of" : "PS", - "Palestine" : "PS", - "occupied Palestinian territory" : "PS", - "State of Palestine" : "PS", - "The West Bank and Gaza" : "PS", - "West Bank and Gaza" : "PS", - "Panama" : "PA", - "Papua New Guinea" : "PG", - "Paraguay" : "PY", - "Peru" : "PE", - "Philippines" : "PH", - "Pitcairn" : "PN", - "Poland" : "PL", - "Portugal" : "PT", - "Puerto Rico" : "PR", - "Qatar" : "QA", - "Réunion" : "RE", - "Reunion" : "RE", - "Romania" : "RO", - "Russian Federation" : "RU", - "Russia" : "RU", - "Rwanda" : "RW", - "Saint Barthélemy" : "BL", - "Saint Barthelemy" : "BL", - "Saint Helena, Ascension and Tristan da Cunha" : "SH", - "Saint Helena" : "SH", - "Saint Kitts and Nevis" : "KN", - "Saint Kitts & Nevis" : "KN", - "Saint Lucia" : "LC", - "Saint Martin (French part)" : "MF", - "Saint Martin" : "MF", - "St. Martin" : "MF", - "Saint Pierre and Miquelon" : "PM", - "Saint Pierre & Miquelon" : "PM", - "Saint Vincent and the Grenadines" : "VC", - "St. Vincent & Grenadines" : "VC", - "Samoa" : "WS", - "San Marino" : "SM", - "Sao Tome and Principe" : "ST", - "São Tomé and Príncipe" : "ST", - "Sao Tome & Principe" : "ST", - "Saudi Arabia" : "SA", - "Senegal" : "SN", - "Serbia" : "RS", - "Seychelles" : "SC", - "Sierra Leone" : "SL", - "Singapore" : "SG", - "Sint Maarten (Dutch part)" : "SX", - "Sint Maarten" : "SX", - "Slovakia" : "SK", - "Slovenia" : "SI", - "Solomon Islands" : "SB", - "Somalia" : "SO", - "South Africa" : "ZA", - "South Georgia and the South Sandwich Islands" : "GS", - "South Sudan" : "SS", - "Spain" : "ES", - "Sri Lanka" : "LK", - "Sudan" : "SD", - "Suriname" : "SR", - "Svalbard and Jan Mayen" : "SJ", - "Eswatini" : "SZ", # previous name "Swaziland" - "Swaziland" : "SZ", - "Sweden" : "SE", - "Switzerland" : "CH", - "Syrian Arab Republic" : "SY", - "Syria" : "SY", - "Taiwan, Province of China" : "TW", - "Taiwan*" : "TW", - "Taipei and environs" : "TW", - "Taiwan" : "TW", - "Tajikistan" : "TJ", - "Tanzania, United Republic of" : "TZ", - "Tanzania" : "TZ", - "Thailand" : "TH", - "Timor-Leste" : "TL", - "East Timor" : "TL", - "Togo" : "TG", - "Tokelau" : "TK", - "Tonga" : "TO", - "Trinidad and Tobago" : "TT", - "Tunisia" : "TN", - "Turkey" : "TR", - "Turkmenistan" : "TM", - "Turks and Caicos Islands" : "TC", - "Turks and Caicos" : "TC", - "Tuvalu" : "TV", - "Uganda" : "UG", - "Ukraine" : "UA", - "United Arab Emirates" : "AE", - "Emirates" : "AE", - "United Kingdom" : "GB", - "UK" : "GB", - # Conjoin North Ireland on United Kingdom - "North Ireland" : "GB", - "United States" : "US", - "US" : "US", - "United States Minor Outlying Islands" : "UM", - "Uruguay" : "UY", - "Uzbekistan" : "UZ", - "Vanuatu" : "VU", - "Venezuela, Bolivarian Republic of" : "VE", - "Venezuela" : "VE", - "Viet Nam" : "VN", - "Vietnam" : "VN", - "Virgin Islands, British" : "VG", - "British Virgin Islands" : "VG", - "Virgin Islands, U.S." : "VI", - "U.S. Virgin Islands" : "VI", - "Wallis and Futuna" : "WF", - "Wallis & Futuna" : "WF", - "Western Sahara" : "EH", - "Yemen" : "YE", - "Zambia" : "ZM", - "Zimbabwe" : "ZW", - - # see also - # https://en.wikipedia.org/wiki/List_of_sovereign_states_and_dependent_territories_by_continent_(data_file)#Data_file - # https://en.wikipedia.org/wiki/List_of_sovereign_states_and_dependent_territories_by_continent - "United Nations Neutral Zone" : "XD", - "Iraq-Saudi Arabia Neutral Zone" : "XE", - "Spratly Islands" : "XS", + "Afghanistan" : "AF", + "Åland Islands" : "AX", + "Albania" : "AL", + "Algeria" : "DZ", + "American Samoa" : "AS", + "Andorra" : "AD", + "Angola" : "AO", + "Anguilla" : "AI", + "Antarctica" : "AQ", + "Antigua and Barbuda" : "AG", + "Argentina" : "AR", + "Armenia" : "AM", + "Aruba" : "AW", + "Australia" : "AU", + "Austria" : "AT", + "Azerbaijan" : "AZ", + " Azerbaijan" : "AZ", + "Bahamas" : "BS", + "The Bahamas" : "BS", + "Bahamas, The" : "BS", + "Bahrain" : "BH", + "Bangladesh" : "BD", + "Barbados" : "BB", + "Belarus" : "BY", + "Belgium" : "BE", + "Belize" : "BZ", + "Benin" : "BJ", + "Bermuda" : "BM", + "Bhutan" : "BT", + "Bolivia, Plurinational State of" : "BO", + "Bolivia" : "BO", + "Bonaire, Sint Eustatius and Saba" : "BQ", + "Caribbean Netherlands" : "BQ", + "Bosnia and Herzegovina" : "BA", + # "Bosnia–Herzegovina" : "BA", + "Bosnia" : "BA", + "Botswana" : "BW", + "Bouvet Island" : "BV", + "Brazil" : "BR", + "British Indian Ocean Territory" : "IO", + "Brunei Darussalam" : "BN", + "Brunei" : "BN", + "Bulgaria" : "BG", + "Burkina Faso" : "BF", + "Burundi" : "BI", + "Cambodia" : "KH", + "Cameroon" : "CM", + "Canada" : "CA", + "Cape Verde" : "CV", + "Cabo Verde" : "CV", + "Cayman Islands" : "KY", + "Central African Republic" : "CF", + "Chad" : "TD", + "Chile" : "CL", + "China" : "CN", + "Mainland China" : "CN", + "Christmas Island" : "CX", + "Cocos (Keeling) Islands" : "CC", + "Colombia" : "CO", + "Comoros" : "KM", + "Congo" : "CG", + "Congo (Brazzaville)" : "CG", + "Republic of the Congo" : "CG", + "Congo, the Democratic Republic of the" : "CD", + "Congo (Kinshasa)" : "CD", + "DR Congo" : "CD", + "Cook Islands" : "CK", + "Costa Rica" : "CR", + "Côte d'Ivoire" : "CI", + "Cote d'Ivoire" : "CI", + "Ivory Coast" : "CI", + "Croatia" : "HR", + "Cuba" : "CU", + "Curaçao" : "CW", + "Curacao" : "CW", + "Cyprus" : "CY", + "Czech Republic" : "CZ", + "Czechia" : "CZ", + "Denmark" : "DK", + "Djibouti" : "DJ", + "Dominica" : "DM", + "Dominican Republic" : "DO", + "Dominican Rep" : "DO", + "Ecuador" : "EC", + "Egypt" : "EG", + "El Salvador" : "SV", + "Equatorial Guinea" : "GQ", + "Eritrea" : "ER", + "Estonia" : "EE", + "Ethiopia" : "ET", + "Falkland Islands (Malvinas)" : "FK", + "Falkland Islands" : "FK", + "Faroe Islands" : "FO", + "Faeroe Islands" : "FO", + "Fiji" : "FJ", + "Finland" : "FI", + "France" : "FR", + "French Guiana" : "GF", + "French Polynesia" : "PF", + "French Southern Territories" : "TF", + "Gabon" : "GA", + "Gambia" : "GM", + "The Gambia" : "GM", + "Gambia, The" : "GM", + "Georgia" : "GE", + "Germany" : "DE", + "Deutschland" : "DE", + "Ghana" : "GH", + "Gibraltar" : "GI", + "Greece" : "GR", + "Greenland" : "GL", + "Grenada" : "GD", + "Guadeloupe" : "GP", + "Guam" : "GU", + "Guatemala" : "GT", + "Guernsey" : "GG", + "Guinea" : "GN", + "Guinea-Bissau" : "GW", + "Guyana" : "GY", + "Haiti" : "HT", + "Heard Island and McDonald Islands" : "HM", + "Holy See (Vatican City State)" : "VA", + "Holy See" : "VA", + "Vatican City" : "VA", + "Honduras" : "HN", + "Hong Kong" : "HK", + "Hong Kong SAR" : "HK", + "Hungary" : "HU", + "Iceland" : "IS", + "India" : "IN", + "Indonesia" : "ID", + "Iran, Islamic Republic of" : "IR", + "Iran" : "IR", + "Iran (Islamic Republic of)" : "IR", + "Iraq" : "IQ", + "Ireland" : "IE", + "Republic of Ireland" : "IE", + "Isle of Man" : "IM", + "Israel" : "IL", + "Italy" : "IT", + "Jamaica" : "JM", + "Japan" : "JP", + "Jersey" : "JE", + # Guernsey and Jersey form Channel Islands. Conjoin Guernsey on Jersey. + # Jersey has higher population. + # https://en.wikipedia.org/wiki/Channel_Islands + "Guernsey and Jersey" : "JE", + "Channel Islands" : "JE", + # "Channel Islands" : "GB", + "Jordan" : "JO", + "Kazakhstan" : "KZ", + "Kenya" : "KE", + "Kiribati" : "KI", + "Korea, Democratic People's Republic of" : "KP", + "North Korea" : "KP", + "Korea, Republic of" : "KR", + "Korea, South" : "KR", + "South Korea" : "KR", + "Republic of Korea" : "KR", + "Kosovo, Republic of" : "XK", + "Kosovo" : "XK", + "Kuwait" : "KW", + "Kyrgyzstan" : "KG", + "Lao People's Democratic Republic" : "LA", + "Laos" : "LA", + "Latvia" : "LV", + "Lebanon" : "LB", + "Lesotho" : "LS", + "Liberia" : "LR", + "Libya" : "LY", + "Liechtenstein" : "LI", + "Lithuania" : "LT", + "Luxembourg" : "LU", + "Macao" : "MO", + # TODO Macau is probably a typo. Report it to CSSEGISandData/COVID-19 + "Macau" : "MO", + "Macao SAR" : "MO", + "North Macedonia" : "MK", + "Macedonia" : "MK", + "Madagascar" : "MG", + "Malawi" : "MW", + "Malaysia" : "MY", + "Maldives" : "MV", + "Mali" : "ML", + "Malta" : "MT", + "Marshall Islands" : "MH", + "Martinique" : "MQ", + "Mauritania" : "MR", + "Mauritius" : "MU", + "Mayotte" : "YT", + "Mexico" : "MX", + "Micronesia, Federated States of" : "FM", + "F.S. Micronesia" : "FM", + "Micronesia" : "FM", + "Moldova, Republic of" : "MD", + "Republic of Moldova" : "MD", + "Moldova" : "MD", + "Monaco" : "MC", + "Mongolia" : "MN", + "Montenegro" : "ME", + "Montserrat" : "MS", + "Morocco" : "MA", + "Mozambique" : "MZ", + "Myanmar" : "MM", + "Burma" : "MM", + "Namibia" : "NA", + "Nauru" : "NR", + "Nepal" : "NP", + "Netherlands" : "NL", + "New Caledonia" : "NC", + "New Zealand" : "NZ", + "Nicaragua" : "NI", + "Niger" : "NE", + "Nigeria" : "NG", + "Niue" : "NU", + "Norfolk Island" : "NF", + "Northern Mariana Islands" : "MP", + "Norway" : "NO", + "Oman" : "OM", + "Pakistan" : "PK", + "Palau" : "PW", + "Palestine, State of" : "PS", + "Palestine" : "PS", + "occupied Palestinian territory" : "PS", + "State of Palestine" : "PS", + "The West Bank and Gaza" : "PS", + "West Bank and Gaza" : "PS", + "Panama" : "PA", + "Papua New Guinea" : "PG", + "Paraguay" : "PY", + "Peru" : "PE", + "Philippines" : "PH", + "Pitcairn" : "PN", + "Poland" : "PL", + "Portugal" : "PT", + "Puerto Rico" : "PR", + "Qatar" : "QA", + "Réunion" : "RE", + "Reunion" : "RE", + "Romania" : "RO", + "Russian Federation" : "RU", + "Russia" : "RU", + "Rwanda" : "RW", + "Saint Barthélemy" : "BL", + "Saint Barthelemy" : "BL", + "Saint Helena, Ascension and Tristan da Cunha" : "SH", + "Saint Helena" : "SH", + "Saint Kitts and Nevis" : "KN", + "Saint Kitts & Nevis" : "KN", + "Saint Lucia" : "LC", + "Saint Martin (French part)" : "MF", + "Saint Martin" : "MF", + "St. Martin" : "MF", + "Saint Pierre and Miquelon" : "PM", + "Saint Pierre & Miquelon" : "PM", + "Saint Vincent and the Grenadines" : "VC", + "St. Vincent & Grenadines" : "VC", + "Samoa" : "WS", + "San Marino" : "SM", + "Sao Tome and Principe" : "ST", + "São Tomé and Príncipe" : "ST", + "Sao Tome & Principe" : "ST", + "Saudi Arabia" : "SA", + "Senegal" : "SN", + "Serbia" : "RS", + "Seychelles" : "SC", + "Sierra Leone" : "SL", + "Singapore" : "SG", + "Sint Maarten (Dutch part)" : "SX", + "Sint Maarten" : "SX", + "Slovakia" : "SK", + "Slovenia" : "SI", + "Solomon Islands" : "SB", + "Somalia" : "SO", + "South Africa" : "ZA", + "South Georgia and the South Sandwich Islands" : "GS", + "South Sudan" : "SS", + "Spain" : "ES", + "Sri Lanka" : "LK", + "Sudan" : "SD", + "Suriname" : "SR", + "Svalbard and Jan Mayen" : "SJ", + "Eswatini" : "SZ", # previous name "Swaziland" + "Swaziland" : "SZ", + "Sweden" : "SE", + "Switzerland" : "CH", + "Syrian Arab Republic" : "SY", + "Syria" : "SY", + "Taiwan, Province of China" : "TW", + "Taiwan*" : "TW", + "Taipei and environs" : "TW", + "Taiwan" : "TW", + "Tajikistan" : "TJ", + "Tanzania, United Republic of" : "TZ", + "Tanzania" : "TZ", + "Thailand" : "TH", + "Timor-Leste" : "TL", + "East Timor" : "TL", + "Togo" : "TG", + "Tokelau" : "TK", + "Tonga" : "TO", + "Trinidad and Tobago" : "TT", + "Tunisia" : "TN", + "Turkey" : "TR", + "Turkmenistan" : "TM", + "Turks and Caicos Islands" : "TC", + "Turks and Caicos" : "TC", + "Tuvalu" : "TV", + "Uganda" : "UG", + "Ukraine" : "UA", + "United Arab Emirates" : "AE", + "Emirates" : "AE", + "United Kingdom" : "GB", + "UK" : "GB", + # Conjoin North Ireland on United Kingdom + "North Ireland" : "GB", + "United States" : "US", + "US" : "US", + "United States Minor Outlying Islands" : "UM", + "Uruguay" : "UY", + "Uzbekistan" : "UZ", + "Vanuatu" : "VU", + "Venezuela, Bolivarian Republic of" : "VE", + "Venezuela" : "VE", + "Viet Nam" : "VN", + "Vietnam" : "VN", + "Virgin Islands, British" : "VG", + "British Virgin Islands" : "VG", + "Virgin Islands, U.S." : "VI", + "U.S. Virgin Islands" : "VI", + "Wallis and Futuna" : "WF", + "Wallis & Futuna" : "WF", + "Western Sahara" : "EH", + "Yemen" : "YE", + "Zambia" : "ZM", + "Zimbabwe" : "ZW", - # "Diamond Princess" : default_country_code, - # TODO "Disputed Territory" conflicts with `default_country_code` - # "Disputed Territory" : "XX", + # see also + # https://en.wikipedia.org/wiki/List_of_sovereign_states_and_dependent_territories_by_continent_(data_file)#Data_file + # https://en.wikipedia.org/wiki/List_of_sovereign_states_and_dependent_territories_by_continent + "United Nations Neutral Zone" : "XD", + "Iraq-Saudi Arabia Neutral Zone" : "XE", + "Spratly Islands" : "XS", - # "Others" has no mapping, i.e. the default val is used + # "Diamond Princess" : default_country_code, + # TODO "Disputed Territory" conflicts with `default_country_code` + # "Disputed Territory" : "XX", - # ships: - # "Cruise Ship" - # "MS Zaandam" -} + # "Others" has no mapping, i.e. the default val is used -# fmt: on -def country_code(value): - """ - Return two letter country code (Alpha-2) according to https://en.wikipedia.org/wiki/ISO_3166-1 - Defaults to "XX". - """ - code = COUNTRY_NAME__COUNTRY_CODE.get(value, DEFAULT_COUNTRY_CODE) - if code == DEFAULT_COUNTRY_CODE: - # log at sub DEBUG level - LOGGER.log(5, f"No country code found for '{value}'. Using '{code}'!") + # ships: + # "Cruise Ship" + # "MS Zaandam" + } +DEFAULT_COUNTRY_CODE = "XX" +class Country: + def __init__(self, country): + self.LOGGER = logging.getLogger(__name__) + + # Mapping of country names to alpha-2 codes according to + # https://en.wikipedia.org/wiki/ISO_3166-1. + # As a reference see also https://github.com/TakahikoKawasaki/nv-i18n (in Java) + # fmt: off + + self.country = country + + def get_country(self): + """ + Return country + """ + return self.country + # fmt: on + def get_country_code(self): + """ + Return two letter country code (Alpha-2) according to https://en.wikipedia.org/wiki/ISO_3166-1 + Defaults to "XX". + """ + country_code = COUNTRY_NAME__COUNTRY_CODE.get(self.get_country(), DEFAULT_COUNTRY_CODE) + if country_code == DEFAULT_COUNTRY_CODE: + # log at sub DEBUG level + self.LOGGER.log(5, f"No country code found for '{self.country}'. Using '{country_code}'!") - return code + return country_code + + def get_default_country_code(self): + """ + Return default country code (XX) + """ + return DEFAULT_COUNTRY_CODE + \ No newline at end of file From 50953f62db37c0938745a87c58c789243ebdcc79 Mon Sep 17 00:00:00 2001 From: DukeM23 Date: Sat, 24 Jul 2021 21:42:42 -0600 Subject: [PATCH 4/6] Lab8: Coutnries Aggregate --- CONTRIBUTING.md | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 91b53c02..00000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,40 +0,0 @@ -# Contribution to Coronavirus Tracker API - -First off, thanks for taking the time to contribute! -Every commit supports the open source ecosystem in case of [COVID-19](https://en.wikipedia.org/wiki/2019%E2%80%9320_coronavirus_pandemic). - -## Testing - -We have a handful of unit tests to cover most of functions. -Please write new test cases for new code you create. - -## Submitting changes - -* If you're unable to find an open issue, [open a new one](https://github.com/ExpDev07/coronavirus-tracker-api/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible -* Open a new [GitHub Pull Request to coronavirus-tracker-api](https://github.com/ExpDev07/coronavirus-tracker-api/pulls) with a clear list of what you've done (read more about [pull requests](http://help.github.com/pull-requests/)). Include the relevant issue number if applicable. -* We will love you forever if you include unit tests. We can always use more test coverage -* If you have updated [Pipefile](./Pipfile), you have to update `Pipfile.lock`, `requirements.txt` and `requirements-dev.txt`. See section [Update requirements files](./README.md#update-requirements-files). - -## Some about the database - -* There is gonna be something that must be added into the database because blah blah this is a test. This is something in consideration about the database wanting to be added to add stability blah - -## Your First Code Contribution - -Unsure where to begin contributing to coronavirus-tracker-api ? You can start by looking through these issues labels: - -* [Enhancement issues](https://github.com/ExpDev07/coronavirus-tracker-api/labels/enhancement) - issues for new feature or request -* [Help wanted issues](https://github.com/ExpDev07/coronavirus-tracker-api/labels/help%20wanted) - extra attention is needed -* [Documentation issues](https://github.com/ExpDev07/coronavirus-tracker-api/labels/documentation) - improvements or additions to documentation - -## Styleguide - -Please follow [PEP8](https://www.python.org/dev/peps/pep-0008/) guide. -See [Running Test](./README.md#running-tests), [Linting](./README.md#linting) and [Formatting](./README.md#formatting) sections for further instructions to validate your change. - - -We encourage you to pitch in and join the [Coronavirus Tracker API Team](https://github.com/ExpDev07/coronavirus-tracker-api#contributors-)! - -Thanks! :heart: :heart: :heart: - -[Coronavirus Tracker API Team](https://github.com/ExpDev07/coronavirus-tracker-api#contributors-) From df3d01932a198a634f93f63dc2fe17874a4bbc04 Mon Sep 17 00:00:00 2001 From: DukeM23 Date: Sat, 24 Jul 2021 19:50:11 -0600 Subject: [PATCH 5/6] Delete __init__.py --- app/data/__init__.py | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 app/data/__init__.py diff --git a/app/data/__init__.py b/app/data/__init__.py deleted file mode 100644 index c23c76c8..00000000 --- a/app/data/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -"""app.data""" -from ..services.location.csbs import CSBSLocationService -from ..services.location.jhu import JhuLocationService -from ..services.location.nyt import NYTLocationService - -# Mapping of services to data-sources. -DATA_SOURCES = { - "jhu": JhuLocationService(), - "csbs": CSBSLocationService(), - "nyt": NYTLocationService(), -} - -class DataSourceRequest: - def __init__(self, request): # request is of Obj reference of Reqeust from FastAPI - self.request = request - - def get_data_source(self): - """ - Retrieves the provided data-source service. - - :returns: The service. - :rtype: LocationService - """ - request_source = self.request.query_params.get("source", default="jhu") # gets source parameters - return DATA_SOURCES.get(request_source.lower()) From 20342d689633b0e2a386cb8b29955b88f0775bfb Mon Sep 17 00:00:00 2001 From: DukeM23 Date: Sat, 24 Jul 2021 19:54:46 -0600 Subject: [PATCH 6/6] Delete main.py --- app/main.py | 123 ---------------------------------------------------- 1 file changed, 123 deletions(-) delete mode 100644 app/main.py diff --git a/app/main.py b/app/main.py deleted file mode 100644 index c9ff29da..00000000 --- a/app/main.py +++ /dev/null @@ -1,123 +0,0 @@ -""" -app.main.py -""" -import logging - -import pydantic -import sentry_sdk -import uvicorn -from fastapi import FastAPI, Request, Response -from fastapi.middleware.cors import CORSMiddleware -from fastapi.middleware.gzip import GZipMiddleware -from fastapi.responses import JSONResponse -from scout_apm.async_.starlette import ScoutMiddleware -from sentry_sdk.integrations.asgi import SentryAsgiMiddleware - -from .config import get_settings -from .data import DataSourceRequest -from .routers import V1, V2 -from .utils.httputils import setup_client_session, teardown_client_session - -# ############ -# FastAPI App -# ############ -LOGGER = logging.getLogger("api") - -SETTINGS = get_settings() - -if SETTINGS.sentry_dsn: # pragma: no cover - sentry_sdk.init(dsn=SETTINGS.sentry_dsn) - -APP = FastAPI( - title="Coronavirus Tracker", - description=( - "API for tracking the global coronavirus (COVID-19, SARS-CoV-2) outbreak." - " Project page: https://github.com/ExpDev07/coronavirus-tracker-api." - ), - version="2.0.4", - docs_url="/", - redoc_url="/docs", - on_startup=[setup_client_session], - on_shutdown=[teardown_client_session], -) - -# ##################### -# Middleware -####################### - -# Scout APM -if SETTINGS.scout_name: # pragma: no cover - LOGGER.info(f"Adding Scout APM middleware for `{SETTINGS.scout_name}`") - APP.add_middleware(ScoutMiddleware) -else: - LOGGER.debug("No SCOUT_NAME config") - -# Sentry Error Tracking -if SETTINGS.sentry_dsn: # pragma: no cover - LOGGER.info("Adding Sentry middleware") - APP.add_middleware(SentryAsgiMiddleware) - -# Enable CORS. -APP.add_middleware( - CORSMiddleware, - allow_credentials=True, - allow_origins=["*"], - allow_methods=["*"], - allow_headers=["*"], -) -APP.add_middleware(GZipMiddleware, minimum_size=1000) - - -@APP.middleware("http") -async def add_datasource(request: Request, call_next): - """ - Attach the data source to the request.state. - """ - # Retrieve the datas ource from query param. - requested_data_source = DataSourceRequest(request) - data_source = requested_data_source.get_data_source() - - - # Abort with 404 if data_source cannot be found. - if not data_source: - return Response("The provided data-source was not found.", status_code=404) - - # Attach source to request. - request.state.data_source = data_source - - # Move on... - LOGGER.debug(f"source provided: {data_source.__class__.__name__}") - response = await call_next(request) - return response - - -# ################ -# Exception Handler -# ################ - - -@APP.exception_handler(pydantic.error_wrappers.ValidationError) -async def handle_validation_error( - request: Request, exc: pydantic.error_wrappers.ValidationError -): # pylint: disable=unused-argument - """ - Handles validation errors. - """ - return JSONResponse({"message": exc.errors()}, status_code=422) - - -# ################ -# Routing -# ################ - - -# Include routers. -APP.include_router(V1, prefix="", tags=["v1"]) -APP.include_router(V2, prefix="/v2", tags=["v2"]) - - -# Running of app. -if __name__ == "__main__": - uvicorn.run( - "app.main:APP", host="127.0.0.1", port=SETTINGS.port, log_level="info", - )