Modify RecordStats to accept a timestamp and note

This commit is contained in:
Kyle Johnson 2015-02-24 09:39:29 -05:00
parent 22b73c1610
commit c84457e3ef
3 changed files with 27 additions and 5 deletions

View File

@ -1551,7 +1551,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 );
}
}
}
}
@ -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 );
}
}
}
}

View File

@ -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 ) );

View File

@ -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 );