jablonka.czprosek.czf

weatherstats

Subversion Repositories:
[/] [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 = (
1462simandl "1h" => 3600,
147 "6h" => 21600,
1481simandl "24h" => 86400,
1492simandl "7d" => 604800,
1501simandl "30d" => 2592000,
151 "1y" => 31536000,
152 "5y" => 157680000
153 );
154 my @color = ( "#dc0000", "#dc00dc", "#5800dc", "#009bdc", "#00dc87" );
155 my $coloridx = 0;
156 # N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNw
157 my @direction_cols = ( "#ff0000", "#ff6600", "#ffcc00", "#ccff00", "#66ff00", "#00ff00", "#00ff66", "#00ffcc", "#00ccff", "#0066ff", "#0000ff", "#6600ff", "#cc00ff", "#ff00cc", "#ff0066", "#ff0000");
158 
159 foreach $gtime (keys %gtimes) {
160 $arguments = "";
161 $coloridx = 0;
162 $img = $wwwdir.$wname."_".$gtime.".gif";
163 $cmd_arguments = $rrdtoolp." graph ".$img." --start -".$gtimes{$gtime}." --width 550 --height 150 --vertical-label \"".ucfirst($wname)."\" --watermark \"WeatherStats\" \\"; #jak udelat scale?? --vertical-label".$scale\" \\";
164 $cmd_arguments = $rrdtoolp." graph ".$img." --start -".$gtimes{$gtime}." --width 550 --height 150 --vertical-label \"".ucfirst($wname)."\" \\"; #jak udelat scale?? --vertical-label".$scale\" \\";
165 
166 # compile the graphs arguments
167 if ($wname eq "temperature") {
168 foreach $atribute (keys %hasharray) {
169 if ($atribute =~ /out/) {
170 $scale = ${$hasharray{$atribute}}[2];
171 $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":AVERAGE ";
172 $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" ";
173 $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" ";
174 $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" ";
175 $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" ";
176 $coloridx++;
177 }
178 }
179 $arguments = $arguments."HRULE:0#474747";
180 $cmd_arguments_tmp = $cmd_arguments;
181 $cmd_arguments_tmp =~ s/$gtime/out_$gtime/g;
182 &callsys($cmd_arguments_tmp.$arguments);
183 $arguments = "";
184 $coloridx = 0;
185 foreach $atribute (keys %hasharray) {
186 $scale = ${$hasharray{$atribute}}[2];
187 $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":AVERAGE ";
188 $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" ";
189 $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" ";
190 $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" ";
191 $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" ";
192 $coloridx++;
193 }
194 $arguments = $arguments."HRULE:0#474747";
195 } elsif ($wname eq "wind") {
196 foreach $atribute (keys %hasharray) {
197 if ($atribute eq "direction") {
198 $scale = ${$hasharray{$atribute}}[2];
199 if ($gtime = "24h") {
200 $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":AVERAGE ";
201 } else {
202 $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":MAX ";
203 }
204 $arguments = $arguments."CDEF:North=".$atribute.",0,GE,-4,* ";
205 $arguments = $arguments."CDEF:NNE=".$atribute.",1,GE,-4,* ";
206 $arguments = $arguments."CDEF:NE=".$atribute.",2,GE,-4,* ";
207 $arguments = $arguments."CDEF:ENE=".$atribute.",3,GE,-4,* ";
208 $arguments = $arguments."CDEF:East=".$atribute.",4,GE,-4,* ";
209 $arguments = $arguments."CDEF:ESE=".$atribute.",5,GE,-4,* ";
210 $arguments = $arguments."CDEF:SE=".$atribute.",6,GE,-4,* ";
211 $arguments = $arguments."CDEF:SSE=".$atribute.",7,GE,-4,* ";
212 $arguments = $arguments."CDEF:South=".$atribute.",8,GE,-4,* ";
213 $arguments = $arguments."CDEF:SSW=".$atribute.",9,GE,-4,* ";
214 $arguments = $arguments."CDEF:SW=".$atribute.",10,GE,-4,* ";
215 $arguments = $arguments."CDEF:WSW=".$atribute.",11,GE,-4,* ";
216 $arguments = $arguments."CDEF:West=".$atribute.",12,GE,-4,* ";
217 $arguments = $arguments."CDEF:WNW=".$atribute.",13,GE,-4,* ";
218 $arguments = $arguments."CDEF:NW=".$atribute.",14,GE,-4,* ";
219 $arguments = $arguments."CDEF:NNW=".$atribute.",15,GE,-4,* ";
220 $arguments = $arguments."AREA:North".$direction_cols[0].":N ";
221 $arguments = $arguments."AREA:NNE".$direction_cols[1].": ";
222 $arguments = $arguments."AREA:NE".$direction_cols[2].":NE ";
223 $arguments = $arguments."AREA:ENE".$direction_cols[3].": ";
224 $arguments = $arguments."AREA:East".$direction_cols[4].":E ";
225 $arguments = $arguments."AREA:ESE".$direction_cols[5].": ";
226 $arguments = $arguments."AREA:SE".$direction_cols[6].":SE ";
227 $arguments = $arguments."AREA:SSE".$direction_cols[7].": ";
228 $arguments = $arguments."AREA:South".$direction_cols[8].":S ";
229 $arguments = $arguments."AREA:SSW".$direction_cols[9].": ";
230 $arguments = $arguments."AREA:SW".$direction_cols[10].":SW ";
231 $arguments = $arguments."AREA:WSW".$direction_cols[11].": ";
232 $arguments = $arguments."AREA:West".$direction_cols[12].":W ";
233 $arguments = $arguments."AREA:WNW".$direction_cols[13].": ";
234 $arguments = $arguments."AREA:NW".$direction_cols[14].":\"NW\\l\" ";
235 $arguments = $arguments."AREA:NNW".$direction_cols[15].": ";
236 } else {
237 $scale = ${$hasharray{$atribute}}[2];
238 $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":MAX ";
239 $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" ";
240 $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" ";
241 $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" ";
242 $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" ";
243 $coloridx++;
244 }
245 }
246 } elsif ($wname eq "rain") {
247 foreach $atribute (keys %hasharray) {
248 if ($atribute eq "1h") {
249 $scale = ${$hasharray{$atribute}}[2];
250 $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":AVERAGE ";
251 $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" ";
252 $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" ";
253 $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" ";
254 $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" ";
255 $coloridx++;
256 $cmd_arguments_tmp = $cmd_arguments;
257 $cmd_arguments_tmp =~ s/$gtime/1h_$gtime/g;
258 &callsys($cmd_arguments_tmp.$arguments);
259 $arguments = "";
260 } else {
261 $scale = ${$hasharray{$atribute}}[2];
262 $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":AVERAGE ";
263 $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" ";
264 $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" ";
265 $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" ";
266 $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" ";
267 $coloridx++;
268 }
269 }
270 } else {
271 foreach $atribute (keys %hasharray) {
272 $scale = ${$hasharray{$atribute}}[2];
273 $arguments = $arguments."DEF:".$atribute."=".$rrdbp.$wname."_".$atribute.".rrd:".$atribute.":AVERAGE ";
274 $arguments = $arguments."LINE1:".$atribute.$color[$coloridx].":\"".${$hasharray{$atribute}}[0]."\" ";
275 $arguments = $arguments."GPRINT:".$atribute.":MIN:\"Min\\: %4.2lf \" ";
276 $arguments = $arguments."GPRINT:".$atribute.":AVERAGE:\"Avg\\: %4.2lf \" ";
277 $arguments = $arguments."GPRINT:".$atribute.":MAX:\"Max\\: %4.2lf ".$scale."\\j\" ";
278 $coloridx++;
279 }
280 }
281 &callsys($cmd_arguments.$arguments);
282 }
283}
284 
285sub create_graphs {
286 &create_graphs_for(\%temperature, "temperature");
287 &create_graphs_for(\%humidity, "humidity");
288 &create_graphs_for(\%wind, "wind");
289 &create_graphs_for(\%rain, "rain");
290 &create_graphs_for(\%pressure, "pressure");
291}
292 
293sub print_header {
294 open (INDEX, ">$wwwdir"."index\.html.new") || die "ERROR: WeatherStats: Could not create $wwwdir index.html.new";
295 print INDEX "<html>\n<head><title>Weather statistic from WATSON W-8681</title>
296 <link rel=\"StyleSheet\" href=\"styles.css\" type=\"text/css\" media=\"screen\">
297 </head>\n<body>\n";
298 print INDEX "<a href=p3211521.jpg><img src=p3211521_detail.jpg alt=\"WATSON W-8681\" title=\"WATSON W-8681\" align=\"right\" /></a>\n";
299 print INDEX "<h1>Weather statistic</h1>\n";
300 $date = `date`;
301 print INDEX "<p>Generated: ".$date."</p>\n";
302 print INDEX "<p>Station altitude: <span class=\"wvalue\">".$altitude."</span><span class=\"wscale\">mnm</span></p>\n";
303}
304 
305sub print_footer {
306 print INDEX "<div id=\"credits\">WeatherStats - <a href=\"http://meteolinger.lowlevel.cz/\">http://meteolinger.lowlevel.cz/</a></div>\n";
307 print INDEX "</body></html>";
308 close INDEX;
309 open (INDEX, ">$wwwdir"."index\.html") || die "ERROR: WeatherStats: Could not create $wwwdir index.html";
310 open (INDEX_NEW, "$wwwdir"."index\.html.new") || die "ERROR: WeatherStats: Could not create $wwwdir index.html";
311 while (<INDEX_NEW>) { print INDEX $_ };
312 close INDEX_NEW;
313 close INDEX;
314 unlink "index.html.new";
315}
316 
317sub print_body_line {
318 my @atribute = @_;
319 printf INDEX "<div>\n<div class=\"wname\"><a href=\"$atribute[0].html\">$atribute[1]</a></div>
320<span class=\"wvalue\"><a href=\"$atribute[0].html\">%.1f</a></span>
321<span class=\"wscale\"><a href=\"$atribute[0].html\">%s</a></span>\n</div>\n", $atribute[3], $atribute[4];
322}
323 
324sub print_page {
325 my $page = $_[0];
326 open ( PAGE, ">$wwwdir".$page."\.html") || die "ERROR: WeatherStats: Could not create page $wwwdir $rrdbn";
327 print PAGE "<html>\n<head><title>Weather statistic from TOPCOM 265 NE</title></head>\n<body>\n";
328 print PAGE "<h1>".ucfirst($page)."</h1>\n";
3292simandl print PAGE "<img src=\"".$page."_1h.gif\"/><br />\n";
330 print PAGE "<img src=\"".$page."_6h.gif\"/><br />\n";
3311simandl print PAGE "<img src=\"".$page."_24h.gif\"/><br />\n";
3322simandl print PAGE "<img src=\"".$page."_7d.gif\"/><br />\n";
3331simandl print PAGE "<img src=\"".$page."_30d.gif\"/><br />\n";
334 print PAGE "<img src=\"".$page."_1y.gif\"/><br />\n";
335 print PAGE "<img src=\"".$page."_5y.gif\"/><br />\n";
336 print PAGE "</body></html>";
337 close PAGE
338}
339 
340sub print_body_begin {
341 my $wtype = $_[0];
342 
343 print INDEX "<div id=\"".$wtype."\">\n";
344 print INDEX "<span class=\"wimg\"><a href=\"".$wtype.".html\"><img src=\"".$wtype."_24h.gif\" width=\"164\" /></a></span><br />\n";
345 print INDEX "<a class=\"mname\" href=\"".$wtype.".html\">".ucfirst($wtype)."</a><br/>\n";
346}
347 
348sub print_body {
349 
350 
351 $wtype = "temperature";
352 &print_body_begin($wtype);
353 $wtype = "temperature_out";
354 &print_body_begin($wtype);
355 print INDEX "</div>\n";
356 &print_page($wtype);
357 $wtype = "temperature";
358 foreach $atribute (keys %temperature) {
359 &print_body_line($wtype,$atribute, ${$temperature{$atribute}}[0], ${$temperature{$atribute}}[1], ${$temperature{$atribute}}[2]);
360 }
361 print INDEX "</div>\n";
362 &print_page($wtype);
363 
364 $wtype = "humidity";
365 &print_body_begin($wtype);
366 foreach $atribute (keys %humidity) {
3672simandl &print_body_line($wtype, $atribute, ${$humidity{$atribute}}[0], ${$humidity{$atribute}}[1], "%");
3681simandl }
369 print INDEX "</div>\n";
370 &print_page($wtype);
371 
372 $wtype = "wind";
373 &print_body_begin($wtype);
374 foreach $atribute (keys %wind) {
375 &print_body_line($wtype, $atribute, ${$wind{$atribute}}[0], ${$wind{$atribute}}[1], ${$wind{$atribute}}[2]);
376 }
377 print INDEX "</div>\n";
378 &print_page($wtype);
379 
380 $wtype = "rain";
381 &print_body_begin($wtype);
382 $wtype = "rain_1h";
383 &print_body_begin($wtype);
384 print INDEX "</div>\n";
385 &print_page($wtype);
386 $wtype = "rain";
387 foreach $atribute (keys %rain) {
388 &print_body_line($wtype, $atribute, ${$rain{$atribute}}[0], ${$rain{$atribute}}[1], ${$rain{$atribute}}[2]);
389 }
390 print INDEX "</div>\n";
391 &print_page($wtype);
392 
393 $wtype = "pressure";
394 &print_body_begin($wtype);
395 foreach $atribute (keys %pressure) {
396 &print_body_line("$wtype", $atribute, ${$pressure{$atribute}}[0], ${$pressure{$atribute}}[1], ${$pressure{$atribute}}[2]);
397 }
398 print INDEX "</div>\n";
399 &print_page($wtype);
400}
401 
402 
403 
404#################
405##### MAIN ######
406#################
407 
408@wwsr = `/usr/local/bin/wwsr -y`;
409#@wwsr = `cat wwsr6.out`;
410#@wwsr = `tail -14 /var/www/html/wwss/log`;
411 
412$wwwdir = "/home/www/html/wwss/";
413#$wwwdir = "wwss/";
414$en_dbg = 0;
415$rrdtoolp = "/usr/bin/rrdtool";
416$rrdbp = "/opt/meteolinger/rrd/";
417#$rrdbp = "wwss/";
418 
419$graphs = 0;
420 
421# What options are defined on command line?
422if ( defined($ARGV[0]) ) {
423 for ($i = 0; $i < @ARGV; $i++) {
424 $argmnt = $ARGV[$i];
425 if ($argmnt eq "-g") {
426 $graphs = 1;
427 }
428 if ($argmnt eq "-a") {
429 if (defined ($ARGV[$i+1] and length($ARGV[$i+1] == 1)) ) {
430 $altitude = $ARGV[$i+1];
431 $i++;
432 } else {
433 die "ERROR: Unknown or missing argument to -a"
434 }
435 }
436 }
437} else {
438 &help;
439};
440 
441 
442open (LOG, ">>$wwwdir"."log") || die "ERROR: no log";
443print LOG "------- ".`date`;
444for ($i=0;$i<=($#wwsr-1);$i++) {
445 print LOG $wwsr[$i];
446}
447close LOG;
448 
449for ($i=0;$i<=($#wwsr-1);$i++) {
450 if ($wwsr[$i] =~ /^For postprocessing/) {
451 $wwsr[$i] = "";
452 last;
453 } else {
454 $wwsr[$i] = "";
455 }
456 if ($i==($#wwsr-1)) {
457 print INDEX "ERROR: wwsr output - for postprocessing sequence not found!</br>";
458 for ($ii=0;$ii<=($#wwsr-1);$ii++) { print INDEX $wwsr[$ii]."</br>"; }
459 }
460}
461 
462 
463# define main hashes for value groups
464%temperature = ();
465%pressure = ();
466%humidity = ();
467%wind = ();
468%rain = ();
469 
470# store all values that wwsr returns
471foreach $line (@wwsr) {
472 chomp $line;
473 if ( $line ne "" ) {
474 @aline = split ("\t", $line);
475 ($value, $scale) = split (" ", $aline[1]);
476# $value = $aline[$#aline]; #posledni prvek je hodnota
477 
478 $rrdbn = $aline[0];
479 $rrdbn =~ s/ /_/g;
480 $rrdbn = lc($rrdbn);
481 
482 if ($rrdbn eq "interval") { next };
483 
484 &insertdb($rrdbn,$value,$scale,$aline[0]);
485# &print_page($rrdbn,$aline[0]);
486# &print_body($rrdbn,$value,$aline[0],$scale);
487 }
488};
489 
490# additional calculate values
491$rrdbnt = "temperature_feelout";
492$wname = "Feels like temperature";
493$value = ${$wind{'speed'}}[1];
494$tout = ${$temperature{'outdoor'}}[1];
495# windchill calculation is only valid for wind speed > 4.5km/h ~ 1.25m/s and $tout < 10C
496if ($value > 1.25 and $tout < 10) {
497 #Convert $value=m/s $ws=km/h
498 $ws=$value*3.6;
499 $ws = $ws**0.16;
500 #Wind chill
501 $twc = 13.12+(0.6215*$tout)-(11.37*($ws))+((0.3965*$tout)*($ws));
502} else {
503 $twc = $tout;
504}
505&insertdb($rrdbnt,$twc,"C",$wname);
506 
507$rrdbnt = "pressure_airsea";
508$wname = "Air pressure sea";
509$value = ${$pressure{'air'}}[1];
510$scale = ${$pressure{'air'}}[2];
511# aaMADIS calculation
512$k1 = 0.190284; # discrepency with calculated k1 probably because Smithsonian used less precise gas constant and gravity values
513$k2 = 8.4184960528E-5; # (standardLapseRate / standardTempK) * (Power(standardSLP, k1)
514$aps = ((($value-0.3)**$k1)+($k2*$altitude))**(1/$k1); # Power(Power(pressureHPa - 0.3, k1) + (k2 * elevationM), 1/k1);
515&insertdb($rrdbnt,$aps,$scale,$wname);
516 
517$rrdbnt = "temperature_dewout";
518$wname = "Due point temperature";
519$value = ${$humidity{'outdoor'}}[1];
520$tdp = $tout-((100-$value)/5); # aproximation
521&insertdb($rrdbnt,$tdp,"C",$wname);
522 
523&print_header;
524&print_body;
525&print_footer;
526 
527if ($graphs == 1) {
528 &create_graphs;
529}
530 
531 

Powered by WebSVN 2.2.1