Skip to content

Commit

Permalink
chore: updating master (#55)
Browse files Browse the repository at this point in the history
* refactor: change Aaron to standard feat: adding basic test
- Changed APP to app according to Flask/FastAPI standard
- Changed config_ to _config. trailing space is for python default conflicts not import
- Adding basic tests for endpoints

* test: added test structures
- 	est_app.py: testing �pp.py app title, description, version
- 	est_config.py: tested ProductionConfig, DevelopmentConfig, config loader
- 	est_endpoints.py: tested root test

* test: added test structures
- 	est_app.py: testing �pp.py app title, description, version
- 	est_config.py: tested ProductionConfig, DevelopmentConfig, config loader
- 	est_endpoints.py: tested root test

* tests: add testing for custom error messages

* chore: updated README

* chore: fixed PR template

* chore: updated README

* chore: updated README

* tests: adds test cases for endpoints
- '/' done
- '/news' only testing for 422 and 405, no validation yet
- '/twitter': tested 422, 404, 405, and random data sample validation
- '/county': tested 404, 405, 422. no data return validation yet
- '/state': tested 405, 422.
- '/country': tested 405, 422.
- '/stats': tested 405, 422.

* style: fix for codefactor.
- 	est_config.py: keeping assert == True/False for code readability
- 	est_endpoints.py: keeping TODO as a reminder to fix endpoints.py

* style: changed config_ to �pp_config after technical discussion

* style: chore:
- added .pylintrc
- fixed all files for pylint
- added .github/workflow/pythonapp.yml
- added pipenv, pylint and pytest

* chore:
- streamlining pythonapp.yml
- triggers pythonapp.yml on all push and pull_request

* chore: updated pythonapp.yml

* chore: updated pythonapp.yml

* chore: updated pythonapp.yml, readme.md

* chore: updated pythonapp.yml

* chore: updated pythonapp.yml

* chore: updated pythonapp.yml

* chore: updated pythonapp.yml

* chore: updated pythonapp.yml

* chore: updated pythonapp.yml

* chore: updated pythonapp.yml

* chore: updated pythonapp.yml

* feat: rerouting root endpoint to postman

* feat: rerouting root endpoint to postman

* feat: added redirect to postman, added test

* fix: added uvloop

* feat: adding coverall

* feat: installed coveralls for coverall.io

* feat: installed coveralls for coverall.io

* feat: installed coveralls for coverall.io

* feat: installed coveralls for coverall.io attempt 6

* feat: installed coveralls for coverall.io attempt 8

* feat: installed coveralls for coverall.io attempt 9

* feat: settingup coverall attempt #11

* feat: coverall badge attempt #12

* feat: coverall added, feat: routing root to redoc

* fix: default config logic

* fix: default config logic

* Update LICENSE

* chore: updating README again  🤧 (#46)

* chore: updating READMEs

* chore: updating READMEs

* chore: updating READMEs (#48)

* fix: post county new_death nan error (#50)

* fix: /post county new_death nan error

* fix: /post county new_death nan error

* feat: test: (#52)

* feat: adding zip route

* feat: zip route #1

* feat: removed uszipcode, added zipcodes

* feat:
- feat: added zip endpoint to return county data given zip code
- test: added tests for the zip endpoint
- feat: modified github actions to trigger on push, and on pr to master/staging

* han: attempt to fix codefactor #1

* feat: zip endpoint
- added custom exception handlers
- mal-formed zip codes now return 422 instead of 404
- changed mal-formed zip codes test cases from 404 to 422

* fixed zip endpoint for nyc (#54)

Co-authored-by: leehanchung <[email protected]>
Co-authored-by: Hanchung Lee <[email protected]>
  • Loading branch information
3 people committed Apr 20, 2020
1 parent 51ecd4a commit b5043f9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
15 changes: 10 additions & 5 deletions api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,18 +451,23 @@ def post_zip(zip_code: ZIPInput) -> JSONResponse:
try:
zip_info = zipcodes.matching(zip_code.zip_code)[0]
except Exception as ex:
_logger.warning(f"Endpoint: /zip --- POST --- {ex}")
message = f"ZIP code {zip_code.zip_code} not found in US Zipcode database."
_logger.warning(f"Endpoint: /zip --- POST --- {message}")
raise HTTPException(status_code=422,
detail=f"[Error] get '/zip' API: {ex}")
detail=f"[Error] POST '/zip' {message}")


try:
county = zip_info['county'].rsplit(' ', 1)[0]
state = zip_info['state']
_logger.info(f"State: {state}, County: {county}")
if state == "NY":
print('NY')
data = read_county_stats_zip_ny(zip_code.zip_code)
nyc_counties = ["Bronx", "Kings", "Queens", "Richmond"]
if county in nyc_counties:
county = "New York"
data = read_county_stats(state, county)[0]
else:
print("not NY")

data = read_county_stats(state, county)[0]
json_data = {"success": True, "message": data}
del data
Expand Down
20 changes: 10 additions & 10 deletions api/utils/county.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def read_county_stats(state: str, county: str) -> Dict:

try:
df = pd.read_csv(app_config.COUNTY_URL)
deaths = pd.read_csv(app_config.STATE_DEATH)
#deaths = pd.read_csv(app_config.STATE_DEATH)
except:
raise DataReadingError(
f"Data reading error State: {state}, and County: {county}."
Expand All @@ -32,18 +32,18 @@ def read_county_stats(state: str, county: str) -> Dict:
df.columns = map(str.lower, df.columns)
df.columns = df.columns.str.replace(" ", "_")

# used data source 2 for new death number
deaths = deaths[deaths['Province_State'] == reverse_states_map[state]]
deaths = deaths[deaths['Admin2'] == county]
# 4/15/20: force cast into int before diff as pd sometimes read as
# float and throws nan.
deaths = deaths.iloc[:, 12:].astype('int32').\
diff(axis=1).iloc[:, -1].values[0]

# # used data source 2 for new death number
# deaths = deaths[deaths['Province_State'] == reverse_states_map[state]]
# deaths = deaths[deaths['Admin2'] == county]
# # 4/15/20: force cast into int before diff as pd sometimes read as
# # float and throws nan.
# deaths = deaths.iloc[:, 12:].astype('int32').\
# diff(axis=1).iloc[:, -1].values[0]

df = df[df["state_name"] == reverse_states_map[state]]
# df = df.query(f"county_name == '{county}'")
df = df[df["county_name"] == county]
df.new_death.iloc[0] = deaths
# df.new_death.iloc[0] = deaths
df = pd.DataFrame.to_dict(df, orient="records")
if len(df) == 0:
raise DataValidationError("county.py len(df) == 0")
Expand Down

0 comments on commit b5043f9

Please sign in to comment.