[weewx-user] Re: extension to calculate rainstorm info: total rainfall, ending time, duration

2018-04-09 Thread Manuel
Ok Rich now its ok.

El viernes, 6 de abril de 2018, 1:39:41 (UTC+2), Rich Altmaier escribió:
>
> This is my first try at an extension.  This is one file to place in user 
> (/usr/share/weewx/user), with info in the header for the skin.conf and 
> Standard/index.html.tmpl changes to place the data into a report.
> Please do give feedback!
> Thanks, Rich
>
>
>

-- 
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.


[weewx-user] Re: extension to calculate rainstorm info: total rainfall, ending time, duration

2018-04-08 Thread Manuel
Hello Rich I have been stealing the second file storm.py and I have this 
error when generating the report: 

Apr  8 02:56:24 raspberrypi weewx[3785]: reportengine: Caught unrecoverable 
exception ingenerator weewx.cheetahgenerator.CheetahGenerator
Apr  8 02:56:24 raspberrypi weewx[3785]:   time data 
'2017-07-05 16:00:00-PST' does not match format '%Y-%m-%d %H:%M:%S-%Z'
Apr  8 02:56:24 raspberrypi weewx[3785]:   Traceback (most 
recent call last):
Apr  8 02:56:24 raspberrypi weewx[3785]: File 
"/usr/share/weewx/weewx/reportengine.py", line 239, in run
Apr  8 02:56:24 raspberrypi weewx[3785]:   obj.start()
Apr  8 02:56:24 raspberrypi weewx[3785]: File 
"/usr/share/weewx/weewx/reportengine.py", line 273, in start
Apr  8 02:56:24 raspberrypi weewx[3785]:   self.run()
Apr  8 02:56:24 raspberrypi weewx[3785]: File 
"/usr/share/weewx/weewx/cheetahgenerator.py", line 158, in run
Apr  8 02:56:24 raspberrypi weewx[3785]:   ngen = 
self.generate(gen_dict[section_name], self.gen_ts)
Apr  8 02:56:24 raspberrypi weewx[3785]: File 
"/usr/share/weewx/weewx/cheetahgenerator.py", line 232, in generate
Apr  8 02:56:24 raspberrypi weewx[3785]:   ngen += 
self.generate(section[subsection], gen_ts)
Apr  8 02:56:24 raspberrypi weewx[3785]: File 
"/usr/share/weewx/weewx/cheetahgenerator.py", line 232, in generate
Apr  8 02:56:24 raspberrypi weewx[3785]:   ngen += 
self.generate(section[subsection], gen_ts)
Apr  8 02:56:24 raspberrypi weewx[3785]: File 
"/usr/share/weewx/weewx/cheetahgenerator.py", line 320, in generate
Apr  8 02:56:24 raspberrypi weewx[3785]:   default_binding)
Apr  8 02:56:24 raspberrypi weewx[3785]: File 
"/usr/share/weewx/weewx/cheetahgenerator.py", line 372, in _getSearchList
Apr  8 02:56:24 raspberrypi weewx[3785]:   searchList += 
obj.get_extension_list(timespan, db_lookup)
Apr  8 02:56:24 raspberrypi weewx[3785]: File 
"/usr/share/weewx/user/storm.py", line 100, in get_extension_list
Apr  8 02:56:24 raspberrypi weewx[3785]:   StructTime  = 
time.strptime('2017-07-05 16:00:00-PST', '%Y-%m-%d %H:%M:%S-%Z')
Apr  8 02:56:24 raspberrypi weewx[3785]: File 
"/usr/lib/python2.7/_strptime.py", line 467, in _strptime_time
Apr  8 02:56:24 raspberrypi weewx[3785]:   return 
_strptime(data_string,format)[0]
Apr  8 02:56:24 raspberrypi weewx[3785]: File 
"/usr/lib/python2.7/_strptime.py", line 325, in _strptime
Apr  8 02:56:24 raspberrypi weewx[3785]:   (data_string, 
format))
Apr  8 02:56:24 raspberrypi weewx[3785]:   ValueError: time 
data '2017-07-0516:00:00-PST' does not match format '%Y-%m-%d %H:%M:%S-%Z'
Apr  8 02:56:24 raspberrypi weewx[3785]:   Generator terminated
Apr  8 02:56:24 raspberrypi weewx[3785]: reportengine: Caught unrecoverable 
exception ingenerator weewx.cheetahgenerator.CheetahGenerator
Apr  8 02:56:24 raspberrypi weewx[3785]:   time data 
'2017-07-05 16:00:00-PS' does not match format '%Y-%m-%d %H:%M:%S-%Z'
Apr  8 02:56:24 raspberrypi weewx[3785]:   Traceback (most 
recent call last):
Apr  8 02:56:24 raspberrypi weewx[3785]: File 
"/usr/share/weewx/weewx/reportengine.py", line 239, in run
Apr  8 02:56:24 raspberrypi weewx[3785]:   obj.start()
Apr  8 02:56:24 raspberrypi weewx[3785]: File 
"/usr/share/weewx/weewx/reportengine.py", line 273, in start
Apr  8 02:56:24 raspberrypi weewx[3785]:   self.run()
Apr  8 02:56:24 raspberrypi weewx[3785]: File 
"/usr/share/weewx/weewx/cheetahgenerator.py", line 158, in run
Apr  8 02:56:24 raspberrypi weewx[3785]:   ngen = 
self.generate(gen_dict[section_name], self.gen_ts)
Apr  8 02:56:24 raspberrypi weewx[3785]: File 
"/usr/share/weewx/weewx/cheetahgenerator.py", line 232, in generate
Apr  8 02:56:24 raspberrypi weewx[3785]:   ngen += 
self.generate(section[subsection], gen_ts)
Apr  8 02:56:24 raspberrypi weewx[3785]: File 
"/usr/share/weewx/weewx/cheetahgenerator.py", line 232, in generate
Apr  8 02:56:24 raspberrypi weewx[3785]:   ngen += 
self.generate(section[subsection], gen_ts)
Apr  8 02:56:24 raspberrypi weewx[3785]: File 
"/usr/share/weewx/weewx/cheetahgenerator.py", line 320, in generate
Apr  8 02:56:24 raspberrypi weewx[3785]:   default_binding)
Apr  8 02:56:24 raspberrypi weewx[3785]: File 
"/usr/share/weewx/weewx/cheetahgenerator.py", line 372, in _getSearchList
Apr  8 02:56:24 raspberrypi weewx[3785]:   searchList += 
obj.get_extension_list(timespan, db_lookup)
Apr  8 02:56:24 raspberrypi weewx[3785]: File 

[weewx-user] Re: extension to calculate rainstorm info: total rainfall, ending time, duration

2018-04-07 Thread 'Rich Altmaier' via weewx-user
I have an update, storm v1.1.  I misunderstood the timestamp on archive 
records.  I now see the timestamp value is the time at end of the interval 
of rain accumulation.  Fixed that!   
Rich


On Thursday, April 5, 2018 at 4:39:41 PM UTC-7, Rich Altmaier wrote:
>
> This is my first try at an extension.  This is one file to place in user 
> (/usr/share/weewx/user), with info in the header for the skin.conf and 
> Standard/index.html.tmpl changes to place the data into a report.
> Please do give feedback!
> Thanks, Rich
>
>
>

-- 
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.

# Copyright 2018 Rich Altmaier  richa...@yahoo.com
#
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see .
#

"""
storm.py  v1.1

This search list extension calculates tags, one is a time interval,
 and one is a duration, of the most recent rainstorm:

'last_rain_storm': finds the last rain interval, allowing stats to
   be calculated over that interval.
 We search back to find the storm end, which might be still on-going,
 and search still further back to find the rain start (after a dry period)
'storm_duration':  duration in days

***
Usage:
 1) copy this file to the user directory
/usr/share/weewx/user

 2) add the option search_list_extensions in the 
   /etc/weewx/skins/Standard/skin.conf configuration file, 
   adding the name of this extension.  When you're done, 
   it will look  like this:

 [CheetahGenerator]
search_list_extensions = user.storm.RainStorm

 3) in the html template /etc/weewx/skins/Standard/index.html.tmpl
in the Current Conditions section, perhaps after Inside Temperature,
add this table row:
   
  last storm total rain,
  ending $last_rain_storm.end
  of duration $storm_duration days
  $last_rain_storm.rain.sum
   

You can also use other tags such as $last_rain_storm.outTemp.max for the max
temperature, or $last_rain_storm.rain.sum for the total rainfall in the last
storm

***
"""
import datetime
import time

from weewx.cheetahgenerator import SearchList
from weewx.tags import TimespanBinder
from weeutil.weeutil import TimeSpan

class RainStorm(SearchList): 

def __init__(self, generator): 
SearchList.__init__(self, generator)

def get_extension_list(self, timespan, db_lookup): 
"""Returns a search list extension for storm detection

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 find end of most recent storm.
#   may be still ongoing (e.g. rain in most recent record).
#   parameterized with:  
storm_dry_period = 24   # number of hours of no rain to delimit
# storm end and storm start.
storm_in_past = 20  # number of days to look back for a storm
storm_now = int(time.time() )   # right now this second
   # can choose other epoch value for testing!

# set now to a testing time, to look at various past rain records
#StructTime  = time.strptime('2017-02-05 16:00:00-PST', '%Y-%m-%d %H:%M:%S-%Z')
 # 0.80in, from 2017-02-01 to 2017-02-04
#StructTime  = time.strptime('2017-01-05 16:00:00-PST', '%Y-%m-%d %H:%M:%S-%Z')
 # 1.58 in, from 2017-01-01 to 2017-01-05
StructTime  = time.strptime('2017-07-05 16:00:00-PST', '%Y-%m-%d %H:%M:%S-%Z')
 # 0.0 in. 
#storm_now = int(time.mktime(StructTime))

wx_db_mgr = db_lookup()
	c = wx_db_mgr.connection.cursor()

#caching method:
#  temporary table RainStormcache,
#fields:  entryEpoch, startE, endEall are Integer
#just