source: trunk/LATMOS-Accounts/bin/la-sql-stat2csv @ 2043

Last change on this file since 2043 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
3use strict;
4use warnings;
5use LATMOS::Accounts::Maintenance;
6use LATMOS::Accounts::Log;
7use Getopt::Long;
8use Pod::Usage;
9use 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
21GetOptions(
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
33Use this configuration directory instead of the default one.
34
35=item -b|--base base
36
37Use this specific base
38
39=back
40
41=cut
42
43my $LA = LATMOS::Accounts->new($config, noacl => 1);
44my $labase = $LA->base($base);
45$labase && $labase->load or die "Cannot load base";
46$labase->wexported(1);
47
48my ($name) = @ARGV;
49
50my $stat = $labase->get_object('stat', $name) or die "no stat name $name";
51
52my $data = $stat->getAllStat();
53my $csv = Text::CSV->new({eol => $/});
54
55foreach 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
61exit 0
Note: See TracBrowser for help on using the repository browser.