2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-05-02 06:55:26 +00:00

98_DOIF.pm: new data type barAvg, new import function DOIF_get_file_data, wrong collect definition in card will be outputted, / and - is now allowed in DOIF block name

git-svn-id: https://svn.fhem.de/fhem/trunk@27262 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Damian 2023-02-21 19:36:39 +00:00
parent 4fff2542f0
commit 141d46b8b4

View File

@ -1077,7 +1077,7 @@ sub AggrIntDoIf
$result=$num; $result=$num;
} }
if ($mode eq "#") { if ($mode eq "#") {
if ($format eq "d") { if (defined $result and $format eq "d") {
$result = ($result =~ /(-?\d+(\.\d+)?)/ ? $1 : 0); $result = ($result =~ /(-?\d+(\.\d+)?)/ ? $1 : 0);
$result = round ($result,$place) if (defined $place); $result = round ($result,$place) if (defined $place);
} }
@ -1298,16 +1298,17 @@ sub ReadingValDoIf
if (!defined $hash->{collect}{"$name $reading"}{$hours}) { if (!defined $hash->{collect}{"$name $reading"}{$hours}) {
return(undef); return(undef);
} }
setValue_collect($hash,\%{$hash->{collect}{"$name $reading"}{$hours}}); DOIF_setValue_collect($hash,\%{$hash->{collect}{"$name $reading"}{$hours}});
return (\%{$hash->{collect}{"$name $reading"}{$hours}}); return (\%{$hash->{collect}{"$name $reading"}{$hours}});
} elsif ($regExp =~ /^(bar(\d*)(day|week|month|year|decade))/) { } elsif ($regExp =~ /^((bar|barAvg)(\d*)(day|week|month|year|decade))/) {
my $num = $2; my $bartype=$2;
my $period = $3; my $num = $3;
if (!defined $hash->{bar}{"$name $reading"}{"$num $period"}) { my $period = $4;
if (!defined $hash->{$bartype}{"$name $reading"}{"$num $period"}) {
return(undef); return(undef);
} }
setValue_bar($hash,\%{$hash->{bar}{"$name $reading"}{"$num $period"}}); DOIF_setValue_bar($hash,\%{$hash->{$bartype}{"$name $reading"}{"$num $period"}});
return (\%{$hash->{bar}{"$name $reading"}{"$num $period"}}); return (\%{$hash->{$bartype}{"$name $reading"}{"$num $period"}});
} elsif ($regExp =~ /^d(\d)?/) { } elsif ($regExp =~ /^d(\d)?/) {
my $round=$1; my $round=$1;
$r = ($r =~ /(-?\d+(\.\d+)?)/ ? $1 : 0); $r = ($r =~ /(-?\d+(\.\d+)?)/ ? $1 : 0);
@ -1349,17 +1350,14 @@ sub DOIF_save_readings {
foreach my $key (keys %{$defs{$hash->{NAME}}{READINGS}}) { foreach my $key (keys %{$defs{$hash->{NAME}}{READINGS}}) {
delete $defs{$hash->{NAME}}{READINGS}{$key} if ($key =~ /^(\.col|\.bar)/); delete $defs{$hash->{NAME}}{READINGS}{$key} if ($key =~ /^(\.col|\.bar)/);
} }
if (defined $hash->{collect}) {
DOIF_collect_save_values($hash); DOIF_collect_save_values($hash);
}
if (defined $hash->{bar}) {
DOIF_bar_save_values($hash); DOIF_bar_save_values($hash);
}
} }
sub DOIF_collect_save_values { sub DOIF_collect_save_values {
my ($hash)=@_; my ($hash)=@_;
if (defined $hash->{collect}) {
foreach my $dev_reading (keys %{$hash->{collect}}) { foreach my $dev_reading (keys %{$hash->{collect}}) {
foreach my $hours (keys %{$hash->{collect}{"$dev_reading"}}) { foreach my $hours (keys %{$hash->{collect}{"$dev_reading"}}) {
if (ref($hash->{collect}{$dev_reading}{$hours}{values}) eq "ARRAY") { if (ref($hash->{collect}{$dev_reading}{$hours}{values}) eq "ARRAY") {
@ -1375,24 +1373,29 @@ sub DOIF_collect_save_values {
} }
} }
} }
}
} }
sub DOIF_bar_save_values { sub DOIF_bar_save_values {
my ($hash)=@_; my ($hash)=@_;
foreach my $dev_reading (keys %{$hash->{bar}}) { foreach my $bartype ("bar","barAvg") {
foreach my $num_period (keys %{$hash->{bar}{"$dev_reading"}}) { if (defined $hash->{$bartype}) {
if (ref($hash->{bar}{$dev_reading}{$num_period}{values}) eq "ARRAY") { foreach my $dev_reading (keys %{$hash->{$bartype}}) {
setValue_bar($hash,\%{$hash->{bar}{$dev_reading}{$num_period}}); foreach my $num_period (keys %{$hash->{$bartype}{"$dev_reading"}}) {
my @va=@{$hash->{bar}{$dev_reading}{$num_period}{values}}; if (ref($hash->{$bartype}{$dev_reading}{$num_period}{values}) eq "ARRAY") {
DOIF_setValue_bar($hash,\%{$hash->{$bartype}{$dev_reading}{$num_period}});
my @va=@{$hash->{$bartype}{$dev_reading}{$num_period}{values}};
for (@va) { $_ = "" if (!defined $_); }; for (@va) { $_ = "" if (!defined $_); };
my $dim=$hash->{bar}{$dev_reading}{$num_period}{dim}; my $dim=$hash->{$bartype}{$dev_reading}{$num_period}{dim};
my $last_period2=$hash->{bar}{$dev_reading}{$num_period}{last_period2}; my $last_period2=$hash->{$bartype}{$dev_reading}{$num_period}{last_period2};
my $last_period1=$hash->{bar}{$dev_reading}{$num_period}{last_period1}; my $last_period1=$hash->{$bartype}{$dev_reading}{$num_period}{last_period1};
my $devReading=$dev_reading; my $devReading=$dev_reading;
$devReading =~ s/ /_/g; $devReading =~ s/ /_/g;
my $numPeriod=$num_period; my $numPeriod=$num_period;
$numPeriod =~ s/ /_/g; $numPeriod =~ s/ /_/g;
::readingsSingleUpdate($hash,".bar_".$devReading."_".$numPeriod."_values","$last_period1,$last_period2,".join(",",@va),0); ::readingsSingleUpdate($hash,".".$bartype."_".$devReading."_".$numPeriod."_values","$last_period1,$last_period2,".join(",",@va),0);
}
}
} }
} }
} }
@ -1431,6 +1434,20 @@ sub DOIF_setColvalue
} }
} }
sub DOIF_get_file_data
{
my ($file) = @_;
my $fh;
if(!open($fh, $file)) {
return "Can't open $file: $!";
}
my @tpl=<$fh>;
close $fh;
my $cmd=join("",@tpl);
$cmd =~ s/\r//g;
return ($cmd);
}
sub DOIF_modify_card_data sub DOIF_modify_card_data
{ {
my ($name,$device,$reading,$colBarDes,$timeOffset,$valueData)=@_; my ($name,$device,$reading,$colBarDes,$timeOffset,$valueData)=@_;
@ -1462,33 +1479,52 @@ sub DOIF_setCardValues
if (!defined $timeOffset or $timeOffset eq "") { if (!defined $timeOffset or $timeOffset eq "") {
$timeOffset=0; $timeOffset=0;
} }
if ($valueData !~ /^\d\d\d\d/) { ##if ($valueData !~ /^\d\d\d\d/) {
return("invalid syntax: $valueData"); ## return("invalid syntax: $valueData");
} ##}
if ($type eq "bar") { if ($type eq "bar") {
setValue_bar($hash,$collect); DOIF_setValue_bar($hash,$collect);
} else { } else {
setValue_collect($hash,$collect); DOIF_setValue_collect($hash,$collect);
} }
my @data=split (/[\n\,]/,$valueData); my @data;
#${$collect}{last_v}=undef; if ($valueData =~ /\n/) {
@data=split (/[\n]/,$valueData);
} else {
@data=split (/[\,]/,$valueData);
}
my $out="";
for (my $i=0;$i < scalar (@data);$i++) { for (my $i=0;$i < scalar (@data);$i++) {
my ($dateTime,$value)=split (/[ \;]/,$data[$i]); if ($data[$i] !~ /\s*#/) {
if ($dateTime =~ /^\d\d\d\d/) { if ($data[$i] =~ /(.*)[\s;]+([\S^;]*)$/) {
my $dateTime = $1;
my $value = $2;
$value =~ s/\,/\./g;
my $time=DOIF_time_sec($dateTime);
if (defined $time) {
if ($type eq "bar") { if ($type eq "bar") {
DOIF_setBarvalue ($collect,DOIF_time_sec($dateTime)+$timeOffset,$value); DOIF_setBarvalue ($collect,$time+$timeOffset,$value);
} else { } else {
DOIF_setColvalue ($collect,DOIF_time_sec($dateTime)+$timeOffset,$value,$optimize); DOIF_setColvalue ($collect,$time+$timeOffset,$value,$optimize);
}
} else {
$out.="error at: $data[$i]\n";
}
} else {
$out.="error at: $data[$i]\n";
} }
} }
} }
if ($type eq "bar") { if ($type eq "bar") {
setValue_bar($hash,$collect,undef,1); DOIF_setValue_bar($hash,$collect,undef,1);
} else { } else {
setValue_collect($hash,$collect); DOIF_setValue_collect($hash,$collect);
} }
#DOIF_statistic_col ($collect); if ($out eq "") {
return; return;
} else {
return ($out);
}
} }
sub DOIF_delete_card_data sub DOIF_delete_card_data
@ -1529,7 +1565,7 @@ sub DOIF_delete_values
} }
} }
sub setValue_collect sub DOIF_setValue_collect
{ {
my ($hash,$collect,$statistic)=@_; my ($hash,$collect,$statistic)=@_;
if (!defined ${$collect}{dim}) { if (!defined ${$collect}{dim}) {
@ -1685,18 +1721,30 @@ sub DOIF_statistic_col
sub DOIF_time_sec($) sub DOIF_time_sec($)
{ {
my ($str) = @_; my ($dateTime) = @_;
my @a; my @a;
my ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst);
if ($dateTime =~/^(\d\d\d\d)(?:.(.*))?/) {
$year=$1;
($month,$mday,$hour,$min,$sec) = split(/[\D]/, $2) if (defined $2);
} elsif ($dateTime =~/(\d\d).(\d\d).(\d\d\d\d)(?:.(\d\d):(\d\d)(?::(\d\d))?)?/) {
$mday=$1;
$month=$2;
$year=$3;
$hour=$4;
$min=$5;
$sec=$6;
} else {
return (undef);
}
return time() if(!$str); $month=1 if (!defined $month);
@a = split(/[\D]/, $str); $mday=1 if (!defined $mday);
$a[1]=1 if (!defined $a[1]); $hour=0 if (!defined $hour);
$a[2]=1 if (!defined $a[2]); $min=0 if (!defined $min);
$a[3]=0 if (!defined $a[3]); $sec=0 if (!defined $sec);
$a[4]=0 if (!defined $a[4]);
$a[5]=0 if (!defined $a[5]);
return mktime($a[5],$a[4],$a[3],$a[2],$a[1]-1,$a[0]-1900,0,0,-1); return mktime($sec,$min,$hour,$mday,$month-1,$year-1900,0,0,-1);
} }
sub DOIF_statistic_bar sub DOIF_statistic_bar
@ -1812,6 +1860,27 @@ sub DOIF_setPeriod
return ($period1,$period2,$begin_period2); return ($period1,$period2,$begin_period2);
} }
sub DOIF_setBarPosValue
{
my ($bar,$pos,$value)=@_;
my $va=${$bar}{values};
if (defined ${$bar}{barType} and ${$bar}{barType} eq "barAvg") {
if (defined ${$va}[$pos] and defined ${$bar}{value_pos} and $pos == ${$bar}{value_pos}) {
${$bar}{value_sum}+=$value;
${$bar}{value_num}++;
${$va}[$pos]=${$bar}{value_sum}/${$bar}{value_num};
} else {
${$bar}{value_pos}=$pos;
${$bar}{value_sum}=$value;
${$bar}{value_num}=1;
${$va}[$pos]=$value;
}
} else {
${$va}[$pos]=$value;
}
}
sub DOIF_setBarvalue sub DOIF_setBarvalue
{ {
my ($bar,$seconds,$value)=@_; my ($bar,$seconds,$value)=@_;
@ -1824,13 +1893,12 @@ sub DOIF_setBarvalue
if (defined ${$bar}{last_period2} and $period2 <= ${$bar}{last_period2}) { if (defined ${$bar}{last_period2} and $period2 <= ${$bar}{last_period2}) {
my $diff=(${$bar}{last_period2} - $period2); my $diff=(${$bar}{last_period2} - $period2);
if ($diff < $num) { if ($diff < $num) {
my $va=${$bar}{values}; DOIF_setBarPosValue($bar,$diff*$dim+$period1,$value);
${$va}[$diff*$dim+$period1]=$value;
} }
} }
} }
sub setValue_bar sub DOIF_setValue_bar
{ {
my ($hash,$bar,$trigger,$statistic)=@_; my ($hash,$bar,$trigger,$statistic)=@_;
if (!defined ${$bar}{dim}) { if (!defined ${$bar}{dim}) {
@ -1904,7 +1972,8 @@ sub setValue_bar
${$bar}{value}=$r; ${$bar}{value}=$r;
if (defined $trigger and $r ne "N/A") { if (defined $trigger and $r ne "N/A") {
if ($timeOffset == 0) { if ($timeOffset == 0) {
${$va}[$period1]=${$bar}{value}; DOIF_setBarPosValue($bar,$period1,${$bar}{value})
#${$va}[$period1]=${$bar}{value};
} else { } else {
DOIF_setBarvalue ($bar,$seconds+$timeOffset,${$bar}{value}); DOIF_setBarvalue ($bar,$seconds+$timeOffset,${$bar}{value});
} }
@ -2153,14 +2222,15 @@ sub ReplaceReadingDoIf
} else { } else {
$hash->{collect}{"$name $reading"}{$hours}{output}=$output; $hash->{collect}{"$name $reading"}{$hours}{output}=$output;
} }
setValue_collect($hash,\%{$hash->{collect}{"$name $reading"}{$hours}},1); DOIF_setValue_collect($hash,\%{$hash->{collect}{"$name $reading"}{$hours}},1);
} }
} elsif ($format =~ /^(bar(\d*)(day|week|month|year|decade))(-?\d*)?(?::(.*))?/) { } elsif ($format =~ /^((bar|barAvg)(\d*)(day|week|month|year|decade))(-?\d*)?(?::(.*))?/) {
$regExp = $1; $regExp = $1;
my $num = $2; my $bartype=$2;
my $period = $3; my $num = $3;
my $timeOffset = $4; my $period = $4;
$output = $5; my $timeOffset = $5;
$output = $6;
if (defined $cond and $cond >= -7 and $cond <= -4) { #DOIF_Readings,event_Readings,uiTable,uiState if (defined $cond and $cond >= -7 and $cond <= -4) { #DOIF_Readings,event_Readings,uiTable,uiState
my $dim; my $dim;
if ($period eq "decade") { if ($period eq "decade") {
@ -2174,14 +2244,14 @@ sub ReplaceReadingDoIf
} elsif ($period eq "day") { } elsif ($period eq "day") {
$dim=24; $dim=24;
} }
AddRegexpTriggerDoIf($hash,"bar","","bar",$name,$reading); AddRegexpTriggerDoIf($hash,$bartype,"",$bartype,$name,$reading);
if (ref($hash->{bar}{"$name $reading"}{"$num $period"}{values}) ne "ARRAY") { if (ref($hash->{$bartype}{"$name $reading"}{"$num $period"}{values}) ne "ARRAY") {
delete $hash->{bar}{"$name $reading"}{"$num $period"}; delete $hash->{$bartype}{"$name $reading"}{"$num $period"};
my $values=::ReadingsVal($hash->{NAME},".bar_".$name."_".$reading."_".$num."_".$period."_values",""); my $values=::ReadingsVal($hash->{NAME},".".$bartype."_".$name."_".$reading."_".$num."_".$period."_values","");
my $va; my $va;
my $vadim=($num == 1 ? 2 : $num)*$dim; my $vadim=($num == 1 ? 2 : $num)*$dim;
if ($values ne "") { if ($values ne "") {
($hash->{bar}{"$name $reading"}{"$num $period"}{last_period1},$hash->{bar}{"$name $reading"}{"$num $period"}{last_period2},@{$va})=split (",",$values); ($hash->{$bartype}{"$name $reading"}{"$num $period"}{last_period1},$hash->{$bartype}{"$name $reading"}{"$num $period"}{last_period2},@{$va})=split (",",$values);
if (@{$va} < $vadim) { if (@{$va} < $vadim) {
${$va}[$vadim-1]=undef; ${$va}[$vadim-1]=undef;
} }
@ -2189,25 +2259,25 @@ sub ReplaceReadingDoIf
} else { } else {
${$va}[$vadim-1]=undef; ${$va}[$vadim-1]=undef;
} }
$hash->{bar}{"$name $reading"}{"$num $period"}{values} = $va; $hash->{$bartype}{"$name $reading"}{"$num $period"}{values} = $va;
$hash->{bar}{"$name $reading"}{"$num $period"}{numOrig} = $num; $hash->{$bartype}{"$name $reading"}{"$num $period"}{numOrig} = $num;
$hash->{bar}{"$name $reading"}{"$num $period"}{num} = $num == 1 ? 2 : $num; $hash->{$bartype}{"$name $reading"}{"$num $period"}{num} = $num == 1 ? 2 : $num;
$hash->{bar}{"$name $reading"}{"$num $period"}{period} = $period; $hash->{$bartype}{"$name $reading"}{"$num $period"}{period} = $period;
$hash->{bar}{"$name $reading"}{"$num $period"}{name} = $name; $hash->{$bartype}{"$name $reading"}{"$num $period"}{name} = $name;
$hash->{bar}{"$name $reading"}{"$num $period"}{reading} = $reading; $hash->{$bartype}{"$name $reading"}{"$num $period"}{reading} = $reading;
#$hash->{bar}{"$name $reading"}{"$num $period"}{counter}=$counter; #$hash->{$bartype}{"$name $reading"}{"$num $period"}{counter}=$counter;
$hash->{bar}{"$name $reading"}{"$num $period"}{dim} = $dim;
$hash->{bar}{"$name $reading"}{"$num $period"}{type} = "bar";
$hash->{$bartype}{"$name $reading"}{"$num $period"}{dim} = $dim;
$hash->{$bartype}{"$name $reading"}{"$num $period"}{type} = "bar";
$hash->{$bartype}{"$name $reading"}{"$num $period"}{barType} = $bartype;
} }
if (!defined $output or $output eq "") { if (!defined $output or $output eq "") {
delete $hash->{bar}{"$name $reading"}{"$num $period"}{output}; delete $hash->{$bartype}{"$name $reading"}{"$num $period"}{output};
} else { } else {
$hash->{bar}{"$name $reading"}{"$num $period"}{output} = $output; $hash->{$bartype}{"$name $reading"}{"$num $period"}{output} = $output;
} }
$hash->{bar}{"$name $reading"}{"$num $period"}{timeOffset} = (defined $timeOffset and $timeOffset ne "") ? $timeOffset : 0; $hash->{$bartype}{"$name $reading"}{"$num $period"}{timeOffset} = (defined $timeOffset and $timeOffset ne "") ? $timeOffset : 0;
setValue_bar($hash,\%{$hash->{bar}{"$name $reading"}{"$num $period"}},undef,1); DOIF_setValue_bar($hash,\%{$hash->{$bartype}{"$name $reading"}{"$num $period"}},undef,1);
} }
} elsif ($format =~ /^(d[^:]*)(?::(.*))?/) { } elsif ($format =~ /^(d[^:]*)(?::(.*))?/) {
$regExp =$1; $regExp =$1;
@ -3435,19 +3505,21 @@ DOIF_Notify($$)
my $readingregex=CheckRegexpDoIf($hash,"collect",$dev->{NAME},"collect",$eventa,$eventas,$reading); my $readingregex=CheckRegexpDoIf($hash,"collect",$dev->{NAME},"collect",$eventa,$eventas,$reading);
if (defined $readingregex) { if (defined $readingregex) {
foreach my $hours (keys %{$hash->{collect}{"$device $readingregex"}}){ foreach my $hours (keys %{$hash->{collect}{"$device $readingregex"}}){
setValue_collect($hash,\%{$hash->{collect}{"$device $readingregex"}{$hours}}); DOIF_setValue_collect($hash,\%{$hash->{collect}{"$device $readingregex"}{$hours}});
} }
} }
} }
} }
if (defined $hash->{Regex}{"bar"}{"$dev->{NAME}"}) { foreach my $bartype ("bar","barAvg") {
if (defined $hash->{Regex}{$bartype}{"$dev->{NAME}"}) {
my $device=$dev->{NAME}; my $device=$dev->{NAME};
foreach my $reading (keys %{$hash->{Regex}{"bar"}{$device}{"bar"}}) { foreach my $reading (keys %{$hash->{Regex}{$bartype}{$device}{$bartype}}) {
my $readingregex=CheckRegexpDoIf($hash,"bar",$dev->{NAME},"bar",$eventa,$eventas,$reading); my $readingregex=CheckRegexpDoIf($hash,$bartype,$dev->{NAME},$bartype,$eventa,$eventas,$reading);
if (defined $readingregex) { if (defined $readingregex) {
foreach my $period (keys %{$hash->{bar}{"$device $readingregex"}}){ foreach my $period (keys %{$hash->{$bartype}{"$device $readingregex"}}){
setValue_bar($hash,\%{$hash->{bar}{"$device $readingregex"}{$period}},1); DOIF_setValue_bar($hash,\%{$hash->{$bartype}{"$device $readingregex"}{$period}},1);
}
} }
} }
} }
@ -3962,7 +4034,7 @@ sub DOIF_Perlblock
my ($hash,$table,$tail,$subs) =@_; my ($hash,$table,$tail,$subs) =@_;
my ($beginning,$perlblock,$err,$i); my ($beginning,$perlblock,$err,$i);
$i=0; $i=0;
while($tail =~ /(?:^|\n)\s*([\w\.]*)\s*\{/g) { while($tail =~ /(?:^|\n)\s*([\w\.\/\-]*)\s*\{/g) {
my $blockname=$1; my $blockname=$1;
($beginning,$perlblock,$err,$tail)=GetBlockDoIf($tail,'[\{\}]'); ($beginning,$perlblock,$err,$tail)=GetBlockDoIf($tail,'[\{\}]');
if ($err) { if ($err) {
@ -4464,7 +4536,7 @@ DOIF_Set($@)
} elsif ($arg eq "enable" ) { } elsif ($arg eq "enable" ) {
#delete ($defs{$hash->{NAME}}{READINGS}{mode}); #delete ($defs{$hash->{NAME}}{READINGS}{mode});
if ($hash->{MODEL} ne "Perl") { if ($hash->{MODEL} ne "Perl") {
readingsSingleUpdate ($hash,"state",ReadingsVal($pn,"last_cmd",""),0) if (ReadingsVal($pn,"last_cmd","") ne ""); readingsSingleUpdate ($hash,"state",ReadingsVal($pn,"last_cmd",""),1) if (ReadingsVal($pn,"last_cmd","") ne "");
delete ($defs{$hash->{NAME}}{READINGS}{last_cmd}); delete ($defs{$hash->{NAME}}{READINGS}{last_cmd});
} }
readingsSingleUpdate ($hash,"mode","enabled",1) readingsSingleUpdate ($hash,"mode","enabled",1)
@ -5444,7 +5516,7 @@ sub card
my $begin_period2; my $begin_period2;
if (!defined $col) { if (!defined $col) {
return(""); return("no definition at collect parameter");
} }
if (ref($col) eq "ARRAY") { if (ref($col) eq "ARRAY") {
@ -5466,8 +5538,7 @@ sub card
$value1[$i]{value}=${$col}[$i]; $value1[$i]{value}=${$col}[$i];
} }
} }
} else { } elsif (ref ($col) eq "HASH") {
if (ref ($col) eq "HASH") {
$colcount++; $colcount++;
$value1[0]=$col; $value1[0]=$col;
if (!defined $dim) { if (!defined $dim) {
@ -5481,21 +5552,20 @@ sub card
$begin_period2=$value1[0]{begin_period2}; $begin_period2=$value1[0]{begin_period2};
} }
} else { } else {
$value1[0]{value}=$col; return ("wrong definition at collect parameter: $col");
} # $value1[0]{value}=$col;
} }
if (ref($unit_a) eq "ARRAY") { if (ref($unit_a) eq "ARRAY") {
for (my $i=0;$i < @{$unit_a};$i++) { for (my $i=0;$i < @{$unit_a};$i++) {
$unit1[$i]=${$unit_a}[$i]; $unit1[$i]=${$unit_a}[$i];
} }
} else { } elsif (!defined $unit_a) {
if (!defined $unit_a) {
$unit1[0]=""; $unit1[0]="";
} else { } else {
$unit1[0]=$unit_a; $unit1[0]=$unit_a;
} }
}
if (defined $col2) { if (defined $col2) {
if (ref($col2) eq "ARRAY") { if (ref($col2) eq "ARRAY") {
for (my $i=0;$i< @{$col2};$i++) { for (my $i=0;$i< @{$col2};$i++) {
@ -5513,8 +5583,7 @@ sub card
$value2[$i]{value}=${$col2}[$i]; $value2[$i]{value}=${$col2}[$i];
} }
} }
} else { } elsif (ref ($col2) eq "HASH") {
if (ref ($col2) eq "HASH") {
$col2count++; $col2count++;
$value2[0]=$col2; $value2[0]=$col2;
if (!defined $dim) { if (!defined $dim) {
@ -5525,25 +5594,19 @@ sub card
$period=$value2[0]{period}; $period=$value2[0]{period};
} }
} else { } else {
$value2[0]{value}=$col2; return ("wrong definition at collect2 parameter: $col2");
} # $value2[0]{value}=$col2;
} }
} }
if (ref($unit_b) eq "ARRAY") { if (ref($unit_b) eq "ARRAY") {
for (my $i=0;$i < @{$unit_b};$i++) { for (my $i=0;$i < @{$unit_b};$i++) {
$unit2[$i]=${$unit_b}[$i]; $unit2[$i]=${$unit_b}[$i];
} }
} else { } elsif (!defined $unit_b) {
if (!defined $unit_b) {
$unit2[0]=""; $unit2[0]="";
} else { } else {
$unit2[0]=$unit_b; $unit2[0]=$unit_b;
} }
}
# if (!defined $value1[0]{value}) {
# return("");
# }
if (!defined $dim) { if (!defined $dim) {
return(""); return("");
@ -5749,7 +5812,9 @@ sub card
my @outfooter; my @outfooter;
if ($type eq "bar") { if ($type eq "bar") {
my ($sec,$minutes,$hour,$mday,$month,$year,$wday,$yday,$isdst);
my @desc; my @desc;
my @monthDays;
my $x; my $x;
my $dimplot=$dim; my $dimplot=$dim;
if ($period eq "decade") { if ($period eq "decade") {
@ -5758,6 +5823,9 @@ sub card
@desc= qw(Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez); @desc= qw(Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez);
} elsif ($period eq "month") { } elsif ($period eq "month") {
@desc=qw(01 03 05 07 09 11 13 15 17 19 21 23 25 27 29 31); @desc=qw(01 03 05 07 09 11 13 15 17 19 21 23 25 27 29 31);
($sec,$minutes,$hour,$mday,$month,$year,$wday,$yday,$isdst) = localtime();
@monthDays=qw(31 28 31 30 31 30 31 31 30 31 30 31);
$monthDays[1]=($year % 4 == 0 and $year % 100 != 0 or $year % 400 == 0) ? 29 : 28;
$dimplot=32; $dimplot=32;
} elsif ($period eq "week") { } elsif ($period eq "week") {
@desc=qw(Mo Di Mi Do Fr Sa So); @desc=qw(Mo Di Mi Do Fr Sa So);
@ -5766,15 +5834,26 @@ sub card
@desc=qw(00 02 04 06 08 10 12 14 16 18 20 22 24); @desc=qw(00 02 04 06 08 10 12 14 16 18 20 22 24);
} }
my $xOffset=0.5*$chart_dim/@desc; my $xOffset=0.5*$chart_dim/@desc;
$x=int(($xOffset+$period1*$chart_dim/$dimplot)*10)/10; $x=int(($xOffset+$period1*$chart_dim/$dimplot)*10)/10;
$out.= sprintf('<text text-anchor="end" x=-2.5 y=61 style="fill:#CCCCCC;font-size:7px;">%s</text>',$begin_period2); $out.= sprintf('<text text-anchor="end" x=-2.5 y=61 style="fill:#CCCCCC;font-size:7px;">%s</text>',$begin_period2);
$out.= sprintf('<circle cx="%s" cy="%s" r="1.5" fill=#CCCCCC opacity="1"/>',$x,53); $out.= sprintf('<circle cx="%s" cy="53" r="1.5" fill=#CCCCCC opacity="1"/>',$x);
for (my $i=0;$i<@desc;$i++) { for (my $i=0;$i<@desc;$i++) {
$x=int(($i+0.5)*$chart_dim/@desc*10)/10; $x=int(($i+0.5)*$chart_dim/@desc*10)/10;
$out.=sprintf('<polyline points="%s,%s %s,%s" style="stroke:#505050; stroke-width:0.3; stroke-opacity:1" />',$x,0,$x,50); $out.=sprintf('<polyline points="%s,%s %s,%s" style="stroke:#505050; stroke-width:0.3; stroke-opacity:1" />',$x,0,$x,50);
$out.=sprintf('<text text-anchor="middle" x="%s" y="61" style="fill:#CCCCCC;font-size:7px">%s</text>',$x,$desc[$i]); $out.=sprintf('<text text-anchor="middle" x="%s" y="61" style="fill:%s;font-size:7px">%s</text>',$x,($period eq "month" and $desc[$i] > $monthDays[$month]) ? "#A0A0A0":"#CCCCCC",$desc[$i]);
}
if ($period eq "month") {
my $su=$period1+7-$wday;
my $first=$su % 7;
for (my $i=0;$i<5;$i++) {
my $day=$first+$i*7;
$x=int(($xOffset+($first+$i*7)*$chart_dim/$dimplot)*10)/10;
$out.=sprintf('<polyline points="%s,63,%s,63" style="stroke:#CCCCCC; stroke-width:1; stroke-opacity:1" />',$x-2,$x+2) if ($day < $monthDays[$month]);
}
} }
my $minVal; my $minVal;