FileLog_get with CURRENT as argument is searching for the data in older logfiles (%Y%m%d substitution)

git-svn-id: https://svn.fhem.de/fhem/trunk@3248 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2013-06-06 15:09:39 +00:00
parent 8ed776eff0
commit a366612ee4
2 changed files with 36 additions and 17 deletions

View File

@ -119,6 +119,7 @@ FileLog_Log($$)
my $ct = $dev->{CHANGETIME}; my $ct = $dev->{CHANGETIME};
my $wrotesome; my $wrotesome;
my $fh = $log->{FH}; my $fh = $log->{FH};
my $switched;
for (my $i = 0; $i < $max; $i++) { for (my $i = 0; $i < $max; $i++) {
my $s = $dev->{CHANGED}[$i]; my $s = $dev->{CHANGED}[$i];
@ -127,7 +128,10 @@ FileLog_Log($$)
if($n =~ m/^$re$/ || "$n:$s" =~ m/^$re$/ || "$t:$n:$s" =~ m/^$re$/) { if($n =~ m/^$re$/ || "$n:$s" =~ m/^$re$/ || "$t:$n:$s" =~ m/^$re$/) {
$t =~ s/ /_/; # Makes it easier to parse with gnuplot $t =~ s/ /_/; # Makes it easier to parse with gnuplot
FileLog_Switch($log); if(!$switched) {
FileLog_Switch($log);
$switched = 1;
}
print $fh "$t $n $s\n"; print $fh "$t $n $s\n";
$wrotesome = 1; $wrotesome = 1;
@ -135,8 +139,8 @@ FileLog_Log($$)
} }
if($wrotesome) { if($wrotesome) {
$fh->flush; $fh->flush;
# Too much IO # Skip sync, it costs too much HD strain, esp. on SSD
# $fh->sync if !($^O eq 'MSWin32'); #not implemented in Windows # $fh->sync if !($^O eq 'MSWin32'); #not implemented in Windows
} }
return ""; return "";
} }
@ -375,28 +379,48 @@ FileLog_Get($@)
my $from = shift @a; my $from = shift @a;
my $to = shift @a; # Now @a contains the list of column_specs my $to = shift @a; # Now @a contains the list of column_specs
my $internal; my $internal;
if($outf eq "INT") { if($outf eq "INT") {
$outf = "-"; $outf = "-";
$internal = 1; $internal = 1;
} }
FileLog_Switch($hash);
if($inf eq "-") { if($inf eq "-") {
# In case the plot is drawn afte midnight, before the first event is logged.
FileLog_Switch($hash);
$inf = $hash->{currentlogfile}; $inf = $hash->{currentlogfile};
} else { } else {
my $linf;
if($inf eq "CURRENT") {
# Try to guess
if($from =~ m/^(....)-(..)-(..)/) {
$linf = $hash->{logfile};
my ($Y,$m,$d) = ($1,$2,$3);
$linf =~ s/%Y/$Y/g;
$linf =~ s/%m/$m/g;
$linf =~ s/%d/$d/g;
} else {
$linf = $hash->{currentlogfile};
}
} else {
$linf = "$1/$inf" if($hash->{currentlogfile} =~ m,^(.*)/[^/]*$,);
$linf = "" if(!$linf); # Missing log directory
}
# Look for the file in the log directory... # Look for the file in the log directory...
my $linf = "$1/$inf" if($hash->{currentlogfile} =~ m,^(.*)/[^/]*$,);
return undef if(!$linf);
if(!-f $linf) { if(!-f $linf) {
# ... or in the archivelog # ... or in the archivelog
$linf = AttrVal($hash->{NAME},"archivedir",".") ."/". $inf; $linf = AttrVal($hash->{NAME},"archivedir",".") ."/". $inf;
return "Error: cannot access $linf" if(!-f $linf); $linf = "";
} }
$inf = $linf; $inf = $linf;
} }
my $ifh = new IO::File $inf; my $ifh = new IO::File $inf if($inf);
seekTo($inf, $ifh, $hash, $from); seekTo($inf, $ifh, $hash, $from) if($ifh);
############# #############
# Digest the input. # Digest the input.
@ -456,7 +480,7 @@ RESCAN:
last if($rescanIdx<1 || !$rescanNum); last if($rescanIdx<1 || !$rescanNum);
$l = $rescanArr[$rescanIdx--]; $l = $rescanArr[$rescanIdx--];
} else { } else {
$l = <$ifh>; $l = <$ifh> if($ifh);
last if(!$l); last if(!$l);
} }
@ -544,7 +568,7 @@ RESCAN:
# If no value found for some of the required columns, then look for the last # If no value found for some of the required columns, then look for the last
# matching entry outside of the range. Known as the "window left open # matching entry outside of the range. Known as the "window left open
# yesterday" problem # yesterday" problem
if(!$rescan) { if(!$rescan && $ifh) {
$rescanNum = 0; $rescanNum = 0;
map { $rescanNum++ if(!$d[$_]->{count} && $d[$_]->{df} eq "") } (0..$#a); map { $rescanNum++ if(!$d[$_]->{count} && $d[$_]->{df} eq "") } (0..$#a);
if($rescanNum) { if($rescanNum) {
@ -561,7 +585,7 @@ RESCAN:
} }
} }
$ifh->close(); $ifh->close() if($ifh);
my $ret = ""; my $ret = "";
for(my $i = 0; $i < int(@a); $i++) { for(my $i = 0; $i < int(@a); $i++) {

View File

@ -181,11 +181,6 @@ weblink_FwFn($$$$)
$ret .= weblink_FwDetail($d, "Broken definition "); $ret .= weblink_FwDetail($d, "Broken definition ");
} else { } else {
if(defined($va[2]) && $va[2] eq "CURRENT") {
$defs{$va[0]}{currentlogfile} =~ m,([^/]*)$,;
$va[2] = $1;
}
if ($wltype eq "dbplot") { if ($wltype eq "dbplot") {
$va[2] = "-"; $va[2] = "-";
} }