From 14dabb095c051adfe5f477100a7ccaf837482e29 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Thu, 13 Aug 2015 18:06:20 -0500 Subject: [PATCH 1/3] set scroe to zero if less than zero --- src/zm_event.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/zm_event.cpp b/src/zm_event.cpp index 3e723fa48..2655742a6 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -567,13 +567,15 @@ void Event::AddFrame( Image *image, struct timeval timestamp, int score, Image * struct DeltaTimeval delta_time; DELTA_TIMEVAL( delta_time, timestamp, start_time, DT_PREC_2 ); - bool db_frame = (score>=0) || ((frames%config.bulk_frame_interval)==0) || !frames; + const char *frame_type = score>0?"Alarm":(score<0?"Bulk":"Normal"); + if ( score < 0 ) + score = 0; + bool db_frame = (score>=0) || ((frames%config.bulk_frame_interval)==0) || !frames; if ( db_frame ) { - const char *frame_type = score>0?"Alarm":(score<0?"Bulk":"Normal"); - Debug( 1, "Adding frame %d to DB", frames ); + Debug( 1, "Adding frame %d of type \"%s\" to DB", frames ); static char sql[ZM_SQL_MED_BUFSIZ]; snprintf( sql, sizeof(sql), "insert into Frames ( EventId, FrameId, Type, TimeStamp, Delta, Score ) values ( %d, %d, '%s', from_unixtime( %ld ), %s%ld.%02ld, %d )", id, frames, frame_type, timestamp.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec, score ); if ( mysql_query( &dbconn, sql ) ) @@ -583,8 +585,8 @@ void Event::AddFrame( Image *image, struct timeval timestamp, int score, Image * } last_db_frame = frames; - // We are writing a bulk frame - if ( score < 0 ) + // We are writing a Bulk frame + if ( !strcmp( frame_type,"Bulk") ) { snprintf( sql, sizeof(sql), "update Events set Length = %s%ld.%02ld, Frames = %d, AlarmFrames = %d, TotScore = %d, AvgScore = %d, MaxScore = %d where Id = %d", delta_time.positive?"":"-", delta_time.sec, delta_time.fsec, frames, alarm_frames, tot_score, (int)(alarm_frames?(tot_score/alarm_frames):0), max_score, id ); if ( mysql_query( &dbconn, sql ) ) @@ -597,7 +599,8 @@ void Event::AddFrame( Image *image, struct timeval timestamp, int score, Image * end_time = timestamp; - if ( score > 0 ) + // We are writing an Alarm frame + if ( !strcmp( frame_type,"Alarm") ) { alarm_frames++; From 19174adfa162e7ad616b435ce4ea8fc91d566678 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Thu, 13 Aug 2015 20:47:14 -0500 Subject: [PATCH 2/3] add frame_type to debug message --- src/zm_event.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zm_event.cpp b/src/zm_event.cpp index 2655742a6..47d41d300 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -575,7 +575,7 @@ void Event::AddFrame( Image *image, struct timeval timestamp, int score, Image * if ( db_frame ) { - Debug( 1, "Adding frame %d of type \"%s\" to DB", frames ); + Debug( 1, "Adding frame %d of type \"%s\" to DB", frames, frame_type ); static char sql[ZM_SQL_MED_BUFSIZ]; snprintf( sql, sizeof(sql), "insert into Frames ( EventId, FrameId, Type, TimeStamp, Delta, Score ) values ( %d, %d, '%s', from_unixtime( %ld ), %s%ld.%02ld, %d )", id, frames, frame_type, timestamp.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec, score ); if ( mysql_query( &dbconn, sql ) ) From 5b0288e5f5795f3e0eb400a5d842063fd7752307 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Fri, 14 Aug 2015 07:03:08 -0500 Subject: [PATCH 3/3] use frame_type instead of score in conditional --- src/zm_event.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zm_event.cpp b/src/zm_event.cpp index 47d41d300..1e8cfc791 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -571,7 +571,7 @@ void Event::AddFrame( Image *image, struct timeval timestamp, int score, Image * if ( score < 0 ) score = 0; - bool db_frame = (score>=0) || ((frames%config.bulk_frame_interval)==0) || !frames; + bool db_frame = (strcmp(frame_type,"Bulk") != 0) || ((frames%config.bulk_frame_interval)==0) || !frames; if ( db_frame ) {