From a8517bc7a28b3dd86e331c69cb8e70f143b1c56f Mon Sep 17 00:00:00 2001 From: Conor Brady Date: Tue, 13 Aug 2024 08:47:51 -0700 Subject: [PATCH] Square area result --- api/app/routers/fba.py | 8 +++++--- api/app/schemas/fba.py | 2 +- api/app/tests/fba/test_fba_endpoint.py | 8 +++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/api/app/routers/fba.py b/api/app/routers/fba.py index 19a051c59..7af041a04 100644 --- a/api/app/routers/fba.py +++ b/api/app/routers/fba.py @@ -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 @@ -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, ) diff --git a/api/app/schemas/fba.py b/api/app/schemas/fba.py index 5e3a3bf8d..4a3c60a82 100644 --- a/api/app/schemas/fba.py +++ b/api/app/schemas/fba.py @@ -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 diff --git a/api/app/tests/fba/test_fba_endpoint.py b/api/app/tests/fba/test_fba_endpoint.py index 9e5677611..191d7d984 100644 --- a/api/app/tests/fba/test_fba_endpoint.py +++ b/api/app/tests/fba/test_fba_endpoint.py @@ -1,4 +1,5 @@ from unittest.mock import patch +import math import pytest from fastapi.testclient import TestClient from datetime import date, datetime, timezone @@ -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