jablonka.czprosek.czf

meteolinger

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

 

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

Powered by WebSVN 2.2.1