X-Git-Url: https://git.rvb.name/weathermon.git/blobdiff_plain/b7dcd298e5f0565be8e5ca3d9477cb6de97ae3ac..7edb3771717d15f7c36d8459fa12b3d6f76d7d9a:/filter_meteo.py?ds=sidebyside diff --git a/filter_meteo.py b/filter_meteo.py old mode 100644 new mode 100755 index b20dc41..fc497db --- a/filter_meteo.py +++ b/filter_meteo.py @@ -35,6 +35,10 @@ def Yesterday(): dt = Today() return dt - datetime.timedelta(days=1) +def Prehistoric(): + dt = datetime.date(2000,01,01) + return dt + def GetData(sid,pid,fromDate=Yesterday(),toDate=Today()): if database: c = database.cursor() @@ -48,7 +52,6 @@ def FixRecord(id,value): if database: c = database.cursor() command="UPDATE sensor_values SET value={} WHERE id='{}'".format(value,id) - print command c.execute(command) else: print "No connection to DB" @@ -56,10 +59,16 @@ def FixRecord(id,value): def ProcessTable(sid,pid): - if not current: + if process_all: + data=GetData(sid,pid,Prehistoric(),Today()) + elif not current: data=GetData(sid,pid) else: data=GetData(sid,pid,Today(),Tomorrow()) + + if not data: + return + sID=[] sTime=[] sValue=[] @@ -75,8 +84,6 @@ def ProcessTable(sid,pid): avg=np.mean(sValueDiff) - print "Average="+str(avg) - for i in range(0,len(sTime)-1): if sValueDiff[i]>avg*filterThreshold: print "fixing %s : %5.2f %5.2f %5.2f" % (sTime[i],sValue[i],sValueFilt[i],sValueDiff[i]) @@ -89,6 +96,10 @@ if len(sys.argv)==2 and sys.argv[1]=='current': else: current=False +if len(sys.argv)==2 and sys.argv[1]=='all': + process_all=True +else: + process_all=False try: