#!/usr/bin/python3 from config_parse import CFG from datetime import datetime, timedelta from dbfread import DBF import plot_timeutils line_colors = ['b', 'r', 'g', 'c', 'm', 'y'] tname = CFG("temperatur_plot_name") hname = CFG("humidity_plot_name") dname = CFG("dewcels_plot_name") color_id = 0 class Data: def __init__(self,name,plot=False): global color_id,line_colors self.name = name self.color=line_colors[color_id%len(line_colors)] color_id += 1 self.data = [] self.times = [] self.plot = plot def get_timeframe(self, callback,date1=None,date2=None): out_x = [] out_y = [] i = 0 if(len(self.times) != len(self.data)): raise RuntimeError("len(timestamps) != len(data), cannot continue, this should never happen") if(len(self.times) <= 2): print("WARNING: No Data for %s!"%self.name) return (None,None) ############ AVERAGE OUT DATA ############# if(CFG("combine_data_points") >= (self.times[1] - self.times[0]).total_seconds()): x_dp = 5 m_t = 3 while(i+x_dp>") or l.startswith("--") or l.startswith("NO."): count += 1 continue else: row_arg = list(map(lambda s:s.replace(" ","").replace(",","."),l.split("\t"))) row = {"temp":None,"hum":None,"taupunkt":None,"datetime":None} row["datetime"] = row_arg[1]+row_arg[2] row["temp"] = float(row_arg[3]) row["hum"] = float(row_arg[4]) row["taupunkt"] = float(row_arg[5]) parse_line(datapoints,row,'datetime',[ ('temp',pt) , ('hum',ph) , ('taupunkt',pd) ],\ plot_timeutils.time_from_csv,timeformat="%d-%m-%Y%H:%M:%S") print("Info: Ignored %d lines at beginning of file"%count) import codecs def csvread_txt(path,datapoints,pt,ph,pd): count = 0; f = open(path) try: for l in f: if any(s in l for s in ["Logger","Datenquelle","Sensortyp","Einheit","Daten"]): count += 1 continue else: row_arg = list(map(lambda s:s.replace(" ","").replace(",","."),l.split("\t"))) row = {"temp":None,"hum":None,"taupunkt":None,"datetime":None} row["datetime"] = "%s-%s-%s_%s:%s"%(row_arg[0],row_arg[1],row_arg[2],row_arg[3],row_arg[4]) row["temp"] = float(row_arg[6]) row["hum"] = float(row_arg[7]) row["taupunkt"] = 0.0 parse_line(datapoints,row,'datetime',[ ('temp',pt) , ('hum',ph) , ('taupunkt',pd) ],\ plot_timeutils.time_from_csv,timeformat="%d-%m-%Y_%H:%M") except (UnicodeError, IndexError): count = csvread_txt_fallback(path,datapoints,pt,ph,pd) print("Info: Ignored %d lines at beginning of the file"%count) f.close() def csvread_txt_fallback(path,datapoints,pt,ph,pd): '''fallback for different format and encoding of txt''' count = 0 with codecs.open(path, "r",encoding="ISO8859_2", errors='repalce') as f: for l in f: if any(s in l for s in ["Logger","Datenquelle","Sensortyp","Einheit","Daten"]): count += 1 continue else: date,time,temp,hum = l.replace(" ","").replace(".","-").replace(",",".").split("\t") row = {"temp":None,"hum":None,"taupunkt":None,"datetime":None} row["datetime"] = "{}_{}".format(date,time[:5]) row["temp"] = float(temp) row["hum"] = float(hum) row["taupunkt"] = 0.0 parse_line(datapoints,row,'datetime',[ ('temp',pt) , ('hum',ph) , ('taupunkt',pd) ],\ plot_timeutils.time_from_csv,timeformat="%d-%m-%Y_%H:%M") return count def check_read_in(datapoints): good = False for v in datapoints.values(): if len(v.times) != len(v.data): print("more timestamps than data (or visa versa), this indicates that the file is corrupted, cannot continue") good = False break if len(v.times) > 1: good = True if not good: input("reading input file failed for an unknown reason, to exit") import sys sys.exit(1)