Skip to content

Commit e96a3fd

Browse files
Processor Basic Info Endpoint. HasBeenConfigured Config (#84)
* Processor Basic Info Endpoint, Added HasBeenConfigured Config Co-authored-by: Mathias Claassen <mathias@xmartlabs.com>
1 parent bf82aad commit e96a3fd

14 files changed

+92
-43
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NOTIFICATION_EMAIL_FROM=noreply@yourdomain.com

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ oauth2_cred.json
1616
.aws
1717
venv/
1818
slack_token.txt
19+
.env

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,16 @@ You can read and modify the configurations in `config-*.ini` files, accordingly:
212212

213213
`config-x86-openvino.ini`: for x86 systems accelerated with Openvino
214214

215+
Please note that if you modify these values you should also set `[App]` `HasBeenConfigured` to `"True"`.
216+
This allows for a client to recognize if this processor was previously configured.
217+
215218
You can also modify some of them using the [UI](https://beta.lanthorn.ai).
216219
If you choose this option, make sure to mount the config file as a volume to keep the changes after any restart of the container.
217220

218221
All the configurations are grouped in *sections* and some of them can vary depending on the chosen device.
219222

220223
- `[App]`
224+
- `HasBeenConfigured`: A boolean parameter that states whether the *config.ini* was set up or not.
221225
- `Resolution`: Specifies the image resolution that the whole processor will use. If you are using a single camera we recommend using that resolution.
222226
- `Encoder`: Specifies the video encoder used by the processing pipeline.
223227
- `MaxProcesses`: Defines the number of processes executed in the processor. If you are using multiple cameras per processor we recommend increasing this number.

api/config.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22

33
from fastapi import APIRouter
4+
from pydantic import BaseModel
45
from typing import Optional
56

67
from .areas import map_area, map_to_area_file_format
@@ -9,12 +10,28 @@
910
from .utils import (
1011
extract_config, handle_response, update_and_restart_config
1112
)
13+
from constants import PROCESSOR_VERSION
1214

1315
logger = logging.getLogger(__name__)
1416

1517
config_router = APIRouter()
1618

1719

20+
class ConfigInfo(BaseModel):
21+
version: str
22+
device: str
23+
has_been_configured: bool
24+
25+
class Config:
26+
schema_extra = {
27+
"example": {
28+
"version": PROCESSOR_VERSION,
29+
"device": "device",
30+
"has_been_configured": True
31+
}
32+
}
33+
34+
1835
def map_to_config_file_format(config_dto: ConfigDTO):
1936
config_dict = dict()
2037
for count, camera in enumerate(config_dto.cameras):
@@ -33,6 +50,18 @@ def map_config(config, options):
3350
}
3451

3552

53+
def processor_info(config):
54+
has_been_configured = bool(config["App"]["HasBeenConfigured"])
55+
device = config["Detector"]["Device"]
56+
if config["Detector"]["Name"] == "openvino":
57+
device += "-openvino"
58+
return {
59+
"version": PROCESSOR_VERSION,
60+
"device": device,
61+
"has_been_configured": has_been_configured
62+
}
63+
64+
3665
@config_router.get("", response_model=ConfigDTO)
3766
async def get_config(options: Optional[str] = ""):
3867
"""
@@ -50,3 +79,11 @@ async def update_config(config: ConfigDTO):
5079
config_dict = map_to_config_file_format(config)
5180
success = update_and_restart_config(config_dict)
5281
return handle_response(config_dict, success)
82+
83+
84+
@config_router.get("/info", response_model=ConfigInfo)
85+
async def get_processor_info():
86+
"""
87+
Returns basic info regarding this processor
88+
"""
89+
return processor_info(extract_config())

api/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ fastapi==0.61.1
44
pandas==1.1.2
55
pyhumps==1.6.1
66
pytest==6.0.1
7+
python-dotenv==0.15.0
78
requests==2.24.0
89
schedule==0.6.0
10+
slackclient==2.8.2
911
uvicorn==0.11.8
1012
yagmail==0.11.224
11-
slackclient==2.8.2

api/settings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from pydantic import BaseSettings
22
from libs.config_engine import ConfigEngine
33

4-
54
class Settings:
65
instance = None
76

config-coral.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[App]
2+
HasBeenConfigured = False
23
Resolution = 640,480
34
Encoder = videoconvert ! video/x-raw,format=I420 ! x264enc speed-preset=ultrafast
45
MaxProcesses = 1

config-jetson.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[App]
2+
HasBeenConfigured = False
23
Resolution = 640,480
34
Encoder: videoconvert ! video/x-raw,format=I420 ! x264enc speed-preset=ultrafast
45
MaxProcesses = 1

config-x86-gpu.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ QueuePort = 8010
1111
QueueAuthKey = shibalba
1212

1313
[App]
14+
HasBeenConfigured = False
1415
Resolution = 640,480
1516
Encoder = videoconvert ! video/x-raw,format=I420 ! x264enc speed-preset=ultrafast
1617
MaxProcesses = 1

config-x86-openvino.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ QueuePort = 8010
1111
QueueAuthKey = shibalba
1212

1313
[App]
14+
HasBeenConfigured = False
1415
Resolution = 640,480
1516
Encoder = videoconvert ! video/x-raw,format=I420 ! x264enc speed-preset=ultrafast
1617
MaxProcesses = 2

0 commit comments

Comments
 (0)