mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
Bugfixes for the FileLog get function. Now in real use by the SVG module
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@203 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
21f3505cc9
commit
b602e3c9af
@ -157,7 +157,7 @@ FileLog_Get($@)
|
|||||||
my ($hash, @a) = @_;
|
my ($hash, @a) = @_;
|
||||||
|
|
||||||
return "Usage: get $a[0] <infile> <outfile> <from> <to> <column_spec>...\n".
|
return "Usage: get $a[0] <infile> <outfile> <from> <to> <column_spec>...\n".
|
||||||
" where column_spec is <col>:<regexp>:<fn>\n" .
|
" where column_spec is <col>:<regexp>:<default>:<fn>\n" .
|
||||||
" see the FileLogGrep entries in he .gplot files\n" .
|
" see the FileLogGrep entries in he .gplot files\n" .
|
||||||
" <infile> is without direcory, - means the current file\n" .
|
" <infile> is without direcory, - means the current file\n" .
|
||||||
" <outfile> is a prefix, - means stdout\n"
|
" <outfile> is a prefix, - means stdout\n"
|
||||||
@ -167,7 +167,7 @@ FileLog_Get($@)
|
|||||||
my $inf = shift @a;
|
my $inf = shift @a;
|
||||||
my $outf = shift @a;
|
my $outf = shift @a;
|
||||||
my $from = shift @a;
|
my $from = shift @a;
|
||||||
my $to = shift @a;
|
my $to = shift @a; # Now @a contains the list of column_specs
|
||||||
|
|
||||||
if($inf eq "-") {
|
if($inf eq "-") {
|
||||||
$inf = $hash->{currentlogfile};
|
$inf = $hash->{currentlogfile};
|
||||||
@ -189,7 +189,7 @@ FileLog_Get($@)
|
|||||||
# last3: last delta timestamp (d or h)
|
# last3: last delta timestamp (d or h)
|
||||||
my (@d, @fname);
|
my (@d, @fname);
|
||||||
for(my $i = 0; $i < int(@a); $i++) {
|
for(my $i = 0; $i < int(@a); $i++) {
|
||||||
my @fld = split(":", $a[$i], 3);
|
my @fld = split(":", $a[$i], 4);
|
||||||
|
|
||||||
my %h;
|
my %h;
|
||||||
if($outf ne "-") {
|
if($outf ne "-") {
|
||||||
@ -197,9 +197,10 @@ FileLog_Get($@)
|
|||||||
$h{fh} = new IO::File "> $fname[$i]";
|
$h{fh} = new IO::File "> $fname[$i]";
|
||||||
}
|
}
|
||||||
$h{re} = $fld[1];
|
$h{re} = $fld[1];
|
||||||
$h{fn} = $fld[2];
|
$h{df} = defined($fld[2]) ? $fld[2] : "";
|
||||||
$h{didx} = 2 if($fld[2] && $fld[2] eq "delta-d");
|
$h{fn} = $fld[3];
|
||||||
$h{didx} = 3 if($fld[2] && $fld[2] eq "delta-h");
|
$h{didx} = 10 if($fld[3] && $fld[3] eq "delta-d");
|
||||||
|
$h{didx} = 13 if($fld[3] && $fld[3] eq "delta-h");
|
||||||
|
|
||||||
if($fld[0] =~ m/"(.*)"/) {
|
if($fld[0] =~ m/"(.*)"/) {
|
||||||
$h{col} = $1;
|
$h{col} = $1;
|
||||||
@ -207,7 +208,7 @@ FileLog_Get($@)
|
|||||||
} else {
|
} else {
|
||||||
$h{col} = $fld[0]-1;
|
$h{col} = $fld[0]-1;
|
||||||
}
|
}
|
||||||
$h{ret} = [];
|
$h{ret} = "";
|
||||||
$d[$i] = \%h;
|
$d[$i] = \%h;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,7 +216,7 @@ FileLog_Get($@)
|
|||||||
while(my $l = <$ifh>) {
|
while(my $l = <$ifh>) {
|
||||||
last if($l gt $to);
|
last if($l gt $to);
|
||||||
my @fld = split("[ \r\n]+", $l);
|
my @fld = split("[ \r\n]+", $l);
|
||||||
for(my $i = 0; $i < int(@a); $i++) { # Process each req. field
|
for my $i (0..int(@a)-1) { # Process each req. field
|
||||||
my $h = $d[$i];
|
my $h = $d[$i];
|
||||||
my $re = $h->{re};
|
my $re = $h->{re};
|
||||||
next if($re && $l !~ m/$re/);
|
next if($re && $l !~ m/$re/);
|
||||||
@ -229,38 +230,42 @@ FileLog_Get($@)
|
|||||||
} elsif(!$h->{fn}) { # The column
|
} elsif(!$h->{fn}) { # The column
|
||||||
$line = "$fld[0] $fld[$col]";
|
$line = "$fld[0] $fld[$col]";
|
||||||
|
|
||||||
} elsif($h->{fn} eq "int") { # int function
|
|
||||||
my $val = $fld[$col];
|
|
||||||
$val =~ s/[^\d.]//;
|
|
||||||
$line = "$fld[0] $val";
|
|
||||||
|
|
||||||
} elsif($h->{didx}) { # delta-h or delta-d
|
} elsif($h->{didx}) { # delta-h or delta-d
|
||||||
|
|
||||||
my $hd = $h->{didx};
|
my $hd = $h->{didx};
|
||||||
my @ld = split("[-_:]", $fld[0]);
|
my $ld = substr($fld[0],0,$hd);
|
||||||
if(!defined($h->{last1}) || $h->{last3} ne $ld[$hd]) {
|
if(!defined($h->{last1}) || $h->{last3} ne $ld) {
|
||||||
if(defined($h->{last1})) {
|
if(defined($h->{last1})) {
|
||||||
my @lda = split("[_:]", $lastdate{$hd});
|
my @lda = split("[_:]", $lastdate{$hd});
|
||||||
my $ts = "12:00:00"; # middle timestamp
|
my $ts = "12:00:00"; # middle timestamp
|
||||||
$ts = "$lda[1]:30:00" if($hd == 3);
|
$ts = "$lda[1]:30:00" if($hd == 13);
|
||||||
$line = sprintf("%s_%s %0.1f", $lda[0],$ts, $fld[$col]-$h->{last1});
|
my $v = $fld[$col]-$h->{last1};
|
||||||
|
$v = 0 if($v < 0); # Skip negative delta
|
||||||
|
$line = sprintf("%s_%s %0.1f", $lda[0],$ts, $v);
|
||||||
}
|
}
|
||||||
$h->{last1} = $fld[$col];
|
$h->{last1} = $fld[$col];
|
||||||
$h->{last3} = $ld[$hd];
|
$h->{last3} = $ld;
|
||||||
}
|
}
|
||||||
$h->{last2} = $fld[$col];
|
$h->{last2} = $fld[$col];
|
||||||
$lastdate{$hd} = $fld[0];
|
$lastdate{$hd} = $fld[0];
|
||||||
|
|
||||||
|
} elsif($h->{fn} eq "int") { # int function
|
||||||
|
my $val = $fld[$col];
|
||||||
|
$line = "$fld[0] $1" if($val =~ m/^([0-9]+).*/);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$line = "$fld[0] " . eval($h->{fn});
|
$line = "$fld[0] " . eval($h->{fn});
|
||||||
}
|
}
|
||||||
|
|
||||||
next if(!$line);
|
next if(!$line);
|
||||||
|
|
||||||
|
$h->{count}++;
|
||||||
|
$line .= "\n";
|
||||||
if($outf eq "-") {
|
if($outf eq "-") {
|
||||||
push @{$h->{ret}}, $line;
|
$h->{ret} .= $line;
|
||||||
} else {
|
} else {
|
||||||
my $fh = $h->{fh};
|
my $fh = $h->{fh};
|
||||||
print $fh $line,"\n";
|
print $fh $line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -276,19 +281,28 @@ FileLog_Get($@)
|
|||||||
my @lda = split("[_:]", $lastdate{$hd});
|
my @lda = split("[_:]", $lastdate{$hd});
|
||||||
my $ts = "12:00:00"; # middle timestamp
|
my $ts = "12:00:00"; # middle timestamp
|
||||||
$ts = "$lda[1]:30:00" if($hd == 3);
|
$ts = "$lda[1]:30:00" if($hd == 3);
|
||||||
my $line = sprintf("%s_%s %0.1f", $lda[0],$ts, $h->{last2}-$h->{last1});
|
my $line = sprintf("%s_%s %0.1f\n", $lda[0],$ts, $h->{last2}-$h->{last1});
|
||||||
|
|
||||||
if($outf eq "-") {
|
if($outf eq "-") {
|
||||||
push @{$h->{ret}}, $line;
|
$h->{ret} .= $line;
|
||||||
|
$h->{count}++;
|
||||||
} else {
|
} else {
|
||||||
my $fh = $h->{fh};
|
my $fh = $h->{fh};
|
||||||
print $fh $line,"\n";
|
print $fh $line;
|
||||||
|
$h->{count}++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($outf eq "-") {
|
if($outf eq "-") {
|
||||||
$ret .= join("\n", @{$h->{ret}}) if($h->{ret});
|
$h->{ret} .= "$from $h->{df}\n" if(!$h->{count} && $h->{df} ne "");
|
||||||
|
$ret .= $h->{ret} if($h->{ret});
|
||||||
|
$ret .= "#$a[$i]\n";
|
||||||
} else {
|
} else {
|
||||||
$h->{fh}->close();
|
my $fh = $h->{fh};
|
||||||
|
#Log 0, "FLg: $i: >$h->{count}, $h->{df}<";
|
||||||
|
if(!$h->{count} && $h->{df} ne "") {
|
||||||
|
print $fh "$from $h->{df}\n";
|
||||||
|
}
|
||||||
|
$fh->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +331,10 @@ seekTo($$$$)
|
|||||||
if($data !~ m/^20\d\d-\d\d-\d\d_\d\d:\d\d:\d\d /) {
|
if($data !~ m/^20\d\d-\d\d-\d\d_\d\d:\d\d:\d\d /) {
|
||||||
$next = $fh->tell;
|
$next = $fh->tell;
|
||||||
$data = <$fh>;
|
$data = <$fh>;
|
||||||
$next = $last if(!$data);
|
if(!$data) {
|
||||||
|
$last = $next;
|
||||||
|
last;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if($next eq $last) {
|
if($next eq $last) {
|
||||||
$fh->seek($next, 0);
|
$fh->seek($next, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user