root/weatherstats/weatherstats

Revision 14, 18.6 KB (checked in by apribyl, 15 months ago)

Few small fixes.

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2
3
4#
5# Run this periodicaly by cron as root
6#
7
8#
9# WeatherStats
10#
11# version:      0.6.2
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                if ($wname eq "pressure") { $cmd_arguments = $cmd_arguments."-A \\" } #scale na max a min hodnotu pro tlak
162
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 eq "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";
292        print INDEX "<html>\n<head><title>Weather statistic from TOPCOM 265 NE</title>
293            <link rel=\"StyleSheet\" href=\"styles.css\" type=\"text/css\" media=\"screen\">
294            </head>\n<body>\n";
295        print INDEX "<h1>Weather statistic</h1>\n";
296        $date = `date`;
297        print INDEX "<p>Generated: ".$date."</p>\n";
298        print INDEX "<p>Station altitude: <span class=\"wvalue\">".$altitude."</span><span class=\"wscale\">mnm</span></p>\n";
299}
300
301sub print_footer {
302        print INDEX "<div id=\"credits\">WeatherStats - <a href=\"http://meteolinger.lowlevel.cz/\">http://meteolinger.lowlevel.cz/</a></div>\n";
303        print INDEX "</body></html>";
304        close INDEX;
305        open (INDEX, ">$wwwdir"."index\.html") || die "ERROR: WeatherStats: Could not create $wwwdir index.html";
306        open (INDEX_NEW, "$wwwdir"."index\.html.new") || die "ERROR: WeatherStats: Could not create $wwwdir index.html";
307        while (<INDEX_NEW>) { print INDEX $_ };
308        close INDEX_NEW;
309        close INDEX;
310        unlink "index.html.new";
311}
312
313sub print_body_line {
314        my @atribute = @_;
315        printf INDEX "<div>\n<div class=\"wname\"><a href=\"$atribute[0].html\">$atribute[1]</a></div>
316<span class=\"wvalue\"><a href=\"$atribute[0].html\">%.1f</a></span>
317<span class=\"wscale\"><a href=\"$atribute[0].html\">%s</a></span>\n</div>\n", $atribute[3], $atribute[4];
318}
319
320sub print_page {
321        my $page = $_[0];
322        open ( PAGE, ">$wwwdir".$page."\.html") || die "ERROR: WeatherStats: Could not create page $wwwdir $rrdbn";
323        print PAGE "<html>\n<head><title>Weather statistic from TOPCOM 265 NE</title></head>\n<body>\n";
324        print PAGE "<h1>".ucfirst($page)."</h1>\n";
325        print PAGE "<img src=\"".$page."_24h.gif\"/><br />\n";
326        print PAGE "<img src=\"".$page."_30d.gif\"/><br />\n";
327        print PAGE "<img src=\"".$page."_1y.gif\"/><br />\n";
328        print PAGE "<img src=\"".$page."_5y.gif\"/><br />\n";
329        print PAGE "</body></html>";
330        close PAGE
331}
332
333sub print_body_begin {
334        my $wtype = $_[0];
335
336        print INDEX "<div id=\"".$wtype."\">\n";
337        print INDEX "<span class=\"wimg\"><a href=\"".$wtype.".html\"><img src=\"".$wtype."_24h.gif\" width=\"164\" /></a></span><br />\n";
338        print INDEX "<a class=\"mname\" href=\"".$wtype.".html\">".ucfirst($wtype)."</a><br/>\n";
339}
340
341sub print_body {
342
343
344        $wtype = "temperature";
345        &print_body_begin($wtype);
346        $wtype = "temperature_out";
347        &print_body_begin($wtype);
348        print INDEX "</div>\n";
349        &print_page($wtype);
350        $wtype = "temperature";
351        foreach $atribute (keys %temperature) {
352                &print_body_line($wtype,$atribute, ${$temperature{$atribute}}[0], ${$temperature{$atribute}}[1], ${$temperature{$atribute}}[2]);
353        }
354        print INDEX "</div>\n";
355        &print_page($wtype);
356
357        $wtype = "humidity";
358        &print_body_begin($wtype);
359        foreach $atribute (keys %humidity) {
360                &print_body_line($wtype, $atribute, ${$humidity{$atribute}}[0], ${$humidity{$atribute}}[1], ${$humidity{$atribute}}[2]);
361        }
362        print INDEX "</div>\n";
363        &print_page($wtype);
364
365        $wtype = "wind";
366        &print_body_begin($wtype);
367        foreach $atribute (keys %wind) {
368                &print_body_line($wtype, $atribute, ${$wind{$atribute}}[0], ${$wind{$atribute}}[1], ${$wind{$atribute}}[2]);
369        }
370        print INDEX "</div>\n";
371        &print_page($wtype);
372
373        $wtype = "rain";
374        &print_body_begin($wtype);
375        $wtype = "rain_1h";
376        &print_body_begin($wtype);
377        print INDEX "</div>\n";
378        &print_page($wtype);
379        $wtype = "rain";
380        foreach $atribute (keys %rain) {
381                &print_body_line($wtype, $atribute, ${$rain{$atribute}}[0], ${$rain{$atribute}}[1], ${$rain{$atribute}}[2]);
382        }
383        print INDEX "</div>\n";
384        &print_page($wtype);
385
386        $wtype = "pressure";
387        &print_body_begin($wtype);
388        foreach $atribute (keys %pressure) {
389                &print_body_line("$wtype", $atribute, ${$pressure{$atribute}}[0], ${$pressure{$atribute}}[1], ${$pressure{$atribute}}[2]);
390        }
391        print INDEX "</div>\n";
392        &print_page($wtype);
393}
394
395
396
397#################
398##### MAIN ######
399#################
400
401@wwsr = `./wwsr -y`;
402#@wwsr = `cat wwsr6.out`;
403#@wwsr = `tail -14 /var/www/html/wwss/log`;
404
405$wwwdir = "/var/www/html/wwss/";
406#$wwwdir = "wwss/";
407$en_dbg = 0;
408$rrdtoolp = "/usr/bin/rrdtool";
409$rrdbp = "/var/www/html/wwss/";
410#$rrdbp = "wwss/";
411
412$graphs = 0;
413
414# What options are defined on command line?
415if ( defined($ARGV[0]) ) {
416        for ($i = 0; $i < @ARGV; $i++) {
417                $argmnt = $ARGV[$i];
418                if ($argmnt eq "-g") {
419                        $graphs = 1;
420                }
421                if ($argmnt eq "-a") {
422                        if (defined ($ARGV[$i+1] and length($ARGV[$i+1] == 1)) ) {
423                                $altitude = $ARGV[$i+1];
424                                $i++;
425                        } else { 
426                                die "ERROR: Unknown or missing argument to -a"
427                        }
428                }
429        }
430} else {
431        &help;
432};
433
434
435open (LOG, ">>$wwwdir"."log") || die "ERROR: no log";
436print LOG "------- ".`date`;
437for ($i=0;$i<=($#wwsr-1);$i++) {
438        print LOG $wwsr[$i];
439}
440close LOG;
441
442for ($i=0;$i<=($#wwsr-1);$i++) {
443    if ($wwsr[$i] =~ /^For postprocessing/) {
444        $wwsr[$i] = "";
445        last;
446    } else {
447        $wwsr[$i] = "";
448    }
449    if ($i==($#wwsr-1)) {
450        print INDEX "ERROR: wwsr output - for postprocessing sequence not found!</br>";
451        for ($ii=0;$ii<=($#wwsr-1);$ii++) { print INDEX $wwsr[$ii]."</br>"; }
452    }
453}
454
455
456# define main hashes for value groups
457%temperature = ();
458%pressure = ();
459%humidity = ();
460%wind = ();
461%rain = ();
462
463# store all values that wwsr returns
464foreach $line (@wwsr) {
465        chomp $line;
466        if ( $line ne "" ) {
467            @aline = split ("\t", $line);
468                ($value, $scale) = split (" ", $aline[1]);
469#               $value = $aline[$#aline]; #posledni prvek je hodnota
470
471                $rrdbn = $aline[0];
472                $rrdbn =~ s/ /_/g;
473                $rrdbn = lc($rrdbn);
474               
475                if ($rrdbn eq "interval") { next };
476
477                #The only difference if the order of words in wwsr output changes is, that the description of values in graphs is different. Values are processed correctly anyway.
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
485$rrdbnt = "temperature_feel-out";
486$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
501$rrdbnt = "pressure_air-sea";
502$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
511$rrdbnt = "temperature_dew-out";
512$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
Note: See TracBrowser for help on using the browser.