| | 54 | $min = "U"; |
| | 55 | $max = "U"; #unlimited |
| | 56 | if ($rrdbn =~ /temperature/) { |
| | 57 | $min = "-60"; |
| | 58 | $max = "60"; |
| | 59 | $value_type =~ s/temperature//g; |
| | 60 | $value_type =~ s/_//g; |
| | 61 | push(@{$temperature{$value_type}}, $wname); |
| | 62 | push(@{$temperature{$value_type}}, $value); |
| | 63 | push(@{$temperature{$value_type}}, $scale); |
| | 64 | $rrdbn = "temperature_".$value_type; |
| | 65 | } elsif ($rrdbn eq "wind_speed" or $rrdbn eq "wind_gust") { |
| | 66 | $min = "0"; |
| | 67 | $max = "100"; #m/s > 330km/h |
| | 68 | $value_type =~ s/wind//g; |
| | 69 | $value_type =~ s/_//g; |
| | 70 | push(@{$wind{$value_type}}, $wname); |
| | 71 | push(@{$wind{$value_type}}, $value); |
| | 72 | push(@{$wind{$value_type}}, $scale); |
| | 73 | $rrdbn = "wind_".$value_type; |
| | 74 | } elsif ($rrdbn eq "wind_direction") { |
| | 75 | $min = "0"; |
| | 76 | $max = "15"; |
| | 77 | $value_type =~ s/wind//g; |
| | 78 | $value_type =~ s/_//g; |
| | 79 | push(@{$wind{$value_type}}, $wname); |
| | 80 | push(@{$wind{$value_type}}, $value); |
| | 81 | push(@{$wind{$value_type}}, $scale); |
| | 82 | $rrdbn = "wind_".$value_type; |
| | 83 | } elsif ($rrdbn =~ /humidity/) { |
| | 84 | $min = "0"; |
| | 85 | $max = "100"; #% |
| | 86 | $value_type =~ s/humidity//g; |
| | 87 | $value_type =~ s/_//g; |
| | 88 | push(@{$humidity{$value_type}}, $wname); |
| | 89 | push(@{$humidity{$value_type}}, $value); |
| | 90 | push(@{$humidity{$value_type}}, $scale.$scale); |
| | 91 | $rrdbn = "humidity_".$value_type; |
| | 92 | } elsif ($rrdbn eq "rain_1h") { |
| | 93 | $min = "0"; |
| | 94 | $max = "100"; #mm/h |
| | 95 | $value_type =~ s/rain//g; |
| | 96 | $value_type =~ s/_//g; |
| | 97 | push(@{$rain{$value_type}}, $wname); |
| | 98 | push(@{$rain{$value_type}}, $value); |
| | 99 | push(@{$rain{$value_type}}, $scale); |
| | 100 | $rrdbn = "rain_".$value_type; |
| | 101 | } elsif ($rrdbn eq "rain_total") { |
| | 102 | $value_type =~ s/rain//g; |
| | 103 | $value_type =~ s/_//g; |
| | 104 | push(@{$rain{$value_type}}, $wname); |
| | 105 | push(@{$rain{$value_type}}, $value); |
| | 106 | push(@{$rain{$value_type}}, $scale); |
| | 107 | $rrdbn = "rain_".$value_type; |
| | 108 | } elsif ($rrdbn =~ /pressure/) { |
| | 109 | $min = "800"; |
| | 110 | $max = "1200"; |
| | 111 | $value_type =~ s/pressure//g; |
| | 112 | $value_type =~ s/_//g; |
| | 113 | push(@{$pressure{$value_type}}, $wname); |
| | 114 | push(@{$pressure{$value_type}}, $value); |
| | 115 | push(@{$pressure{$value_type}}, $scale); |
| | 116 | $rrdbn = "pressure_".$value_type; |
| | 117 | } |
| | 118 | |
| 93 | | if ($graphs == 1) { |
| 94 | | #86400 = 24h |
| 95 | | $img = $wwwdir.$rrdbn."_24h.gif"; |
| 96 | | &callsys($rrdtoolp." graph ".$img." --start -86400 -i \\ |
| 97 | | --vertical-label \"$wname $scale\" \\ |
| 98 | | DEF:in=".$rrdbp.$rrdbn.".rrd:$rrdbn:AVERAGE \\ |
| 99 | | LINE1:in#00FF00:\"$rrdbn\" \\ |
| 100 | | GPRINT:in:MAX:\"max %6.2lf %s\" \\ |
| 101 | | GPRINT:in:MIN:\"min %6.2lf %s\" \\ |
| 102 | | GPRINT:in:AVERAGE:\"avg %6.2lf %s\" \\ |
| 103 | | "); |
| 104 | | #2592000 = 30*86400 |
| 105 | | $img = $wwwdir.$rrdbn."_30d.gif"; |
| 106 | | &callsys($rrdtoolp." graph ".$img." --start -2592000 -i\\ |
| 107 | | --vertical-label \"$wname\" \\ |
| 108 | | DEF:in=".$rrdbp.$rrdbn.".rrd:$rrdbn:AVERAGE \\ |
| 109 | | LINE1:in#00FF00:\"$rrdbn\" \\ |
| 110 | | GPRINT:in:MAX:\"max %6.2lf %s\" \\ |
| 111 | | GPRINT:in:MIN:\"min %6.2lf %s\" \\ |
| 112 | | GPRINT:in:AVERAGE:\"avg %6.2lf %s\" \\ |
| 113 | | "); |
| 114 | | #365*86400 |
| 115 | | $img = $wwwdir.$rrdbn."_1y.gif"; |
| 116 | | &callsys($rrdtoolp." graph ".$img." --start -31536000 -i\\ |
| 117 | | --vertical-label \"$wname\" \\ |
| 118 | | DEF:in=".$rrdbp.$rrdbn.".rrd:$rrdbn:AVERAGE \\ |
| 119 | | LINE1:in#00FF00:\"$rrdbn\" \\ |
| 120 | | GPRINT:in:MAX:\"max %6.2lf %s\" \\ |
| 121 | | GPRINT:in:MIN:\"min %6.2lf %s\" \\ |
| 122 | | GPRINT:in:AVERAGE:\"avg %6.2lf %s\" \\ |
| 123 | | "); |
| 124 | | #365*5*86400 |
| 125 | | $img = $wwwdir.$rrdbn."_5y.gif"; |
| 126 | | &callsys($rrdtoolp." graph ".$img." --start -157680000 -i\\ |
| 127 | | --vertical-label \"$wname\" \\ |
| 128 | | DEF:in=".$rrdbp.$rrdbn.".rrd:$rrdbn:AVERAGE \\ |
| 129 | | LINE1:in#00FF00:\"$rrdbn\" \\ |
| 130 | | GPRINT:in:MAX:\"max %6.2lf %s\" \\ |
| 131 | | GPRINT:in:MIN:\"min %6.2lf %s\" \\ |
| 132 | | GPRINT:in:AVERAGE:\"avg %6.2lf %s\" \\ |
| 133 | | "); |
| | 138 | }; |
| | 139 | }; |
| | 140 | |
| | 141 | |
| | 142 | sub create_graphs_for { |
| | 143 | my %hasharray = %{$_[0]}; |
| | 144 | my $wname = $_[1]; |
| | 145 | my %gtimes = ( |
| | 146 | "24h" => 86400, |
| | 147 | "30d" => 2592000, |
| | 148 | "1y" => 31536000, |
| | 149 | "5y" => 157680000 |
| | 150 | ); |
| | 151 | my @color = ( "#dc0000", "#dc00dc", "#5800dc", "#009bdc", "#00dc87" ); |
| | 152 | my $coloridx = 0; |
| | 153 | # N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNw |
| | 154 | my @direction_cols = ( "#ff0000", "#ff6600", "#ffcc00", "#ccff00", "#66ff00", "#00ff00", "#00ff66", "#00ffcc", "#00ccff", "#0066ff", "#0000ff", "#6600ff", "#cc00ff", "#ff00cc", "#ff0066", "#ff0000"); |
| | 155 | |
| | 156 | foreach $gtime (keys %gtimes) { |
| | 157 | $arguments = ""; |
| | 158 | $coloridx = 0; |
| | 159 | $img = $wwwdir.$wname."_".$gtime.".gif"; |
| | 160 | $cmd_arguments = $rrdtoolp." graph ".$img." --start -".$gtimes{$gtime}." --width 550 --height 150 --vertical-label \"".ucfirst($wname)."\" --watermark \"WeatherStats\" \\"; #jak udelat scale?? --vertical-label".$scale\" \\"; |
| | 161 | |
| | 162 | # compile the graphs arguments |
| | 163 | if ($wname eq "temperature") { |
| | 164 | foreach $atribute (keys %hasharray) { |
| | 165 | if ($atribute =~ /out/) { |
| | 166 | $scale = ${$hasharray{$atribute}}[2]; |
| | 167 | $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":AVERAGE "; |
| | 168 | $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" "; |
| | 169 | $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" "; |
| | 170 | $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" "; |
| | 171 | $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" "; |
| | 172 | $coloridx++; |
| | 173 | } |
| | 174 | } |
| | 175 | $arguments = $arguments."HRULE:0#474747"; |
| | 176 | $cmd_arguments_tmp = $cmd_arguments; |
| | 177 | $cmd_arguments_tmp =~ s/$gtime/out_$gtime/g; |
| | 178 | &callsys($cmd_arguments_tmp.$arguments); |
| | 179 | $arguments = ""; |
| | 180 | $coloridx = 0; |
| | 181 | foreach $atribute (keys %hasharray) { |
| | 182 | $scale = ${$hasharray{$atribute}}[2]; |
| | 183 | $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":AVERAGE "; |
| | 184 | $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" "; |
| | 185 | $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" "; |
| | 186 | $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" "; |
| | 187 | $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" "; |
| | 188 | $coloridx++; |
| | 189 | } |
| | 190 | $arguments = $arguments."HRULE:0#474747"; |
| | 191 | } elsif ($wname eq "wind") { |
| | 192 | foreach $atribute (keys %hasharray) { |
| | 193 | if ($atribute eq "direction") { |
| | 194 | $scale = ${$hasharray{$atribute}}[2]; |
| | 195 | $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":MAX "; |
| | 196 | $arguments = $arguments."CDEF:North=".$atribute.",0,GE,-4,* "; |
| | 197 | $arguments = $arguments."CDEF:NNE=".$atribute.",1,GE,-4,* "; |
| | 198 | $arguments = $arguments."CDEF:NE=".$atribute.",2,GE,-4,* "; |
| | 199 | $arguments = $arguments."CDEF:ENE=".$atribute.",3,GE,-4,* "; |
| | 200 | $arguments = $arguments."CDEF:East=".$atribute.",4,GE,-4,* "; |
| | 201 | $arguments = $arguments."CDEF:ESE=".$atribute.",5,GE,-4,* "; |
| | 202 | $arguments = $arguments."CDEF:SE=".$atribute.",6,GE,-4,* "; |
| | 203 | $arguments = $arguments."CDEF:SSE=".$atribute.",7,GE,-4,* "; |
| | 204 | $arguments = $arguments."CDEF:South=".$atribute.",8,GE,-4,* "; |
| | 205 | $arguments = $arguments."CDEF:SSW=".$atribute.",9,GE,-4,* "; |
| | 206 | $arguments = $arguments."CDEF:SW=".$atribute.",10,GE,-4,* "; |
| | 207 | $arguments = $arguments."CDEF:WSW=".$atribute.",11,GE,-4,* "; |
| | 208 | $arguments = $arguments."CDEF:West=".$atribute.",12,GE,-4,* "; |
| | 209 | $arguments = $arguments."CDEF:WNW=".$atribute.",13,GE,-4,* "; |
| | 210 | $arguments = $arguments."CDEF:NW=".$atribute.",14,GE,-4,* "; |
| | 211 | $arguments = $arguments."CDEF:NNW=".$atribute.",15,GE,-4,* "; |
| | 212 | $arguments = $arguments."AREA:North".$direction_cols[0].":N "; |
| | 213 | $arguments = $arguments."AREA:NNE".$direction_cols[1].": "; |
| | 214 | $arguments = $arguments."AREA:NE".$direction_cols[2].":NE "; |
| | 215 | $arguments = $arguments."AREA:ENE".$direction_cols[3].": "; |
| | 216 | $arguments = $arguments."AREA:East".$direction_cols[4].":E "; |
| | 217 | $arguments = $arguments."AREA:ESE".$direction_cols[5].": "; |
| | 218 | $arguments = $arguments."AREA:SE".$direction_cols[6].":SE "; |
| | 219 | $arguments = $arguments."AREA:SSE".$direction_cols[7].": "; |
| | 220 | $arguments = $arguments."AREA:South".$direction_cols[8].":S "; |
| | 221 | $arguments = $arguments."AREA:SSW".$direction_cols[9].": "; |
| | 222 | $arguments = $arguments."AREA:SW".$direction_cols[10].":SW "; |
| | 223 | $arguments = $arguments."AREA:WSW".$direction_cols[11].": "; |
| | 224 | $arguments = $arguments."AREA:West".$direction_cols[12].":W "; |
| | 225 | $arguments = $arguments."AREA:WNW".$direction_cols[13].": "; |
| | 226 | $arguments = $arguments."AREA:NW".$direction_cols[14].":\"NW\\l\" "; |
| | 227 | $arguments = $arguments."AREA:NNW".$direction_cols[15].": "; |
| | 228 | } else { |
| | 229 | $scale = ${$hasharray{$atribute}}[2]; |
| | 230 | $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":MAX "; |
| | 231 | $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" "; |
| | 232 | $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" "; |
| | 233 | $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" "; |
| | 234 | $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" "; |
| | 235 | $coloridx++; |
| | 236 | } |
| | 237 | } |
| | 238 | } elsif ($wname eq "rain") { |
| | 239 | foreach $atribute (keys %hasharray) { |
| | 240 | if ($atribute eq "1h") { |
| | 241 | $scale = ${$hasharray{$atribute}}[2]; |
| | 242 | $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":AVERAGE "; |
| | 243 | $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" "; |
| | 244 | $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" "; |
| | 245 | $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" "; |
| | 246 | $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" "; |
| | 247 | $coloridx++; |
| | 248 | $cmd_arguments_tmp = $cmd_arguments; |
| | 249 | $cmd_arguments_tmp =~ s/$gtime/1h_$gtime/g; |
| | 250 | &callsys($cmd_arguments_tmp.$arguments); |
| | 251 | $arguments = ""; |
| | 252 | } else { |
| | 253 | $scale = ${$hasharray{$atribute}}[2]; |
| | 254 | $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":AVERAGE "; |
| | 255 | $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" "; |
| | 256 | $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" "; |
| | 257 | $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" "; |
| | 258 | $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" "; |
| | 259 | $coloridx++; |
| | 260 | } |
| | 261 | } |
| | 262 | } else { |
| | 263 | foreach $atribute (keys %hasharray) { |
| | 264 | $scale = ${$hasharray{$atribute}}[2]; |
| | 265 | $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":AVERAGE "; |
| | 266 | $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" "; |
| | 267 | $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" "; |
| | 268 | $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" "; |
| | 269 | $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" "; |
| | 270 | $coloridx++; |
| | 271 | } |
| 241 | | if ($rrdbn eq "outdoor_temperature") { |
| 242 | | $tout = $value; |
| 243 | | } |
| 244 | | if ($rrdbn eq "wind_speed") { |
| 245 | | $rrdbnt = "wind_chill"; |
| 246 | | $wname = "Wind chill"; |
| 247 | | # windchill calculation is only valid for wind speed > 4.5km/h ~ 1.25m/s |
| 248 | | if ($value > 1.25) { |
| 249 | | $ws = $value**0.16; |
| 250 | | #Wind chill |
| 251 | | $twc = 13.12+(0.6215*$tout)-(11.37*($ws))+((0.3965*$tout)*($ws)); |
| 252 | | } else { |
| 253 | | $twc = $tout; |
| 254 | | } |
| 255 | | &insertdb($rrdbnt,$twc,$wname); #store also wind chill |
| 256 | | &print_page($rrdbnt,$wname); |
| 257 | | &print_body($rrdbnt,$twc,$wname,"C"); |
| 258 | | } |
| 259 | | |
| 260 | | &insertdb($rrdbn,$value,$aline[0]); |
| 261 | | &print_page($rrdbn,$aline[0]); |
| 262 | | &print_body($rrdbn,$value,$aline[0],$scale); |
| 263 | | } |
| 264 | | } |
| 265 | | |
| | 469 | if ($rrdbn eq "interval") { next }; |
| | 470 | |
| | 471 | &insertdb($rrdbn,$value,$scale,$aline[0]); |
| | 472 | # &print_page($rrdbn,$aline[0]); |
| | 473 | # &print_body($rrdbn,$value,$aline[0],$scale); |
| | 474 | } |
| | 475 | }; |
| | 476 | |
| | 477 | # additional calculate values |
| | 478 | $rrdbnt = "temperature_feel-out"; |
| | 479 | $wname = "Feels like temperature"; |
| | 480 | $value = ${$wind{'speed'}}[1]; |
| | 481 | $tout = ${$temperature{'outdoor'}}[1]; |
| | 482 | # windchill calculation is only valid for wind speed > 4.5km/h ~ 1.25m/s |
| | 483 | if ($value > 1.25) { |
| | 484 | $ws = $value**0.16; |
| | 485 | #Wind chill |
| | 486 | $twc = 13.12+(0.6215*$tout)-(11.37*($ws))+((0.3965*$tout)*($ws)); |
| | 487 | } else { |
| | 488 | $twc = $tout; |
| | 489 | } |
| | 490 | &insertdb($rrdbnt,$twc,"C",$wname); |
| | 491 | |
| | 492 | $rrdbnt = "pressure_air-sea"; |
| | 493 | $wname = "Air pressure sea"; |
| | 494 | $value = ${$pressure{'air'}}[1]; |
| | 495 | $scale = ${$pressure{'air'}}[2]; |
| | 496 | # aaMADIS calculation |
| | 497 | $k1 = 0.190284; # discrepency with calculated k1 probably because Smithsonian used less precise gas constant and gravity values |
| | 498 | $k2 = 8.4184960528E-5; # (standardLapseRate / standardTempK) * (Power(standardSLP, k1) |
| | 499 | $aps = ((($value-0.3)**$k1)+($k2*$altitude))**(1/$k1); # Power(Power(pressureHPa - 0.3, k1) + (k2 * elevationM), 1/k1); |
| | 500 | &insertdb($rrdbnt,$aps,$scale,$wname); |
| | 501 | |
| | 502 | $rrdbnt = "temperature_dew-out"; |
| | 503 | $wname = "Due point temperature"; |
| | 504 | $value = ${$humidity{'outdoor'}}[1]; |
| | 505 | $tdp = $tout-((100-$value)/5); # aproximation |
| | 506 | &insertdb($rrdbnt,$tdp,"C",$wname); |
| | 507 | |
| | 508 | &print_header; |
| | 509 | &print_body; |