Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASA Labels to DB #3910

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Adds placename labels to advisory_shapes

Revision ID: c5bea0920d53
Revises: c9e46d098c73
Create Date: 2024-09-10 12:54:07.552418

"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy.orm.session import Session
from app.db.models.auto_spatial_advisory import Shape
from sqlalchemy import update
from app.utils.zone_units import get_zone_units_geojson

# revision identifiers, used by Alembic.
revision = "c5bea0920d53"
down_revision = "c9e46d098c73"
branch_labels = None
depends_on = None


def upgrade():
session = Session(bind=op.get_bind())

op.add_column("advisory_shapes", sa.Column("placename_label", sa.String(), nullable=True))

fire_zone_units = get_zone_units_geojson()
for feature in fire_zone_units.get("features", []):
properties = feature.get("properties", {})
object_id = properties.get("OBJECTID")

prefix = properties.get("FIRE_ZONE_")
suffix = properties.get("FIRE_ZON_1")
placename_label = f"{prefix}-{suffix}"

stmt = update(Shape).where(Shape.source_identifier == str(object_id)).values(placename_label=placename_label)

session.execute(stmt)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic ###
op.drop_column("advisory_shapes", "placename_label")
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion api/app/db/crud/auto_spatial_advisory.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ async def get_provincial_rollup(session: AsyncSession, run_type: RunTypeEnum, ru
Shape.id,
Shape.source_identifier,
Shape.combustible_area,
Shape.label,
Shape.placename_label,
FireCentre.name.label("fire_centre_name"),
HighHfiArea.id,
HighHfiArea.advisory_shape_id,
Expand Down
3 changes: 2 additions & 1 deletion api/app/db/models/auto_spatial_advisory.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Shape(Base):
combustible_area = Column(Float, nullable=True)
geom = Column(Geometry("MULTIPOLYGON", spatial_index=False, srid=NAD83_BC_ALBERS), nullable=False)
label = Column(String, nullable=True, index=False)
placename_label = Column(String, nullable=True, index=False)
fire_centre = Column(Integer, ForeignKey(FireCentre.id), nullable=True, index=True)


Expand Down Expand Up @@ -211,6 +212,7 @@ class AdvisoryTPIStats(Base):
upper_slope = Column(Integer, nullable=False, index=False)
pixel_size_metres = Column(Integer, nullable=False, index=False)


class CriticalHours(Base):
"""
Critical hours for a fuel type in a firezone unit.
Expand All @@ -225,4 +227,3 @@ class CriticalHours(Base):
fuel_type = Column(Integer, ForeignKey(SFMSFuelType.id), nullable=False, index=True)
start_hour = Column(Integer, nullable=False)
end_hour = Column(Integer, nullable=False)

2 changes: 1 addition & 1 deletion api/app/routers/fba.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async def get_provincial_summary(run_type: RunType, run_datetime: datetime, for_
fire_shape_area_details.append(
FireShapeAreaDetail(
fire_shape_id=row.source_identifier,
fire_shape_name=row.label,
fire_shape_name=row.placename_label,
fire_centre_name=row.fire_centre_name,
threshold=row.threshold,
combustible_area=row.combustible_area,
Expand Down
Loading