KeshavRa commited on
Commit
3f8e536
·
verified ·
1 Parent(s): 810460f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -40
app.py CHANGED
@@ -5,6 +5,42 @@ import requests
5
  import os
6
  import math
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def get_zip_codes(city, state):
9
  url = f'http://api.zippopotam.us/us/{state}/{city}'
10
  response = requests.get(url)
@@ -53,7 +89,7 @@ def form_dialog():
53
  domestic_violence = st.radio("Have you experienced domestic violence (some shelters serve these individuals specifically", ["No", "Yes"])
54
 
55
  urgency = st.radio("How quickly do you need help?", ("Today", "In the next few days", "In a week or more"))
56
- duration = st.radio("How long do you need a place to stay?", ("Overnight", "A month of less", "A couple of months", "A year or more"))
57
  needs = st.text_area("Optional - Needs (tell us what you need and how we can help)", value="")
58
 
59
  if st.button("Submit"):
@@ -125,53 +161,24 @@ else:
125
  distances.append(haversine(coordinates[0], coordinates[1], user_coordinates[0], user_coordinates[1]))
126
 
127
  max = max(distances) if (max(distances) != 0) else 1
128
- print(max)
129
  shelters['zipcode_score'] = [d / max for d in distances]
130
 
131
- # urgency
132
-
133
- # Immidiate
134
- # --> immidiate: 0
135
- # --> high: 0.75
136
- # --> moderate: 1
137
 
138
- # High
139
- # --> immidiate: 0.25
140
- # --> high: 0
141
- # --> moderate = 0.75
142
-
143
- # Moderate
144
- # --> immidiate: 0.75
145
- # --> high: 0.25
146
- # --> moderate: 0
147
 
148
  # duration
 
 
 
149
 
150
- # Overnight
151
- # --> overnight: 0
152
- # --> temp: 0.5
153
- # --> trans: 0.75
154
- # --> long: 1
155
-
156
- # Temp
157
- # --> overnight: 0.25
158
- # --> temp: 0
159
- # --> trans: 0.25
160
- # --> long: 0.75
161
-
162
- # Trans
163
- # --> overnight: 0.75
164
- # --> temp: 0.25
165
- # --> trans: 0
166
- # --> long: 0.25
167
-
168
- # Long
169
- # --> overnight: 1
170
- # --> temp: 0.75
171
- # --> trans: 0.5
172
- # --> long: 0
173
 
174
  # services
 
175
 
176
  st.table(shelters)
177
 
 
5
  import os
6
  import math
7
 
8
+ def get_urgency_score(user, shelter):
9
+ if user == "Today":
10
+ if shelter == "Immdiaite": return 0
11
+ if shelter == "High": return 0.75
12
+ if shelter == "Moderate": return 1
13
+ elif user == "In the next few days":
14
+ if shelter == "Immdiaite": return 0.25
15
+ if shelter == "High": return 0
16
+ if shelter == "Moderate": return 0.75
17
+ elif user == "In a week or so":
18
+ if shelter == "Immdiaite": return 0.75
19
+ if shelter == "High": return 0.25
20
+ if shelter == "Moderate": return 0
21
+
22
+ def get_duration_score(user, shelter):
23
+ if user == "Overnight":
24
+ if shelter == "Overnight": return 0
25
+ if shelter == "Temporary": return 0.5
26
+ if shelter == "Transitional": return 0.75
27
+ if shelter == "Long-Term": return 1
28
+ elif user == "A month or less":
29
+ if shelter == "Overnight": return 0.5
30
+ if shelter == "Temporary": return 0
31
+ if shelter == "Transitional": return 0.25
32
+ if shelter == "Long-Term": return 0.75
33
+ elif user == "A couple of months":
34
+ if shelter == "Overnight": return 0.75
35
+ if shelter == "Temporary": return 0.25
36
+ if shelter == "Transitional": return 0
37
+ if shelter == "Long-Term": return 0.5
38
+ elif user == "A year or more":
39
+ if shelter == "Overnight": return 1
40
+ if shelter == "Temporary": return 0.75
41
+ if shelter == "Transitional": return 0.5
42
+ if shelter == "Long-Term": return 0
43
+
44
  def get_zip_codes(city, state):
45
  url = f'http://api.zippopotam.us/us/{state}/{city}'
46
  response = requests.get(url)
 
89
  domestic_violence = st.radio("Have you experienced domestic violence (some shelters serve these individuals specifically", ["No", "Yes"])
90
 
91
  urgency = st.radio("How quickly do you need help?", ("Today", "In the next few days", "In a week or more"))
92
+ duration = st.radio("How long do you need a place to stay?", ("Overnight", "A month or less", "A couple of months", "A year or more"))
93
  needs = st.text_area("Optional - Needs (tell us what you need and how we can help)", value="")
94
 
95
  if st.button("Submit"):
 
161
  distances.append(haversine(coordinates[0], coordinates[1], user_coordinates[0], user_coordinates[1]))
162
 
163
  max = max(distances) if (max(distances) != 0) else 1
 
164
  shelters['zipcode_score'] = [d / max for d in distances]
165
 
166
+ # get urgency scores
167
+ urgency_scores = []
168
+ for shelter in shelters:
169
+ urgency_scores.append(get_urgency_score(data['Urgency'], shelter['Urgency']))
 
 
170
 
171
+ shelters['urgency_score'] = urgency_scores
 
 
 
 
 
 
 
 
172
 
173
  # duration
174
+ duration_scores = []
175
+ for shelter in shelters:
176
+ duration_scores.append(get_duration_score(data['Duration'], shelter['Duration']))
177
 
178
+ shelters['duration_score'] = urgency_scores
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
 
180
  # services
181
+
182
 
183
  st.table(shelters)
184