set scroe to zero if less than zero

This commit is contained in:
Andrew Bauer 2015-08-13 18:06:20 -05:00
parent 415521477c
commit 14dabb095c
1 changed files with 9 additions and 6 deletions

View File

@ -567,13 +567,15 @@ void Event::AddFrame( Image *image, struct timeval timestamp, int score, Image *
struct DeltaTimeval delta_time; struct DeltaTimeval delta_time;
DELTA_TIMEVAL( delta_time, timestamp, start_time, DT_PREC_2 ); 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 ) 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]; 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 ); 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 ) ) if ( mysql_query( &dbconn, sql ) )
@ -583,8 +585,8 @@ void Event::AddFrame( Image *image, struct timeval timestamp, int score, Image *
} }
last_db_frame = frames; last_db_frame = frames;
// We are writing a bulk frame // We are writing a Bulk frame
if ( score < 0 ) 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 ); 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 ) ) if ( mysql_query( &dbconn, sql ) )
@ -597,7 +599,8 @@ void Event::AddFrame( Image *image, struct timeval timestamp, int score, Image *
end_time = timestamp; end_time = timestamp;
if ( score > 0 ) // We are writing an Alarm frame
if ( !strcmp( frame_type,"Alarm") )
{ {
alarm_frames++; alarm_frames++;