From e2a81cc2c5454192f5039757b809611131c6269d Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 2 Jan 2022 18:38:34 -0500 Subject: [PATCH] make max_score an int to get rid of the casts. Move assignment of it above the event UPDATE sql so that it is immediately accurate. --- src/zm_event.cpp | 15 ++++++++------- src/zm_event.h | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/zm_event.cpp b/src/zm_event.cpp index 2d95ec23a..f927eac5c 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -55,7 +55,7 @@ Event::Event( alarm_frames(0), alarm_frame_written(false), tot_score(0), - max_score(0), + max_score(-1), //path(""), //snapshit_file(), //alarm_file(""), @@ -486,12 +486,12 @@ void Event::AddFrame(Image *image, Debug(1, "frames %d, score %d max_score %d", frames, score, max_score); // If this is the first frame, we should add a thumbnail to the event directory - if ((frames == 1) || (score > (int)max_score)) { + if ((frames == 1) || (score > max_score)) { write_to_db = true; // web ui might show this as thumbnail, so db needs to know about it. Debug(1, "Writing snapshot"); WriteFrameImage(image, timestamp, snapshot_file.c_str()); } else { - Debug(1, "Not Writing snapshot because score %d > max %d", score, max_score); + Debug(1, "Not Writing snapshot because frames %d score %d > max %d", frames, score, max_score); } // We are writing an Alarm frame @@ -523,11 +523,15 @@ void Event::AddFrame(Image *image, bool db_frame = ( frame_type == BULK ) or ( frame_type == ALARM ) or ( frames == 1 ) - or ( score > (int)max_score ) + or ( score > max_score ) or ( monitor_state == Monitor::ALERT ) or ( monitor_state == Monitor::ALARM ) or ( monitor_state == Monitor::PREALARM ); + if (score > max_score) { + max_score = score; + } + if (db_frame) { Microseconds delta_time = std::chrono::duration_cast(timestamp - start_time); Debug(1, "Frame delta is %.2f s - %.2f s = %.2f s, score %u zone_stats.size %zu", @@ -568,9 +572,6 @@ void Event::AddFrame(Image *image, } // end if frame_type == BULK } // end if db_frame - if (score > (int) max_score) { - max_score = score; - } end_time = timestamp; } diff --git a/src/zm_event.h b/src/zm_event.h index 611b2f716..a26c029b5 100644 --- a/src/zm_event.h +++ b/src/zm_event.h @@ -77,8 +77,8 @@ class Event { int frames; int alarm_frames; bool alarm_frame_written; - unsigned int tot_score; - unsigned int max_score; + int tot_score; + int max_score; std::string path; std::string snapshot_file; std::string alarm_file;