Added monitor specific event prefixes.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1104 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2004-09-23 13:43:10 +00:00
parent d951c3e986
commit 23ea7dff66
7 changed files with 85 additions and 55 deletions

View File

@ -1,3 +1,15 @@
--
-- There are no updates from a 1.19.4 database to 1.19.5
-- This updates a 1.19.4 database to 1.19.5
--
-- Make changes to Monitors table
--
alter table Monitors add column EventPrefix varchar(32) not null default 'Event-' after Orientation;
--
-- These are optional, but we might as well
--
optimize table Frames;
optimize table Events;
optimize table Filters;
optimize table Zones;
optimize table Monitors;
optimize table Stats;

View File

@ -111,6 +111,7 @@ CREATE TABLE Monitors (
Height smallint(5) unsigned NOT NULL default '0',
Palette tinyint(3) unsigned NOT NULL default '1',
Orientation enum('0','90','180','270') NOT NULL default '0',
EventPrefix varchar(32) NOT NULL default 'Event-',
LabelFormat varchar(32) NOT NULL default '%%s - %y/%m/%d %H:%M:%S',
LabelX smallint(5) unsigned default NULL,
LabelY smallint(5) unsigned default NULL,

View File

@ -292,7 +292,7 @@ do
}
# New audit to close any events that were left open for longer than 5 minutes
my $sql9 = "select E.Id, max(F.TimeStamp) as EndTime, unix_timestamp(max(F.TimeStamp)) - unix_timestamp(E.StartTime) as Length, count(F.Id) as Frames, count(if(F.Score>0,1,NULL)) as AlarmFrames, sum(F.Score) as TotScore, max(F.Score) as MaxScore from Events as E inner join Frames as F on E.Id = F.EventId where isnull(E.Frames) group by E.Id having EndTime < (now() - interval 5 minute)";
my $sql9 = "select E.Id, max(F.TimeStamp) as EndTime, unix_timestamp(max(F.TimeStamp)) - unix_timestamp(E.StartTime) as Length, count(F.Id) as Frames, count(if(F.Score>0,1,NULL)) as AlarmFrames, sum(F.Score) as TotScore, max(F.Score) as MaxScore, M.EventPrefix as Prefix from Events as E left join Monitors as M on E.MonitorId = M.Id inner join Frames as F on E.Id = F.EventId where isnull(E.Frames) group by E.Id having EndTime < (now() - interval 5 minute)";
my $sth9 = $dbh->prepare_cached( $sql9 ) or die( "Can't prepare '$sql9': ".$dbh->errstr() );
my $sql10 = "update Events set Name = ?, EndTime = ?, Length = ?, Frames = ?, AlarmFrames = ?, TotScore = ?, AvgScore = ?, MaxScore = ? where Id = ?";
my $sth10 = $dbh->prepare_cached( $sql10 ) or die( "Can't prepare '$sql10': ".$dbh->errstr() );
@ -302,7 +302,7 @@ do
print( "Found open event '$event->{Id}'" );
if ( confirm( 'close', 'closing' ) )
{
$res = $sth10->execute( sprintf( "Event-%d(r)", $event->{Id}), $event->{EndTime}, $event->{Length}, $event->{Frames}, $event->{AlarmFrames}, $event->{TotScore}, $event->{AlarmFrames}?int($event->{TotScore}/$event->{AlarmFrames}):0, $event->{MaxScore}, $event->{Id} ) or die( "Can't execute: ".$sth10->errstr() );
$res = $sth10->execute( sprintf( "%s-%d(r)", $event->{Prefix}, $event->{Id} ), $event->{EndTime}, $event->{Length}, $event->{Frames}, $event->{AlarmFrames}, $event->{TotScore}, $event->{AlarmFrames}?int($event->{TotScore}/$event->{AlarmFrames}):0, $event->{MaxScore}, $event->{Id} ) or die( "Can't execute: ".$sth10->errstr() );
}
}

View File

@ -101,7 +101,7 @@ Event::~Event()
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='Event-%d', EndTime = '%s', Length = %s%ld.%02ld, Frames = %d, AlarmFrames = %d, TotScore = %d, AvgScore = %d, MaxScore = %d where Id = %d", 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 );
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 ) )
{
Error(( "Can't update event: %s", mysql_error( &dbconn ) ));

View File

@ -47,6 +47,7 @@ Monitor::Monitor(
int p_height,
int p_palette,
int p_orientation,
char *p_event_prefix,
char *p_label_format,
const Coord &p_label_coord,
int p_image_buffer_count,
@ -85,6 +86,7 @@ Monitor::Monitor(
name = new char[strlen(p_name)+1];
strcpy( name, p_name );
strncpy( event_prefix, p_event_prefix, sizeof(event_prefix) );
strncpy( label_format, p_label_format, sizeof(label_format) );
camera = new LocalCamera( p_device, p_channel, p_format, (p_orientation%2)?width:height, (orientation%2)?height:width, p_palette, purpose==CAPTURE );
@ -103,6 +105,7 @@ Monitor::Monitor(
int p_height,
int p_palette,
int p_orientation,
char *p_event_prefix,
char *p_label_format,
const Coord &p_label_coord,
int p_image_buffer_count,
@ -141,6 +144,7 @@ Monitor::Monitor(
name = new char[strlen(p_name)+1];
strcpy( name, p_name );
strncpy( event_prefix, p_event_prefix, sizeof(event_prefix) );
strncpy( label_format, p_label_format, sizeof(label_format) );
camera = new RemoteCamera( p_host, p_port, p_path, (p_orientation%2)?width:height, (orientation%2)?height:width, p_palette, purpose==CAPTURE );
@ -861,11 +865,11 @@ int Monitor::Load( int device, Monitor **&monitors, Purpose purpose )
static char sql[BUFSIZ];
if ( device == -1 )
{
strncpy( sql, "select Id, Name, Function+0, Device, Channel, Format, Width, Height, Palette, Orientation+0, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc from Monitors where Function != 'None' and Type = 'Local'", sizeof(sql) );
strncpy( sql, "select Id, Name, Function+0, Device, Channel, Format, Width, Height, Palette, Orientation+0, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc from Monitors where Function != 'None' and Type = 'Local'", sizeof(sql) );
}
else
{
snprintf( sql, sizeof(sql), "select Id, Name, Function+0, Device, Channel, Format, Width, Height, Palette, Orientation+0, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc from Monitors where Function != 'None' and Type = 'Local' and Device = %d", device );
snprintf( sql, sizeof(sql), "select Id, Name, Function+0, Device, Channel, Format, Width, Height, Palette, Orientation+0, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc from Monitors where Function != 'None' and Type = 'Local' and Device = %d", device );
}
if ( mysql_query( &dbconn, sql ) )
{
@ -896,17 +900,18 @@ int Monitor::Load( int device, Monitor **&monitors, Purpose purpose )
atoi(dbrow[7]), // Height
atoi(dbrow[8]), // Palette
atoi(dbrow[9]), // Orientation
dbrow[10], // LabelFormat
Coord( atoi(dbrow[11]), atoi(dbrow[12]) ), // LabelX, LabelY
atoi(dbrow[13]), // ImageBufferCount
atoi(dbrow[14]), // WarmupCount
atoi(dbrow[15]), // PreEventCount
atoi(dbrow[16]), // PostEventCount
atoi(dbrow[17]), // SectionLength
atoi(dbrow[18]), // FrameSkip
atof(dbrow[19])>0.0?int(DT_PREC_3/atof(dbrow[19])):0, // MaxFPS
atoi(dbrow[20]), // FPSReportInterval
atoi(dbrow[21]), // RefBlendPerc
dbrow[10], // EventPrefix
dbrow[11], // LabelFormat
Coord( atoi(dbrow[12]), atoi(dbrow[13]) ), // LabelX, LabelY
atoi(dbrow[14]), // ImageBufferCount
atoi(dbrow[15]), // WarmupCount
atoi(dbrow[16]), // PreEventCount
atoi(dbrow[17]), // PostEventCount
atoi(dbrow[18]), // SectionLength
atoi(dbrow[19]), // FrameSkip
atof(dbrow[20])>0.0?int(DT_PREC_3/atof(dbrow[20])):0, // MaxFPS
atoi(dbrow[21]), // FPSReportInterval
atoi(dbrow[22]), // RefBlendPerc
purpose
);
Zone **zones = 0;
@ -930,11 +935,11 @@ int Monitor::Load( const char *host, const char*port, const char *path, Monitor
static char sql[BUFSIZ];
if ( !host )
{
strncpy( sql, "select Id, Name, Function+0, Host, Port, Path, Width, Height, Palette, Orientation+0, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc from Monitors where Function != 'None' and Type = 'Remote'", sizeof(sql) );
strncpy( sql, "select Id, Name, Function+0, Host, Port, Path, Width, Height, Palette, Orientation+0, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc from Monitors where Function != 'None' and Type = 'Remote'", sizeof(sql) );
}
else
{
snprintf( sql, sizeof(sql), "select Id, Name, Function+0, Host, Port, Path, Width, Height, Palette, Orientation+0, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc from Monitors where Function != 'None' and Type = 'Remote' and Host = '%s' and Port = '%s' and Path = '%s'", host, port, path );
snprintf( sql, sizeof(sql), "select Id, Name, Function+0, Host, Port, Path, Width, Height, Palette, Orientation+0, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc from Monitors where Function != 'None' and Type = 'Remote' and Host = '%s' and Port = '%s' and Path = '%s'", host, port, path );
}
if ( mysql_query( &dbconn, sql ) )
{
@ -965,17 +970,18 @@ int Monitor::Load( const char *host, const char*port, const char *path, Monitor
atoi(dbrow[7]), // Height
atoi(dbrow[8]), // Palette
atoi(dbrow[9]), // Orientation
dbrow[10], // LabelFormat
Coord( atoi(dbrow[11]), atoi(dbrow[12]) ), // LabelX, LabelY
atoi(dbrow[13]), // ImageBufferCount
atoi(dbrow[14]), // WarmupCount
atoi(dbrow[15]), // PreEventCount
atoi(dbrow[16]), // PostEventCount
atoi(dbrow[17]), // SectionLength
atoi(dbrow[18]), // FrameSkip
atof(dbrow[19])>0.0?int(DT_PREC_3/atof(dbrow[19])):0, // MaxFPS
atoi(dbrow[20]), // FPSReportInterval
atoi(dbrow[21]), // RefBlendPerc
dbrow[10], // EventPrefix
dbrow[11], // LabelFormat
Coord( atoi(dbrow[12]), atoi(dbrow[13]) ), // LabelX, LabelY
atoi(dbrow[14]), // ImageBufferCount
atoi(dbrow[15]), // WarmupCount
atoi(dbrow[16]), // PreEventCount
atoi(dbrow[17]), // PostEventCount
atoi(dbrow[18]), // SectionLength
atoi(dbrow[19]), // FrameSkip
atof(dbrow[20])>0.0?int(DT_PREC_3/atof(dbrow[20])):0, // MaxFPS
atoi(dbrow[21]), // FPSReportInterval
atoi(dbrow[22]), // RefBlendPerc
purpose
);
Zone **zones = 0;
@ -997,7 +1003,7 @@ int Monitor::Load( const char *host, const char*port, const char *path, Monitor
Monitor *Monitor::Load( int id, bool load_zones, Purpose purpose )
{
static char sql[BUFSIZ];
snprintf( sql, sizeof(sql), "select Id, Name, Type, Function+0, Device, Channel, Format, Host, Port, Path, Width, Height, Palette, Orientation+0, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc from Monitors where Id = %d", id );
snprintf( sql, sizeof(sql), "select Id, Name, Type, Function+0, Device, Channel, Format, Host, Port, Path, Width, Height, Palette, Orientation+0, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, SectionLength, FrameSkip, MaxFPS, FPSReportInterval, RefBlendPerc from Monitors where Id = %d", id );
if ( mysql_query( &dbconn, sql ) )
{
Error(( "Can't run query: %s", mysql_error( &dbconn ) ));
@ -1028,17 +1034,18 @@ Monitor *Monitor::Load( int id, bool load_zones, Purpose purpose )
atoi(dbrow[11]), // Height
atoi(dbrow[12]), // Palette
atoi(dbrow[13]), // Orientation
dbrow[14], // LabelFormat
Coord( atoi(dbrow[15]), atoi(dbrow[16]) ), // LabelX, LabelY
atoi(dbrow[17]), // ImageBufferCount
atoi(dbrow[18]), // WarmupCount
atoi(dbrow[19]), // PreEventCount
atoi(dbrow[20]), // PostEventCount
atoi(dbrow[21]), // SectionLength
atoi(dbrow[22]), // FrameSkip
atof(dbrow[23])>0.0?int(DT_PREC_3/atof(dbrow[23])):0, // MaxFPS
atoi(dbrow[24]), // FPSReportInterval
atoi(dbrow[25]), // RefBlendPerc
dbrow[14], // EventPrefix
dbrow[15], // LabelFormat
Coord( atoi(dbrow[16]), atoi(dbrow[17]) ), // LabelX, LabelY
atoi(dbrow[18]), // ImageBufferCount
atoi(dbrow[19]), // WarmupCount
atoi(dbrow[20]), // PreEventCount
atoi(dbrow[21]), // PostEventCount
atoi(dbrow[22]), // SectionLength
atoi(dbrow[23]), // FrameSkip
atof(dbrow[24])>0.0?int(DT_PREC_3/atof(dbrow[24])):0, // MaxFPS
atoi(dbrow[25]), // FPSReportInterval
atoi(dbrow[26]), // RefBlendPerc
purpose
);
}
@ -1055,17 +1062,18 @@ Monitor *Monitor::Load( int id, bool load_zones, Purpose purpose )
atoi(dbrow[11]), // Height
atoi(dbrow[12]), // Palette
atoi(dbrow[13]), // Orientation
dbrow[14], // LabelFormat
Coord( atoi(dbrow[15]), atoi(dbrow[16]) ), // LabelX, LabelY
atoi(dbrow[17]), // ImageBufferCount
atoi(dbrow[18]), // WarmupCount
atoi(dbrow[19]), // PreEventCount
atoi(dbrow[20]), // PostEventCount
atoi(dbrow[21]), // SectionLength
atoi(dbrow[22]), // FrameSkip
atof(dbrow[23])>0.0?int(DT_PREC_3/atof(dbrow[23])):0, // MaxFPS
atoi(dbrow[24]), // FPSReportInterval
atoi(dbrow[25]), // RefBlendPerc
dbrow[14], // EventPrefix
dbrow[15], // LabelFormat
Coord( atoi(dbrow[16]), atoi(dbrow[17]) ), // LabelX, LabelY
atoi(dbrow[18]), // ImageBufferCount
atoi(dbrow[19]), // WarmupCount
atoi(dbrow[20]), // PreEventCount
atoi(dbrow[21]), // PostEventCount
atoi(dbrow[22]), // SectionLength
atoi(dbrow[23]), // FrameSkip
atof(dbrow[24])>0.0?int(DT_PREC_3/atof(dbrow[24])):0, // MaxFPS
atoi(dbrow[25]), // FPSReportInterval
atoi(dbrow[26]), // RefBlendPerc
purpose
);
}
@ -1307,6 +1315,7 @@ bool Monitor::DumpSettings( char *output, bool verbose )
sprintf( output+strlen(output), "Height : %d\n", camera->Height() );
sprintf( output+strlen(output), "Palette : %d\n", camera->Palette() );
sprintf( output+strlen(output), "Colours : %d\n", camera->Colours() );
sprintf( output+strlen(output), "Event Prefix : %s\n", event_prefix );
sprintf( output+strlen(output), "Label Format : %s\n", label_format );
sprintf( output+strlen(output), "Label Coord : %d,%d\n", label_coord.X(), label_coord.Y() );
sprintf( output+strlen(output), "Image Buffer Count : %d\n", image_buffer_count );

View File

@ -81,6 +81,7 @@ protected:
unsigned int height; // Normally the same as the camera, but not if partly rotated
RunMode run_mode; // Whether the monitor is running continuously or is triggered
Orientation orientation; // Whether the image has to be rotated at all
char event_prefix[64]; // The prefix applied to event names as they are created
char label_format[64]; // The format of the timestamp on the images
Coord label_coord; // The coordinates of the timestamp on the images
int image_buffer_count; // Size of circular image buffer, at least twice the size of the pre_event_count
@ -157,8 +158,8 @@ protected:
}
public:
Monitor( int p_id, char *p_name, int p_function, int p_device, int p_channel, int p_format, int p_width, int p_height, int p_palette, int p_orientation, char *p_label_format, const Coord &p_label_coord, int p_image_buffer_count, int p_warmup_count, int p_pre_event_count, int p_post_event_count, int p_section_length, int p_frame_skip, int p_capture_delay, int p_fps_report_interval, int p_ref_blend_perc, Purpose p_purpose=QUERY, int p_n_zones=0, Zone *p_zones[]=0 );
Monitor( int p_id, char *p_name, int p_function, const char *p_host, const char *p_port, const char *p_path, int p_width, int p_height, int p_palette, int p_orientation, char *p_label_format, const Coord &p_label_coord, int p_image_buffer_count, int p_warmup_count, int p_pre_event_count, int p_post_event_count, int p_section_length, int p_frame_skip, int p_capture_delay, int p_fps_report_interval, int p_ref_blend_perc, Purpose p_purpose=QUERY, int p_n_zones=0, Zone *p_zones[]=0 );
Monitor( int p_id, char *p_name, int p_function, int p_device, int p_channel, int p_format, int p_width, int p_height, int p_palette, int p_orientation, char *p_event_prefix, char *p_label_format, const Coord &p_label_coord, int p_image_buffer_count, int p_warmup_count, int p_pre_event_count, int p_post_event_count, int p_section_length, int p_frame_skip, int p_capture_delay, int p_fps_report_interval, int p_ref_blend_perc, Purpose p_purpose=QUERY, int p_n_zones=0, Zone *p_zones[]=0 );
Monitor( int p_id, char *p_name, int p_function, const char *p_host, const char *p_port, const char *p_path, int p_width, int p_height, int p_palette, int p_orientation, char *p_event_prefix, char *p_label_format, const Coord &p_label_coord, int p_image_buffer_count, int p_warmup_count, int p_pre_event_count, int p_post_event_count, int p_section_length, int p_frame_skip, int p_capture_delay, int p_fps_report_interval, int p_ref_blend_perc, Purpose p_purpose=QUERY, int p_n_zones=0, Zone *p_zones[]=0 );
~Monitor();
void Setup();
@ -178,6 +179,10 @@ public:
{
return( name );
}
inline const char *EventPrefix() const
{
return( event_prefix );
}
State GetState() const;
int GetImage( int index=-1, int scale=100 ) const;
struct timeval GetTimestamp( int index=-1 ) const;

View File

@ -77,6 +77,7 @@ else
$monitor['PostEventCount'] = 10;
$monitor['SectionLength'] = 600;
$monitor['FrameSkip'] = 0;
$monitor['EventPrefix'] = 'Event-';
$monitor['MaxFPS'] = 0;
$monitor['FPSReportInterval'] = 1000;
$monitor['RefBlendPerc'] = 10;
@ -229,6 +230,7 @@ if ( $tab != 'buffers' )
if ( $tab != 'misc' )
{
?>
<input type="hidden" name="new_monitor[EventPrefix]" value="<?= $new_monitor['EventPrefix'] ?>">
<input type="hidden" name="new_monitor[MaxFPS]" value="<?= $new_monitor['MaxFPS'] ?>">
<input type="hidden" name="new_monitor[FPSReportInterval]" value="<?= $new_monitor['FPSReportInterval'] ?>">
<input type="hidden" name="new_monitor[RefBlendPerc]" value="<?= $new_monitor['RefBlendPerc'] ?>">
@ -357,6 +359,7 @@ switch ( $tab )
case 'misc' :
{
?>
<tr><td align="left" class="text"><?= $zmSlangMaximumFPS ?></td><td align="left" class="text"><input type="text" name="new_monitor[EventPrefix]" value="<?= $new_monitor['EventPrefix'] ?>" size="24" class="form"></td></tr>
<tr><td align="left" class="text"><?= $zmSlangMaximumFPS ?></td><td align="left" class="text"><input type="text" name="new_monitor[MaxFPS]" value="<?= $new_monitor['MaxFPS'] ?>" size="6" class="form"></td></tr>
<tr><td align="left" class="text"><?= $zmSlangFPSReportInterval ?></td><td align="left" class="text"><input type="text" name="new_monitor[FPSReportInterval]" value="<?= $new_monitor['FPSReportInterval'] ?>" size="6" class="form"></td></tr>
<tr><td align="left" class="text"><?= $zmSlangRefImageBlendPct ?></td><td align="left" class="text"><input type="text" name="new_monitor[RefBlendPerc]" value="<?= $new_monitor['RefBlendPerc'] ?>" size="4" class="form"></td></tr>