miércoles, 6 de enero de 2016

Mantenimiento de la base de datos. Weewx.sdb

2016-1-6.
Como arreglar las incongruencias de la base de datos era algo que tenía pendiente y contra mas tiempo pase mas incongruencias se me iban acumulando, hoy he decidido ponerme manos a la obra.
Tras leer el post de Jantoni en el que explica este procedimiento y viendo que en la documentación de Weewx viene también documentado, no he visto mayor problema que seguir las indicaciones.

  1. Parar el programa. sudo /etc/init.d/weewx stop
  2. Ejecutar sqlite3 abriendo la base de datos. O nos ponemos en el directorio /var/lib/weewx o lo direccionamos con el comando:
    sqlite3 weewx.sdb. Ojo si no lo hacemos con Sudo asegurarse que con el usuario que estamos trabajando tiene permisos de escritura sobre el archivo.
  3. Realizar las modificaciones que tengamos pendiente, todo sobre la tabla archives. Este es el procedimiento que aconsejan en la documentación de Weewx:

Spikes in the graphs

  1. Occasionally you may see anomalous readings, typically manifested as spikes in the graphs. The source could be a flaky serial/USB connection, radio or other interference, a cheap USB-Serial adapter, low-quality sensors, or simply an anomalous reading.
    Sensor quality matters. It is not unusual for some low-end hardware to report odd sensor readings occasionally (once every few days). Some sensors, such as solar radiation/UV, have a limited lifespan of about 5 years. The (analog) humidity sensors on older Vantage stations are known to deteriorate after a few years in wet environments.
    If you frequently see anomalous data, first check the hardware.
    To keep bad data from the database, add a quality control (QC) rule such as Min/Max bounds. See the QC section for details.
    To remove bad data from the database, you will have to do some basic SQL commands. For example, let's say the station emitted some very high temperatures and wind speeds for one or two readings. This is how to remove them:
    1. stop weewx
    2. Make a copy of the archive database
      cp weewx.sdb weewx-YYMMDD.sdb
    3. Verify the bad data exist where you think they exist
      sqlite3 weewx.sdb
      sqlite> select dateTime,outTemp from archive where outTemp > 1000;
    4. See whether the bad temperature and wind data happened at the same time
      sqlite> select dateTime,outTemp,windSpeed from archive where outTemp > 1000;
    5. Remove the bad data by setting to NULL
      sqlite> update archive set windSpeed=NULL where outTemp > 1000;
      sqlite> update archive set outTemp=NULL where outTemp > 1000;
    6. Delete the statistics database so that weewx can regenerate it without the anomalies
    7. start weewx
  2. Rehacer las tablas diarias:
pi@raspberrypi:/var/lib/weewx$ wee_database --drop-daily
Using configuration file /etc/weewx/weewx.conf
Using database binding 'wx_binding', which is bound to database 'archive_sqlite'
Proceeding will delete all your daily summaries from database 'weewx.sdb'
Are you sure you want to proceed (y/n)? y
Dropping daily summary tables from 'weewx.sdb' ... 
Dropped daily summary tables from database 'weewx.sdb'
pi@raspberrypi:/var/lib/weewx$ wee_database --backfill-daily
Using configuration file /etc/weewx/weewx.conf
Using database binding 'wx_binding', which is bound to database 'archive_sqlite'
Backfilling daily summaries in database 'weewx.sdb'
Backfilled 'weewx.sdb' with 151756 records over 554 days in 1814.17 seconds
pi@raspberrypi:/var/lib/weewx$ 


No hay comentarios:

Publicar un comentario