Skip to content

Instantly share code, notes, and snippets.

@jiobu1
Last active April 27, 2021 01:28
Show Gist options
  • Save jiobu1/bfe8360c7cbcd32e73d10e3f450b7aba to your computer and use it in GitHub Desktop.
Save jiobu1/bfe8360c7cbcd32e73d10e3f450b7aba to your computer and use it in GitHub Desktop.
pickled schools endpoint
# Schools Listing Endpoint
async def schools_listings(current_city:City, school_category):
"""
Listing of school information for the city
(locates specific pickled dictionary based on school category for the city)
- Ratings -> sorted, listed from highest to lowest
- Type -> public, private, charter
- Grades -> pre-k, elementary, middle, high school
- District -> district in city
# Query Parameters
- city
- school category -> pre-k, elementary, middle school, high school
# Response
sorted dataframe as JSON string to render with react-plotly.js
- returns first 25 schools for speed
"""
city = validate_city(current_city)
city_name = city.city + ', ' + city.state
if school_category == 'pre-k':
pre_k = load(open("app/data/pickle_model/pre_k.pkl", "rb"))
school_listing = pre_k[city_name][:25]
elif school_category == 'elementary':
elem = load(open("app/data/pickle_model/elem.pkl", "rb"))
school_listing = elem[city_name][:25]
elif school_category == 'middle school':
middle = load(open("app/data/pickle_model/middle.pkl", "rb"))
school_listing = middle[city_name][:25]
else:
high = load(open("app/data/pickle_model/high.pkl", "rb"))
school_listing = high[city_name][:25]
return school_listing.to_dict('records')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment