Skip to content

Commit

Permalink
feat: use is_wildfire instead of a new boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronan committed Jul 11, 2024
1 parent 6669c5a commit 2cc5fc0
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 14 deletions.
8 changes: 5 additions & 3 deletions client/pyroclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This program is licensed under the Apache License 2.0.
# See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.

from typing import Dict
from typing import Dict, Optional
from urllib.parse import urljoin

import requests
Expand Down Expand Up @@ -188,19 +188,21 @@ def fetch_detections(self) -> Response:
timeout=self.timeout,
)

def fetch_unacknowledged_detections(self) -> Response:
def fetch_unacknowledged_detections(self, from_date: Optional[str] = None) -> Response:
"""List the detections accessible to the authenticated user
>>> from pyroclient import client
>>> api_client = Client("MY_USER_TOKEN")
>>> response = api_client.fetch_unacknowledged_detections()
>>> response = api_client.fetch_unacknowledged_detections("2023-07-04")
Returns:
HTTP response
"""
params = {"from_date": from_date}
return requests.get(
self.routes["detections-fetch-unck"],
headers=self.headers,
params=params,
timeout=self.timeout,
)

Expand Down
2 changes: 1 addition & 1 deletion src/app/api/api_v1/endpoints/detections.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async def fetch_unacknowledged_detections(
telemetry_client.capture(token_payload.sub, event="unacknowledged-fetch")

try:
all_unck_detections = [elt for elt in await detections.fetch_all() if not elt.acknowledged]
all_unck_detections = [elt for elt in await detections.fetch_all() if elt.is_wildfire is None]
if from_date is not None:
all_unck_detections = [detection for detection in all_unck_detections if detection.created_at >= from_date]
except Exception as e: # noqa
Expand Down
1 change: 0 additions & 1 deletion src/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class Detection(SQLModel, table=True):
azimuth: float = Field(..., gt=0, lt=360)
bucket_key: str
is_wildfire: Union[bool, None] = None
acknowledged: bool = Field(default=False, nullable=False)
created_at: datetime = Field(default_factory=datetime.utcnow, nullable=False)
updated_at: datetime = Field(default_factory=datetime.utcnow, nullable=False)

Expand Down
1 change: 0 additions & 1 deletion src/app/schemas/detections.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Azimuth(BaseModel):

class DetectionCreate(Azimuth):
camera_id: int = Field(..., gt=0)
acknowledged: bool = Field(default=False)
bucket_key: str


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def upgrade() -> None:
sa.Column("azimuth", sa.Float(), nullable=False),
sa.Column("bucket_key", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column("is_wildfire", sa.Boolean(), nullable=True),
sa.Column("acknowledged", sa.Boolean(), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ def downgrade() -> None:
op.drop_constraint("fk_user_orga", "user", type_="foreignkey")
op.drop_column("camera", "organization_id")
op.drop_column("user", "organization_idation_id")
op.drop_table("detection")
op.drop_table("organization")
3 changes: 0 additions & 3 deletions src/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
"azimuth": 43.7,
"bucket_key": "my_file",
"is_wildfire": True,
"acknowledged": False,
"created_at": datetime.strptime("2023-11-07T15:08:19.226673", dt_format),
"updated_at": datetime.strptime("2023-11-07T15:08:19.226673", dt_format),
},
Expand All @@ -101,7 +100,6 @@
"azimuth": 43.7,
"bucket_key": "my_file",
"is_wildfire": False,
"acknowledged": True,
"created_at": datetime.strptime("2023-11-07T15:08:19.226673", dt_format),
"updated_at": datetime.strptime("2023-11-07T15:08:19.226673", dt_format),
},
Expand All @@ -111,7 +109,6 @@
"azimuth": 43.7,
"bucket_key": "my_file",
"is_wildfire": None,
"acknowledged": False,
"created_at": datetime.strptime("2023-11-07T15:08:19.226673", dt_format),
"updated_at": datetime.strptime("2023-11-07T15:08:19.226673", dt_format),
},
Expand Down
6 changes: 3 additions & 3 deletions src/tests/endpoints/test_detections.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def test_create_detection(
assert {
k: v
for k, v in response.json().items()
if k not in {"created_at", "updated_at", "id", "is_wildfire", "bucket_key", "camera_id", "acknowledged"}
if k not in {"created_at", "updated_at", "id", "is_wildfire", "bucket_key", "camera_id"}
} == payload
assert response.json()["id"] == max(entry["id"] for entry in pytest.detection_table) + 1
assert response.json()["camera_id"] == pytest.camera_table[cam_idx]["id"]
Expand Down Expand Up @@ -136,8 +136,8 @@ async def test_fetch_detections(
("user_idx", "status_code", "status_detail", "expected_result"),
[
(None, 401, "Not authenticated", None),
(0, 200, None, [pytest.detection_table[0], pytest.detection_table[2]]),
(1, 200, None, [pytest.detection_table[0]]),
(0, 200, None, [pytest.detection_table[2]]),
(1, 200, None, []),
],
)
@pytest.mark.asyncio()
Expand Down

0 comments on commit 2cc5fc0

Please sign in to comment.