jablonka.czprosek.czf

meteolinger

Subversion Repositories:
[/] [weatherstats/] [weatherstats] - Blame information for rev 2

 

Line No. Rev Author Line
11simandl#!/usr/bin/perl
2 
3 
4#
5# Run this periodicaly by cron as root
6#
7 
8#
9# WeatherStats
10#
11# version: 0.6
12#
13# author: Adam Pribyl, covex@lowlevel.cz
14# url: http://meteolinger.lowlevel.cz/
15# desc: perl scripts to save weather conditions from TOPCOM 265 NE Weather station into RRD tool chain
16# deps: wwsr, perl, rrdtools (best >= 1.0.42)
17# lic: GNU GPL
18# howto use: call this every 2 minutes from crontab as root
19#
20 
21sub help {
22 print "usage: \n";
23 print " weatherstats -a <altitude> reads out the data from the weather station and stores them in round robin database\n";
24 print " weatherstats -a <altitude> -g reads out the data and generates graphs\n";
25 exit(0);
26}
27 
28sub callsys {
29 my @cmd = @_;
30 
31 # debug messages
32 if ( $en_dbg == 1 ) {
33 $out = "";
34 print "---- DBG: WeatherStats: Issuing command:\n @cmd\n";
35 } else {
36 $out = "> /dev/null";
37 }
38 
39 system("@cmd $out");
40 my $err = $?/256;
41 if ( $err > 0 ) { die "ERROR: WeatherStats: System error nr. $err while executing @cmd" }
42}
43 
44 
45sub insertdb {
46 my $rrdbn = $_[0];
47 my $value = $_[1];
48 my $scale = $_[2];
49 my $wname = $_[3];
50 my $value_type = $rrdbn;
51 
52 $tm = time;
53 
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 
119 if ( !( -e $rrdbp.$rrdbn.".rrd") ) {
120 # every 120s (2min), 600s maximum interval between feeding data
121 # 1. AVERAGE, every 1st value, store 720 (30*24) values (1day)
122 # 2. AVERAGE, every 30th value (each hour), store 720 values (30days)
123 # 3. AVERAGE, every 720th value (each day), store 5*365 values (5 year)
124 # same for MAX values
125 &callsys($rrdtoolp." create ".$rrdbp.$rrdbn.".rrd --start $tm -s 120 \\
126 DS:".$value_type.":GAUGE:600:".$min.":".$max." \\
127 RRA:AVERAGE:0.5:1:720 \\
128 RRA:AVERAGE:0.5:30:720 \\
129 RRA:AVERAGE:0.5:720:1825 \\
130 RRA:MAX:0.5:1:720 \\
131 RRA:MAX:0.5:30:720 \\
132 RRA:MAX:0.5:720:1825 \\
133 ");
134# print "Database $rrdbn created.\n";
135 return(0);
136 } else {
137 &callsys($rrdtoolp." update ".$rrdbp.$rrdbn.".rrd ".$tm.":".$value);
138 };
139};
140 
141 
142sub 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\" \\";
1612simandl $cmd_arguments = $rrdtoolp." graph ".$img." --start -".$gtimes{$gtime}." --width 550 --height 150 --vertical-label \"".ucfirst($wname)."\" \\"; #jak udelat scale?? --vertical-label".$scale\" \\";
1621simandl 
163 # compile the graphs arguments
164 if ($wname eq "temperature") {
165 foreach $atribute (keys %hasharray) {
166 if ($atribute =~ /out/) {
167 $scale = ${$hasharray{$atribute}}[2];
168 $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":AVERAGE ";
169 $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" ";
170 $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" ";
171 $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" ";
172 $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" ";
173 $coloridx++;
174 }
175 }
176 $arguments = $arguments."HRULE:0#474747";
177 $cmd_arguments_tmp = $cmd_arguments;
178 $cmd_arguments_tmp =~ s/$gtime/out_$gtime/g;
179 &callsys($cmd_arguments_tmp.$arguments);
180 $arguments = "";
181 $coloridx = 0;
182 foreach $atribute (keys %hasharray) {
183 $scale = ${$hasharray{$atribute}}[2];
184 $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":AVERAGE ";
185 $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" ";
186 $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" ";
187 $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" ";
188 $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" ";
189 $coloridx++;
190 }
191 $arguments = $arguments."HRULE:0#474747";
192 } elsif ($wname eq "wind") {
193 foreach $atribute (keys %hasharray) {
194 if ($atribute eq "direction") {
195 $scale = ${$hasharray{$atribute}}[2];
196 if ($gtime = "24h") {
197 $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":AVERAGE ";
198 } else {
199 $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":MAX ";
200 }
201 $arguments = $arguments."CDEF:North=".$atribute.",0,GE,-4,* ";
202 $arguments = $arguments."CDEF:NNE=".$atribute.",1,GE,-4,* ";
203 $arguments = $arguments."CDEF:NE=".$atribute.",2,GE,-4,* ";
204 $arguments = $arguments."CDEF:ENE=".$atribute.",3,GE,-4,* ";
205 $arguments = $arguments."CDEF:East=".$atribute.",4,GE,-4,* ";
206 $arguments = $arguments."CDEF:ESE=".$atribute.",5,GE,-4,* ";
207 $arguments = $arguments."CDEF:SE=".$atribute.",6,GE,-4,* ";
208 $arguments = $arguments."CDEF:SSE=".$atribute.",7,GE,-4,* ";
209 $arguments = $arguments."CDEF:South=".$atribute.",8,GE,-4,* ";
210 $arguments = $arguments."CDEF:SSW=".$atribute.",9,GE,-4,* ";
211 $arguments = $arguments."CDEF:SW=".$atribute.",10,GE,-4,* ";
212 $arguments = $arguments."CDEF:WSW=".$atribute.",11,GE,-4,* ";
213 $arguments = $arguments."CDEF:West=".$atribute.",12,GE,-4,* ";
214 $arguments = $arguments."CDEF:WNW=".$atribute.",13,GE,-4,* ";
215 $arguments = $arguments."CDEF:NW=".$atribute.",14,GE,-4,* ";
216 $arguments = $arguments."CDEF:NNW=".$atribute.",15,GE,-4,* ";
217 $arguments = $arguments."AREA:North".$direction_cols[0].":N ";
218 $arguments = $arguments."AREA:NNE".$direction_cols[1].": ";
219 $arguments = $arguments."AREA:NE".$direction_cols[2].":NE ";
220 $arguments = $arguments."AREA:ENE".$direction_cols[3].": ";
221 $arguments = $arguments."AREA:East".$direction_cols[4].":E ";
222 $arguments = $arguments."AREA:ESE".$direction_cols[5].": ";
223 $arguments = $arguments."AREA:SE".$direction_cols[6].":SE ";
224 $arguments = $arguments."AREA:SSE".$direction_cols[7].": ";
225 $arguments = $arguments."AREA:South".$direction_cols[8].":S ";
226 $arguments = $arguments."AREA:SSW".$direction_cols[9].": ";
227 $arguments = $arguments."AREA:SW".$direction_cols[10].":SW ";
228 $arguments = $arguments."AREA:WSW".$direction_cols[11].": ";
229 $arguments = $arguments."AREA:West".$direction_cols[12].":W ";
230 $arguments = $arguments."AREA:WNW".$direction_cols[13].": ";
231 $arguments = $arguments."AREA:NW".$direction_cols[14].":\"NW\\l\" ";
232 $arguments = $arguments."AREA:NNW".$direction_cols[15].": ";
233 } else {
234 $scale = ${$hasharray{$atribute}}[2];
235 $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":MAX ";
236 $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" ";
237 $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" ";
238 $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" ";
239 $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" ";
240 $coloridx++;
241 }
242 }
243 } elsif ($wname eq "rain") {
244 foreach $atribute (keys %hasharray) {
245 if ($atribute eq "1h") {
246 $scale = ${$hasharray{$atribute}}[2];
247 $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":AVERAGE ";
248 $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" ";
249 $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" ";
250 $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" ";
251 $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" ";
252 $coloridx++;
253 $cmd_arguments_tmp = $cmd_arguments;
254 $cmd_arguments_tmp =~ s/$gtime/1h_$gtime/g;
255 &callsys($cmd_arguments_tmp.$arguments);
256 $arguments = "";
257 } else {
258 $scale = ${$hasharray{$atribute}}[2];
259 $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":AVERAGE ";
260 $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" ";
261 $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" ";
262 $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" ";
263 $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" ";
264 $coloridx++;
265 }
266 }
267 } else {
268 foreach $atribute (keys %hasharray) {
269 $scale = ${$hasharray{$atribute}}[2];
270 $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":AVERAGE ";
271 $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" ";
272 $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" ";
273 $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" ";
274 $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" ";
275 $coloridx++;
276 }
277 }
278 &callsys($cmd_arguments.$arguments);
279 }
280}
281 
282sub create_graphs {
283 &create_graphs_for(\%temperature, "temperature");
284 &create_graphs_for(\%humidity, "humidity");
285 &create_graphs_for(\%wind, "wind");
286 &create_graphs_for(\%rain, "rain");
287 &create_graphs_for(\%pressure, "pressure");
288}
289 
290sub print_header {
291 open (INDEX, ">$wwwdir"."index\.html.new") || die "ERROR: WeatherStats: Could not create $wwwdir index.html.new";
2922simandl print INDEX "<html>\n<head><title>Weather statistic from WATSON W-8681</title>
2931simandl <link rel=\"StyleSheet\" href=\"styles.css\" type=\"text/css\" media=\"screen\">
294 </head>\n<body>\n";
2952simandl print INDEX "<a href=p3211521.jpg><img src=p3211521_detail.jpg alt=\"WATSON W-8681\" title=\"WATSON W-8681\" align=\"right\" /></a>\n";
2961simandl print INDEX "<h1>Weather statistic</h1>\n";
297 $date = `date`;
298 print INDEX "<p>Generated: ".$date."</p>\n";
299 print INDEX "<p>Station altitude: <span class=\"wvalue\">".$altitude."</span><span class=\"wscale\">mnm</span></p>\n";
300}
301 
302sub print_footer {
303 print INDEX "<div id=\"credits\">WeatherStats - <a href=\"http://meteolinger.lowlevel.cz/\">http://meteolinger.lowlevel.cz/</a></div>\n";
304 print INDEX "</body></html>";
305 close INDEX;
306 open (INDEX, ">$wwwdir"."index\.html") || die "ERROR: WeatherStats: Could not create $wwwdir index.html";
307 open (INDEX_NEW, "$wwwdir"."index\.html.new") || die "ERROR: WeatherStats: Could not create $wwwdir index.html";
308 while (<INDEX_NEW>) { print INDEX $_ };
309 close INDEX_NEW;
310 close INDEX;
311 unlink "index.html.new";
312}
313 
314sub print_body_line {
315 my @atribute = @_;
316 printf INDEX "<div>\n<div class=\"wname\"><a href=\"$atribute[0].html\">$atribute[1]</a></div>
317<span class=\"wvalue\"><a href=\"$atribute[0].html\">%.1f</a></span>
318<span class=\"wscale\"><a href=\"$atribute[0].html\">%s</a></span>\n</div>\n", $atribute[3], $atribute[4];
319}
320 
321sub print_page {
322 my $page = $_[0];
323 open ( PAGE, ">$wwwdir".$page."\.html") || die "ERROR: WeatherStats: Could not create page $wwwdir $rrdbn";
324 print PAGE "<html>\n<head><title>Weather statistic from TOPCOM 265 NE</title></head>\n<body>\n";
325 print PAGE "<h1>".ucfirst($page)."</h1>\n";
326 print PAGE "<img src=\"".$page."_24h.gif\"/><br />\n";
327 print PAGE "<img src=\"".$page."_30d.gif\"/><br />\n";
328 print PAGE "<img src=\"".$page."_1y.gif\"/><br />\n";
329 print PAGE "<img src=\"".$page."_5y.gif\"/><br />\n";
330 print PAGE "</body></html>";
331 close PAGE
332}
333 
334sub print_body_begin {
335 my $wtype = $_[0];
336 
337 print INDEX "<div id=\"".$wtype."\">\n";
338 print INDEX "<span class=\"wimg\"><a href=\"".$wtype.".html\"><img src=\"".$wtype."_24h.gif\" width=\"164\" /></a></span><br />\n";
339 print INDEX "<a class=\"mname\" href=\"".$wtype.".html\">".ucfirst($wtype)."</a><br/>\n";
340}
341 
342sub print_body {
343 
344 
345 $wtype = "temperature";
346 &print_body_begin($wtype);
347 $wtype = "temperature_out";
348 &print_body_begin($wtype);
349 print INDEX "</div>\n";
350 &print_page($wtype);
351 $wtype = "temperature";
352 foreach $atribute (keys %temperature) {
353 &print_body_line($wtype,$atribute, ${$temperature{$atribute}}[0], ${$temperature{$atribute}}[1], ${$temperature{$atribute}}[2]);
354 }
355 print INDEX "</div>\n";
356 &print_page($wtype);
357 
358 $wtype = "humidity";
359 &print_body_begin($wtype);
360 foreach $atribute (keys %humidity) {
361 &print_body_line($wtype, $atribute, ${$humidity{$atribute}}[0], ${$humidity{$atribute}}[1], ${$humidity{$atribute}}[2]);
362 }
363 print INDEX "</div>\n";
364 &print_page($wtype);
365 
366 $wtype = "wind";
367 &print_body_begin($wtype);
368 foreach $atribute (keys %wind) {
369 &print_body_line($wtype, $atribute, ${$wind{$atribute}}[0], ${$wind{$atribute}}[1], ${$wind{$atribute}}[2]);
370 }
371 print INDEX "</div>\n";
372 &print_page($wtype);
373 
374 $wtype = "rain";
375 &print_body_begin($wtype);
376 $wtype = "rain_1h";
377 &print_body_begin($wtype);
378 print INDEX "</div>\n";
379 &print_page($wtype);
380 $wtype = "rain";
381 foreach $atribute (keys %rain) {
382 &print_body_line($wtype, $atribute, ${$rain{$atribute}}[0], ${$rain{$atribute}}[1], ${$rain{$atribute}}[2]);
383 }
384 print INDEX "</div>\n";
385 &print_page($wtype);
386 
387 $wtype = "pressure";
388 &print_body_begin($wtype);
389 foreach $atribute (keys %pressure) {
390 &print_body_line("$wtype", $atribute, ${$pressure{$atribute}}[0], ${$pressure{$atribute}}[1], ${$pressure{$atribute}}[2]);
391 }
392 print INDEX "</div>\n";
393 &print_page($wtype);
394}
395 
396 
397 
398#################
399##### MAIN ######
400#################
401 
4022simandl@wwsr = `/usr/local/bin/wwsr -y`;
4031simandl#@wwsr = `cat wwsr6.out`;
404#@wwsr = `tail -14 /var/www/html/wwss/log`;
405 
4062simandl$wwwdir = "/home/www/html/wwss/";
4071simandl#$wwwdir = "wwss/";
408$en_dbg = 0;
409$rrdtoolp = "/usr/bin/rrdtool";
4102simandl$rrdbp = "/opt/meteolinger/rrd/";
4111simandl#$rrdbp = "wwss/";
412 
413$graphs = 0;
414 
415# What options are defined on command line?
416if ( defined($ARGV[0]) ) {
417 for ($i = 0; $i < @ARGV; $i++) {
418 $argmnt = $ARGV[$i];
419 if ($argmnt eq "-g") {
420 $graphs = 1;
421 }
422 if ($argmnt eq "-a") {
423 if (defined ($ARGV[$i+1] and length($ARGV[$i+1] == 1)) ) {
424 $altitude = $ARGV[$i+1];
425 $i++;
426 } else {
427 die "ERROR: Unknown or missing argument to -a"
428 }
429 }
430 }
431} else {
432 &help;
433};
434 
435 
436open (LOG, ">>$wwwdir"."log") || die "ERROR: no log";
437print LOG "------- ".`date`;
438for ($i=0;$i<=($#wwsr-1);$i++) {
439 print LOG $wwsr[$i];
440}
441close LOG;
442 
443for ($i=0;$i<=($#wwsr-1);$i++) {
444 if ($wwsr[$i] =~ /^For postprocessing/) {
445 $wwsr[$i] = "";
446 last;
447 } else {
448 $wwsr[$i] = "";
449 }
450 if ($i==($#wwsr-1)) {
451 print INDEX "ERROR: wwsr output - for postprocessing sequence not found!</br>";
452 for ($ii=0;$ii<=($#wwsr-1);$ii++) { print INDEX $wwsr[$ii]."</br>"; }
453 }
454}
455 
456 
457# define main hashes for value groups
458%temperature = ();
459%pressure = ();
460%humidity = ();
461%wind = ();
462%rain = ();
463 
464# store all values that wwsr returns
465foreach $line (@wwsr) {
466 chomp $line;
467 if ( $line ne "" ) {
468 @aline = split ("\t", $line);
469 ($value, $scale) = split (" ", $aline[1]);
470# $value = $aline[$#aline]; #posledni prvek je hodnota
471 
472 $rrdbn = $aline[0];
473 $rrdbn =~ s/ /_/g;
474 $rrdbn = lc($rrdbn);
475 
476 if ($rrdbn eq "interval") { next };
477 
478 &insertdb($rrdbn,$value,$scale,$aline[0]);
479# &print_page($rrdbn,$aline[0]);
480# &print_body($rrdbn,$value,$aline[0],$scale);
481 }
482};
483 
484# additional calculate values
4852simandl$rrdbnt = "temperature_feelout";
4861simandl$wname = "Feels like temperature";
487$value = ${$wind{'speed'}}[1];
488$tout = ${$temperature{'outdoor'}}[1];
489# windchill calculation is only valid for wind speed > 4.5km/h ~ 1.25m/s and $tout < 10C
490if ($value > 1.25 and $tout < 10) {
491 #Convert $value=m/s $ws=km/h
492 $ws=$value*3.6;
493 $ws = $ws**0.16;
494 #Wind chill
495 $twc = 13.12+(0.6215*$tout)-(11.37*($ws))+((0.3965*$tout)*($ws));
496} else {
497 $twc = $tout;
498}
499&insertdb($rrdbnt,$twc,"C",$wname);
500 
5012simandl$rrdbnt = "pressure_airsea";
5021simandl$wname = "Air pressure sea";
503$value = ${$pressure{'air'}}[1];
504$scale = ${$pressure{'air'}}[2];
505# aaMADIS calculation
506$k1 = 0.190284; # discrepency with calculated k1 probably because Smithsonian used less precise gas constant and gravity values
507$k2 = 8.4184960528E-5; # (standardLapseRate / standardTempK) * (Power(standardSLP, k1)
508$aps = ((($value-0.3)**$k1)+($k2*$altitude))**(1/$k1); # Power(Power(pressureHPa - 0.3, k1) + (k2 * elevationM), 1/k1);
509&insertdb($rrdbnt,$aps,$scale,$wname);
510 
5112simandl$rrdbnt = "temperature_dewout";
5121simandl$wname = "Due point temperature";
513$value = ${$humidity{'outdoor'}}[1];
514$tdp = $tout-((100-$value)/5); # aproximation
515&insertdb($rrdbnt,$tdp,"C",$wname);
516 
517&print_header;
518&print_body;
519&print_footer;
520 
521if ($graphs == 1) {
522 &create_graphs;
523}
524 
525 

Powered by WebSVN 2.2.1