mirror of
https://github.com/FAUSheppy/ths-datenlogger
synced 2025-12-09 05:08:32 +01:00
added history feature
This commit is contained in:
committed by
atlantispc_sheppy
parent
77bc8f6ef5
commit
b696de9f9b
@@ -17,9 +17,13 @@ def main_repl(datapoints,path,date1=None,date2=None,done1=False,done2=False):
|
|||||||
### READ IN DATES ###
|
### READ IN DATES ###
|
||||||
futils.info_list(datapoints)
|
futils.info_list(datapoints)
|
||||||
while not done1:
|
while not done1:
|
||||||
date1,done1 = futils.input_date_repl(datapoints,startdate=True)
|
date1,done1,raw1 = futils.input_date_repl(datapoints,startdate=True)
|
||||||
while not done2:
|
while not done2:
|
||||||
date2,done2 = futils.input_date_repl(datapoints,startdate=False)
|
date2,done2,raw2 = futils.input_date_repl(datapoints,startdate=False)
|
||||||
|
|
||||||
|
# save history here
|
||||||
|
futils.save_history(raw1)
|
||||||
|
futils.save_history(raw2)
|
||||||
|
|
||||||
### CHECK DATES ###
|
### CHECK DATES ###
|
||||||
done1,done2 = futils.check_dates(path,date1,date2)
|
done1,done2 = futils.check_dates(path,date1,date2)
|
||||||
|
|||||||
@@ -141,7 +141,72 @@ def correct_month(date,data_start,data_end):
|
|||||||
|
|
||||||
return (date,True)
|
return (date,True)
|
||||||
|
|
||||||
|
#TODO cfg histfile
|
||||||
|
#TODO cfg histlength
|
||||||
|
#TODO cfg histshow
|
||||||
|
#TODO cfg dontsaveonhistcall
|
||||||
|
history=None
|
||||||
|
def load_history(histfile="history.log"):
|
||||||
|
tmp = []
|
||||||
|
histlength = CFG("history_file_length")
|
||||||
|
try:
|
||||||
|
with open(histfile,"r") as f:
|
||||||
|
for l in f:
|
||||||
|
tmp_line = l.strip("\n")
|
||||||
|
if not tmp_line in tmp:
|
||||||
|
tmp += [tmp_line]
|
||||||
|
if len(tmp) > histlength:
|
||||||
|
with open(histfile,"w") as f:
|
||||||
|
for l in tmp[(len(tmp)-histlength-1):]:
|
||||||
|
f.write("{}\n".format(l.strip("\n")))
|
||||||
|
tmp = tmp[(len(tmp)-histlength-1):]
|
||||||
|
except IOError:
|
||||||
|
print(">> Warnung: Eingabehistorie Datei nicht gefunden <<")
|
||||||
|
return tmp
|
||||||
|
|
||||||
|
def save_history(string,histfile="history.log"):
|
||||||
|
global history
|
||||||
|
if not string:
|
||||||
|
return
|
||||||
|
# remove previous occourence if exists
|
||||||
|
if string in history:
|
||||||
|
history.remove(string)
|
||||||
|
# add
|
||||||
|
string = string.strip("\n")
|
||||||
|
history += [string]
|
||||||
|
# check max file length
|
||||||
|
with open(histfile,"a") as f:
|
||||||
|
f.write("{}\n".format(string.strip("\n")))
|
||||||
|
|
||||||
|
def load_from_history(index):
|
||||||
|
global history
|
||||||
|
index = int(index)
|
||||||
|
return history[-index]
|
||||||
|
|
||||||
|
def recently_used():
|
||||||
|
global history
|
||||||
|
if not history:
|
||||||
|
history = load_history()
|
||||||
|
ret = ""
|
||||||
|
if len(history) == 0:
|
||||||
|
return " Historie leider nicht verfügbar."
|
||||||
|
count = 1
|
||||||
|
count_max = CFG("history_show")
|
||||||
|
count_max = len(history) if len(history) < count_max else count_max
|
||||||
|
double_col = CFG("history_double_col")
|
||||||
|
col = 0
|
||||||
|
hist_reversed = history[-count_max:].copy()
|
||||||
|
hist_reversed.reverse()
|
||||||
|
print(hist_reversed)
|
||||||
|
for e in hist_reversed:
|
||||||
|
if col == 0 and double_col:
|
||||||
|
ret += " [{}] {}\t".format(count,e)
|
||||||
|
col = 1
|
||||||
|
else:
|
||||||
|
ret += " [{}] {}\n".format(count,e)
|
||||||
|
col = 0
|
||||||
|
count += 1
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def info_list(datapoints):
|
def info_list(datapoints):
|
||||||
@@ -149,12 +214,16 @@ def info_list(datapoints):
|
|||||||
print("Erster Datensatz: "+min(datapoints[list(datapoints.keys())[0]].times).strftime(timeformat))
|
print("Erster Datensatz: "+min(datapoints[list(datapoints.keys())[0]].times).strftime(timeformat))
|
||||||
print("Letzer Datensatz: "+max(datapoints[list(datapoints.keys())[0]].times).strftime(timeformat))
|
print("Letzer Datensatz: "+max(datapoints[list(datapoints.keys())[0]].times).strftime(timeformat))
|
||||||
print("Anzahl Datensätze: "+str(len(datapoints[list(datapoints.keys())[0]].times)))
|
print("Anzahl Datensätze: "+str(len(datapoints[list(datapoints.keys())[0]].times)))
|
||||||
|
print("Kürzlich genutze Data/Zeiten: (auswählen mit 1-5 <ENTER>):\n\n{}".format(recently_used()))
|
||||||
else:
|
else:
|
||||||
print("Keine Datesätze gefunden!")
|
print("Keine Datesätze gefunden!")
|
||||||
print_sep_line(True)
|
print_sep_line(True)
|
||||||
|
|
||||||
|
end_date_available = None
|
||||||
def input_date_repl(datapoints,startdate=True):
|
def input_date_repl(datapoints,startdate=True):
|
||||||
|
global end_date_available
|
||||||
date = None
|
date = None
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
if startdate:
|
if startdate:
|
||||||
@@ -162,9 +231,19 @@ def input_date_repl(datapoints,startdate=True):
|
|||||||
else:
|
else:
|
||||||
ret = input(l["input_second_date"])
|
ret = input(l["input_second_date"])
|
||||||
except EOFError:
|
except EOFError:
|
||||||
return (date,True)
|
return (date,True,None)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
# change ret to value if it was an history one
|
||||||
|
try:
|
||||||
|
if int(ret) in range(1,CFG("history_show")+1):
|
||||||
|
try:
|
||||||
|
ret = load_from_history(ret)
|
||||||
|
except Exception:
|
||||||
|
print("Konnte historische Eingabe nicht finden.")
|
||||||
|
continue
|
||||||
|
except:
|
||||||
|
pass
|
||||||
if ret in ["h","help","hilfe"]:
|
if ret in ["h","help","hilfe"]:
|
||||||
if startdate:
|
if startdate:
|
||||||
print(l["input_first_date_help"])
|
print(l["input_first_date_help"])
|
||||||
@@ -181,12 +260,12 @@ def input_date_repl(datapoints,startdate=True):
|
|||||||
else:
|
else:
|
||||||
date,ok=parse_date_from_user_input(ret,True,datapoints)
|
date,ok=parse_date_from_user_input(ret,True,datapoints)
|
||||||
if not ok:
|
if not ok:
|
||||||
return (None,False)
|
return (None,False,ret)
|
||||||
else:
|
else:
|
||||||
return (date,True)
|
return (date,True,ret)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
print(l["cannot_parse_date"] + "( was: {} )\n".format(ret))
|
print(l["cannot_parse_date"] + "( was: {} )\n".format(ret))
|
||||||
return (None,False)
|
return (None,False,ret)
|
||||||
|
|
||||||
def print_sep_line(ln=False):
|
def print_sep_line(ln=False):
|
||||||
if not ln:
|
if not ln:
|
||||||
|
|||||||
@@ -47,6 +47,12 @@ name_of_plot = None
|
|||||||
|
|
||||||
enable_automatic_date_correction = yes
|
enable_automatic_date_correction = yes
|
||||||
|
|
||||||
|
# history options
|
||||||
|
history_file_length = 1000
|
||||||
|
history_show = 10
|
||||||
|
history_save_on_call = no
|
||||||
|
history_double_col = yes
|
||||||
|
|
||||||
###### PLOT Styles (Farben, Scala, Linestyles) ######
|
###### PLOT Styles (Farben, Scala, Linestyles) ######
|
||||||
empty_space_above_plot = 10
|
empty_space_above_plot = 10
|
||||||
yaxis_minnimum_hight = 95
|
yaxis_minnimum_hight = 95
|
||||||
|
|||||||
Reference in New Issue
Block a user