Skip to content

Commit

Permalink
Use precomputed fuel type (#3266)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgboss authored Nov 29, 2023
1 parent 38de174 commit 9f77f68
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 24 additions & 0 deletions api/app/db/crud/auto_spatial_advisory.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,30 @@ async def get_all_sfms_fuel_types(session: AsyncSession) -> List[SFMSFuelType]:
return fuel_types


async def get_precomputed_high_hfi_fuel_type_areas_for_shape(session: AsyncSession, run_type: RunTypeEnum, run_datetime: datetime, for_date: date, advisory_shape_id: int) -> List[Row]:
perf_start = perf_counter()
stmt = (
select(AdvisoryFuelStats.advisory_shape_id, AdvisoryFuelStats.fuel_type, AdvisoryFuelStats.threshold, AdvisoryFuelStats.area, AdvisoryFuelStats.run_parameters)
.join_from(AdvisoryFuelStats, RunParameters, AdvisoryFuelStats.run_parameters == RunParameters.id)
.join_from(AdvisoryFuelStats, Shape, AdvisoryFuelStats.advisory_shape_id == Shape.id)
.where(
Shape.source_identifier == str(advisory_shape_id),
RunParameters.run_type == run_type.value,
RunParameters.run_datetime == run_datetime,
RunParameters.for_date == for_date,
)
.order_by(AdvisoryFuelStats.fuel_type)
.order_by(AdvisoryFuelStats.threshold)
)
result = await session.execute(stmt)
all_results = result.all()
perf_end = perf_counter()
delta = perf_end - perf_start
logger.info('%f delta count before and after fuel types/high hfi/zone query', delta)
return all_results



async def get_high_hfi_fuel_types_for_shape(session: AsyncSession,
run_type: RunTypeEnum,
run_datetime: datetime,
Expand Down
6 changes: 3 additions & 3 deletions api/app/routers/fba.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from app.db.crud.auto_spatial_advisory import (get_all_sfms_fuel_types,
get_all_hfi_thresholds,
get_hfi_area,
get_high_hfi_fuel_types_for_shape,
get_precomputed_high_hfi_fuel_type_areas_for_shape,
get_run_datetimes,
get_zonal_elevation_stats)
from app.db.models.auto_spatial_advisory import RunTypeEnum
Expand Down Expand Up @@ -82,11 +82,11 @@ async def get_hfi_fuels_data_for_fire_zone(run_type: RunType,
fuel_types = await get_all_sfms_fuel_types(session)

# get HFI/fuels data for specific zone
hfi_fuel_type_ids_for_zone = await get_high_hfi_fuel_types_for_shape(session,
hfi_fuel_type_ids_for_zone = await get_precomputed_high_hfi_fuel_type_areas_for_shape(session,
run_type=RunTypeEnum(run_type.value),
for_date=for_date,
run_datetime=run_datetime,
shape_id=zone_id)
advisory_shape_id=zone_id)
data = []

for record in hfi_fuel_type_ids_for_zone:
Expand Down

0 comments on commit 9f77f68

Please sign in to comment.