Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- # Name: log2spreadsheet.pl
- # gepostet hier:
- # Funktion: Daten, die mit zukunfts_stats_threaded.pl erstellt wurden, in CSV-Format umwandeln
- #
- # Hinweise des Autors:
- # das log2spreadsheet script einfach via
- # perl log2spreadsheet.pl > import_me.csv
- # starten ... das import_me.csv kann man dann einfach
- # in open office importieren und mit 2 mausclicks einen schönen chart zaubern.
- use strict;
- use warnings;
- my %timestamps = ();
- my %ids = ();
- my $dirname = './logs';
- opendir(DIR,$dirname) || die $! . "\n";
- while(my $file = readdir(DIR)){
- next if $file =~ /^\.+$/;
- #print $file . "\n";
- open(IN,$dirname . '/' . $file) or die $! . "\n";
- while(<IN>){
- chomp();
- if($_ =~ /^TIME:(\d+)\/ID:(\d+)\/COUNT:(\d+)/){
- my($time,$id,$count)=($1,$2,$3);
- $timestamps{$time}{$id}=$count;
- $ids{$id}++;
- }
- }
- close(IN);
- }
- closedir(DIR) or warn $! . "\n";
- my @ids=sort({$a<=>$b}keys %ids);
- print '"time",' . join(',',@ids) . "\n";
- foreach my $timestamp(sort{$a<=>$b}(keys %timestamps)){
- print '"' . t2t($timestamp) . '",';
- my @tmp=();
- foreach my $id (@ids){
- my $value = defined $timestamps{$timestamp}{$id} ? $timestamps{$timestamp}{$id} : '';
- push(@tmp,$value);
- }
- print join(',',@tmp);
- print "\n";
- }
- sub t2t {
- my($unixtime)=@_;
- my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($unixtime);
- $mon++;
- $year+=1900;
- my $timestamp = $mday . '.' . $mon . '.' . $year . ' ' . $hour . ':' . $min . ':' . $sec;
- return $timestamp;
- }
- # 0 1 2 3 4 5 6 7 8
- # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
- # localtime(time);
- # my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
- # print "$abbr[$mon] $mday";
- # $mon=9, $mday=18 gives "Oct 18"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement