Spaces:
Sleeping
Sleeping
Commit
·
8fc4aaf
1
Parent(s):
30a3b83
Update app.py
Browse files
app.py
CHANGED
@@ -79,18 +79,20 @@ def geocode(address):
|
|
79 |
return lat, lon
|
80 |
|
81 |
|
|
|
82 |
#Side Bar
|
83 |
-
address = st.sidebar.text_input(
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
date_str = date.strftime("%Y%m%d")
|
88 |
|
89 |
#Geocode Addreses
|
|
|
|
|
90 |
lat, lon = geocode(address)
|
91 |
|
92 |
#Filter Data
|
93 |
-
df_hail_cut = get_data(lat,
|
94 |
|
95 |
|
96 |
df_hail_cut["Lat_address"] = lat
|
@@ -98,6 +100,7 @@ df_hail_cut["Lon_address"] = lon
|
|
98 |
df_hail_cut['Miles to Hail'] = [
|
99 |
distance(i) for i in df_hail_cut[['LAT', 'LON', 'Lat_address', 'Lon_address']].values]
|
100 |
df_hail_cut['MAXSIZE'] = df_hail_cut['MAXSIZE'].round(1)
|
|
|
101 |
df_hail_cut = df_hail_cut.query("`Miles to Hail`<10")
|
102 |
df_hail_cut['Category'] = np.where(df_hail_cut['Miles to Hail'] < 1, "Within 1 Mile",
|
103 |
np.where(df_hail_cut['Miles to Hail'] < 3, "Within 3 Miles",
|
@@ -110,15 +113,21 @@ df_hail_cut_group = pd.pivot_table(df_hail_cut, index='Date_utc',
|
|
110 |
aggfunc='max')
|
111 |
|
112 |
cols = df_hail_cut_group.columns
|
113 |
-
cols_focus = [ "Within 1 Mile",
|
114 |
"Within 5 Miles", "Within 10 Miles"]
|
115 |
|
116 |
missing_cols = set(cols_focus)-set(cols)
|
117 |
for c in missing_cols:
|
118 |
df_hail_cut_group[c] = np.nan
|
|
|
|
|
|
|
119 |
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
122 |
|
123 |
for i in range(len(cols_focus)-1):
|
124 |
df_hail_cut_group2[cols_focus[i+1]] = np.where(df_hail_cut_group2[cols_focus[i+1]].fillna(0) <
|
@@ -129,8 +138,8 @@ for i in range(len(cols_focus)-1):
|
|
129 |
|
130 |
df_hail_cut_group2 = df_hail_cut_group2.sort_index(ascending=False)
|
131 |
|
132 |
-
df_hail_cut_group2.index
|
133 |
-
|
134 |
|
135 |
|
136 |
#Map Data
|
|
|
79 |
return lat, lon
|
80 |
|
81 |
|
82 |
+
|
83 |
#Side Bar
|
84 |
+
address = st.sidebar.text_input("Address", "Dallas, TX")
|
85 |
+
date = st.sidebar.date_input("Loss Date (Max)", pd.Timestamp(2023, 7, 14), key='date')
|
86 |
+
show_data = st.sidebar.selectbox('Show Data At Least Within:', ('Show All', '1 Mile', '3 Miles', '5 Miles'))
|
87 |
+
show_data='3 Miles'
|
|
|
88 |
|
89 |
#Geocode Addreses
|
90 |
+
date_str=date.strftime("%Y%m%d")
|
91 |
+
|
92 |
lat, lon = geocode(address)
|
93 |
|
94 |
#Filter Data
|
95 |
+
df_hail_cut = get_data(lat,lon, date_str)
|
96 |
|
97 |
|
98 |
df_hail_cut["Lat_address"] = lat
|
|
|
100 |
df_hail_cut['Miles to Hail'] = [
|
101 |
distance(i) for i in df_hail_cut[['LAT', 'LON', 'Lat_address', 'Lon_address']].values]
|
102 |
df_hail_cut['MAXSIZE'] = df_hail_cut['MAXSIZE'].round(1)
|
103 |
+
|
104 |
df_hail_cut = df_hail_cut.query("`Miles to Hail`<10")
|
105 |
df_hail_cut['Category'] = np.where(df_hail_cut['Miles to Hail'] < 1, "Within 1 Mile",
|
106 |
np.where(df_hail_cut['Miles to Hail'] < 3, "Within 3 Miles",
|
|
|
113 |
aggfunc='max')
|
114 |
|
115 |
cols = df_hail_cut_group.columns
|
116 |
+
cols_focus = [ "Within 1 Mile","Within 3 Miles",
|
117 |
"Within 5 Miles", "Within 10 Miles"]
|
118 |
|
119 |
missing_cols = set(cols_focus)-set(cols)
|
120 |
for c in missing_cols:
|
121 |
df_hail_cut_group[c] = np.nan
|
122 |
+
|
123 |
+
#Filter
|
124 |
+
df_hail_cut_group2 = df_hail_cut_group[cols_focus]
|
125 |
|
126 |
+
if show_data=='Show All':
|
127 |
+
pass
|
128 |
+
else:
|
129 |
+
df_hail_cut_group2 = df_hail_cut_group2.query(
|
130 |
+
f"`Within {show_data}`==`Within {show_data}`")
|
131 |
|
132 |
for i in range(len(cols_focus)-1):
|
133 |
df_hail_cut_group2[cols_focus[i+1]] = np.where(df_hail_cut_group2[cols_focus[i+1]].fillna(0) <
|
|
|
138 |
|
139 |
df_hail_cut_group2 = df_hail_cut_group2.sort_index(ascending=False)
|
140 |
|
141 |
+
df_hail_cut_group2.index=pd.to_datetime(df_hail_cut_group2.index,format='%Y%m%d')
|
142 |
+
df_hail_cut_group2.index=df_hail_cut_group2.index.strftime("%Y-%m-%d")
|
143 |
|
144 |
|
145 |
#Map Data
|