mirror of
https://github.com/FAUSheppy/ths-datenlogger
synced 2025-12-06 04:11:34 +01:00
replace print outputs with outputs to qt
This commit is contained in:
@@ -2,10 +2,12 @@
|
|||||||
from config_parse import CFG
|
from config_parse import CFG
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import math
|
import math
|
||||||
def check_and_rotate(path):
|
import localization.de as localization
|
||||||
|
|
||||||
|
def check_and_rotate(path, qtTextBrowser):
|
||||||
img = Image.open(path)
|
img = Image.open(path)
|
||||||
div=abs(float(img.size[1])/float(img.size[0])-a4_aspect())/a4_aspect()*100
|
div=abs(float(img.size[1])/float(img.size[0])-a4_aspect())/a4_aspect()*100
|
||||||
print("Seitenverhältnisabweichung zu A4: %.2f"%div+r'%')
|
qtTextBrowser.append(localization.info_divergence.format(div))
|
||||||
img.rotate(CFG("image_rotation"),expand=True).save(path.strip(".png")+"_rotated.png")
|
img.rotate(CFG("image_rotation"),expand=True).save(path.strip(".png")+"_rotated.png")
|
||||||
|
|
||||||
def a4_aspect():
|
def a4_aspect():
|
||||||
|
|||||||
@@ -29,3 +29,11 @@ special_err_1 = "Zeitstempelanzahl stimmt nicht mit Datensatzzahl überein
|
|||||||
warn_no_data = "Warnung, keine Daten für {}"
|
warn_no_data = "Warnung, keine Daten für {}"
|
||||||
pg_request = "Downloading: {}"
|
pg_request = "Downloading: {}"
|
||||||
info_ig_lines = "INFO: Ignoriere {} Zeilen ohne Daten am Anfang der Datei"
|
info_ig_lines = "INFO: Ignoriere {} Zeilen ohne Daten am Anfang der Datei"
|
||||||
|
|
||||||
|
# plot.py
|
||||||
|
warn_empty_series = "WARN: Leere Datenserie (vielleicht falsches Start-/Enddatum?)"
|
||||||
|
err_empty_series = "ERR: Alle gewählten Datenserie sind leer."
|
||||||
|
info_output_path = "INFO: Output wird gespeichert nach: {}"
|
||||||
|
|
||||||
|
# imageutils.py
|
||||||
|
info_divergence = "INFO: Seitenverhältnisabweichung zu A4: {:.2f}%"
|
||||||
|
|||||||
@@ -17,13 +17,15 @@ import plot_graphutils
|
|||||||
import imageutils
|
import imageutils
|
||||||
import timeutils
|
import timeutils
|
||||||
|
|
||||||
|
import localization.de as localization
|
||||||
|
|
||||||
def plot(datapoints, path=None, date1=None, date2=None, forcePath=False):
|
|
||||||
|
def plot(datapoints, path=None, date1=None, date2=None, forcePath=False, qtTextBrowser=None):
|
||||||
plotname = "" if CFG("name_of_plot") == "None" else CFG("name_of_plot")
|
plotname = "" if CFG("name_of_plot") == "None" else CFG("name_of_plot")
|
||||||
tup = [None,None,timeutils.between_dates,plotname]
|
tup = [None,None,timeutils.between_dates,plotname]
|
||||||
return __plot(tup, datapoints, path, date1, date2, forcePath)
|
return __plot(tup, datapoints, path, date1, date2, forcePath, qtTextBrowser)
|
||||||
|
|
||||||
def __plot(tup, datapoints, path, date1=None, date2=None, forcePath=False):
|
def __plot(tup, datapoints, path, date1=None, date2=None, forcePath=False, qtTextBrowser=None):
|
||||||
NO_SERIES = True
|
NO_SERIES = True
|
||||||
x,y,ymin,ymax,unix_x,major_xticks = ( [] , [], -1 , -1 , [], [] )
|
x,y,ymin,ymax,unix_x,major_xticks = ( [] , [], -1 , -1 , [], [] )
|
||||||
lw = CFG("plot_line_width")
|
lw = CFG("plot_line_width")
|
||||||
@@ -47,7 +49,7 @@ def __plot(tup, datapoints, path, date1=None, date2=None, forcePath=False):
|
|||||||
# plot #
|
# plot #
|
||||||
for x, y, g in tupelsToIterate:
|
for x, y, g in tupelsToIterate:
|
||||||
if not x or not y or len(x) <= 0 or len(y) <= 0:
|
if not x or not y or len(x) <= 0 or len(y) <= 0:
|
||||||
print("Warning: Empty series of data '%s' (wrong start/end time?)"%g.name)
|
qtTextBrowser.append(localization.warn_empty_series)
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
NO_SERIES = False
|
NO_SERIES = False
|
||||||
@@ -61,8 +63,8 @@ def __plot(tup, datapoints, path, date1=None, date2=None, forcePath=False):
|
|||||||
lagacy_y_save = y
|
lagacy_y_save = y
|
||||||
|
|
||||||
if NO_SERIES:
|
if NO_SERIES:
|
||||||
print("Error: no data, nothing to plot. cannot continue. exit.")
|
qtTextBrowser.append(localization.err_empty_series)
|
||||||
sys.exit(1)
|
raise ValueError(localization.err_empty_series)
|
||||||
|
|
||||||
## GRID ##
|
## GRID ##
|
||||||
plot_graphutils.general_background_setup(tup, ymin, ymax, legacy_x_save)
|
plot_graphutils.general_background_setup(tup, ymin, ymax, legacy_x_save)
|
||||||
@@ -72,7 +74,7 @@ def __plot(tup, datapoints, path, date1=None, date2=None, forcePath=False):
|
|||||||
path = open_file()
|
path = open_file()
|
||||||
|
|
||||||
if not forcePath:
|
if not forcePath:
|
||||||
pic_path = output_path(path, date1, date2)
|
pic_path = output_path(path, date1, date2, qtTextBrowser)
|
||||||
else:
|
else:
|
||||||
pic_path = path
|
pic_path = path
|
||||||
|
|
||||||
@@ -87,11 +89,11 @@ def __plot(tup, datapoints, path, date1=None, date2=None, forcePath=False):
|
|||||||
tup[FIGURE].savefig(pic_path,dpi=DPI,pad_inches=0.1,bbox_inches='tight',transparent=CFG("transparent_background"))
|
tup[FIGURE].savefig(pic_path,dpi=DPI,pad_inches=0.1,bbox_inches='tight',transparent=CFG("transparent_background"))
|
||||||
|
|
||||||
### do operations on the finished png ###
|
### do operations on the finished png ###
|
||||||
imageutils.check_and_rotate(pic_path)
|
imageutils.check_and_rotate(pic_path, qtTextBrowser)
|
||||||
|
|
||||||
return pic_path
|
return pic_path
|
||||||
|
|
||||||
def output_path(path,date1,date2):
|
def output_path(path, date1, date2, qtTextBrowser):
|
||||||
if date1 != None and date2 == None:
|
if date1 != None and date2 == None:
|
||||||
pic_path = path + "-nach-%s"%date1.strftime("%d.%m.%y") + ".png"
|
pic_path = path + "-nach-%s"%date1.strftime("%d.%m.%y") + ".png"
|
||||||
elif date1 == None and date2 != None:
|
elif date1 == None and date2 != None:
|
||||||
@@ -100,5 +102,5 @@ def output_path(path,date1,date2):
|
|||||||
pic_path = path + "-alles" + ".png"
|
pic_path = path + "-alles" + ".png"
|
||||||
else:
|
else:
|
||||||
pic_path = path + "-%s_to_%s"%(date1.strftime("%d.%m.%y"),date2.strftime("%d.%m.%y")) + ".png"
|
pic_path = path + "-%s_to_%s"%(date1.strftime("%d.%m.%y"),date2.strftime("%d.%m.%y")) + ".png"
|
||||||
print("Output wird gespeichert nach: %s"%str(pic_path))
|
qtTextBrowser.append(localization.info_output_path.format(pic_path))
|
||||||
return pic_path
|
return pic_path
|
||||||
|
|||||||
Reference in New Issue
Block a user