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
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
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 @@
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,

Check warning on line 85 in api/app/routers/fba.py

View check run for this annotation

Codecov / codecov/patch

api/app/routers/fba.py#L85

Added line #L85 was not covered by tests
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
Loading