i use to update "maxSolarRad", "cloudbase", "windRun" and so on
def clear_v2_data(config_dict, db_binding_wx): """ Clear any legacy humidex and apparent temperature data from the Weewx (not Weewx-WD) database. Under Weewx v2.x Weewx-WD stored humidex and apparent temperature data in the Weewx archive in fields extraTemp1 and extratemp2 respectively. Under Weewx v3 Weewx-WD now stores this data in a separate database and hence this legacy data can be removed from the Weewx database. Parameters: config_dict: a dictionary of the weewx.conf settings db_binding_wx: binding for Weewx database Returns: Nothing. """
...
# we do so go ahead and clear them for _rec in dbmanager_wx.genBatchRecords(start_ts - 1, stop_ts): dbmanager_wx.updateValue(_rec['dateTime'], 'extraTemp1', None) dbmanager_wx.updateValue(_rec['dateTime'], 'extraTemp2', None) nrecs += 1 # all done, say so and give some stats print "Done. 'extraTemp1' and 'extraTemp2' cleared in %d records (approx %d days)." %(nrecs, ndays)
...
i have the line "dbmanager_wx.updateValue(_rec['dateTime'], 'extraTemp1', None)"
replaced by "dbmanager_wx.updateValue(_rec['dateTime'], 'maxSolarRad', msr) "
my plan is:
"""
if _rec['outTemp'] <> 0 and _rec['outHumidity'] <> 0:
cb1 = weewx.wxformulas.cloudbase_Metric(_rec['outTemp'], _rec['outHumidity'], 53)
else:
cb1 = 0
dbmanager_wx.updateValue(_rec['dateTime'], 'cloudbase', cb1)
# get the outTemp units and group used in the record
(t, g) = weewx.units.getStandardUnitType(_rec['usUnits'], 'outTemp')
# get _rec outTemp as a ValueTuple
temp_vt = weewx.units.ValueTuple(_rec['outTemp'], t, g)
# now get temperature in Celsius
temp_c = weewx.units.convert(temp_vt, 'degree_C').value
# calculate cloudbase, the result will be in meters
cb_m = weewx.wxformulas.cloudbase_Metric(temp_c, _rec['outHumidity'], 53)
# get the calculated cloudbase as a ValueTuple, it will now be an altitude in m
cb_m_vt = weewx.units.ValueTuple(cb_m, 'meter', 'group_altitude')
# convert the calculated cloudbase to the altitude units used in _rec
cb1 = weewx.units.convertStd(cb_m_vt, _rec['usUnits']).value
# update the archive cloudbase value
dbmanager_wx.updateValue(_rec['dateTime'], 'cloudbase', cb1)if _rec['windSpeed'] > 0:
vt = (_rec['windSpeed'], "mile_per_hour", "group_speed")
ws_kts = weewx.units.convert(vt, "knot")[0]
be2 = ws_kts * 5.0 / 60.0
else:
be2 = 0.0
dbmanager_wx.updateValue(_rec['dateTime'], 'windrun', be2)
if _rec['windSpeed'] is not None:
# get the windSpeed units and group used in _rec
(t, g) = weewx.units.getStandardUnitType(_rec['usUnits'], 'windSpeed')
# get the _rec windSpeed as a ValueTuple
ws_vt = weewx.units.ValueTuple(_rec['windSpeed'], t, g)
# now convert windSpeed to a known unit, say km per hour
ws_kmh = weewx.units.convert(ws_vt, 'km_per_hour').value
# calculate windrun, it will be a result in km
be2_km = ws_kmh * 5.0/60
# get the calculated windrun as a ValueTuple, it will now be a distance in km
be2_km_vt = weewx.units.ValueTuple(be2_km, 'km', 'group_distance')
# convert the calculated windrun to the distance units used in _rec
be2 = weewx.units.convertStd(be2_km_vt, _rec['usUnits']).value
else:
# if windSpeed is None then so is windrun, no need for any unit conversions
be2 = None
# update the archive windrun value
dbmanager_wx.updateValue(_rec['dateTime'], 'windrun', be2)
import weewx.units
"dbmanager_wx.updateValue(_rec['dateTime'], 'windrun', be2)"
updateValue from weewx does not workLet's wind things back a bit. A couple of questions:
1. What are you trying to do? Are you trying to calculate maxSolarRad, cloudbase and windrun for historical data in you archive?
2. Have you added fields maxSolarRad, cloudbase and windrun to your archive schema as I mentioned in my previous post?
Gary
Hi,Let's wind things back a bit. A couple of questions:
1. What are you trying to do? Are you trying to calculate maxSolarRad, cloudbase and windrun for historical data in you archive?
2. Have you added fields maxSolarRad, cloudbase and windrun to your archive schema as I mentioned in my previous post?
Gary
YES I would like to insert values like maxSolarRad, windrun and other into the old database "weewx"
1. I have 89 fields in my database
$ mysql -u root -p
mysql> USE archive_mysql
mysql> DESC archive;
"""
For "first Time in weewx-database" to "last Time in weewx-database" step 1:
cursor.execute("UPDATE archive SET maxSolarRad = %s WHERE dateTime = %s", ("123.98", "1394092770"))
cursor.execute("UPDATE archive SET windRun = %s WHERE dateTime = %s", ("233.08", "1394092770"))
cursor.execute("UPDATE archive SET cdIndex = %s WHERE dateTime = %s", ("45.7", "1394092770"))
"""
Hartmut
Ein Beispiel zur Ermittlung der Anzahl der Tage wenn 'min' größer ist als
nach:
bin/weewx/tags.py
def max_ge(self, val): return self._do_query('max_ge', val=val)
zur Ermittlung der Tage ergänzt
def min_ge(self, val): return self._do_query('min_ge', val=val)
eingefügt.
bin/weewx/manager.py
'max_ge': "SELECT SUM(max >= %(val)s) FROM %(table_name)s_day_%(obs_key)s
WHERE dateTime >= %(start)s AND dateTime < %(stop)s",
'min_ge': "SELECT SUM(min >= %(val)s) FROM %(table_name)s_day_%(obs_key)s
WHERE dateTime >= %(start)s AND dateTime < %(stop)s",
elif aggregate_type in ['mintime', 'maxmintime', 'maxtime', 'minmaxtime', 'maxsumtime',
'count', 'max_ge', 'max_le', 'min_ge', 'min_le', 'sum_ge']:
bin/weewx/units.py
'max_ge' : "group_count",
'max_le' : "group_count",
'min_ge' : "group_count",
These are uncritical since they have been functioning correctly for several monthsSo removing the """ fixed the problem? That was the first thing I noticed when I opened the file but I had not yet had a chance to look through the rest of the code. I don't know what editor you are using but an editor that has syntax highlighting is very good for picking up these sorts of errors - as soon as I opened you file in Notepad++ the extra """ was very easy to see.
At least there was a good outcome.
Gary
PS. That is a smart looking site you have.
So I see data has appeared in the maxSolarRad daily summary(archive_day_maxSolarRad), that implies there must be maxSolarRad data in your archive. So is everything as you expect or is there still a problem?
Gary
table "archive_day_maxSolarRad" after UPDATE dateTime min mintime max maxtime sum count wsum sumtime 1383174000 0 1383254340 0 1383254340 0 21 0 6300 1383260400 0 1383260640 295.461855977661 1383303541 18656.2263424185 288 5596867.90272548 86400 1383346800 0 1383347041 289.813642518552 1383389941 18163.9155725552 288 5449174.67176655 86400 1383433200 0 1383433441 284.239023967007 1383476341 17683.3831545144 287 5305014.94635428 86400
$ weewxwd_config --clear-v2-data
$ weewxwd_config --clear-v2-data --wx-binding=wx3080_binding
$ mysql -u root -p
mysql> USE weewxacer
mysql> SELECT dateTime,maxSolarRad FROM archive ORDER BY dateTime DESC LIMIT 10;
mysql> SELECT dateTime,maxSolarRad FROM archive ORDER BY dateTime ASC LIMIT 10;
Gary
- create the Weewx-WD database and archive table:
weewxwd_config --create-archive (((weewxacerWD))))
- check if there is any legacy data to copy, or if any historical Weewx-WD data can be reconstructed:
weewxwd_config --status
- copy any legacy data or reconstruct any historical Weewx-WD data:
weewxwd_config --copy-v2-data (((from weewxacer to weewxacerWD)))
After 17 hours I had a copy of the weewxacer as weewxacerWD database
the weewxacer database the old
the weewxacerWD one kopie of the old weewxacer-database and the newly calculated values
all TEST TEST TEST
Only for the calculation of about 300 values I will not take my original weather database 17 hours offline.
17 hours offline at the davis should not be a problem
however the o-wire temperature, water-temperature-sensors does not store any data
I am looking for a simple update solution
for example
#!/usr/bin/python
# -*- coding: utf-8 -*-
import MySQLdb as mdb
import sys
try:
conn = mdb.connect('localhost', 'testuser',
'test623', 'testdb');
For "first Time in weewx-database" to "last Time in weewx-database" step 1:
cursor = conn.cursor()
cursor.execute("UPDATE archive SET maxSolarRad = %s WHERE dateTime = %s", ("123.98", "1394092770"))
cursor.execute("UPDATE archive SET windRun = %s WHERE dateTime = %s", ("233.08", "1394092770"))
cursor.execute("UPDATE archive SET cdIndex = %s WHERE dateTime = %s", ("45.7", "1394092770")) conn.commit()
cursor.close()
conn.close()
"""Hallo Gary,
You do not have to apologize for anything.
I have already done this several times
Right now runs the next attempt instead of outTemp1 with NULL I want to replace maxSolarRad with values.
Simply
# we do so go ahead and clear them
for _rec in dbmanager_wx.genBatchRecords(start_ts - 1, stop_ts):
msr = weewx.wxformulas.solar_rad_Bras(53.605963, 11.341407, 53, _rec['dateTime'], 2)
dbmanager_wx.updateValue(_rec['dateTime'], 'maxSolarRad', msr)
For security, I just leave the current values per print on the screen issue.
In addition, weewx runs normally
result: "cleared in 350828 records (approx 1225 days)" on screen
weewx_copy_fill: record 350825 unter 128.238500608 tag
weewx_copy_fill: record 350826 unter 117.421041055 tag
weewx_copy_fill: record 350827 unter 106.746424888 tag
an in database NULL, NULL, NULL ....
the funktion from manager:
def updateValue(self, timestamp, obs_type, new_value):
"""Update (replace) a single value in the database."""
self.connection.execute("UPDATE %s SET %s=? WHERE dateTime=?" %
(self.table_name, obs_type), (new_value, timestamp))
Is called but nothing appears in the database
Hartmut
It is missing a call closes the function update (dbmanager_wx.updateValue) and writes to the database
It is missing a call which closes the function update (dbmanager_wx.updateValue) and writes to the database
for example --> finally: _cursor.close()
with weewx.manager.open_manager_with_config(config_dict, db_binding_wx) as dbmanager_wx:
dbmanager_wx is an object of type class Manager() and when we exit the above with statement the Manager() __exit__ method is called which handles the closure (have a look in bin/weewx/manager.py)
I think there has been quite a few changes since we started on this problem. I would like to sit down with the code you are using and try it on a machine here and likely put some logging into it so we can see exactly what is going on. Can you please post:
1. the python file you are running (modified weewxwd_config ?)
2. the contents of the [DataBindings], [Databases] and [DatabaseTypes] sections of weewx.conf
3. the exact command you typed at the command line that did not work
This code is very straightforward, there will be something equally basic that is causing the issue.
Gary
Version: 1.2.0b2
#!/usr/bin/env python # # 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 2 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. # # Version: 1.2.0b2 Date: 5 September 2015 # # Revision History # ?? September 2015 v1.2.0 - Initial implementation, based upon portions of # weewxwd3.py # """Manage the databases used by Weewx-WD""" from __future__ import with_statement
############################################
to clear extraTemp1 and extraTemp2 from weewxAlt (current weewx database)
#######################################
my weewx.conf
[DataBindings]
[[wx_binding]]
# The database must match one of the sections in [Databases].
# This is likely to be the only option you would want to change.
database = archive_mysql
# The name of the table within the database
table_name = archive
# The manager handles aggregation of data for historical summaries
manager = weewx.wxmanager.WXDaySummaryManager
# The schema defines the structure of the database.
# It is *only* used when the database is created.
schema = schemas.schemas.schema
[[wd_binding]]
# The database must match one of the sections in [Databases]
database = wd_mysql
table_name = archive
manager = weewx.wxmanager.WXDaySummaryManager
schema = schemas.wdSchema.weewxwd_schema
##############################################
and for weewxwd database weewxAltWD
Datenbank: weewxAlt »
Tabelle: archiveSELECT `dateTime`, `usUnits`, `interval`, `extraTemp1`, `extraTemp2` FROM `archive` WHERE `extraTemp1` >0;
| dateTime | usUnits | interval | extraTemp1 | extraTemp2 | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Bearbeiten
|
Kopieren
|
Löschen
| 1406844062 | 16 | 5 | 19.375 | 16.4375 | |||||||
Bearbeiten
|
Kopieren
|
Löschen
| 1406844361 | 16 | 5 | 19.375 | 16.375 | |||||||
Bearbeiten
|
Kopieren
|
Löschen
| 1406844662 | 16 | 5 | 19.375 | 16.3125 | |||||||
Bearbeiten
|
Kopieren
|
Löschen
| 1406844961 | 16 | 5 | 19.375 | 16.25 | |||||||
| ||||||||||||||
root@acer:/home/weewx/bin/user# ./weewxwd_config.py --clear-v2-data --wx-binding=wx_binding
Using configuration file /home/weewx/weewx.conf
Using database binding 'wx_binding', which is bound to database 'archive_mysql'
Using database binding 'wd_binding', which is bound to database 'wd_mysql'
'extraTemp1' and 'extraTemp2' data in database 'weewxAlt' from 2013-10-31 22:19:00 CET (1383254340) to 2017-03-11 12:50:00 CET (1489233000) (approx 1227 days) is about to be cleared.
| dateTime | extraTemp1 | extraTemp2 | |||
|---|---|---|---|---|---|---|
| 1489591200 | 7.93245825531825 | 13.9417930834273 |
| 1489591500 | 7.78199553157776 | 13.8184127927065 |
| 1489591800 | 7.63258845783752 | 13.6979746027028 |
| 1489592100 | 7.48430814377277 | 13.5805358354716 |
| 1489592400 | 7.33722516278218 | 13.4661523855058 |
| 1489592700 | 7.19140951839869 | 13.3548786931324 |
| 1489593000 | 7.0469306109717 | 13.2467677186025 |
| 1489593300 | 6.90385720463619 | 13.1418709168848 |
| 1489593600 | 6.76225739458474 | 13.0402382131756 |
| 1489593900 | 6.62219857465792 | 12.9419179791375 |
| 1489594200 | 6.48374740526844 | 12.8469570098769 |
| 1489594500 | 6.34696978167446 | 12.755400501672 |
| 1489594800 | 6.21193080261695 | 12.6672920304622 |
| 1489595100 | 6.07869473933625 | 12.5826735311078 |
| 1489595400 | 5.94732500498246 | 12.5015852774315 |
| 1489595700 | 5.81788412443414 | 12.4240658630503 |
| 1489596000 | 5.69043370453996 | 12.3501521830071 |
| 1489596300 | 5.5650344047971 | 12.2798794162105 |
Zeige Datensätze 266100 - 266101 (266102 insgesamt, Die Abfrage dauerte 1.6579 Sekunden.)SELECT * FROM `archive` dbmanager_wx.updateValue(_rec['dateTime'], 'extraTemp1', None)
dbmanager_wx.updateValue(_rec['dateTime'], 'extraTemp2', None)
nrecs += 1
dbmanager_wx.connection.commit()
# all done, say so and give some stats
print "Done. 'extraTemp1' and 'extraTemp2' cleared in %d records (approx %d days)." %(nrecs, ndays)
Hallo Gary,
the result
<td data-decimals="0" data-type="int" class="right data grid_edit click2 no