2006-02-14 10:45:11 +01:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
tsplotv - plot time series given in vertical format
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
This program expects time series data in vertical format, I.e.,
|
|
|
|
each line contains a tripel <time, series, value>.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use TimeSeries;
|
2006-08-29 10:14:27 +02:00
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
my $output_format ='png';
|
|
|
|
my $stacked = 0;
|
|
|
|
my $legend_position = 'top right';
|
|
|
|
GetOptions('output_format|output-format=s' => \$output_format,
|
|
|
|
'stacked' => \$stacked,
|
|
|
|
'legend_position|legend-position=s' => \$legend_position,
|
|
|
|
) or die "Usage: $0 [--output_format format] [files...]\n";
|
|
|
|
|
2006-02-14 10:45:11 +01:00
|
|
|
|
|
|
|
binmode STDOUT, ':raw';
|
|
|
|
|
|
|
|
my %series;
|
|
|
|
my $ns;
|
|
|
|
my %data;
|
|
|
|
|
2006-08-29 10:14:27 +02:00
|
|
|
my $ts = TimeSeries->new(output_format => $output_format);
|
2006-02-14 10:45:11 +01:00
|
|
|
while (<>) {
|
|
|
|
chomp;
|
|
|
|
my ($timestamp, $series, $value) = split(/\t/);
|
|
|
|
$series{$series} = ++$ns unless ($series{$series});
|
|
|
|
$data{$timestamp}{$series} = $value;
|
|
|
|
}
|
|
|
|
my @series = sort { $series{$a} <=> $series{$b} } keys %series;
|
|
|
|
$ts->legend(@series);
|
2006-08-29 10:14:27 +02:00
|
|
|
$ts->legend_position($legend_position);
|
|
|
|
$ts->stacked($stacked);
|
2006-02-14 10:45:11 +01:00
|
|
|
for my $timestamp (sort keys %data) {
|
|
|
|
my %d = %{$data{$timestamp}};
|
|
|
|
my @values = @d{@series};
|
|
|
|
$ts->add_timestring($timestamp, @values);
|
|
|
|
}
|
|
|
|
|
|
|
|
my $g = $ts->plot();
|
|
|
|
print $g
|