Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: cc252a3feb
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 91 lines (75 sloc) 2.71 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
#!/usr/bin/perl
use strict;
use warnings;
use DateTime;
use DateTime::Format::DateParse;
use Text::Graph;
use Text::Graph::DataSet;

#open(my $fh, "/var/log/vhs.log.0");
my $log_file = shift || '/var/log/vhs.log';
open(my $fh, $log_file) or die;

my $last_close = 0;
my $last_flush = 0;

my %stats;
while (my $line = <$fh>) {
    if ($line =~ m/^(.+): bathroom door close/) {
        $last_close = DateTime::Format::DateParse->parse_datetime($1);
    }
    if ($line =~ m/^(.+): bathroom door open/) {
        my $open_time = DateTime::Format::DateParse->parse_datetime($1);
        my $closed_duration = $open_time - $last_close;
        my $closed_secs = $closed_duration->delta_minutes * 60 + $closed_duration->delta_seconds;
        warn "door was closed for $closed_secs\n";

        $stats{close_sum} += $closed_secs;
        $stats{close_count}++;
    }
    if ($line =~ m/^(.+): plunger down/) {
        my $flush = DateTime::Format::DateParse->parse_datetime($1);
        my $bio_time = $flush - $last_close;
        my $bio_secs = $bio_time->delta_minutes * 60 + $bio_time->delta_seconds;
        if ($bio_secs < 20) {
            warn "skipping - tooo low ($bio_secs)";
            next;
        }
        if ($bio_secs > 30 * 60) {
            warn "Someone was in the can for too long: $bio_secs - skipping\n";
            next;
        }
        warn "Bio time: $bio_secs\n";

        $stats{bio_sum} += $bio_secs;
        $stats{bio_count}++;
        $last_flush = $flush;
        push @{ $stats{bio_secs} }, $bio_secs;
    }
}

print "\n\n";

my $bio_avg = int($stats{bio_sum} / $stats{bio_count});
print "Average bio time: $bio_avg seconds"
    . " (Over $stats{bio_count} trips)\n";
my $close_avg = int($stats{close_sum} / $stats{close_count});
print "Average close time: $close_avg seconds"
    . " (Over $stats{close_count} trips)\n";

my $flush_rate = int($stats{bio_count} / $stats{close_count} * 100);
print "Flush rate $flush_rate%\n";

my $max = 0;
my $min = 99999999;
my %sum;
for (@{ $stats{bio_secs} }) {
    $min = $_ if $_ < $min;
    $max = $_ if $_ > $max;

    my $bucket = int($_/10) * 10;

    $sum{$bucket}++;
}

print "min=$min max=$max";

my @sorted_secs = sort { $a <=> $b } keys %sum;
my $dataset = Text::Graph::DataSet->new(
    [ map { $sum{$_} || 0 } @sorted_secs ],
    \@sorted_secs,
);

my $graph = Text::Graph->new( 'Line',
                              right => 1, # right-justify labels
                              fill => '.', # change fill-marker
                              log => 1, # logarithmic graph
                              showval => 1 # show actual values
                           );
print $graph->to_string( $dataset );

Something went wrong with that request. Please try again.