mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-16 10:33:00 +03:00
CI / ARM Build (push) Canceled after 0s
CI / Jetson Jetpack 6 (push) Canceled after 0s
CI / AMD64 Build (push) Canceled after 0s
CI / AMD64 Extra Build (push) Canceled after 0s
CI / AMD64 Smoke Test (push) Canceled after 0s
CI / ARM Extra Build (push) Canceled after 0s
CI / Synaptics Build (push) Canceled after 0s
CI / Assemble and push default build (push) Canceled after 0s
* analytics notifications flag and device grant warnings - report notifications as on when any camera enables them, not only the global setting - don't warn about device nodes the runtime users can already use, such as world-rw nodes in an unprivileged LXC * clarify which stream the All Cameras dashboard uses * add exception catchall for autotracking calibration * only default review api after to 24 hours when no bounds are given The review endpoint replaced a missing or zero `after` with 24 hours ago, so a `before`-only query older than 24 hours returned nothing and `after=0` couldn't mean no lower bound. The default now applies only when neither `before` nor `after` is sent, a `before`-only query has no lower bound, and both bounds use `is not None` checks. The Live dashboard alerts bar sends no bounds and keeps the 24 hour window.
141 lines
5.1 KiB
Python
141 lines
5.1 KiB
Python
"""Tests for the features collector."""
|
|
|
|
import logging
|
|
import os
|
|
import unittest
|
|
|
|
from peewee import SqliteDatabase
|
|
from peewee_migrate import Router
|
|
from playhouse.sqliteq import SqliteQueueDatabase
|
|
|
|
from frigate.analytics.collectors import features
|
|
from frigate.analytics.schema import EnrichmentDevice, SemanticSearchModel
|
|
from frigate.models import User
|
|
from frigate.test.analytics_helpers import FRONT_CAMERA, make_config, make_context
|
|
from frigate.test.const import TEST_DB, TEST_DB_CLEANUPS
|
|
|
|
CONFIG = {
|
|
"mqtt": {"host": "mqtt", "enabled": True},
|
|
"genai": {
|
|
"local": {
|
|
"provider": "ollama",
|
|
"model": "llava",
|
|
"base_url": "http://ollama:11434",
|
|
"roles": ["descriptions", "embeddings"],
|
|
}
|
|
},
|
|
"semantic_search": {"enabled": True, "model": "local"},
|
|
"face_recognition": {"enabled": True, "model_size": "large"},
|
|
"birdseye": {"enabled": True, "modes": ["motion", "alerts"], "restream": True},
|
|
"proxy": {"header_map": {"user": "x-forwarded-user"}},
|
|
"camera_groups": {"outside": {"cameras": ["front"], "icon": "LuCar", "order": 0}},
|
|
"cameras": {
|
|
"front": {
|
|
**FRONT_CAMERA,
|
|
"semantic_search": {
|
|
"triggers": {
|
|
"cat": {
|
|
"type": "description",
|
|
"data": "a cat",
|
|
"threshold": 0.8,
|
|
"actions": ["notification"],
|
|
}
|
|
}
|
|
},
|
|
}
|
|
},
|
|
}
|
|
|
|
|
|
class TestFeaturesCollector(unittest.TestCase):
|
|
def setUp(self):
|
|
migrate_db = SqliteDatabase(TEST_DB)
|
|
del logging.getLogger("peewee_migrate").handlers[:]
|
|
Router(migrate_db).run()
|
|
migrate_db.close()
|
|
self.db = SqliteQueueDatabase(TEST_DB)
|
|
self.db.bind([User])
|
|
|
|
def tearDown(self):
|
|
# close() leaves the queue's writer thread running against the deleted file
|
|
self.db.stop()
|
|
|
|
if not self.db.is_closed():
|
|
self.db.close()
|
|
|
|
for file in TEST_DB_CLEANUPS:
|
|
try:
|
|
os.remove(file)
|
|
except OSError:
|
|
pass
|
|
|
|
def test_collects_enrichments_genai_integrations_and_users(self):
|
|
for username, role in (("a", "admin"), ("v", "viewer"), ("o", "operator")):
|
|
User.create(
|
|
username=username, role=role, password_hash="x", notification_tokens=[]
|
|
)
|
|
|
|
stats = {
|
|
"embeddings": {
|
|
"devices": {
|
|
"face_recognition": "OpenVINO GPU.0",
|
|
"semantic_search": "CUDA",
|
|
}
|
|
}
|
|
}
|
|
|
|
section = features.collect(make_context(make_config(CONFIG), stats))
|
|
|
|
self.assertEqual(section.face_recognition.device, EnrichmentDevice.openvino_gpu)
|
|
self.assertEqual(section.face_recognition.model_size, "large")
|
|
self.assertIsNone(section.lpr.device)
|
|
self.assertEqual(section.semantic_search.model, SemanticSearchModel.genai)
|
|
self.assertEqual(section.semantic_search.device, EnrichmentDevice.cuda)
|
|
self.assertEqual(section.semantic_search.triggers, 1)
|
|
self.assertEqual(section.genai.providers, {"ollama": 1})
|
|
self.assertEqual(section.genai.roles, {"descriptions": 1, "embeddings": 1})
|
|
self.assertEqual(section.birdseye.modes, ["motion", "alerts"])
|
|
self.assertTrue(section.mqtt)
|
|
self.assertTrue(section.proxy_auth)
|
|
self.assertEqual(section.users, {"admin": 1, "viewer": 1, "custom": 1})
|
|
self.assertEqual((section.camera_groups, section.profiles), (1, 0))
|
|
self.assertFalse(section.plus_api_key)
|
|
self.assertFalse(section.notifications)
|
|
|
|
def test_camera_notifications_count_as_on(self):
|
|
config = {
|
|
**CONFIG,
|
|
"cameras": {"front": {**FRONT_CAMERA, "notifications": {"enabled": True}}},
|
|
}
|
|
|
|
section = features.collect(make_context(make_config(config), {}))
|
|
|
|
self.assertTrue(section.notifications)
|
|
|
|
|
|
class TestFeatureMappings(unittest.TestCase):
|
|
def test_enrichment_device_labels(self):
|
|
cases = {
|
|
"CPU": EnrichmentDevice.cpu,
|
|
"MIGraphX": EnrichmentDevice.migraphx,
|
|
"OpenVINO NPU": EnrichmentDevice.openvino_npu,
|
|
"OpenVINO GPU.0,CPU": EnrichmentDevice.openvino_gpu,
|
|
"OpenVINO (CPU)": EnrichmentDevice.openvino_cpu,
|
|
"OpenVINO": EnrichmentDevice.other,
|
|
"CoreML": EnrichmentDevice.other,
|
|
}
|
|
|
|
for label, device in cases.items():
|
|
with self.subTest(label=label):
|
|
self.assertEqual(features.enrichment_device(label), device)
|
|
|
|
self.assertIsNone(features.enrichment_device(None))
|
|
|
|
def test_models_named_after_a_provider_are_genai(self):
|
|
self.assertEqual(features.semantic_model("jinav2"), SemanticSearchModel.jinav2)
|
|
self.assertEqual(
|
|
features.semantic_model("my-ollama"), SemanticSearchModel.genai
|
|
)
|
|
self.assertIsNone(features.semantic_model(None))
|
|
self.assertEqual(features.transcription_model("openai"), "genai")
|