Spaces:
Sleeping
Sleeping
Update pages/market_rent_estimation.py
Browse files- pages/market_rent_estimation.py +205 -204
pages/market_rent_estimation.py
CHANGED
|
@@ -14,248 +14,249 @@ import geopandas as gpd
|
|
| 14 |
def main():
|
| 15 |
st.set_page_config(initial_sidebar_state="collapsed", layout="wide")
|
| 16 |
tab1, tab2 = st.tabs(["Combined estimation", "Comps"])#, "Market distributions", "Rexy"])
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
with tab1:
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
st.session_state['
|
| 25 |
-
|
| 26 |
-
st.session_state['
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
|
| 76 |
-
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
|
| 83 |
-
|
| 84 |
|
| 85 |
-
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
|
| 101 |
-
#comps page
|
| 102 |
-
with tab2:
|
| 103 |
-
|
| 104 |
-
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
|
| 141 |
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
|
| 177 |
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
# folium.GeoJson(
|
| 198 |
-
# data=row['geometry'].__geo_interface__,
|
| 199 |
-
# style_function=lambda feature: {
|
| 200 |
-
# 'fillColor': '#00000000', # Make the fill color transparent
|
| 201 |
-
# 'color': 'blue', # Set the border color
|
| 202 |
-
# 'weight': 2 # Set the border width
|
| 203 |
-
# },
|
| 204 |
-
# tooltip=folium.Tooltip(row['full_submarket']) # Add a tooltip with the name
|
| 205 |
-
# ).add_to(m)
|
| 206 |
|
| 207 |
-
|
| 208 |
-
|
| 209 |
|
| 210 |
-
|
| 211 |
-
|
| 212 |
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
|
| 260 |
back_to_serach_tab2 = st.button("Search page ")
|
| 261 |
if back_to_serach_tab2:
|
|
|
|
| 14 |
def main():
|
| 15 |
st.set_page_config(initial_sidebar_state="collapsed", layout="wide")
|
| 16 |
tab1, tab2 = st.tabs(["Combined estimation", "Comps"])#, "Market distributions", "Rexy"])
|
| 17 |
+
|
| 18 |
+
distances_matrix = np.load('atlanta_matrix.npy')
|
| 19 |
+
df_properties = pd.read_csv("atlanta_data_new.csv", encoding='utf-8')
|
| 20 |
|
| 21 |
|
| 22 |
with tab1:
|
| 23 |
+
st.write('Comps list:')
|
| 24 |
+
display_df = st.table(df_properties)
|
| 25 |
+
with tab2:
|
| 26 |
+
st.write('Comps list:')
|
| 27 |
+
st.write('min_property_size_perc:'st.session_state['min_property_size_perc'])
|
| 28 |
+
st.write('max_property_size_perc:'st.session_state['max_property_size_perc'])
|
| 29 |
+
st.write('months_back:'st.session_state['months_back'])
|
| 30 |
+
# with tab1:
|
| 31 |
+
# st.title('Combined estimation')
|
| 32 |
+
# if 'user_select_value' not in st.session_state:
|
| 33 |
+
# st.session_state['user_select_value'] = ""
|
| 34 |
+
# if 'year_buit' not in st.session_state:
|
| 35 |
+
# st.session_state['year_buit'] = ""
|
| 36 |
+
# if 'submarket_val' not in st.session_state:
|
| 37 |
+
# st.session_state['submarket_val'] = ""
|
| 38 |
+
# if 'market_val' not in st.session_state:
|
| 39 |
+
# st.session_state['market_val'] = ""
|
| 40 |
|
| 41 |
+
# box_contents = [
|
| 42 |
+
# {"header": "Address", "content": st.session_state['user_select_value']},
|
| 43 |
+
# {"header": "LSF", "content": str(st.session_state['property_lsf'])},
|
| 44 |
+
# {"header": "Sub-Market", "content": st.session_state['submarket_val']},
|
| 45 |
+
# {"header": "Market", "content": st.session_state['market_val']}
|
| 46 |
+
# ]
|
| 47 |
|
| 48 |
+
# # Divide the layout into four columns
|
| 49 |
+
# col1, col2, col3, col4 = st.columns(4)
|
| 50 |
|
| 51 |
+
# for i, col in enumerate([col1, col2, col3, col4]):
|
| 52 |
+
# col.markdown(f"""
|
| 53 |
+
# <div style="padding: 20px; margin: 10px; text-align: center;">
|
| 54 |
+
# <h3 style="font-size: small;">{box_contents[i]['header']}</h3>
|
| 55 |
+
# <p style="font-size: small;">{box_contents[i]['content']}</p>
|
| 56 |
+
# </div>
|
| 57 |
+
# """, unsafe_allow_html=True)
|
| 58 |
|
| 59 |
+
# # Add padding between the boxes and the slider
|
| 60 |
+
# st.markdown('<style>div[data-testid="stBlock"]{margin-top: 20px;}</style>', unsafe_allow_html=True)
|
| 61 |
|
| 62 |
+
# def safe_eval(val):
|
| 63 |
+
# try:
|
| 64 |
+
# return ast.literal_eval(val)
|
| 65 |
+
# except (ValueError, SyntaxError):
|
| 66 |
+
# return val
|
| 67 |
|
| 68 |
+
# #comps results with scores
|
| 69 |
+
# df_comps = pd.read_csv("comps_short_atlanta.csv")
|
| 70 |
+
# # all properties
|
| 71 |
+
# df_properties = pd.read_csv("atlanta_data.csv", encoding='utf-8')
|
| 72 |
|
| 73 |
+
# filtered_row = df_comps[df_comps['new_address'] == st.session_state['user_select_value']].iloc[0]
|
| 74 |
+
# #addresses of comps
|
| 75 |
+
# comps_addresses = filtered_row.filter(like='address_').tolist()
|
| 76 |
+
# comps_addresses.insert(0, st.session_state['user_select_value'])
|
| 77 |
+
# #similarity scores
|
| 78 |
+
# comps_scores = filtered_row.filter(like='score_').tolist()
|
| 79 |
+
# comps_scores.insert(0, 0)
|
| 80 |
|
| 81 |
+
# df_comps_data = df_properties[df_properties.google_ola.isin(comps_addresses)]
|
| 82 |
+
# average_rent = df_comps_data.iloc[1:]['rent_combined'].mean()
|
| 83 |
|
| 84 |
+
# x1 ="Comps " + str(average_rent)
|
| 85 |
+
# x3="Rexy " + str(st.session_state['prediction'])
|
| 86 |
|
| 87 |
+
# x2 = (st.session_state['prediction']+average_rent)/2
|
| 88 |
|
| 89 |
+
# pick = st.select_slider(
|
| 90 |
+
# "Combined estimation ",
|
| 91 |
+
# options=[x1, x2, x3],
|
| 92 |
+
# value=x2)
|
| 93 |
|
| 94 |
+
# # st.markdown('<style>div[data-testid="stBlock"]{margin-top: 20px;}</style>', unsafe_allow_html=True)
|
| 95 |
|
| 96 |
+
# # st.markdown('<style>div[data-testid="stBlock"]{margin-top: 20px;}</style>', unsafe_allow_html=True)
|
| 97 |
|
| 98 |
+
# # chart_data = pd.DataFrame(np.random.randn(20, 2), columns=["col1", "col2"])
|
| 99 |
+
# # chart_data['col4'] = np.random.choice(['A','B'], 20)
|
| 100 |
|
| 101 |
+
# # st.scatter_chart(
|
| 102 |
+
# # chart_data,
|
| 103 |
+
# # x='col1',
|
| 104 |
+
# # y='col2',
|
| 105 |
+
# # color='col4',
|
| 106 |
+
# # )
|
| 107 |
|
| 108 |
+
# back_to_serach_tab1 = st.button("Search page")
|
| 109 |
+
# if back_to_serach_tab1:
|
| 110 |
+
# st.switch_page("app.py")
|
| 111 |
|
| 112 |
+
# #comps page
|
| 113 |
+
# with tab2:
|
| 114 |
+
# # Create DataFrame
|
| 115 |
+
# df_data = df_comps_data.copy().reset_index(drop=True)
|
| 116 |
|
| 117 |
+
# # filtered_data2 = df_dataF
|
| 118 |
+
# filtered_data = df_data[["google_ola", "market_costar", "submarket_costar", "execution_date", "rented_sf", "building_sf", "year_built", "office_rate", "min_clear_height", "max_clear_height", "docks", "drive_ins", "rent_combined"]]#pd.concat([filtered_data2])
|
| 119 |
+
# comps_scores = comps_scores[:len(filtered_data)]
|
| 120 |
+
# filtered_data.insert(loc=1, column='Similarity score', value=comps_scores)
|
| 121 |
|
| 122 |
+
# # Formatting the DataFrame
|
| 123 |
+
# filtered_data['Similarity score'] = ((1 - filtered_data['Similarity score']) * 100).apply(lambda x: f"{x:.2f}")
|
| 124 |
+
# filtered_data['execution_date'] = pd.to_datetime(filtered_data['execution_date']).dt.strftime('%m-%d-%Y')
|
| 125 |
+
# filtered_data['LSF (sf)'] = filtered_data['rented_sf'].round(0).astype(int)
|
| 126 |
+
# filtered_data['RSF (sf)'] = filtered_data['building_sf'].round(0).astype(int)
|
| 127 |
+
# filtered_data['Year built'] = filtered_data['year_built'].astype(int)
|
| 128 |
+
# filtered_data.loc[filtered_data['office_rate'].notna(), 'office_rate'] = (filtered_data.loc[filtered_data['office_rate'].notna(), 'office_rate'] * 100).apply(lambda x: f"{x:.2f} %")
|
| 129 |
|
| 130 |
+
# filtered_data.loc[filtered_data['min_clear_height'].notna(), 'min_clear_height'] = (filtered_data.loc[filtered_data['min_clear_height'].notna(), 'min_clear_height']).apply(lambda x: f"{int(x)}")
|
| 131 |
+
# # filtered_data['Clear Height (feet)'] = filtered_data['min_clear_height'].round(0).astype(int)
|
| 132 |
|
| 133 |
+
# filtered_data.loc[filtered_data['docks'].notna(), 'docks'] = (filtered_data.loc[filtered_data['docks'].notna(), 'docks']).apply(lambda x: f"{int(x)}")
|
| 134 |
+
# filtered_data.loc[filtered_data['drive_ins'].notna(), 'drive_ins'] = (filtered_data.loc[filtered_data['drive_ins'].notna(), 'drive_ins']).apply(lambda x: f"{int(x)}")
|
| 135 |
|
| 136 |
+
# # filtered_data['Docks (/10ksf)'] = filtered_data['docks'].astype(int)
|
| 137 |
+
# # filtered_data['Doors (/10ksf)'] = filtered_data['drive_ins'].astype(int)
|
| 138 |
+
# filtered_data['Rent (NNN)'] = filtered_data['rent_combined'].apply(lambda x: f"${x:.2f}")
|
| 139 |
|
| 140 |
+
# # Dropping old columns and renaming headers
|
| 141 |
+
# filtered_data = filtered_data.drop(columns=['rented_sf', 'building_sf', 'year_built', 'max_clear_height', 'rent_combined'])
|
| 142 |
+
# filtered_data = filtered_data.rename(columns={
|
| 143 |
+
# 'google_ola': 'Address',
|
| 144 |
+
# 'office_rate': 'Office %',
|
| 145 |
+
# 'min_clear_height': 'Clear Height (feet)',
|
| 146 |
+
# 'docks': 'Docks (/10ksf)',
|
| 147 |
+
# 'drive_ins': 'Doors (/10ksf)',
|
| 148 |
+
# 'market_costar': 'Market',
|
| 149 |
+
# 'submarket_costar': 'Submarket'
|
| 150 |
+
# })
|
| 151 |
|
| 152 |
|
| 153 |
+
# # Display the filtered data
|
| 154 |
+
# col_1_1, col_1_2 = st.columns([2, 1])
|
| 155 |
+
# with col_1_1:
|
| 156 |
+
# st.write('Comps list:')
|
| 157 |
+
# display_df = st.table(filtered_data)
|
| 158 |
+
# with col_1_2:
|
| 159 |
+
# # Create a map object
|
| 160 |
+
# m = folium.Map(width=500, height=440, location=(df_data['lat'].mean(), df_data['long'].mean()), zoom_start=9)
|
| 161 |
|
| 162 |
+
# # Add markers to the map
|
| 163 |
+
# all_markers = folium.FeatureGroup(name='All Markers')
|
| 164 |
+
# active_markers = folium.FeatureGroup(name='Active Markers', show=False)
|
| 165 |
+
# inactive_markers = folium.FeatureGroup(name='Inactive Markers', show=False)
|
| 166 |
|
| 167 |
+
# for index, row in df_data.iterrows():
|
| 168 |
+
# status_color = 'green' if index==0 else 'red'
|
| 169 |
+
# html_content = f"""
|
| 170 |
+
# <div style="
|
| 171 |
+
# display: inline-block;
|
| 172 |
+
# background-color: white;
|
| 173 |
+
# border: 2px solid black;
|
| 174 |
+
# border-radius: 50%;
|
| 175 |
+
# width: 20px;
|
| 176 |
+
# height: 20px;
|
| 177 |
+
# text-align: center;
|
| 178 |
+
# line-height: 20px;
|
| 179 |
+
# font-size: 8pt;
|
| 180 |
+
# color: {status_color};
|
| 181 |
+
# ">{index}</div>
|
| 182 |
+
# """
|
| 183 |
|
| 184 |
+
# # Create a DivIcon with custom HTML content
|
| 185 |
+
# icon = folium.DivIcon(html=html_content)
|
| 186 |
+
# marker = folium.Marker([row['lat'], row['long']], popup=row['google_ola'], icon=icon).add_to(m)
|
| 187 |
|
| 188 |
|
| 189 |
+
# #add poligons on map
|
| 190 |
+
# gdf = gpd.read_file('costar_sm_polygons.geojson')
|
| 191 |
+
# gdf_Atlanta = gdf[gdf.full_submarket.str.contains("Atlanta")]
|
| 192 |
+
# folium.GeoJson(data=gdf_Atlanta.geometry.to_json(), name='geojson').add_to(m)
|
| 193 |
+
# for _, row in gdf_Atlanta.iterrows():
|
| 194 |
+
# # Convert the row's geometry to GeoJSON
|
| 195 |
+
# geojson = folium.GeoJson(data=row['geometry'].__geo_interface__,
|
| 196 |
+
# style_function=lambda feature: {
|
| 197 |
+
# 'fillColor': '#00000000', # Make the fill color transparent
|
| 198 |
+
# 'color': '#00000000', # Set the border color
|
| 199 |
+
# 'weight': 2 # Set the border width
|
| 200 |
+
# },
|
| 201 |
+
# )
|
| 202 |
+
# # Add a popup with the name
|
| 203 |
+
# popup = folium.Popup(row['full_submarket'], parse_html=True)
|
| 204 |
|
| 205 |
+
# # Add the GeoJson and Popup to the map
|
| 206 |
+
# geojson.add_child(popup).add_to(m)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
+
# # Add layer control to toggle marker visibility
|
| 209 |
+
# folium.LayerControl().add_to(m)
|
| 210 |
|
| 211 |
+
# # Render the map
|
| 212 |
+
# folium_static(m)
|
| 213 |
|
| 214 |
+
# option_add_comps = st.radio("Add comps:", (":rainbow[On]", ":rainbow[Off]"), horizontal=True, index=1)
|
| 215 |
+
# if option_add_comps == ":rainbow[On]":
|
| 216 |
+
# col_3_1, col_3_2, col_3_3 = st.columns([5,1,5])
|
| 217 |
+
# with col_3_1:
|
| 218 |
+
# # Create DataFrame
|
| 219 |
+
# df5 = df_properties
|
| 220 |
+
# df5.insert(loc=0, column='Select rows', value=[False]*len(df5))
|
| 221 |
+
# st.write('Additional comps')
|
| 222 |
+
# test = st.data_editor(
|
| 223 |
+
# df5,
|
| 224 |
+
# column_config={
|
| 225 |
+
# "Select rows": st.column_config.CheckboxColumn(
|
| 226 |
+
# "Your favorite?",
|
| 227 |
+
# help="Select your **favorite** widgets",
|
| 228 |
+
# default=False,
|
| 229 |
+
# )
|
| 230 |
+
# },
|
| 231 |
+
# # disabled=['Address','latitude','longitude','Match score','Market','Sub-market','Lease Date','LSF',
|
| 232 |
+
# # 'RSF','Rent (NNN)','Year Built','Office %','Clear Height','Doors (drive in / Dock)','Lease Term ','Rent (Gross)','TIs '],
|
| 233 |
+
# hide_index=True,
|
| 234 |
+
# )
|
| 235 |
+
# with col_3_2:
|
| 236 |
+
# if st.button("Add comps", help="Click to add more comps"):
|
| 237 |
+
# filtered_data1 = pd.concat([filtered_data, test[test['Select rows']==True].drop(columns=['Select rows'])])
|
| 238 |
+
# # filtered_data.update(test.drop(columns=['favorite']))
|
| 239 |
+
# display_df.table(filtered_data1)
|
| 240 |
+
# with col_3_3:
|
| 241 |
+
# st.write('Filter definition')
|
| 242 |
|
| 243 |
+
# range_1 = st.slider('Lease date', min_value=0, max_value=36,
|
| 244 |
+
# value=(12))
|
| 245 |
+
# range_2 = st.slider('Location in mi', min_value=0, max_value=50,
|
| 246 |
+
# value=(12))
|
| 247 |
+
# range_3 = st.slider('LSF', min_value=0, max_value=500000, step = 1000,
|
| 248 |
+
# value=(20000, 200000))
|
| 249 |
+
# range_4 = st.slider('Clear height', min_value=0, max_value=50,
|
| 250 |
+
# value=(15, 30))
|
| 251 |
+
# range_5 = st.slider('Year built', min_value=1960, max_value=2024,
|
| 252 |
+
# value=(1999, 2010))
|
| 253 |
+
# range_5 = st.slider('Far %', min_value=0, max_value=100,
|
| 254 |
+
# value=50)
|
| 255 |
+
# range_6 = st.slider('Office %', min_value=0, max_value=100,
|
| 256 |
+
# value=30)
|
| 257 |
+
# range_7 = st.slider('Docl doors & Drive-in', min_value=0, max_value=20,
|
| 258 |
+
# value=3)
|
| 259 |
+
# st.button("Apply filter", key="submit_button", help="Click to submit")
|
| 260 |
|
| 261 |
back_to_serach_tab2 = st.button("Search page ")
|
| 262 |
if back_to_serach_tab2:
|