Addressed issues with event start and end times. Now includes the time from first to last frame.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@2631 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2008-09-26 09:45:59 +00:00
parent c207e7720f
commit 506815599b
2 changed files with 7 additions and 18 deletions

View File

@ -53,11 +53,9 @@ Event::Event( Monitor *p_monitor, struct timeval p_start_time, const char *p_cau
strncpy( text, p_text, sizeof(text) ); strncpy( text, p_text, sizeof(text) );
static char sql[BUFSIZ]; static char sql[BUFSIZ];
static char start_time_str[32];
struct tm *stime = localtime( &start_time.tv_sec ); struct tm *stime = localtime( &start_time.tv_sec );
strftime( start_time_str, sizeof(start_time_str), "%Y-%m-%d %H:%M:%S", stime ); snprintf( sql, sizeof(sql), "insert into Events ( MonitorId, Name, StartTime, Width, Height, Cause, Notes ) values ( %d, 'New Event', from_unixtime( %ld ), %d, %d, '%s', '%s' )", monitor->Id(), start_time.tv_sec, monitor->Width(), monitor->Height(), cause, text );
snprintf( sql, sizeof(sql), "insert into Events ( MonitorId, Name, StartTime, Width, Height, Cause, Notes ) values ( %d, 'New Event', '%s', %d, %d, '%s', '%s' )", monitor->Id(), start_time_str, monitor->Width(), monitor->Height(), cause, text );
if ( mysql_query( &dbconn, sql ) ) if ( mysql_query( &dbconn, sql ) )
{ {
Error( "Can't insert event: %s", mysql_error( &dbconn ) ); Error( "Can't insert event: %s", mysql_error( &dbconn ) );
@ -160,14 +158,11 @@ Event::~Event()
} }
static char sql[BUFSIZ]; static char sql[BUFSIZ];
static char end_time_str[32];
struct DeltaTimeval delta_time; struct DeltaTimeval delta_time;
DELTA_TIMEVAL( delta_time, end_time, start_time, DT_PREC_2 ); DELTA_TIMEVAL( delta_time, end_time, start_time, DT_PREC_2 );
strftime( end_time_str, sizeof(end_time_str), "%Y-%m-%d %H:%M:%S", localtime( &end_time.tv_sec ) ); snprintf( sql, sizeof(sql), "update Events set Name='%s%d', EndTime = from_unixtime( %ld ), Length = %s%ld.%02ld, Frames = %d, AlarmFrames = %d, TotScore = %d, AvgScore = %d, MaxScore = %d where Id = %d", monitor->EventPrefix(), id, end_time.tv_sec, 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 Name='%s%d', EndTime = '%s', Length = %s%ld.%02ld, Frames = %d, AlarmFrames = %d, TotScore = %d, AvgScore = %d, MaxScore = %d where Id = %d", monitor->EventPrefix(), id, end_time_str, 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 ) )
{ {
Error( "Can't update event: %s", mysql_error( &dbconn ) ); Error( "Can't update event: %s", mysql_error( &dbconn ) );
@ -406,10 +401,10 @@ void Event::AddFrame( Image *image, struct timeval timestamp, int score, Image *
} }
} }
end_time = timestamp;
if ( score > 0 ) if ( score > 0 )
{ {
end_time = timestamp;
alarm_frames++; alarm_frames++;
tot_score += score; tot_score += score;

View File

@ -1284,18 +1284,12 @@ bool Monitor::Analyse()
if ( signal_change || (function != MOCORD && state != ALERT) ) if ( signal_change || (function != MOCORD && state != ALERT) )
{ {
int pre_index; int pre_index;
if ( alarm_frame_count > 1 ) if ( alarm_frame_count > 1 )
{
int ts_index = ((index+image_buffer_count)-(alarm_frame_count-1))%image_buffer_count;
event = new Event( this, *(image_buffer[ts_index].timestamp), cause, text );
pre_index = ((index+image_buffer_count)-((alarm_frame_count-1)+pre_event_count))%image_buffer_count; pre_index = ((index+image_buffer_count)-((alarm_frame_count-1)+pre_event_count))%image_buffer_count;
}
else else
{
event = new Event( this, *timestamp, cause, text );
pre_index = ((index+image_buffer_count)-pre_event_count)%image_buffer_count; pre_index = ((index+image_buffer_count)-pre_event_count)%image_buffer_count;
}
event = new Event( this, *(image_buffer[pre_index].timestamp), cause, text );
shared_data->last_event = event->Id(); shared_data->last_event = event->Id();
Info( "%s: %03d - Creating new event %d", name, image_count, event->Id() ); Info( "%s: %03d - Creating new event %d", name, image_count, event->Id() );
@ -1423,7 +1417,7 @@ bool Monitor::Analyse()
} }
else if ( state == ALERT ) else if ( state == ALERT )
{ {
event->AddFrame( snap_image, *timestamp ); event->AddFrame( snap_image, *timestamp );
} }
else if ( state == TAPE ) else if ( state == TAPE )
{ {