Hi Chris,
Sorry it took so long, I started a new job a few weeks ago, and hobbies 
have taken a back seat!  Let me start by saying that all the information, 
and better descriptions of what is happening can be found in the Weewx 
Customization Guide that TK and the guys have put together.  
http://weewx.com/docs/customizing.htm

All of the back end is contained in one file, On my system 
\usr\share\weewx\user\ArchiveSearch.py  Look at Defining New Tags 
<http://weewx.com/docs/customizing.htm#defining_new_tags> in the docs, the 
similarities should be immediately apparent.  This then get's included in 
the search list extensions in skin.conf.  You can then include your new 
tags in your *.tmpl files, to be generated each time the generator runs. 

First the ArchiveSearch.py:  I removed most of the comments that are in the 
documentation for the sake of brevity.  It is worth noting that you may 
need to install python relativedelta on your system for this to work.

*import datetime*
*import time*
*from dateutil.relativedelta import relativedelta*

*from weewx.cheetahgenerator import SearchList*
*from weewx.tags import TimespanBinder*
*from weeutil.weeutil import TimeSpan*
*from weeutil.weeutil import archiveDaySpan*
*from weeutil.weeutil import archiveWeekSpan*
*from weeutil.weeutil import archiveMonthSpan*
*from weeutil.weeutil import archiveYearSpan*

*class ArchiveSearch(SearchList):                                          
       # 1*
*    """My search list extension"""*

*    def __init__(self, generator):                                        
   # 2*
*        SearchList.__init__(self, generator)*
    
*    def get_extension_list(self, timespan, db_lookup):                    
   # 3*
*        """Returns a search list extension with two additions.*
        
*        Parameters:*
*          timespan: An instance of weeutil.weeutil.TimeSpan. This will*
*                    hold the start and stop times of the domain of *
*                    valid times.*

*          db_lookup: This is a function that, given a data binding*
*                     as its only parameter, will return a database manager*
*                     object.*


*        """*
*        # First, create TimespanBinder object for all time. This one is 
easy*
*        # because the object timespan already holds all valid times to be*
*        # used in the report.*
*        all_time = TimespanBinder(timespan, *
*                                   db_lookup,*
*                                   formatter=self.generator.formatter,*
*                                   converter=self.generator.converter,*
*                                  context="month")       # 4*
        
*        # Now get a TimespanBinder 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.*
*        today_last_year_dt = datetime.date.fromtimestamp(timespan.stop) - 
relativedelta(years=1)*

*        # Convert it to unix epoch time:*
*        today_last_year_ts = time.mktime(today_last_year_dt.timetuple())  
     # 6*



*        today_last_year_time_span = archiveDaySpan(today_last_year_ts)*
*        # Form a TimespanBinder object, using the time span we just*
*        # calculated:*
*        today_last_year= TimespanBinder(today_last_year_time_span,*
*                                         db_lookup,*
*                                        
 formatter=self.generator.formatter,*
*                                        
 converter=self.generator.converter,*
*                                         context="month") # 7*
*#Assembles this week last year*
*        week_last_year_time_span = archiveWeekSpan(today_last_year_ts)*
*        # Form a TimespanBinder object, using the time span we just*
*        # calculated:*
*        week_last_year= TimespanBinder(week_last_year_time_span,*
*                                         db_lookup,*
*                                        
 formatter=self.generator.formatter,*
*                                        
 converter=self.generator.converter,*
*                                         context="month") # 7*


*#Assembles this month last year.*
*        month_last_year_time_span = archiveMonthSpan(today_last_year_ts)*
*        # Form a TimespanBinder object, using the time span we just*
*        # calculated:*
*        month_last_year= TimespanBinder(month_last_year_time_span,*
*                                         db_lookup,*
*                                        
 formatter=self.generator.formatter,*
*                                        
 converter=self.generator.converter,*
*                                         context="month") # 7*

*#Assembles last year.*
*        last_year_time_span = archiveYearSpan(today_last_year_ts)*
*        # Form a TimespanBinder object, using the time span we just*
*        # calculated:*
*        last_year= TimespanBinder(last_year_time_span,*
*                                         db_lookup,*
*                                        
 formatter=self.generator.formatter,*
*                                        
 converter=self.generator.converter,*
*                                         context="month") # 7*

*        #Assembles last year to date.*
        
*        last_year_start_dt = datetime.date(today_last_year_dt.year,1,1)*

*        last_year_start_ts = time.mktime(last_year_start_dt.timetuple())*

*        # Form a TimespanBinder object, using the time span we just*
*        # calculated:*

*        last_year_to_date= TimespanBinder(TimeSpan(last_year_start_ts, 
today_last_year_ts),*
*                                         db_lookup,*
*                                        
 formatter=self.generator.formatter,*
*                                        
 converter=self.generator.converter,*
*                                         context="month") # 7*

        

*        # Now create a small dictionary with keys 'alltime' and 
'seven_day':*
*        search_list_extension = {'today_last_year'   : today_last_year,*
*                                 'week_last_year' : week_last_year,*
*                                 'month_last_year': month_last_year,*
*                                 'last_year': last_year,*
*                                 'last_year_to_date' : last_year_to_date,*
*                                 'all_time' : all_time}              # 8*
        
*        # Finally, return our extension as a list:*
*        return [search_list_extension]                                    
   # 9*


Next, we add it to skin.conf, I'm using Sofaskin, written by Blaues 
Ledersofa:
[CheetahGenerator]
    # This section is used by the generator CheetahGenerator, and specifies
    # which files are to be generated from which template.
    # Possible encodings are 'html_entities', 'utf8', or 'strict_ascii'
    encoding = html_entities
    search_list_extensions = user.ArchiveSearch.ArchiveSearch

Finally, we use our new tags in our *.tmpl files.  Here is a snippet from 
my Year tab.  You will see how the new tags are being used, again i removed 
some bits for brevity.

      <div class="card" >
                    <h1><i class="fa fa-history m-rot" ></i> History: Last 
Year to Date</h1>
     <div>
    <table class="tablespacer">
      <tr><td colspan=3><h3>Outdoor Conditions</h3></td></tr>
                      <tr><td>High 
Temperature</td><td>$last_year_to_date.outTemp.max</td><td>$last_year_to_date.outTemp.maxtime</td></tr>
                      <tr><td>Low 
Temperature</td><td>$last_year_to_date.outTemp.min</td><td>$last_year_to_date.outTemp.mintime</td></tr>
      <tr><td>Average 
Temperature</td><td>$last_year_to_date.outTemp.avg</td><td></tr></tr>
                        <tr><td>High Heat 
Index</td><td>$last_year_to_date.heatindex.max</td><td>$last_year_to_date.heatindex.maxtime</td></tr>
                        <tr><td>Low Wind 
Chill</td><td>$last_year_to_date.windchill.min</td><td>$last_year_to_date.windchill.mintime</td></tr>
                      <tr><td>High 
Dewpoint</td><td>$last_year_to_date.dewpoint.max</td><td>$last_year_to_date.dewpoint.maxtime</td></tr>
                        <tr><td>Low 
Dewpoint</td><td>$last_year_to_date.dewpoint.min</td><td>$last_year_to_date.dewpoint.mintime</td></tr>
                        <tr><td>High 
Humidity</td><td>$last_year_to_date.outHumidity.max</td><td>$last_year_to_date.outHumidity.maxtime</td></tr>
                        <tr><td>Low 
Humidity</td><td>$year.outHumidity.min</td><td>$last_year_to_date.outHumidity.mintime</td></tr>
                        <tr><td>High 
Barometer</td><td>$last_year_to_date.barometer.max</td><td>$last_year_to_date.barometer.maxtime</td></tr>
                        <tr><td>Low 
Barometer</td><td>$last_year_to_date.barometer.min</td><td>$last_year_to_date.barometer.mintime</td></tr>
      <tr><td colspan=3><h3>Wind and Rain</h3></td></tr>
                      <tr><td>High Wind 
Speed</td><td>$last_year_to_date.wind.max 
$last_year_to_date.wind.gustdir</td><td>$last_year_to_date.wind.maxtime</td></tr>
                        <tr><td>Average 
Wind</td><td>$last_year_to_date.wind.avg</td><td></td></tr>
                        <tr><td>RMS 
Wind</td><td>$last_year_to_date.wind.rms</td><td></td></tr>
                        <tr><td>Vector Average 
Speed</td><td>$last_year_to_date.wind.vecavg</td><td></td></tr>
                        <tr><td>Vector Average 
Direction</td><td>$last_year_to_date.wind.vecdir</td><td></td></tr>
      <tr><td colspan=3><h3>Indoor Conditions</h3></td></tr>
                      <tr><td>High Inside 
Temperature</td><td>$last_year_to_date.inTemp.max</td><td>$last_year_to_date.inTemp.maxtime</td></tr>
                        <tr><td>Low Inside 
Temperature</td><td>$last_year_to_date.inTemp.min</td><td>$last_year_to_date.inTemp.mintime</td></tr>
  
                     
                    </table>
     </div>
      </div>


Before you do any of this to your system, I would take an hour and read 
through the *entire* customization guide.  You may not understand 
everything as you read it, but it will help you.  I asked many stupid 
questions that were covered in the guide when I was getting started.  

Good Luck!

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to weewx-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to