Hi My rain sometimes gets wrong readings. Sometimes by spiders that use the rain tipper as a see-saw. I use a mysql database and have a script to do it:
#!/bin/bash clear if [ "$(id -u)" != "0" ]; then echo "This script must be run as root" 1>&2 exit 1 fi #change this if your reporting interval is different as this will be used to calculate #rainrate. (60 minutes / INTERVAL) * RAIN - which is entered later on INTERVAL="5" #The stuff below is for colours you have to use echo -e RESTORE='\033[0m' RED='\033[00;31m' GREEN='\033[00;32m' YELLOW='\033[00;33m' BLUE='\033[00;34m' PURPLE='\033[00;35m' CYAN='\033[00;36m' LIGHTGRAY='\033[00;37m' LRED='\033[01;31m' LGREEN='\033[01;32m' LYELLOW='\033[01;33m' LBLUE='\033[01;34m' LPURPLE='\033[01;35m' LCYAN='\033[01;36m' WHITE='\033[01;37m' DBUSER=weewx DBPASS=weewx DBNAME=weewx MYSQLUSER=root MYSQLPASS=yourpassword echo This fixes the database if there are any wrong entries echo -e #mysql -u$DBUSER -p$DBPASS --database=$DBNAME --execute="SHOW COLUMNS FROM archive FROM $DBNAME;" echo If you just press enter for the next two prompts you will get all the rainfall for the day echo -e echo -e Input the date in this format ${LRED} 'YYYY-MM-DD' ${RESTORE} Press enter for the current date. read INDATE #if the date is not entered then default to the current year if [[ -z "$INDATE" ]] then INDATE=`date +%F` fi echo -e The date selected is ${LGREEN} $INDATE ${RESTORE} echo -e echo -e Input the time you want to find in this format ${LRED} 'HH:MM:SS' ${RESTORE}Press enter to select midnight. read INTIME #if the date is not entered then default to the current year if [[ -z "$INTIME" ]] then INTIME="00:00:00" fi echo -e The time selected is ${LGREEN} $INTIME ${RESTORE} echo -e echo -e Input the rain amount you want to change in this format ${LRED} 'MM.M' ${RESTORE} Press enter to select zero. read RAIN #if the rain is not entered then default to zero if [[ -z "$RAIN" ]] then RAIN="0" fi echo -e echo -e The rain amount is ${LGREEN} $RAIN ${RESTORE} and the reporting interval is ${LGREEN} $INTERVAL ${RESTORE} minutes. echo -e RAINRATE=$((60 / INTERVAL)) RAINRATE=$(echo "$RAINRATE * $RAIN" | bc) #if the rainrate is not entered then default to .001 so my logic to check for zero still works #and I can redo the rain if needed. Otherwise I don't see any records because they are zero if [[ "$RAINRATE" = "0" ]] then RAINRATE="0.001" fi FINDDATE=`date -d "$INDATE $INTIME" +%s` echo -e The epoch date you want to find in the list below is ${LGREEN} $FINDDATE ${RESTORE} echo -e #need to find the next day epoch time in case this program is run for a date in the past otherwise it #will show all the rain entries on the screen and not just one days worth NEXTDAY=$(($FINDDATE+86400)) echo -e Next day epoch date is ${LGREEN} $NEXTDAY ${RESTORE} MIDNIGHTTIME=`date -d "$INDATE 00:00:00" +%s` echo -e Midnight time is: ${LGREEN} $MIDNIGHTTIME ${RESTORE} echo -e #show the rain for the date selected echo -e ${LGREEN} mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "select dateTime, rain, rainRate from archive where (rainRate > 0 and dateTime <= $NEXTDAY and dateTime >= $MIDNIGHTTIME);" echo -e ${RESTORE} echo -e Rain value is ${LGREEN} $RAIN ${RESTORE} and rain rate value is ${LGREEN} $RAINRATE ${RESTORE} echo -e If there are no records above then that means there are no rain rates for ${LRED} $INDATE $INTIME ${RESTORE} echo -e echo Select the first and last record you want updated echo Usually pick the first record with rain and then the records below it that have rain rates echo but do not have rain records. Hope that makes sense. echo -e read -p "Select the FIRST dateTime you want to update " FIRSTREC echo -e The FISRT date you chose is ${LGREEN} `date -d@$FIRSTREC` ${RESTORE} echo -e read -p "Select the LAST dateTime you want to update " LASTREC echo -e The LAST date you chose is ${LGREEN} `date -d@$LASTREC` ${RESTORE} echo -e echo -e ${LRED}This is the Rain total and will be deleted mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "select * from archive_day_rain WHERE (maxtime >= $FIRSTREC and maxtime <= $LASTREC);" echo -e echo this is the rain rate and will be deleted mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "select * from archive_day_rainRate WHERE (dateTime = $MIDNIGHTTIME);" echo -e ${RESTORE} echo -e The rain amount selected is ${LGREEN} $RAIN ${RESTORE} echo -e The Rain rate will be calculated as: ${LGREEN} $RAINRATE ${RESTORE} echo -e echo Press y to update the database. while true; do echo The changes will take effect if you press y. Press CTRL-C to cancel updates. read -p "Do you wish to update the database?" yn case $yn in [Yy]* ) break;; [Nn]* ) exit;; * ) echo "Please answer yes or no.";; esac done echo Stop weewx /etc/init.d/weewx stop echo Back up database to /tmp if ! /usr/bin/mysqldump --user=$MYSQLUSER --password=$MYSQLPASS $DBNAME > /tmp/weewx-$(date +%F-%T).sql ; then clear echo Backup failed. Do not contiune as data will be changed after this point echo Starting weewx /etc/init.d/weewx start exit 1 fi echo then set the data to 0 #have to zero out all the selected records and then update ONLY the first selected record or the #rain records will be duplicated. SO LEAVE THE 2 LINES BELOW AS IS! mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "UPDATE archive SET rain=0 WHERE (dateTime >= $FIRSTREC and dateTime <= $LASTREC);" mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "UPDATE archive SET rainRate=0.1 WHERE (dateTime >= $FIRSTREC and dateTime <= $LASTREC);" mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "UPDATE archive SET rain=$RAIN WHERE (dateTime = $FIRSTREC);" mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "UPDATE archive SET rainRate=$RAINRATE WHERE (dateTime = $FIRSTREC);" #mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "UPDATE archive SET rainRate=$RAINRATE WHERE (dateTime >= $FIRSTREC and dateTime <= $LASTREC) ;" mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "DELETE from archive_day_rain where dateTime=$MIDNIGHTTIME;" mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "DELETE from archive_day_rainRate where dateTime=$MIDNIGHTTIME;" ##echo If the yearly rainrate is wrong you can use the select statement below to delete the wrong entry ##echo "You can find the date and time on the yearly records." ##echo "'select * from archive_day_rainRate where maxtime = 1502098500;" ##echo "Then delete the entry" mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "DELETE from archive_day_rainRate where maxtime=$MIDNIGHTTIME;" echo -e ${LGREEN} echo -e Number of records to process: mysql -u$DBUSER -p$DBPASS << EOF use $DBNAME; select count(*) from archive; EOF echo -e ${RESTORE} ##echo then once that has been done you have to drop the daily stats usually only if data is corrupted # wee_database /etc/weewx/weewx.conf --drop-daily echo Rebuild the dailiy stats for the date $INDATE wee_database /etc/weewx/weewx.conf --rebuild-daily --from=$INDATE --to=$INDATE #wee_database /etc/weewx/weewx.conf --rebuild-daily --date=$INDATE # wee_database /etc/weewx/weewx.conf --rebuild-daily ##echo if you want to delete data from the database you can use the delete from archive where dateTime < xxxxxxxxx; ##echo you then delete any NOAA files from /var/www/html/weather/NOAA ##echo then run the -drop-daily and rebuild-daily commands on hope it all works. ##echo start weewx again ##echo thats about it echo Start weewx /etc/init.d/weewx start echo regenerate the web pages wee_reports I don't know if that would work for you or not but it works for me. On Saturday, 30 March 2019 18:22:41 UTC+11, Johannes Ebner wrote: > > Hi, > > Somehow I have strange values for Rain and RainRaite on the 28th of March > around 10am CET. > > You can see it on wetter.familie-ebner.at > > How can I show this values in the DB and then select the wrong one for > deleting? > > Br, > Johannes > -- 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.