From 14dabb095c051adfe5f477100a7ccaf837482e29 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Thu, 13 Aug 2015 18:06:20 -0500 Subject: [PATCH] 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++;