mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-01-22 20:18:30 +03:00
Refactor temperatures calculations to use within detector block
This commit is contained in:
parent
513bede475
commit
2ce8ef120b
@ -98,6 +98,70 @@ def get_temperatures() -> dict[str, float]:
|
|||||||
return temps
|
return temps
|
||||||
|
|
||||||
|
|
||||||
|
def get_detector_temperature(
|
||||||
|
detector_type: str,
|
||||||
|
detector_index_by_type: dict[str, int],
|
||||||
|
) -> Optional[float]:
|
||||||
|
"""Get temperature for a specific detector based on its type."""
|
||||||
|
if detector_type == "edgetpu":
|
||||||
|
# Get temperatures for all attached Corals
|
||||||
|
base = "/sys/class/apex/"
|
||||||
|
if os.path.isdir(base):
|
||||||
|
apex_devices = sorted(os.listdir(base))
|
||||||
|
index = detector_index_by_type.get("edgetpu", 0)
|
||||||
|
if index < len(apex_devices):
|
||||||
|
apex_name = apex_devices[index]
|
||||||
|
temp = read_temperature(os.path.join(base, apex_name, "temp"))
|
||||||
|
if temp is not None:
|
||||||
|
return temp
|
||||||
|
elif detector_type == "hailo8l":
|
||||||
|
# Get temperatures for Hailo devices
|
||||||
|
hailo_temps = get_hailo_temps()
|
||||||
|
if hailo_temps:
|
||||||
|
hailo_device_names = sorted(hailo_temps.keys())
|
||||||
|
index = detector_index_by_type.get("hailo8l", 0)
|
||||||
|
if index < len(hailo_device_names):
|
||||||
|
device_name = hailo_device_names[index]
|
||||||
|
return hailo_temps[device_name]
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_detector_stats(
|
||||||
|
stats_tracking: StatsTrackingTypes,
|
||||||
|
) -> dict[str, dict[str, Any]]:
|
||||||
|
"""Get stats for all detectors, including temperatures based on detector type."""
|
||||||
|
detector_stats: dict[str, dict[str, Any]] = {}
|
||||||
|
detector_type_indices: dict[str, int] = {}
|
||||||
|
|
||||||
|
for name, detector in stats_tracking["detectors"].items():
|
||||||
|
pid = detector.detect_process.pid if detector.detect_process else None
|
||||||
|
detector_type = detector.detector_config.type
|
||||||
|
|
||||||
|
# Keep track of the index for each detector type to match temperatures correctly
|
||||||
|
current_index = detector_type_indices.get(detector_type, 0)
|
||||||
|
detector_type_indices[detector_type] = current_index + 1
|
||||||
|
|
||||||
|
detector_stat = {
|
||||||
|
"inference_speed": round(detector.avg_inference_speed.value * 1000, 2), # type: ignore[attr-defined]
|
||||||
|
# issue https://github.com/python/typeshed/issues/8799
|
||||||
|
# from mypy 0.981 onwards
|
||||||
|
"detection_start": detector.detection_start.value, # type: ignore[attr-defined]
|
||||||
|
# issue https://github.com/python/typeshed/issues/8799
|
||||||
|
# from mypy 0.981 onwards
|
||||||
|
"pid": pid,
|
||||||
|
}
|
||||||
|
|
||||||
|
temp = get_detector_temperature(detector_type, {detector_type: current_index})
|
||||||
|
|
||||||
|
if temp is not None:
|
||||||
|
detector_stat["temperature"] = round(temp, 1)
|
||||||
|
|
||||||
|
detector_stats[name] = detector_stat
|
||||||
|
|
||||||
|
return detector_stats
|
||||||
|
|
||||||
|
|
||||||
def get_processing_stats(
|
def get_processing_stats(
|
||||||
config: FrigateConfig, stats: dict[str, str], hwaccel_errors: list[str]
|
config: FrigateConfig, stats: dict[str, str], hwaccel_errors: list[str]
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -296,18 +360,7 @@ def stats_snapshot(
|
|||||||
"audio_dBFS": round(camera_stats.audio_dBFS.value, 4),
|
"audio_dBFS": round(camera_stats.audio_dBFS.value, 4),
|
||||||
}
|
}
|
||||||
|
|
||||||
stats["detectors"] = {}
|
stats["detectors"] = get_detector_stats(stats_tracking)
|
||||||
for name, detector in stats_tracking["detectors"].items():
|
|
||||||
pid = detector.detect_process.pid if detector.detect_process else None
|
|
||||||
stats["detectors"][name] = {
|
|
||||||
"inference_speed": round(detector.avg_inference_speed.value * 1000, 2), # type: ignore[attr-defined]
|
|
||||||
# issue https://github.com/python/typeshed/issues/8799
|
|
||||||
# from mypy 0.981 onwards
|
|
||||||
"detection_start": detector.detection_start.value, # type: ignore[attr-defined]
|
|
||||||
# issue https://github.com/python/typeshed/issues/8799
|
|
||||||
# from mypy 0.981 onwards
|
|
||||||
"pid": pid,
|
|
||||||
}
|
|
||||||
stats["camera_fps"] = round(total_camera_fps, 2)
|
stats["camera_fps"] = round(total_camera_fps, 2)
|
||||||
stats["process_fps"] = round(total_process_fps, 2)
|
stats["process_fps"] = round(total_process_fps, 2)
|
||||||
stats["skipped_fps"] = round(total_skipped_fps, 2)
|
stats["skipped_fps"] = round(total_skipped_fps, 2)
|
||||||
@ -393,7 +446,6 @@ def stats_snapshot(
|
|||||||
"version": VERSION,
|
"version": VERSION,
|
||||||
"latest_version": stats_tracking["latest_frigate_version"],
|
"latest_version": stats_tracking["latest_frigate_version"],
|
||||||
"storage": {},
|
"storage": {},
|
||||||
"temperatures": get_temperatures(),
|
|
||||||
"last_updated": int(time.time()),
|
"last_updated": int(time.time()),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user