2006-02-14 10:45:11 +01:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
tsplotv - plot time series given in vertical format
|
|
|
|
|
2006-09-30 12:28:19 +02:00
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
tsplotv
|
2012-09-03 12:15:00 +02:00
|
|
|
[--finalresolution dpi]
|
2006-09-30 12:28:19 +02:00
|
|
|
[--legend-position pos]
|
2012-09-03 12:15:00 +02:00
|
|
|
[--log-y]
|
2006-09-30 12:28:19 +02:00
|
|
|
[--output-format format ]
|
|
|
|
[--stacked]
|
|
|
|
[--style style]
|
2016-04-21 17:17:33 +02:00
|
|
|
[--time_t]
|
|
|
|
[--colors rgb-list]
|
|
|
|
[--configfile yaml]
|
2019-02-10 15:03:31 +01:00
|
|
|
[--yrange min:max]
|
2006-09-30 12:28:19 +02:00
|
|
|
[file ...]
|
|
|
|
|
2006-02-14 10:45:11 +01:00
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
This program expects time series data in vertical format, I.e.,
|
2007-10-11 16:22:40 +02:00
|
|
|
each line contains a tab-separated tripel <time, series, value>.
|
2006-02-14 10:45:11 +01:00
|
|
|
|
2006-09-30 12:28:19 +02:00
|
|
|
The default legend position is "top right", same as with gnuplot.
|
|
|
|
Another frequently useful position (especially if you have lots of series)
|
2007-10-11 16:22:40 +02:00
|
|
|
is "below". Note that positions which consist of several words (such as
|
2006-09-30 12:28:19 +02:00
|
|
|
"top right" need to be passed to tsplotv as a single argument, so the
|
|
|
|
space needs to be hidden from the shell by use of quotes or a backslash.
|
|
|
|
|
|
|
|
The default output format is "png", the default style is "lines".
|
|
|
|
|
|
|
|
See L<TimeSeries> for a description of possible legend positions,
|
|
|
|
output formats, and styles.
|
|
|
|
|
|
|
|
The --stacked option causes the time series to be stacked on top of each
|
|
|
|
other.
|
|
|
|
|
2006-02-14 10:45:11 +01:00
|
|
|
=cut
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use TimeSeries;
|
2006-08-29 10:14:27 +02:00
|
|
|
use Getopt::Long;
|
2006-09-30 12:28:19 +02:00
|
|
|
use Pod::Usage;
|
2016-04-21 17:17:33 +02:00
|
|
|
use YAML qw(LoadFile);
|
2006-08-29 10:14:27 +02:00
|
|
|
|
2006-09-30 12:28:19 +02:00
|
|
|
my $help;
|
|
|
|
my $legend_position = 'top right';
|
2014-09-18 14:38:57 +02:00
|
|
|
my $output_format = 'png';
|
2006-08-29 10:14:27 +02:00
|
|
|
my $stacked = 0;
|
2006-09-30 12:28:19 +02:00
|
|
|
my $style = "lines";
|
2014-09-18 14:38:57 +02:00
|
|
|
my $log_y = 0;
|
2012-09-03 12:15:00 +02:00
|
|
|
my $finalresolution;
|
2014-09-18 14:38:57 +02:00
|
|
|
my $time_t = 0;
|
|
|
|
my $colors;
|
2016-04-21 17:17:33 +02:00
|
|
|
my $configfile;
|
2019-02-10 15:03:31 +01:00
|
|
|
my $yrange;
|
2012-09-03 12:15:00 +02:00
|
|
|
|
2006-09-30 12:28:19 +02:00
|
|
|
GetOptions('help|?' => \$help,
|
2007-09-06 09:11:14 +02:00
|
|
|
'legend_position|legend-position=s' => \$legend_position,
|
|
|
|
'output_format|output-format=s' => \$output_format,
|
|
|
|
'stacked' => \$stacked,
|
|
|
|
'style:s' => \$style,
|
|
|
|
'log_y|log-y' => \$log_y,
|
2017-12-14 03:33:12 +01:00
|
|
|
'finalresolution=i' => \$finalresolution,
|
2012-09-03 13:42:04 +02:00
|
|
|
'time_t' => \$time_t,
|
2014-09-18 14:38:57 +02:00
|
|
|
'colors=s' => \$colors,
|
2016-04-21 17:17:33 +02:00
|
|
|
'configfile=s' => \$configfile,
|
2019-02-10 15:03:31 +01:00
|
|
|
'yrange=s' => \$yrange,
|
2006-09-30 12:28:19 +02:00
|
|
|
) or pod2usage(2);
|
|
|
|
pod2usage(1) if $help;
|
2006-08-29 10:14:27 +02:00
|
|
|
|
2016-04-21 17:17:33 +02:00
|
|
|
my $config = LoadFile($configfile) if $configfile;
|
2006-02-14 10:45:11 +01:00
|
|
|
|
|
|
|
binmode STDOUT, ':raw';
|
|
|
|
|
2016-04-21 17:17:33 +02:00
|
|
|
my $ns = 0;
|
2006-02-14 10:45:11 +01:00
|
|
|
my %data;
|
|
|
|
|
2016-04-21 17:17:33 +02:00
|
|
|
$config->{timeseries} //= {};
|
2017-12-14 03:28:46 +01:00
|
|
|
for (keys $config->{timeseries}->%*) {
|
2016-04-21 17:17:33 +02:00
|
|
|
$ns = $config->{timeseries}{$_}{order} if ($config->{timeseries}{$_}{order} // 0) > $ns;
|
|
|
|
}
|
|
|
|
|
2006-02-14 10:45:11 +01:00
|
|
|
while (<>) {
|
|
|
|
chomp;
|
|
|
|
my ($timestamp, $series, $value) = split(/\t/);
|
2016-04-21 17:17:33 +02:00
|
|
|
$config->{timeseries}{$series}{order} = ++$ns unless ($config->{timeseries}{$series}{order});
|
2006-02-14 10:45:11 +01:00
|
|
|
$data{$timestamp}{$series} = $value;
|
|
|
|
}
|
2016-04-21 17:17:33 +02:00
|
|
|
my @series = sort { $config->{timeseries}{$a}{order} <=> $config->{timeseries}{$b}{order} }
|
2017-12-14 03:28:46 +01:00
|
|
|
keys $config->{timeseries}->%*;
|
2016-04-21 17:17:33 +02:00
|
|
|
if ($colors) {
|
|
|
|
my @colors = split(/,/, $colors);
|
|
|
|
while (my ($i, $c) = each(@colors)) {
|
|
|
|
$config->{timeseries}{$series[$i]}{color} = $c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my $ts = TimeSeries->new(output_format => $output_format);
|
2006-02-14 10:45:11 +01:00
|
|
|
$ts->legend(@series);
|
2006-08-29 10:14:27 +02:00
|
|
|
$ts->legend_position($legend_position);
|
|
|
|
$ts->stacked($stacked);
|
2006-09-30 12:28:19 +02:00
|
|
|
$ts->style($style);
|
2007-09-06 09:11:14 +02:00
|
|
|
$ts->log_y($log_y);
|
2012-09-03 12:15:00 +02:00
|
|
|
$ts->finalresolution($finalresolution) if $finalresolution;
|
2016-04-21 17:17:33 +02:00
|
|
|
$ts->colors(map $config->{timeseries}{$_}{color}, @series);
|
2006-09-30 12:28:19 +02:00
|
|
|
|
2019-02-10 15:03:31 +01:00
|
|
|
if ($yrange) {
|
|
|
|
$yrange =~s /^\[(.*)\]$/$1/; # remove optional brackets
|
|
|
|
my ($min, $max) = $yrange =~ /^(\*|[-+0-9E.]+):(\*|[-+0-9E.]+)$/;
|
|
|
|
$ts->yrange($min, $max);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-14 10:45:11 +01:00
|
|
|
for my $timestamp (sort keys %data) {
|
|
|
|
my %d = %{$data{$timestamp}};
|
|
|
|
my @values = @d{@series};
|
2012-09-03 13:42:04 +02:00
|
|
|
if ($time_t) {
|
|
|
|
$ts->add($timestamp, @values);
|
|
|
|
} else {
|
|
|
|
$ts->add_timestring($timestamp, @values);
|
|
|
|
}
|
2006-02-14 10:45:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
my $g = $ts->plot();
|
|
|
|
print $g
|