Skip to content

Commit

Permalink
Square area result
Browse files Browse the repository at this point in the history
  • Loading branch information
conbrad committed Aug 13, 2024
1 parent 1576bee commit a8517bc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 5 additions & 3 deletions api/app/routers/fba.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Routers for Auto Spatial Advisory"""

import logging
import math
from datetime import date, datetime
from typing import List
from fastapi import APIRouter, Depends
Expand Down Expand Up @@ -174,9 +175,10 @@ async def get_fire_zone_tpi_stats(fire_zone_id: int, run_type: RunType, run_date
logger.info("/fba/fire-zone-tpi-stats/")
async with get_async_read_session_scope() as session:
stats = await get_zonal_tpi_stats(session, fire_zone_id, run_type, run_datetime, for_date)
square_metres = math.pow(stats.pixel_size_metres, 2)
return FireZoneTPIStats(
fire_zone_id=fire_zone_id,
valley_bottom=stats.valley_bottom * stats.pixel_size_metres,
mid_slope=stats.mid_slope * stats.pixel_size_metres,
upper_slope=stats.upper_slope * stats.pixel_size_metres,
valley_bottom=stats.valley_bottom * square_metres,
mid_slope=stats.mid_slope * square_metres,
upper_slope=stats.upper_slope * square_metres,
)
2 changes: 1 addition & 1 deletion api/app/schemas/fba.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class FireZoneElevationStats(BaseModel):


class FireZoneTPIStats(BaseModel):
"""Classified TPI areas of the fire zone contributing to the HFI >4k"""
"""Classified TPI areas of the fire zone contributing to the HFI >4k. Each area is in square metres."""

fire_zone_id: int
valley_bottom: int
Expand Down
8 changes: 5 additions & 3 deletions api/app/tests/fba/test_fba_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest.mock import patch
import math
import pytest
from fastapi.testclient import TestClient
from datetime import date, datetime, timezone
Expand Down Expand Up @@ -102,8 +103,9 @@ def test_get_sfms_run_datetimes_authorized(client: TestClient):
def test_get_fire_zone_tpi_stats_authorized(client: TestClient):
"""Allowed to get fire zone tpi stats when authorized"""
response = client.get(get_fire_zone_tpi_stats_url)
square_metres = math.pow(mock_tpi_stats.pixel_size_metres, 2)
assert response.status_code == 200
assert response.json()["fire_zone_id"] == 1
assert response.json()["valley_bottom"] == mock_tpi_stats.valley_bottom * mock_tpi_stats.pixel_size_metres
assert response.json()["mid_slope"] == mock_tpi_stats.mid_slope * mock_tpi_stats.pixel_size_metres
assert response.json()["upper_slope"] == mock_tpi_stats.upper_slope * mock_tpi_stats.pixel_size_metres
assert response.json()["valley_bottom"] == mock_tpi_stats.valley_bottom * square_metres
assert response.json()["mid_slope"] == mock_tpi_stats.mid_slope * square_metres
assert response.json()["upper_slope"] == mock_tpi_stats.upper_slope * square_metres

0 comments on commit a8517bc

Please sign in to comment.