Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The algorithm has been implemented such that reports of any duration ranging from a minute to a year are automatically aligned with regular clock hours. Below is a snippet of the code that implements the alignment. The basic trick used is that I store the startperiod of the first report to represent the point in time which should have been the starting point if the report had been aligned with regular clock hours. Once the first report is generated at the proper alignment, all others are generated correctly

Code Block
if ( $report->{count} * $samplerate < 60 ){ # i.e. if size of report interval is less than an hour (e.g. 15 minute reports)

                        my $aligned_timestamp = Time::Local::timelocal (0,0,$hour, $mday, $mon, $year,$wday, $yday, $isdst );
                        my $current_timestamp = $self->{filetime};
                        my $mod = ($current_timestamp - $aligned_timestamp) % ($report->{count} * $samplerate * 60);
                        $report->{aggdata}{startperiod} = $current_timestamp - $mod;
                }
                elsif( $report->{count} * $samplerate < 1440 ){ # i.e. if size of report interval is less than a day (e.g. six-hourly reports)

                        my $aligned_timestamp  = Time::Local::timelocal (0,0,0, $mday, $mon, $year,$wday, $yday, $isdst );
                        my $current_timestamp = $self->{filetime};
                        my $mod = ($current_timestamp - $aligned_timestamp) % ($report->{count} * $samplerate * 60) ;
                        $report->{aggdata}{startperiod} = $current_timestamp - $mod;
                }
                elsif( $report->{count} * $samplerate < 40320 ) { # i.e. if the size of the report interval is less than a month (e.g. 15 day report)

                        my $aligned_timestamp  = Time::Local::timelocal (0,0,0,1, $mon, $year,0, 0, $isdst );
                        my $current_timestamp = $self->{filetime};
                        my $mod = ($current_timestamp - $aligned_timestamp) % ($report->{count} * $samplerate * 60) ;
                        $report->{aggdata}{startperiod} = $current_timestamp - $mod;
                }