Skip to content

Commit

Permalink
feat: add endpoints for AI flooding detection
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-milan committed Nov 14, 2023
1 parent 70ec14b commit 97ac0e5
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api_dados_rio/v2/clima_alagamento/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@
views.LastUpdate120MinFloodView,
basename="ultima_atualizacao_alagamento_120min",
)
router.register(
r"alagamento_detectado_ia",
views.AIFloodingDetectionView,
basename="alagamento_detectado_ia",
)
router.register(
r"ultima_atualizacao_alagamento_detectado_ia",
views.LastUpdateAIFloodingDetectionView,
basename="ultima_atualizacao_alagamento_detectado_ia",
)
77 changes: 77 additions & 0 deletions api_dados_rio/v2/clima_alagamento/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,80 @@ def list(self, request):
{"error": "Something went wrong. Try again later."},
status=500,
)


@method_decorator(
name="list",
decorator=swagger_auto_schema(
operation_summary="Retorna os pontos de alagamento detectados por IA.",
operation_description="""
**Resultado**: Retorna uma lista contendo todos os pontos de alagamento detectados por IA
no seguinte formato:
```json
[
{
"datetime": "",
"id_camera": "",
"url_camera": "",
"latitude": 0.0,
"longitude": 0.0,
"image_base64": "",
"ai_classification": [
{
"object": "alagamento",
"label": false,
"confidence": "",
},
...
],
},
...
]
```
""",
),
)
class AIFloodingDetectionView(LoggingMixin, ViewSet):
def list(self, request):
data_key = "flooding_detection_data"
try:
redis_url = getenv("REDIS_URL")
assert redis_url is not None
redis = RedisPal.from_url(redis_url)
# Get data and set cache
data = redis.get(data_key)
assert data is not None
assert isinstance(data, list)
assert len(data) > 0
return Response(data)
except Exception:
return Response(
{"error": "Something went wrong. Try again later."},
status=500,
)


@method_decorator(
name="list",
decorator=swagger_auto_schema(
operation_summary="Retorna o horário de atualização dos pontos de alagamento detectados por IA.",
operation_description="""
**Resultado**: Retorna um texto contendo o horário de atualização dos pontos de alagamento detectados por IA.
""",
),
)
class LastUpdateAIFloodingDetectionView(LoggingMixin, ViewSet):
def list(self, request):
last_update_key = "flooding_detection_last_update"
try:
redis_url = getenv("REDIS_URL")
assert redis_url is not None
redis = RedisPal.from_url(redis_url)
data = redis.get(last_update_key)
return Response(data)
except Exception:
return Response(
{"error": "Something went wrong. Try again later."},
status=500,
)

0 comments on commit 97ac0e5

Please sign in to comment.