diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 71befb769..bb1ea435b 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -1551,8 +1551,19 @@ bool Monitor::Analyse() } if ( config.record_event_stats && state == ALARM ) { - zones[i]->RecordStats( event ); + std::string note("Alarm"); + struct timeval * p_timestamp = snap->timestamp; + zones[i]->RecordStats( event, note, *p_timestamp ); } + else + { + if ( config.record_event_stats ) + { + std::string note("Idle"); + struct timeval * p_timestamp = snap->timestamp; + zones[i]->RecordStats( event, note, *p_timestamp ); + } + } } } if ( got_anal_image ) @@ -1578,7 +1589,18 @@ bool Monitor::Analyse() { if ( config.record_event_stats && state == ALARM ) { - zones[i]->RecordStats( event ); + std::string note("Alarm"); + struct timeval * p_timestamp = snap->timestamp; + zones[i]->RecordStats( event, note, *p_timestamp ); + } + else + { + if ( config.record_event_stats ) + { + std::string note("Idle"); + struct timeval * p_timestamp = snap->timestamp; + zones[i]->RecordStats( event, note, *p_timestamp ); + } } } } diff --git a/src/zm_zone.cpp b/src/zm_zone.cpp index 90c954d9e..db22f6ee3 100644 --- a/src/zm_zone.cpp +++ b/src/zm_zone.cpp @@ -111,10 +111,10 @@ Zone::~Zone() delete[] ranges; } -void Zone::RecordStats( const Event *event ) +void Zone::RecordStats( const Event *event, std::string const& note, timeval & timestamp ) { static char sql[ZM_SQL_MED_BUFSIZ]; - snprintf( sql, sizeof(sql), "insert into Stats set MonitorId=%d, ZoneId=%d, EventId=%d, FrameId=%d, PixelDiff=%d, AlarmPixels=%d, FilterPixels=%d, BlobPixels=%d, Blobs=%d, MinBlobSize=%d, MaxBlobSize=%d, MinX=%d, MinY=%d, MaxX=%d, MaxY=%d, Score=%d", monitor->Id(), id, event->Id(), event->Frames()+1, pixel_diff, alarm_pixels, alarm_filter_pixels, alarm_blob_pixels, alarm_blobs, min_blob_size, max_blob_size, alarm_box.LoX(), alarm_box.LoY(), alarm_box.HiX(), alarm_box.HiY(), score ); + snprintf( sql, sizeof(sql), "insert into Stats set MonitorId=%d, ZoneId=%d, EventId=%d, FrameId=%d, PixelDiff=%d, AlarmPixels=%d, FilterPixels=%d, BlobPixels=%d, Blobs=%d, MinBlobSize=%d, MaxBlobSize=%d, MinX=%d, MinY=%d, MaxX=%d, MaxY=%d, Score=%d, State='%s', Timestamp=FROM_UNIXTIME( %ld )", monitor->Id(), id, event->Id(), event->Frames()+1, pixel_diff, alarm_pixels, alarm_filter_pixels, alarm_blob_pixels, alarm_blobs, min_blob_size, max_blob_size, alarm_box.LoX(), alarm_box.LoY(), alarm_box.HiX(), alarm_box.HiY(), score, note.c_str(), timestamp.tv_sec ); if ( mysql_query( &dbconn, sql ) ) { Error( "Can't insert event stats: %s", mysql_error( &dbconn ) ); diff --git a/src/zm_zone.h b/src/zm_zone.h index c431f88a0..296cc896a 100644 --- a/src/zm_zone.h +++ b/src/zm_zone.h @@ -143,7 +143,7 @@ public: max_blob_size = 0; score = 0; } - void RecordStats( const Event *event ); + void RecordStats( const Event *event, std::string const& note, timeval & timestamp ); bool CheckAlarms( const Image *delta_image ); bool DumpSettings( char *output, bool verbose );