-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnearest_icu.py
37 lines (30 loc) · 2.62 KB
/
nearest_icu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from Update_Spreadsheet import filter_by_capacity, filter_by_state_calc_distance, access_data_by_name, return_first_k_addresses
import pandas as pd
import numpy as np
ICU_PERCENTAGE = 0.75
INPATIENT_PERCENTAGE = 0.75
N = 10
# get user location
user_location = input("What is your address? \n")
hospital_data = pd.read_csv("https://healthdata.gov/sites/default/files/reported_hospital_capacity_admissions_facility_level_weekly_average_timeseries_20210110.csv") # get the file
# taking specific columns from data
bed_data = pd.concat([hospital_data["state"],hospital_data["hospital_name"],hospital_data["address"],hospital_data["city"],hospital_data["zip"],hospital_data["inpatient_beds_used_7_day_sum"],hospital_data["inpatient_beds_7_day_sum"],hospital_data["icu_beds_used_7_day_sum"],hospital_data["total_icu_beds_7_day_sum"]],axis=1,keys=["state","hospital_name","address","city","zip","inpatient_beds_used_7_day_sum","inpatient_beds_7_day_sum","icu_beds_used_7_day_sum","total_icu_beds_7_day_sum"])
# calculating the percentage of inpatient and icu beds being used
bed_data["percentage inpatient"] = np.where(((bed_data["inpatient_beds_7_day_sum"]<=0) & (bed_data["inpatient_beds_used_7_day_sum"]<0)),np.NaN,bed_data["inpatient_beds_used_7_day_sum"]/bed_data["inpatient_beds_7_day_sum"])
bed_data["percentage icu"] = np.where(((bed_data["total_icu_beds_7_day_sum"]<=0) & (bed_data["icu_beds_used_7_day_sum"]<0)),np.NaN,bed_data["icu_beds_used_7_day_sum"]/bed_data["total_icu_beds_7_day_sum"])
# column for the distance to be calculated by Google API
bed_data["distance"] = np.NaN
# first filter all states out, sort by distance, and return hospitals with capacity under limits
filtered_df = filter_by_state_calc_distance(user_location, ICU_PERCENTAGE, INPATIENT_PERCENTAGE, bed_data)#--------------------------------------------This line--first filter
# # can access a hospital by a comma separated address
# best_hospital = access_data_by_name("2070 CLINTON AVENUE, Alameda, 94501", filtered_df)
# return the addresses(hosp name: addr) of the N hospitals that are closest to you
closest_hospitals = return_first_k_addresses(N, filtered_df)#-----------------------------------------------------then gather-> with both you get the list of hospitals closest
print("\n")
for name in closest_hospitals:
print(name + ": " + closest_hospitals[name])
print("\n")
# ask user to choose one and provide directions
selected = input("Which hospital would you like to select? SELECT A NAME: \n")
selected_address = closest_hospitals[selected].lower().replace(" ","+")
print("\nhttps://www.google.com/maps/dir/" + user_location.lower().replace(" ", "+") + "/" + selected_address)