Skip to content

Commit ed01c65

Browse files
author
Todd Bruner
committed
Merge branch 'master' of baltig.sandia.gov:scot/SCOT
2 parents 8e2c3d5 + 4b1435a commit ed01c65

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

bin/reports.pl

+31-9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ =head1 SYNOPSIS
3333
use DateTime::Format::Strptime;
3434
use Log::Log4perl;
3535
use Getopt::Long qw(GetOptions);
36+
use Statistics::Descriptive::Sparse;
3637

3738
my $now = DateTime->now;
3839
my $lastday = DateTime->last_day_of_month(year=> $now->year, month=>$now->month);
@@ -71,7 +72,7 @@ =head1 PROGRAM ARGUMENTS
7172
7273
=cut
7374

74-
my $config_file = $ENV{'scot_reports_config_file'} // '/opt/scot/etc/reports.cfg.pl';
75+
my $config_file = $ENV{'scot_reports_config_file'} // '/opt/scot/etc/scot.cfg.pl';
7576

7677
my $env = Scot::Env->new(
7778
config_file => $config_file,
@@ -396,27 +397,48 @@ sub event_report {
396397
sub incident_stats {
397398
my $query = {
398399
created => {
399-
'$gte' => $thendt->epoch,
400-
'$lte' => $nowdt->epoch,
400+
'$gte' => $startdt->epoch,
401+
'$lte' => $enddt->epoch,
401402
},
402403
status => 'closed',
403-
closed => { '$ne' => 0 },
404+
"data.closed" => {'$ne' => 0 },
404405
};
405406

406407
my $cursor = $mongo->collection('Incident')->find($query);
408+
my $count = $mongo->collection('Incident')->count($query);
409+
410+
if ( $count eq 0 ) {
411+
die "NO Incidents matching ".Dumper($query);
412+
}
407413
my @values;
408414

415+
print "----------\n";
416+
printf "%5s %20s %20s %20s %s\n",
417+
"id", "Created", "Closed", "Elapsed","errors";
409418
while (my $incident = $cursor->next) {
410-
push @values, $incident->closed - $incident->created
419+
my $id = $incident->id;
420+
my $created = $incident->created;
421+
my $closed = $incident->data->{closed};
422+
next unless $closed;
423+
my $elapsed = $closed - $created;
424+
my $errors = '';
425+
if ( $elapsed < 0 ) {
426+
$errors = 'Negative elapsed time rejected';
427+
}
428+
429+
printf "%5d %20d %20d %20d %s\n", $id, $created,$closed, $elapsed, $errors;
430+
if ( $elapsed > 0 ) {
431+
push @values, $elapsed;
432+
}
411433
}
412434

413435
my $util = Statistics::Descriptive::Sparse->new();
414436
$util->add_data(@values);
415437

416-
print "Average Close = ".$get_readable_time($util->mean)."\n";
417-
print "Minimum Close = ".$get_readable_time($util->min)."\n";
418-
print "Maximum Close = ".$get_readable_time($util->max)."\n";
419-
print "Std. of Dev. = ".$util->statndar_deviation."\n";
438+
print "Average Close = ".get_readable_time($util->mean)."\n";
439+
print "Minimum Close = ".get_readable_time($util->min)."\n";
440+
print "Maximum Close = ".get_readable_time($util->max)."\n";
441+
print "Std. of Dev. = ".$util->standard_deviation."\n";
420442
print "Number of incidents = ".$util->count."\n";
421443

422444
}

0 commit comments

Comments
 (0)