diff --git a/frontend_utils.py b/frontend_utils.py index 75e5398..50905c3 100644 --- a/frontend_utils.py +++ b/frontend_utils.py @@ -246,7 +246,7 @@ def open_file(): return f path=None - path=tkinter.filedialog.askopenfilename(filetypes=(("DBF/XLS Files",("*.DBF","*.dbf","*.xls","*.XLS")),("All Files","*.*"))) + path=tkinter.filedialog.askopenfilename(filetypes=(("DBF/XLS Files",("*.DBF","*.dbf","*.xls","*.XLS","*.txt","*.TXT")),("All Files","*.*"))) if path == None or path=="": print("Error: No file selected!") return None diff --git a/input_backend.py b/input_backend.py index 434a05d..f50a2ec 100644 --- a/input_backend.py +++ b/input_backend.py @@ -103,6 +103,8 @@ def read_in_file(path,backend=None): dbfread(path,datapoints,pt,ph,pd) elif path.endswith(".xls") or path.endswith(".XLS"): csvread(path,datapoints,pt,ph,pd) + elif path.endswith(".txt"): + csvread_txt(path,datapoints,pt,ph,pd) else: raise NotImplementedError("Cannot determine filetype, cannot continue. Exit.") @@ -131,6 +133,25 @@ def csvread(path,datapoints,pt,ph,pd): plot_timeutils.time_from_csv,timeformat="%d-%m-%Y%H:%M:%S") print("Info: Ignored %d lines at beginning of file"%count) +def csvread_txt(path,datapoints,pt,ph,pd): + count = 0; + with open(path) as f: + 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]) + print(row["datetime"]) + 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") + print("Info: Ignored %d lines at beginning of file"%count) + def check_read_in(datapoints): good = False for v in datapoints.values():