/[Sack]/trunk/lib/Sack/Server/Gnuplot.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Sack/Server/Gnuplot.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 252 - (show annotations)
Fri Nov 27 13:48:38 2009 UTC (14 years, 6 months ago) by dpavlin
File size: 1281 byte(s)
relaxed filter to full key name

1 package Sack::Server::Gnuplot;
2
3 use warnings;
4 use strict;
5
6 use Data::Dump qw(dump);
7
8 sub date {
9 my ( $out, $param ) = @_;
10
11 die "out not hash but ", dump($out) unless ref($out) eq 'HASH';
12
13 my @plot;
14 my $uid = '';
15
16 foreach my $key ( keys %$out ) {
17
18 my $title = $key;
19 $title =~ s{\+$}{};
20 next unless $title =~ s{^date,}{};
21
22 if ( my $filter = $param->{filter} ) {
23 $filter = '(' . join('|', @$filter) . ')' if ref $filter eq 'ARRAY';
24 next unless $key =~ m{$filter};
25 }
26
27 my $path = "/tmp/sack.gnuplot.$key.txt";
28 open( my $fh, '>', $path ) || die "$path: $!";
29 print $fh "## out key=$key\n";
30
31 foreach my $name ( sort keys %{ $out->{$key} } ) {
32
33 my $v = $out->{$key}->{$name};
34
35 print $fh "$name $v\n";
36
37 }
38
39 close($fh);
40
41 warn "data $path ", -s $path, " bytes\n";
42
43 push @plot, qq|"$path" using 1:2 title "$title" with linespoints|;
44 $uid .= $key;
45 }
46
47 my $path = "/tmp/sack.gnuplot.$uid.png";
48
49 open(my $gnuplot, '|-', 'gnuplot') || die "gnuplot $!";
50 print $gnuplot qq|
51
52 set terminal png
53 set output '$path'
54
55 set xdata time
56 set timefmt "%Y-%m-%d"
57 set format x "%d.%m."
58 #set xrange [ "2009-01-01":"2010-01-01" ]
59 #set yrange [ 0 : ]
60
61 plot |, join(',', @plot);
62
63 close($gnuplot);
64
65 warn "gnuplot $path ", -s $path, " bytes\n";
66
67 return $path;
68 }
69
70 1;

  ViewVC Help
Powered by ViewVC 1.1.26