[weewx-user] Re: rainstorm total rainfall SQL and demonstration python script

2018-04-05 Thread Manuel
Hi Rich I've tested the extension and it's exactly what I was looking for. 
Show the millimeters of the last rain or storm period and the days of this. I 
think it has been a hard work. Thank you very much.

El viernes, 6 de abril de 2018, 1:41:13 (UTC+2), Rich Altmaier escribió:
>
> Manuel, I just posted an extension to do a rainstorm calculation.  Please 
> give it a try!
> Rich
>
>
> On Monday, April 2, 2018 at 4:33:27 PM UTC-7, Manuel wrote:
>>
>> Hello Rich, I've been studying that tag for some time, but my Python 
>> knowledge is not much. There is a web Spain that I have connected my 
>> station and has that function but I want to do it from weewx. We will 
>> study more. regards
>> The web and my station in Alanís, Sevilla 
>> https://www.meteoclimatic.net/perfil/ESAND410041380A
>>
>> El domingo, 25 de febrero de 2018, 1:09:26 (UTC+1), Rich Altmaier 
>> escribió:
>>>
>>> I studied the weewx archive database and created this SQL, embedded into 
>>> a python script, to find the most recent rain storm and show the running 
>>> total rainfall of the storm.  
>>> You can see the script is parameterized to define a storm as delimited 
>>> by some number of hours of no rain, I selected 8.  
>>>
>>> My objective is to hope someone will extract useful portions for the 
>>> calculation of a tag to add to a report, enabling showing storm total 
>>> rainfall!
>>> If you do this, please do add to this post!!
>>> The script *does not modify* your database, creating only a temporary 
>>> table to make the query reasonably quick. 
>>>
>>> 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: rainstorm total rainfall SQL and demonstration python script

2018-04-05 Thread 'Rich Altmaier' via weewx-user
Manuel, I just posted an extension to do a rainstorm calculation.  Please 
give it a try!
Rich


On Monday, April 2, 2018 at 4:33:27 PM UTC-7, Manuel wrote:
>
> Hello Rich, I've been studying that tag for some time, but my Python 
> knowledge is not much. There is a web Spain that I have connected my 
> station and has that function but I want to do it from weewx. We will 
> study more. regards
> The web and my station in Alanís, Sevilla 
> https://www.meteoclimatic.net/perfil/ESAND410041380A
>
> El domingo, 25 de febrero de 2018, 1:09:26 (UTC+1), Rich Altmaier escribió:
>>
>> I studied the weewx archive database and created this SQL, embedded into 
>> a python script, to find the most recent rain storm and show the running 
>> total rainfall of the storm.  
>> You can see the script is parameterized to define a storm as delimited by 
>> some number of hours of no rain, I selected 8.  
>>
>> My objective is to hope someone will extract useful portions for the 
>> calculation of a tag to add to a report, enabling showing storm total 
>> rainfall!
>> If you do this, please do add to this post!!
>> The script *does not modify* your database, creating only a temporary 
>> table to make the query reasonably quick. 
>>
>> 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: rainstorm total rainfall SQL and demonstration python script

2018-04-02 Thread Manuel
Hello Rich, I've been studying that tag for some time, but my Python 
knowledge is not much. There is a web Spain that I have connected my 
station and has that function but I want to do it from weewx. We will study 
more. regards
The web and my station in Alanís, Sevilla 
https://www.meteoclimatic.net/perfil/ESAND410041380A

El domingo, 25 de febrero de 2018, 1:09:26 (UTC+1), Rich Altmaier escribió:
>
> I studied the weewx archive database and created this SQL, embedded into a 
> python script, to find the most recent rain storm and show the running 
> total rainfall of the storm.  
> You can see the script is parameterized to define a storm as delimited by 
> some number of hours of no rain, I selected 8.  
>
> My objective is to hope someone will extract useful portions for the 
> calculation of a tag to add to a report, enabling showing storm total 
> rainfall!
> If you do this, please do add to this post!!
> The script *does not modify* your database, creating only a temporary 
> table to make the query reasonably quick. 
>
> 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: rainstorm total rainfall SQL and demonstration python script

2018-04-02 Thread 'Rich Altmaier' via weewx-user
Hi Manuel, you and I have the same question!   How to create a weewx new 
tag!   I plan to study that over the next month or so.
Regarding the error below, in storm.py the intention is that you open your 
weewx database in line 42:  sqlite3.connect("your database filename")
For experimentation, assuming you are using weewx on Linux, copy your 
database file, which is probably at /var/lib/weewx, named weewx.sdb, to 
/tmp.  Then put the /tmp/weewx.sdb filename into the .connect line!  
Then you can try out my script.

Rich



On Monday, April 2, 2018 at 1:46:53 PM UTC-7, Manuel wrote:
>
>
>
> El domingo, 25 de febrero de 2018, 18:25:52 (UTC+1), Rich Altmaier 
> escribió:
>>
>> I fixed the licensing statement to be GPL3, added the copyright notice, 
>> and I changed the storm dry period to 24 hours.
>> Thanks, Rich
>>
>> Hi, I run the file storm.py ad i have a error: Traceback (most recent 
>> call last):
>>File "/var/lib/weewx/storm.py", line 53, in 
>>  "" ", {" now ": storm_now," past ": storm_in_past})
>> sqlite3.OperationalError: no such table: archive
>> ? Thanks
>>
>> On Saturday, February 24, 2018 at 4:09:26 PM UTC-8, Rich Altmaier wrote:
>>>
>>> I studied the weewx archive database and created this SQL, embedded into 
>>> a python script, to find the most recent rain storm and show the running 
>>> total rainfall of the storm.  
>>> You can see the script is parameterized to define a storm as delimited 
>>> by some number of hours of no rain, I selected 8.  
>>>
>>> My objective is to hope someone will extract useful portions for the 
>>> calculation of a tag to add to a report, enabling showing storm total 
>>> rainfall!
>>> If you do this, please do add to this post!!
>>> The script *does not modify* your database, creating only a temporary 
>>> table to make the query reasonably quick. 
>>>
>>> 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: rainstorm total rainfall SQL and demonstration python script

2018-04-02 Thread Manuel


El domingo, 25 de febrero de 2018, 18:25:52 (UTC+1), Rich Altmaier escribió:
>
> I fixed the licensing statement to be GPL3, added the copyright notice, 
> and I changed the storm dry period to 24 hours.
> Thanks, Rich
>
> Hi, I run the file storm.py ad i have a error: Traceback (most recent call 
> last):
>File "/var/lib/weewx/storm.py", line 53, in 
>  "" ", {" now ": storm_now," past ": storm_in_past})
> sqlite3.OperationalError: no such table: archive
> ? Thanks
>
> On Saturday, February 24, 2018 at 4:09:26 PM UTC-8, Rich Altmaier wrote:
>>
>> I studied the weewx archive database and created this SQL, embedded into 
>> a python script, to find the most recent rain storm and show the running 
>> total rainfall of the storm.  
>> You can see the script is parameterized to define a storm as delimited by 
>> some number of hours of no rain, I selected 8.  
>>
>> My objective is to hope someone will extract useful portions for the 
>> calculation of a tag to add to a report, enabling showing storm total 
>> rainfall!
>> If you do this, please do add to this post!!
>> The script *does not modify* your database, creating only a temporary 
>> table to make the query reasonably quick. 
>>
>> 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: rainstorm total rainfall SQL and demonstration python script

2018-04-02 Thread Manuel
How can I implement this in weewx as a new tag in a custom search list 
extension? My knowledge of python is not very good. Thank you

El domingo, 25 de febrero de 2018, 1:09:26 (UTC+1), Rich Altmaier escribió:
>
> I studied the weewx archive database and created this SQL, embedded into a 
> python script, to find the most recent rain storm and show the running 
> total rainfall of the storm.  
> You can see the script is parameterized to define a storm as delimited by 
> some number of hours of no rain, I selected 8.  
>
> My objective is to hope someone will extract useful portions for the 
> calculation of a tag to add to a report, enabling showing storm total 
> rainfall!
> If you do this, please do add to this post!!
> The script *does not modify* your database, creating only a temporary 
> table to make the query reasonably quick. 
>
> 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: rainstorm total rainfall SQL and demonstration python script

2018-02-25 Thread 'Rich Altmaier' via weewx-user
I fixed the licensing statement to be GPL3, added the copyright notice, and 
I changed the storm dry period to 24 hours.
Thanks, Rich



On Saturday, February 24, 2018 at 4:09:26 PM UTC-8, Rich Altmaier wrote:
>
> I studied the weewx archive database and created this SQL, embedded into a 
> python script, to find the most recent rain storm and show the running 
> total rainfall of the storm.  
> You can see the script is parameterized to define a storm as delimited by 
> some number of hours of no rain, I selected 8.  
>
> My objective is to hope someone will extract useful portions for the 
> calculation of a tag to add to a report, enabling showing storm total 
> rainfall!
> If you do this, please do add to this post!!
> The script *does not modify* your database, creating only a temporary 
> table to make the query reasonably quick. 
>
> 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 .
#

import time
import sqlite3


# 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.
storm_in_past = 7  # number of days to look back for a storm
storm_now = 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')
#storm_now = int(time.mktime(StructTime))

print "now is ", storm_now
print "  ", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(storm_now))
 
# PRESUMABLY this DB connectivity follows normal weewx methods. 
conn = sqlite3.connect('weewx.sdb')
c = conn.cursor()

c.execute("drop table IF EXISTS RainWeek")
c.execute("""
create TEMPORARY table RainWeek as 
select dateTime, rain, 
   datetime(dateTime, 'unixepoch', 'localtime') as dateString
   from archive where dateTime >= :now - (24 * 3600 * :past )
   AND dateTime <=  :now
   ORDER BY dateTime
   """, {"now": storm_now, "past": storm_in_past})
conn.commit()

#c.execute("select count(*) from temp.RainWeek")
#print "number of rows in storm viewing table is ", int(c.fetchone()[0])

#dump RainWeek table
#c.execute("select rowid, rain, datetime(dateTime, 'unixepoch', 'localtime') as LocalTZ, dateTime from temp.RainWeek")
#StormTable = c.fetchall()
#print StormTable



c.execute("""
   -- find end of first wet period ending at or before storm_now
   -- or storm_now if has been wet within storm_dry_period hours of now. 
   select  CASE 
WHEN 
 ((select MAX(dateTime) as RainEndT  from temp.RainWeek where rain <> 0 ) 
  + (:dry * 3600))
 >  
  :now  
THEN
  :now  -- storm is still on-going

ELSE -- find most recent last wet time
(select MAX(dateTime) from temp.RainWeek where rain <> 0 OR rowid = 
  (select rowid from 
  (select MAX(dateTime) as LastWetT, rowid from temp.RainWeek where rain <> 0 )
  ) + 1  )
   --above is record after latest wet interval, or last wet interval
   --note: DB dateTime stamp is of beginning of interval

END  as RainEndTime

""", {"now": storm_now, "past": storm_in_past, "dry": storm_dry_period})
 
EndT = c.fetchone()
if EndT is None:
print "No storm in past", storm_in_past, " days"
storm_end_epoch = storm_now + storm_in_past*24*3600  # next query will also get null
else:
storm_end_epoch = int(EndT[0])
print "End time epoch ", storm_end_epoch
print "  ", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(storm_end_epoch))



c.execute("""
   -- find dry period preceeding storm_end_epoch.
   -- look at storm_dry_period hours of records preceeding each record to find 
   --  a preceeding sequence of 0 rain.

   select MAX(dateTime) as RainStartT from  
 (select f1.rowid AS ROWID, sum(f2.rain) as RunningRain, f1.dateTime
   FROM temp.RainWeek f1  INNER JOIN temp.RainWeek f2
   ON f1.dateTime > f2.dateTime AND