Added some options to scripts and simple testcases for scripts.

This commit is contained in:
hjp 2006-08-29 08:14:27 +00:00
parent d1284de05d
commit 690629d95f
5 changed files with 54 additions and 4 deletions

4
t/1.data Normal file
View File

@ -0,0 +1,4 @@
date val1 val2
2006-06-01 1 4
2006-07-01 2 1
2006-08-01 4 0

6
t/1.vdata Normal file
View File

@ -0,0 +1,6 @@
2006-06-01 val1 1
2006-06-01 val2 4
2006-07-01 val1 2
2006-07-01 val2 1
2006-08-01 val1 4
2006-08-01 val2 0

24
t/2scripts.t Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests => 7;
my $ps1=`./blib/script/tsplot --output_format ps t/1.data`;
ok($ps1, 'Postscript output of tsplot is not empty');
ok($ps1 =~ m/\(2006-06-04\) Rshow/, 'Postscript output of tsplot contains a date');
ok($ps1 =~ m/\(val1\) Rshow/, 'Postscript output of tsplot contains a column name');
my $ps2=`./blib/script/tsplotv --output_format ps t/1.vdata`;
ok($ps2, 'Postscript output of tsplot is not empty');
ok($ps2 =~ m/\(2006-06-04\) Rshow/, 'Postscript output of tsplot contains a date');
ok($ps2 =~ m/\(val1\) Rshow/, 'Postscript output of tsplot contains a column name');
# title and creation date will be different, but the rest should be
# identical:
$ps1 =~ s/^%%Title: .*//m;
$ps1 =~ s/^%%CreationDate: .*//m;
$ps2 =~ s/^%%Title: .*//m;
$ps2 =~ s/^%%CreationDate: .*//m;
ok($ps1 eq $ps2, 'output of tsplot and tsplotv are identical');
#vim:tw=0

8
tsplot
View File

@ -1,10 +1,16 @@
#!/usr/bin/perl -w
use strict;
use TimeSeries;
use Getopt::Long;
my $output_format ='png';
GetOptions('output_format|output-format=s' => \$output_format)
or die "Usage: $0 [--output_format format] [files...]\n";
binmode STDOUT, ':raw';
my $ts = TimeSeries->new();
my $ts = TimeSeries->new(output_format => $output_format);
while (<>) {
my @legend = split;
shift @legend; # first must be for timestamp

16
tsplotv
View File

@ -13,6 +13,16 @@ each line contains a tripel <time, series, value>.
use strict;
use TimeSeries;
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";
binmode STDOUT, ':raw';
@ -20,7 +30,7 @@ my %series;
my $ns;
my %data;
my $ts = TimeSeries->new();
my $ts = TimeSeries->new(output_format => $output_format);
while (<>) {
chomp;
my ($timestamp, $series, $value) = split(/\t/);
@ -29,8 +39,8 @@ while (<>) {
}
my @series = sort { $series{$a} <=> $series{$b} } keys %series;
$ts->legend(@series);
$ts->legend_position("below");
$ts->stacked(1);
$ts->legend_position($legend_position);
$ts->stacked($stacked);
for my $timestamp (sort keys %data) {
my %d = %{$data{$timestamp}};
my @values = @d{@series};