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

Use precomputed fuel type #3266

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Changes from 1 commit
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
Next Next commit
Use precomputed fuel type
dgboss committed Nov 28, 2023
commit d96c0ab1e8eba9b8141bafaecd01941913198eda
24 changes: 24 additions & 0 deletions api/app/db/crud/auto_spatial_advisory.py
Original file line number Diff line number Diff line change
@@ -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,
6 changes: 3 additions & 3 deletions api/app/routers/fba.py
Original file line number Diff line number Diff line change
@@ -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
@@ -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: