Esempio n. 1
0
    def getToDateSearchList(self, currentRec, stop_ts):  # 2

        # Get a TimeSpan object that represents all time up to the stop time:
        all_time = TimeSpan(self.start_ts, stop_ts)      # 3

        # Get a TimeSpanStats object :
        all_stats = TimeSpanStats(self.statsdb,
                                  all_time,
                                  unit_info=self.unit_info) # 4

        # Get the superclass's search list:       
        search_list = FileGenerator.getToDateSearchList(self, currentRec, stop_ts) #5

        # Now tack on my addition as a small dictionary with key 'alltime':
        search_list += [ {'alltime' : all_stats} ]       # 6
        
        return search_list
Esempio n. 2
0
    def getToDateSearchList(self, archivedb, statsdb, valid_timespan): # 2
        """Returns a search list with two additions. Overrides the
        default "getToDateSearchList" method.
        
        Parameters:
          archivedb: An instance of weewx.archive.Archive
          
          statsdb:   An instance of weewx.stats.StatsDb
          
          valid_timespan: An instance of weeutil.weeutil.TimeSpan. This will
                          hold the start and stop times of the domain of 
                          valid times."""

        # First, get a TimeSpanStats object for all time. This one is easy
        # because the object valid_timespan already holds all valid times to be
        # used in the report.
        all_stats = TimeSpanStats(valid_timespan,
                                  statsdb,
                                  formatter=self.formatter,
                                  converter=self.converter)         # 3
        
        # Now get a TimeSpanStats object for the last seven days. This one we
        # will have to calculate. First, calculate the time at midnight, seven
        # days ago. The variable week_dt will be an instance of datetime.date.
        week_dt = datetime.date.fromtimestamp(valid_timespan.stop) - datetime.timedelta(weeks=1)    #4
        # Now convert it to unix epoch time:
        week_ts = time.mktime(week_dt.timetuple())                  # 5
        # Now form a TimeSpanStats object, using the time span we just calculated:
        seven_day_stats = TimeSpanStats(TimeSpan(week_ts, valid_timespan.stop),
                                        statsdb,
                                        formatter=self.formatter,
                                        converter=self.converter)   #6

        # Get the superclass's search list:       
        search_list = FileGenerator.getToDateSearchList(self, archivedb, statsdb, valid_timespan) # 7

        # Now tack on my two additions as a small dictionary with keys 'alltime' and 'seven_day':
        search_list += [ {'alltime'   : all_stats,
                          'seven_day' : seven_day_stats} ]               # 8
        
        return search_list