Skip to content

Commit

Permalink
Sync the processor data with the dashboard. (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrill committed Apr 28, 2021
1 parent 52ea0b1 commit b430667
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ All the configurations are grouped in *sections* and some of them can vary depen
- `Encoder`: Specifies the video encoder used by the processing pipeline.
- `MaxProcesses`: Defines the number of processes executed in the processor. If you are using multiple cameras per processor we recommend increasing this number.
- `DashboardURL`: Sets the url where the frontend is running. Unless you are using a custom domain, you should keep this value as https://app.lanthorn.ai/.
- `DashboardAuthorizationToken`: Configures the Authorization header required to sync the processor and the dashboard.
- `SlackChannel`: Configures the slack channel used by the notifications. The chosen slack channel must exist in the configured workspace.
- `OccupancyAlertsMinInterval`: Sets the desired interval (in seconds) between occupancy alerts.
- `MaxThreadRestarts`: Defines the number of restarts allowed per thread.
Expand Down
61 changes: 60 additions & 1 deletion api/routers/app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import requests

from fastapi import APIRouter
from starlette import status
from starlette.exceptions import HTTPException
from typing import Optional

from api.models.app import AppDTO
from api.utils import (extract_config, handle_response, update_config,
from api.utils import (extract_config, get_config, handle_response, update_config,
map_section_from_config, map_to_config_file_format)
from libs.metrics.in_out import InOutMetric


from .cameras import get_cameras

app_router = APIRouter()

Expand All @@ -28,3 +36,54 @@ def update_app_config(app: AppDTO, reboot_processor: Optional[bool] = True):
if not success:
return handle_response(app_dict, success)
return map_section_from_config("App", extract_config())


def _get_in_out_for_camera(camera_id: str):
in_out_file_path = InOutMetric.get_in_out_file_path(camera_id, get_config())
in_out_boundaries = InOutMetric.read_in_out_boundaries(in_out_file_path)
if not in_out_boundaries:
return []
return [
{
"name": in_out["name"],
"ax": in_out['in_out_boundary'][0][0],
"ay": in_out['in_out_boundary'][0][1],
"bx": in_out['in_out_boundary'][1][0],
"by": in_out['in_out_boundary'][1][1],
}
for in_out in in_out_boundaries["in_out_boundaries"]
]


@app_router.put("/dashboard-sync", status_code=status.HTTP_204_NO_CONTENT)
def sync_dashboard():
"""
Sync the processor data in the cloud dashbord
"""
config_dict = extract_config()
dashboard_url = config_dict["App"]["DashboardURL"]
endpoint_url = f"{dashboard_url}api/processor/sync/cameras"
authorization_token = config_dict["App"].get("DashboardAuthorizationToken")
headers = {
"content-type": "application/json",
"Authorization": authorization_token
}
if not authorization_token:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Missing authorization token"
)
cameras = [
{
"processor_camera_id": camera["id"],
"name": camera["name"],
"boundary_lines": _get_in_out_for_camera(camera["id"])
}
for camera in get_cameras()
]
response = requests.put(endpoint_url, json=cameras, headers=headers)
if response.status_code != status.HTTP_204_NO_CONTENT:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Error syncing processor with dashbord"
)
1 change: 1 addition & 0 deletions config-coral.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Resolution = 640,480
Encoder = videoconvert ! video/x-raw,format=I420 ! x264enc speed-preset=ultrafast
MaxProcesses = 1
DashboardURL = https://app.lanthorn.ai/
DashboardAuthorizationToken =
SlackChannel = lanthorn-notifications
; OccupancyAlertsMinInterval time is measured in seconds (if interval < 0 then no occupancy alerts are triggered)
OccupancyAlertsMinInterval = 180
Expand Down
1 change: 1 addition & 0 deletions config-jetson-nano.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ MaxProcesses = 1
;Encoder: nvvidconv ! nvv4l2h264enc
; attn: deepstream has nvvideoconvert which should be used with deepstream pipelines
DashboardURL = https://app.lanthorn.ai/
DashboardAuthorizationToken =
SlackChannel = lanthorn-notifications
; OccupancyAlertsMinInterval time is measured in seconds (if interval < 0 then no occupancy alerts are triggered)
OccupancyAlertsMinInterval = 180
Expand Down
1 change: 1 addition & 0 deletions config-jetson-tx2.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ MaxProcesses = 1
;Encoder: nvvidconv ! nvv4l2h264enc
; attn: deepstream has nvvideoconvert which should be used with deepstream pipelines
DashboardURL = https://app.lanthorn.ai/
DashboardAuthorizationToken =
SlackChannel = lanthorn-notifications
; OccupancyAlertsMinInterval time is measured in seconds (if interval < 0 then no occupancy alerts are triggered)
OccupancyAlertsMinInterval = 180
Expand Down
1 change: 1 addition & 0 deletions config-x86-gpu-tensorrt.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ MaxProcesses = 1
; WIP https://github.com/neuralet/neuralet/issues/91
;Encoder: videoconvert ! vaapih264enc
DashboardURL = https://app.lanthorn.ai/
DashboardAuthorizationToken =
EnableSlackNotifications = no
SlackChannel = lanthorn-notifications
; OccupancyAlertsMinInterval time is measured in seconds (if interval < 0 then no occupancy alerts are triggered)
Expand Down
1 change: 1 addition & 0 deletions config-x86-gpu.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ MaxProcesses = 1
; WIP https://github.com/neuralet/neuralet/issues/91
;Encoder: videoconvert ! vaapih264enc
DashboardURL = https://app.lanthorn.ai/
DashboardAuthorizationToken =
SlackChannel = lanthorn-notifications
OccupancyAlertsMinInterval = 180
MaxThreadRestarts = 5
Expand Down
1 change: 1 addition & 0 deletions config-x86-openvino.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ MaxProcesses = 2
; WIP https://github.com/neuralet/neuralet/issues/91
;Encoder: videoconvert ! vaapih264enc
DashboardURL = https://app.lanthorn.ai/
DashboardAuthorizationToken =
SlackChannel = lanthorn-notifications
; OccupancyAlertsMinInterval time is measured in seconds (if interval < 0 then no occupancy alerts are triggered)
OccupancyAlertsMinInterval = 180
Expand Down
1 change: 1 addition & 0 deletions config-x86.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ MaxProcesses = 1
; WIP https://github.com/neuralet/neuralet/issues/91
;Encoder: videoconvert ! vaapih264enc
DashboardURL = https://app.lanthorn.ai/
DashboardAuthorizationToken =
EnableSlackNotifications = no
SlackChannel = lanthorn-notifications
; OccupancyAlertsMinInterval time is measured in seconds (if interval < 0 then no occupancy alerts are triggered)
Expand Down

0 comments on commit b430667

Please sign in to comment.