#!/usr/bin/python3 from config_parse import CFG from datetime import datetime, timedelta import requests import os import localization.de as de from dbfread import DBF import timeutils import codecs 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, qtTextBrowser=None): 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 self.qtTextBrowser = qtTextBrowser def getFirstTime(self): '''Get time of first timestamp''' return min(self.times) def getLastTime(self): '''Get time of last timestamp''' return max(self.times) def get_timeframe(self, callback, date1=None, date2=None): out_x = [] out_y = [] i = 0 if(len(self.times) != len(self.data)): self.qtTextBrowser.append(de.special_err_1) raise ValueError(de.special_err_1) if(len(self.times) <= 2): self.qtTextBrowser.append(de.warn_no_data.format(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)], timeutils.time_from_csv, timeformat="%d-%m-%Y%H:%M:%S") qtTextBrowser.append(de.info_ig_lines.format(count)) def csvread_txt(path,datapoints,pt,ph,pd,qtTextBrowser): count = 0; with open(path) as f: 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"] = "{}-{}-{}_{}:{}".format(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)], timeutils.time_from_csv, timeformat="%d-%m-%Y_%H:%M") except (UnicodeError, IndexError): count = csvread_txt_fallback(path,datapoints,pt,ph,pd) qtTextBrowser.append(de.info_ig_lines.format(count)) 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='replace') 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)], timeutils.time_from_csv, timeformat="%d-%m-%Y_%H:%M") return count