mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-02 11:50:31 +03:00
Rate events over at least one second (#24455)
* Rate events over at least one second EventsPerSecond.eps() divided the event count by the time since start(), which can be a few milliseconds right after a restart. Frames buffered during an ffmpeg restart then report as 100+ fps, and the same happens to the detector fps. Use a window of at least one second. * Keep sub-second windows consistent Floor the divisor at the window length when the window is shorter than a second, so a caller with a sub-second window still gets its true rate.
This commit is contained in:
@@ -56,10 +56,13 @@ class EventsPerSecond:
|
||||
self._start = now
|
||||
# compute the (approximate) events in the last n seconds
|
||||
self.expire_timestamps(now)
|
||||
seconds = min(now - self._start, self._last_n_seconds)
|
||||
# avoid divide by zero
|
||||
if seconds == 0:
|
||||
seconds = 1
|
||||
# rate over at least one second (or the whole window, if shorter),
|
||||
# so a burst of events right after start() is not divided by a
|
||||
# tiny window
|
||||
seconds = max(
|
||||
min(now - self._start, self._last_n_seconds),
|
||||
min(1.0, self._last_n_seconds),
|
||||
)
|
||||
return len(self._timestamps) / seconds
|
||||
|
||||
# remove aged out timestamps
|
||||
|
||||
Reference in New Issue
Block a user