fixed windows related problems

This commit is contained in:
Your Name
2018-01-25 04:59:16 +01:00
committed by atlantispc_sheppy
parent 585a2ea40c
commit a4a259fefc
9 changed files with 204 additions and 80 deletions

View File

@@ -35,8 +35,9 @@ def selection_repl(path):
plot_main.plot(datapoints,path)
return None
main_repl(datapoints,path)
else:
tmp=input( "\n -> Type 'n' or 'new' <ENTER> to restart with another file\n -> Type 'r' or 'restart'<ENTER> to use the current file again\n (restart or selecting the same file WILL OVERRIDE the picture you just generated!)\n -> 'c'<ENTER> oder 'c <CONFIG_OPTION_NAME> <NEW_VALUE>' um Konfigurationsoptionen zu ändern\n -> Or press just <ENTER> to exit: ")
if CFG("always_restart"):
print("----------------------------------------")
tmp=input( " -> Type 'n' or 'new' <ENTER> to restart with another file\n -> Type 'r' or 'restart'<ENTER> to use the current file again\n -> Or press just <ENTER> to exit: ")
if tmp == None or tmp == "":
return None
elif tmp in ["r","restart"]:
@@ -44,9 +45,9 @@ def selection_repl(path):
elif tmp in ["n","new"]:
return futils.open_file()
elif tmp.startswith('c'):
raise NotImplementedError("On the fly configuration not yet implemented.")
config_options(ret)
else:
return path
sys.exit(0)
def main():
### PREVENT MULTICORE SUPPORT ###
@@ -55,7 +56,14 @@ def main():
### PROMT TO OPEN FILE ###
FILE_READY = False
path = None
while True:
path = selection_repl(futils.open_file())
if not FILE_READY:
path = futils.open_file()
path = selection_repl(path)
if path == None:
break
else:
FILE_READY = True

View File

@@ -5,7 +5,8 @@ import plot_main
import config_parse
from config_parse import CFG
from language import LAN
from datetime import datetime
from datetime import datetime,timedelta
from plot_timeutils import between_dates
l = LAN[CFG("language")]
timeformat = "%d.%m.%y %H:%M:%S (%A)"
@@ -20,7 +21,7 @@ def parse_date_from_user_input(s,end_of_day=False,datapoints=None):
## EMPTY ##
if s == None or s == "":
return None
return (None,True)
## TIME ##
if len(s.split(" ")) > 1:
@@ -66,29 +67,82 @@ def parse_date_from_user_input(s,end_of_day=False,datapoints=None):
month = int(date_a[1])
if len(date_a) > 2:
year = int(date_a[2])
if year < 1000:
year+=2000
# remember if an explizit date was give #
NO_YEAR=False
NO_MONTH=False
if year == 0:
NO_YEAR=True
if today.month > month:
year = today.year
else:
year = today.year-1
if month == 0:
NO_MONTH = True
if today.day > day and today.year == year:
month = today.month
else:
month = today.month-1
if month < 1:
month = 12-month
ret = datetime(year,month,day,hour,minute,second)
try:
times = datapoints[CFG("plot_temperatur_key")].times
if ( ret > max(times) or ret < min(times) ) and min(times).day < ret.day < max(times).day and min(times).month == max(times).month:
month = min(times.month)
except Exception as e:
print("Warning, magic date selection failed for an unknown reason")
ret = datetime(year,month,day,hour,minute,second)
return ret
tmp = list(datapoints.values())[0].times
status = True
if NO_MONTH:
ret,status = correct_month(ret,min(tmp),max(tmp))
if NO_YEAR and status:
ret,status = correct_year(ret,min(tmp),max(tmp))
return (ret,status)
def correct_year(date,data_start,data_end):
if not CFG("enable_automatic_date_correction"):
return (date,True)
elif date == None:
return (None,True)
else:
if between_dates(date,data_start,data_end):
return (date,True)
elif data_start.year != data_end.year:
print("Datensätze aus mehr als einem Jahr gefunden, Jahr muss daher angegeben werden.")
return (None,False)
else:
maxi = 12
count = 0
while count < maxi:
if between_dates(date.replace(year=date.year-count),data_start-timedelta(days=1),data_end+timedelta(days=1)):
return (date.replace(year=date.year-count),True)
count += 1
return (date,True)
def correct_month(date,data_start,data_end):
tmp_date = date.replace(year=data_end.year)
if not CFG("enable_automatic_date_correction"):
return (date,True)
elif date == None:
return (None,True)
else:
if between_dates(date,data_start,data_end):
return (date,True)
elif data_start.month != data_end.month:
print("Datensätze aus mehr als einem Monat gefunden, Monat muss daher angegeben werden.")
return (None,False)
else:
maxi = 12
count = maxi
while count >= 0:
if between_dates(date.replace(month=((date.month+count)%12)+1),data_start,data_end):
return (date.replace(month=date.month-count),True)
count -= 1
return (date,True)
def info_list(datapoints):
if len(datapoints.keys()) > 0:
@@ -123,9 +177,12 @@ def input_date_repl(datapoints,startdate=True):
else:
try:
if startdate:
date=parse_date_from_user_input(ret,datapoints=datapoints)
date,ok=parse_date_from_user_input(ret,datapoints=datapoints)
else:
date,ok=parse_date_from_user_input(ret,True,datapoints)
if not ok:
return (None,False)
else:
date=parse_date_from_user_input(ret,True,datapoints)
return (date,True)
except ValueError as e:
print(l["cannot_parse_date"] + "( was: {} )\n".format(ret))

View File

@@ -2,12 +2,5 @@
import frontend_new
import sys
if __name__ == "__main__":
try:
frontend_new.main()
sys.exit(0)
except KeyboardInterrupt as e:
sys.exit(1)
except Exception as e:
print(e)
input("Ein Fehler ist aufgetreten, <ENTER> um zu beenden, wenn dieser Fehler unerwartet war -> Mail!")
sys.exit(1)

View File

@@ -21,8 +21,21 @@ class Data:
self.times = []
self.plot = plot
## no idea on what kind of drugs I was when i wrote this function (it is somewhat ingenious though) ##
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")
while(i<len(self.times)):
if callback(self.times[i],date1,date2):
out_x += [ self.times[i] ]
out_y += [ self.data[i] ]
i += 1
return (out_x,out_y)
## no idea on what kind of drugs I was when i wrote this function (it is somewhat ingenious though) ##
def _get_timeframe(self, callback,date1=None,date2=None):
r=dict()
for t,c in zip(self.times,self.data):
t = callback(t,date1,date2)

14
plot.py Normal file
View File

@@ -0,0 +1,14 @@
#!/usr/bin/python3
import frontend_new
import sys
if __name__ == "__main__":
try:
frontend_new.main()
#input("Done! <ENTER> to exit")
sys.exit(0)
except KeyboardInterrupt as e:
sys.exit(1)
except Exception as e:
print(e)
input("Ein Fehler ist aufgetreten, <ENTER> um zu beenden, wenn dieser Fehler unerwartet war -> Mail!")
sys.exit(1)

View File

@@ -82,12 +82,12 @@ def general_background_setup(tup,ymin,ymax,x):
## AXIS LABELS
ylabel_box = dict(boxstyle="square",facecolor='grey', alpha=0.4, edgecolor='black',lw=0.5)
xlabel_box = ylabel_box
label_size = 6
label_size = CFG("label_font_size")
spacing=0.1
tup[AXIS].set_ylabel(CFG("y_label"),rotation='horizontal',size=label_size,bbox=ylabel_box)
tup[AXIS].yaxis.set_label_coords(0.055,0.95)
tup[AXIS].yaxis.set_label_coords(0.045,0.970)
tup[AXIS].set_xlabel(CFG("x_label"),size=label_size,bbox=xlabel_box)
tup[AXIS].xaxis.set_label_coords(0.925,0.05)
tup[AXIS].xaxis.set_label_coords(0.945,0.03)
## GENERAL LEGEND ##
legend_handle = tup[AXIS].legend(
@@ -98,7 +98,7 @@ def general_background_setup(tup,ymin,ymax,x):
prop={'family': 'monospace','size':CFG("legend_font_size")}
)
legend_handle.get_frame().set_linewidth(0.2)
tup[AXIS].set_aspect(get_aspect_ratio(unix_x,ymin,ymax,major_xticks))
#tup[AXIS].set_aspect(get_aspect_ratio(unix_x,ymin,ymax,major_xticks))
def get_aspect_ratio(ux,ymin,ymax,xticks):
@@ -111,8 +111,8 @@ def get_aspect_ratio(ux,ymin,ymax,xticks):
magic_value = 3.25
return ratio * ( max(ux) - min(ux) ) / float(ymax - ymin + magic_value)
def a4_aspect():
return 1/math.sqrt(2)
def a4_aspect(x):
return ( 1/math.sqrt(2) ) * x
def grid(tup,xticks,ymin,ymax):
lw = CFG("grid_line_width")

View File

@@ -36,6 +36,9 @@ def __plot(tup,datapoints,path,date1=None,date2=None):
tup[FIGURE],tup[AXIS] = plt.subplots(1, 1)
for g in datapoints.values():
#### Check if we are supposed to plot something ####
if not g.plot:
continue
#### GET AND CHECK TIMEFRAMES ####
x,y, = g.get_timeframe(tup[CALLBACK],date1,date2)
if len(x) <= 0 or len(y) <= 0:
@@ -60,9 +63,30 @@ def __plot(tup,datapoints,path,date1=None,date2=None):
## using unix_x relys on unix_x to be the same for all plots ##
if path == None:
path = open_file()
## TODO function for picpathn for picpath
pic_path = path + ".png"
tup[FIGURE].savefig(pic_path,dpi=CFG("outfile_resolution_in_dpi"), bbox_inches='tight',transparent=CFG("transparent_background"))
pic_path = output_path(path,date1,date2)
## set resoltuion ##
DPI = CFG("outfile_resolution_in_dpi")
fig_x_height = CFG("fig_x_height_inches")/float(1000)
fig_y_height = CFG("fig_y_height_inches")/float(1000)
tup[FIGURE].set_size_inches(fig_x_height,fig_y_height)
## save the figure ##
tup[FIGURE].savefig(pic_path,dpi=DPI,pad_inches=0.1,bbox_inches='tight',transparent=CFG("transparent_background"))
### do operations on the finished png ###
plot_imageutils.check_and_rotate(pic_path)
def output_path(path,date1,date2):
if date1 != None and date2 == None:
pic_path = path + "-nach-%s"%date1.strftime("%d.%m.%y") + ".png"
elif date1 == None and date2 != None:
pic_path = path + "-vor-%s"%date2.strftime("%d.%m.%y") + ".png"
elif date1 == None and date2 == None:
pic_path = path + "-alles" + ".png"
else:
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))
return pic_path

View File

@@ -3,7 +3,10 @@ from config_parse import CFG
from datetime import datetime, timedelta
def between_dates(t,date1,date2):
return t if (date1 == None or date1 < t) and (date2 == None or date2 > t) else None
if (date1 == None or date1 <= t) and (date2 == None or date2 > t):
return True
else:
return False
def time_from_dbf(l,timeformat):
timeformat=None #dont need that here

View File

@@ -2,20 +2,12 @@
# Die Zeile '[plot] darf NICHT gelöscht oder verändert werden!
[plot]
plot_humidity = True
plot_temperatur = True
plot_dewcels = False
show_avg = True
show_min = True
show_max = True
raster = True
draw_thresholds = True
interactive = True
language = DE
default_source_path = /home/ik15ydit/reps/random-code/ths/
default_target_dir = /home/ik15ydit/reps/random-code/ths/
output_filename = test.png
plot_humidity = ja
plot_temperatur = ja
plot_dewcels = nein
show_avg = ja
show_min = ja
show_max = ja
humidity_critical = 55
humidity_warning = 50
@@ -29,17 +21,33 @@ dewcels_plot_name = Taupunkt
y_label = Temp./r.L.
x_label = Datum/Uhrzeit
font = calibri
global_text_size = 7
xticks_font_size = 5
yticks_font_size = 5
timeformat_x_axis = '$d.$m, $H:$M'
acceptable_x_intervals = 1m,5m,10m,30m,1h,2h,4h,6h
image_rotation = 90
transparent_background = no
name_of_plot = None
aspect_ratio = A4
############# eye_candy #############
image_rotation = 90
xticks_label_degree = 45
# in milli-inches
#fig_x_height_inches = 23380
#fig_y_height_inches = 16532
fig_x_height_inches = 12100
fig_y_height_inches = 8075
timeformat_x_axis = '$d.$m, $H:$M'
global_text_size = 10
xticks_font_size = 10
yticks_font_size = 10
legend_font_size = 8
label_font_size = 8
always_restart = yes
legend_location = upper right
transparent_background = no
acceptable_x_intervals = 1m,5m,10m,30m,1h,2h,4h,6h
name_of_plot = None
enable_automatic_date_correction = yes
###### PLOT Styles (Farben, Scala, Linestyles) ######
empty_space_above_plot = 10
yaxis_minnimum_hight = 95
yaxis_start_value = 0
@@ -67,41 +75,45 @@ plot_line_width = 0.5
plot_line_style = solid
hline_draw_lines = True
# linestyles: https://matplotlib.org/devdocs/gallery/lines_bars_and_markers/line_styles_reference.html
hline_line_style = --
hline_line_width = 0.5
grid_line_style = :
grid_line_width = 0.15
grid_line_color = black
############# technical #############
enable_multicore_support = False
raster_alligment_auto = True
raster_hline_prefered_interval = 5
raster_minimum_hlines = 10
raster = True
draw_thresholds = True
y_tick_interval = 5
outfile_resolution_in_dpi = 200
legend_location = upper right
terminate_on_missing_input_file = True
terminate_on_fail = True
add_hours_to_input = 1
raster_hline_prefered_interval = 5
prefered_total_xticks = 24
use_gui_backend = Agg
add_x_labels_at_end = 1
xticks_label_degree = 45
major_line_width = 0.5
legend_font_size = 5
minor_xticks_per_major = 5
terminate_on_warning = no
raster_minimum_hlines = 10
add_hours_to_input = 1
add_x_labels_at_end = 1
###### DEBUGGING ######
no_ask_date_input = no
input_filename = test.dbf
input_filename = test.xls
use_input_filename = no
debug_no_interactive = no
terminate_on_warning = no
terminate_on_missing_input_file = True
terminate_on_fail = True
default_source_path = test_data/
default_target_dir = UseSourceDir
###### THINGS THERE IS REALLY NO REASON TO CHANGE ######
plot_temperatur_key = TEMP
plot_humidity_key = HUMIDITY
plot_dewcels_key = DEWCELS
plot_dewcels_key = TAU_P
always_allow_days_as_xticks = yes
language = DE
aspect_ratio = A4
use_gui_backend = Agg
enable_multicore_support = False
raster_alligment_auto = True
outfile_resolution_in_dpi = 250