import%20marimo%0A%0A__generated_with%20%3D%20%220.20.2%22%0Aapp%20%3D%20marimo.App()%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Historical%20Commission%20Review%0A%0A%20%20%20%20Per%20Waltham's%20zoning%20code%20%5Bsection%2023-2%5D(https%3A%2F%2Fecode360.com%2F26936024)%2C%20structures%20older%20than%2075%20years%20must%20go%20through%20Historical%20Commission%20Review.%20The%20Historical%20Commission%20is%20tasked%0A%20%20%20%20to%20determine%20whether%20or%20not%20a%20structure%20should%20be%20preserved%20or%20if%20demoltion%20need%20not%20be%20denied%20to%20preserve%20historic%20character.%20Our%20zoning%20code%20has%20_long_%20forbidden%20multi-family%20housing%2C%0A%20%20%20%20meaning%20a%20lot%20of%20our%20housing%20stock%20is%20low%20density.%20Historical%20review%20could%20present%20a%20barrier%20to%20necessary%20development%20of%20housing.%20The%20more%20restrictive%20our%20zoning%20code%20is%2C%20the%20more%20structures%0A%20%20%20%20could%20be%20subject%20to%20review.%20Given%20the%20subjective%20criteria%20allowed%20by%20the%20code%2C%20there's%20a%20possibility%20that%20we'd%20be%20stuck%20with%20insufficient%20housing%20that%20becomes%20increasingly%20expensive%20to%20maintain.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20pandas%20as%20pd%0A%20%20%20%20import%20geopandas%20as%20gpd%0A%20%20%20%20import%20datetime%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20from%20data.connect_db%20import%20get_db%0A%0A%20%20%20%20from%20waltham.constants%20import%20MASSGIS_CRS%0A%0A%20%20%20%20conn%20%3D%20get_db()%0A%20%20%20%20return%20conn%2C%20datetime%2C%20gpd%2C%20mo%2C%20pd%0A%0A%0A%40app.cell%0Adef%20_(conn%2C%20gpd)%3A%0A%20%20%20%20parcels_query%20%3D%20f%22%22%22%0A%20%20%20%20select%0A%20%20%20%20%20%20%20%20%22geom%22%2C%20%22LOC_ID%22%0A%20%20%20%20from%20%0A%20%20%20%20%20%20%20%20%5C%22M308TaxPar_CY25_FY25%5C%22%0A%20%20%20%20%22%22%22%0A%0A%20%20%20%20parcels_df%20%3D%20gpd.read_postgis(parcels_query%2C%20conn%2C%20geom_col%3D%22geom%22)%0A%20%20%20%20return%20(parcels_df%2C)%0A%0A%0A%40app.cell%0Adef%20_(conn%2C%20pd)%3A%0A%20%20%20%20assess_query%20%3D%20f%22%22%22%0A%20%20%20%20select%0A%20%20%20%20%20%20%20%20%22LOC_ID%22%2C%20%22PROP_ID%22%2C%20%22UNITS%22%2C%20%22YEAR_BUILT%22%2C%20%22USE_CODE%22%3A%3Ainteger%2C%20%22STYLE%22%0A%20%20%20%20from%0A%20%20%20%20%20%20%20%20%5C%22M308Assess_CY25_FY25%5C%22%0A%20%20%20%20%22%22%22%0A%0A%20%20%20%20assess_df%20%3D%20pd.read_sql(assess_query%2C%20conn)%0A%20%20%20%20return%20(assess_df%2C)%0A%0A%0A%40app.cell%0Adef%20_(assess_df%2C%20parcels_df)%3A%0A%20%20%20%20properties_df%20%3D%20parcels_df.merge(assess_df%2C%20how%3D%22outer%22%2C%20on%3D%22LOC_ID%22)%0A%20%20%20%20return%20(properties_df%2C)%0A%0A%0A%40app.cell%0Adef%20_(datetime%2C%20properties_df)%3A%0A%20%20%20%20%23%20model%20how%20much%20ages%20into%20historical%20status%20over%20time%2C%20over%20a%20generation%0A%20%20%20%20this_year%20%3D%20datetime.date.today().year%0A%0A%20%20%20%20properties_df%5B%22IMPUTED%22%5D%20%3D%20properties_df%5B%22YEAR_BUILT%22%5D.map(lambda%20x%3A%20x%20in%20%5Bfloat(%22nan%22)%2C%200%5D)%0A%20%20%20%20residential_criteria%20%3D%20(properties_df%5B%22USE_CODE%22%5D%20%3C%20200)%20%26%20(properties_df%5B%22USE_CODE%22%5D.map(lambda%20x%3A%20x%20not%20in%20range(130%2C%20141)))%0A%0A%20%20%20%20trend_data%20%3D%20%5B%5D%0A%0A%20%20%20%20for%20COMPARE_YEAR%20in%20range(this_year%2C%20this_year%20%2B%2020)%3A%0A%20%20%20%20%20%20%20%20%23%20assume%20age%20is%2075%2C%20if%20unknown%0A%20%20%20%20%20%20%20%20properties_df%5B%22YEAR_BUILT%22%5D%20%3D%20properties_df%5B%22YEAR_BUILT%22%5D.replace(0%2C%20COMPARE_YEAR%20-%2075)%0A%20%20%20%20%20%20%20%20properties_df%5B%22YEAR_BUILT%22%5D%20%3D%20properties_df%5B%22YEAR_BUILT%22%5D.fillna(COMPARE_YEAR%20-%2075)%0A%0A%20%20%20%20%20%20%20%20properties_df%5B%22HISTORIC%22%5D%20%3D%20(COMPARE_YEAR%20-%20properties_df%5B%22YEAR_BUILT%22%5D)%20%3E%3D%2075%0A%0A%20%20%20%20%20%20%20%20%23%20historic%20housing%0A%20%20%20%20%20%20%20%20properties_df%5B%22HISTORIC_RESIDENTIAL%22%5D%20%3D%20properties_df.apply(lambda%20row%3A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20row%5B%22HISTORIC%22%5D%20and%20(row%5B%22USE_CODE%22%5D%20%3C%20200)%20and%20(row%5B%22USE_CODE%22%5D%20not%20in%20range(130%2C%20141))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20axis%3D1%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%20%20%20%20other_residential%20%3D%20properties_df%5Bresidential_criteria%20%26%20~properties_df%5B%22HISTORIC_RESIDENTIAL%22%5D%5D%0A%20%20%20%20%20%20%20%20historic_resdential%20%3D%20properties_df%5Bresidential_criteria%20%26%20properties_df%5B%22HISTORIC_RESIDENTIAL%22%5D%5D%0A%0A%20%20%20%20%20%20%20%20trend_data.append(%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22year%22%3A%20COMPARE_YEAR%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22historic_residential%22%3A%20len(historic_resdential)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22other_residential%22%3A%20len(other_residential)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22historic_residential_units%22%3A%20historic_resdential%5B%22UNITS%22%5D.sum()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22other_residential_units%22%3A%20other_residential%5B%22UNITS%22%5D.sum()%0A%20%20%20%20%20%20%20%20%7D)%0A%20%20%20%20return%20(trend_data%2C)%0A%0A%0A%40app.cell%0Adef%20_(pd%2C%20trend_data)%3A%0A%20%20%20%20pd.DataFrame(trend_data).plot.area(%0A%20%20%20%20%20%20%20%20x%3D%22year%22%2C%20y%3D%5B%22other_residential%22%2C%20%22historic_residential%22%5D%2C%20%0A%20%20%20%20%20%20%20%20title%3D%22Residential%20structures%20changing%20historic%20status%22%2C%0A%20%20%20%20%20%20%20%20figsize%3D(15%2C%2010)%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(pd%2C%20trend_data)%3A%0A%20%20%20%20pd.DataFrame(trend_data).plot.area(%0A%20%20%20%20%20%20%20%20x%3D%22year%22%2C%0A%20%20%20%20%20%20%20%20y%3D%5B%22other_residential_units%22%2C%20%22historic_residential_units%22%5D%2C%0A%20%20%20%20%20%20%20%20title%3D%22Residential%20units%20changing%20historic%20status%22%2C%0A%20%20%20%20%20%20%20%20figsize%3D(15%2C%2010)%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
257a7559922d12be2b63007cbdfcbc95