Last change
on this file since 1834 was
1428,
checked in by nanardon, 9 years ago
|
Add functions to fetch statistics
|
-
Property svn:executable set to
*
|
File size:
1.1 KB
|
Line | |
---|
1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use LATMOS::Accounts::Maintenance; |
---|
6 | use LATMOS::Accounts::Log; |
---|
7 | use Getopt::Long; |
---|
8 | use Pod::Usage; |
---|
9 | use Text::CSV; |
---|
10 | |
---|
11 | =head1 NAME |
---|
12 | |
---|
13 | la-sql-stat2csv - Output collected statistics data |
---|
14 | |
---|
15 | =head1 SYNOPSIS |
---|
16 | |
---|
17 | la-expired-reminder [options] statname |
---|
18 | |
---|
19 | =cut |
---|
20 | |
---|
21 | GetOptions( |
---|
22 | 'c|config=s' => \my $config, |
---|
23 | 'b|base=s' => \my $base, |
---|
24 | 'help' => sub { pod2usage(0) }, |
---|
25 | ) or pod2usage(); |
---|
26 | |
---|
27 | =head1 OPTIONS |
---|
28 | |
---|
29 | =over 4 |
---|
30 | |
---|
31 | =item -c|--config configdir |
---|
32 | |
---|
33 | Use this configuration directory instead of the default one. |
---|
34 | |
---|
35 | =item -b|--base base |
---|
36 | |
---|
37 | Use this specific base |
---|
38 | |
---|
39 | =back |
---|
40 | |
---|
41 | =cut |
---|
42 | |
---|
43 | my $LA = LATMOS::Accounts->new($config, noacl => 1); |
---|
44 | my $labase = $LA->base($base); |
---|
45 | $labase && $labase->load or die "Cannot load base"; |
---|
46 | $labase->wexported(1); |
---|
47 | |
---|
48 | my ($name) = @ARGV; |
---|
49 | |
---|
50 | my $stat = $labase->get_object('stat', $name) or die "no stat name $name"; |
---|
51 | |
---|
52 | my $data = $stat->getAllStat(); |
---|
53 | my $csv = Text::CSV->new({eol => $/}); |
---|
54 | |
---|
55 | foreach my $date (sort keys %$data) { |
---|
56 | foreach my $val (sort keys %{ $data->{$date} }) { |
---|
57 | $csv->print(\*STDOUT, [ $date, $val, $data->{$date}{$val} ]); |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | exit 0 |
---|
Note: See
TracBrowser
for help on using the repository browser.