import solara import duckdb from dashboard_helpers import build_stats, build_station_map, build_fire_stats import os import logging import solara.server.starlette as solara_server from starlette.staticfiles import StaticFiles from starlette.routing import Mount solara_server.app.router.routes.insert(0, Mount("/deck", app=StaticFiles(directory="/app"), name="deck_static") ) logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) DB_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'processed_dashboard.db') if not os.path.exists(DB_PATH): raise FileNotFoundError(f"Database not found at {DB_PATH}") try: con = duckdb.connect(DB_PATH, read_only=True) con.load_extension('spatial') # NO install_extension — it's pre-bundled in the Docker image logger.info("Database connected successfully") except Exception as e: logger.error(f"Database connection failed: {e}") raise selected_scenario = solara.reactive("Low") selected_tier = solara.reactive("Both") selected_warming = solara.reactive("Current") PERSONS_PER_UNIT = 3.11 # acs data for beautiful los angeles county @solara.component def Page(): with solara.Column(style={"max-width": "1600px", "margin": "0 auto", "width": "80%"}): solara.Title("SB 79 Wildfire Risk Dashboard") solara.Style(""" .v-menu__content { z-index: 9999 !important; } .v-select__slot { z-index: 9999 !important; } .jupyter-widgets-output-area { max-width: 1200px !important; margin-left: auto !important; margin-right: auto !important; padding: 0 24px !important; } body > div, .solara-app-root { max-width: 1200px !important; margin-left: auto !important; margin-right: auto !important; } """) solara.Markdown("# SB 79 Transit-Oriented Development and Wildfire Risk", style={"text-align": "center"}) solara.Markdown("### By Chase H. Baugh", style={"text-align": "center"}) solara.Markdown("""
Los Angeles is the nation's largest county and second largest city by population. With a regional economy of global importance, renowned arts and cultural institutions, and year-round perfect weather, tinseltown attracts people from all over the nation and all over the world. The result of large demand and laws that mean environmental review, rezoning, and permitting must move through molasses means one of the worst housing crises in our nation. However, California is not going to go down without a fight. Passed by the California State Assembly and State Senate and signed into law by Governor Gavin Newsom, Senate Bill 79 (SB79) allows for the construction of multifamily housing surrounding rapid transportation stations by overpowering local zoning depending on the type of transit service and the distance from the service.
""") solara.Select( label="Development Scenario", value=selected_scenario, values=["Low","Medium","High"] ) solara.Select( label="Station Tier", value=selected_tier, values=["Both", "Tier 1", "Tier 2"] ) solara.Select( label="Warming Scenario", value=selected_warming, values=["Current", "Moderate (RCP 4.5)", "High (RCP 8.5)"] ) with solara.Card(title="SB 79 Station Buffers and Wildfire Risk"): try: m = build_station_map(con, selected_tier.value, selected_warming.value) solara.display(m) except Exception as e: solara.Markdown(f"**Map error:** {e}") with solara.GridFixed(columns=2): # left column with solara.Column(): try: stats = build_stats(con, selected_scenario.value, selected_tier.value) with solara.Card(title="Total Projected Units"): solara.Markdown(f"## {int(stats['total_units'][0]):,}") with solara.Card(title="Total Parcels Affected"): solara.Markdown(f"## {int(stats['total_parcels'][0]):,}") total_units = int(stats['total_units'][0]) total_population = int(total_units * PERSONS_PER_UNIT) with solara.Card(title="Population Carrying Capacity"): solara.Markdown(f"**Estimated residents able to be housed:** {total_population:,}") solara.Markdown(f"*(Based on {PERSONS_PER_UNIT} people/unit, LA County ACS Data)*") fire_stats = build_fire_stats(con, selected_scenario.value, selected_tier.value, selected_warming.value) with solara.Card(title="Units in Wildfire Risk Zones by Hazard Class"): for _, row in fire_stats.iterrows(): solara.Markdown(f"**{row['HAZ_CLASS']}:** {int(row['units']):,} units") except Exception as e: solara.Markdown(f"**Stats error:** {e}") with solara.Column(): with solara.Card(title="3D Development Scenario"): try: scenario_key = selected_scenario.value.lower().replace("medium", "med") solara.HTML( tag="iframe", attributes={"src": f"/deck/deck_{scenario_key}.html", "width": "100%", "height": "500px"}, style={"border": "none"} ) solara.Markdown(""" **Column Height** = Projected housing units in the chosen SB79 Implementation Scenario **Color** = Parcels eligible under SB79 *Taller columns = more potential housing* """) except Exception as e: logger.error(f"build_3d_map failed: {e}", exc_info=True) solara.Markdown(f"**3d map error:** {e}") Page()