X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=loop.pl;h=2e9549120f84faee71707dd079360d97d9bd9e59;hb=1b7ccfa8837f5ec3fb2c43741b85fa4658c7b1b9;hp=ef8a6734c64ef6ebf14418cf978e71964a86b885;hpb=eb43e5b8fd8bf93c8bd6a3fb5090eea8299b3368;p=dweather.git diff --git a/loop.pl b/loop.pl index ef8a673..2e95491 100755 --- a/loop.pl +++ b/loop.pl @@ -14,6 +14,7 @@ use Debug; use SMGLog; use Math::Round qw(nearest); use File::Copy; +use Data::Random qw(rand_chars); use constant pi => 3.14159265358979; @@ -144,6 +145,8 @@ dbg '***'; dbg "*** starting $0"; dbg '***'; +read_ld(); + our $dlog = SMGLog->new("day"); dbg "before next tick"; Mojo::IOLoop->next_tick(sub { loop() }); @@ -155,12 +158,7 @@ write_ld(); close $dataf if $dataf; # move all the files along one -copy "$datafn.oooo", "$datafn.ooooo"; -copy "$datafn.ooo", "$datafn.oooo"; -copy "$datafn.oo", "$datafn.ooo"; -copy "$datafn.o", "$datafn.oo"; -copy $datafn, "$datafn.o"; - +cycle_loop_data_files(); dbg '***'; dbg "*** ending $0"; @@ -172,12 +170,6 @@ exit 0; sub loop { - - open $dataf, "+>>", $datafn or die "cannot open $datafn $!"; - $dataf->autoflush(1); - - read_ld(); - dbg "last_min: " . scalar gmtime($ld->{last_min}); dbg "last_hour: " . scalar gmtime($ld->{last_hour}); @@ -384,6 +376,8 @@ sub process if ($dayno > $ld->{last_day}) { $ld->{Temp_Out_Max} = $ld->{Temp_Out_Min} = $temp; $ld->{last_day} = $dayno; + write_ld(); + cycle_loop_data_files(); } $ld->{Temp_Out_Max} = $temp if $temp > $ld->{Temp_Out_Max}; $ld->{Temp_Out_Min} = $temp if $temp < $ld->{Temp_Out_Min}; @@ -425,6 +419,7 @@ sub process @{$ld->{wind_hour}} = (); @{$ld->{wind_min}} = (); + output_str($s, 1) if $s; write_ld(); } elsif ($ts >= $ld->{last_min} + 60) { @@ -452,6 +447,7 @@ sub process $ld->{last_min} = int($ts/60)*60; @{$ld->{wind_min}} = (); + output_str($s, 1) if $s; write_ld(); } else { @@ -462,8 +458,8 @@ sub process else { dbg "loop rec not changed" if isdbg 'chan'; } + output_str($s, 0) if $s; } - output_str($s) if $s; $ld->{last_h} = \%h; ++$loop_count; } else { @@ -488,9 +484,11 @@ sub genstr sub output_str { my $s = shift; + my $logit = shift; + dbg $s; # say $s; - $dlog->writenow($s); + $dlog->writenow($s) if $logit; foreach my $ws (keys $WS) { my $tx = $WS->{$ws}; if ($tx) { @@ -627,7 +625,10 @@ sub calc_rain sub read_ld { - return unless $dataf; + unless ($dataf) { + open $dataf, "+>>", $datafn or die "cannot open $datafn $!"; + $dataf->autoflush(1); + } seek $dataf, 0, 0; my $s = <$dataf>; @@ -654,7 +655,10 @@ sub read_ld sub write_ld { - return unless $dataf; + unless ($dataf) { + open $dataf, "+>>", $datafn or die "cannot open $datafn $!"; + $dataf->autoflush(1); + } seek $dataf, 0, 0; truncate $dataf, 0; @@ -664,6 +668,16 @@ sub write_ld print $dataf "$s\n"; } +sub cycle_loop_data_files +{ + close $dataf if $dataf; + + rename "$datafn.oooo", "$datafn.ooooo"; + rename "$datafn.ooo", "$datafn.oooo"; + rename "$datafn.oo", "$datafn.ooo"; + rename "$datafn.o", "$datafn.oo"; + copy $datafn, "$datafn.o"; +} __DATA__ @@ -671,21 +685,34 @@ __DATA__ % my $url = url_for 'weather'; - DWeather + + DWeather + + + + + + + + + + + -

DWeather

+

High View Weather

+ +
+


- +
-
Time: Sunrise: @@ -745,11 +779,19 @@ __DATA__ Minute Avg:
Rain Hour: +Rain 30mins: Day: 24hrs: Month: Year:
+
+
+
+
+ + + +