
| Current Path : /home/cgabriel/20_dev/12_procpy/dataninja/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : //home/cgabriel/20_dev/12_procpy/dataninja/graphproc.py |
# coding: utf8
import os,re,sys,time,functools,random,math,tkinter,codecs,procpy
import procpy.graphmodel
import procpy.graphreport
# import procpy.graphinfo
# import procpy.procobj
try:
import tkinter.ttk,Pmw,xmltodict,json,svgwrite # ,tkintertable
except:
import pip
pip.main(["install","pyttk"])
pip.main(["install","Pmw"])
pip.main(["install","tkintertable"])
pip.main(["install","xmltodict"])
pip.main(["install","json"])
pip.main(["install","svgwrite"])
import tkinter.ttk,Pmw,xmltodict,json,svgwrite # ,tkintertable
import tkinter.filedialog
#**************************************************************************
class Graphproc (tkinter.Frame):
def __init__ (self,storeproc,*pars,**args):
self.storeproc = storeproc
tkinter.Frame.__init__(self,*pars,**args)
# self.config(orient=Tkinter.HORIZONTAL)
self.width = args.setdefault('width', 0)
self.height = args.setdefault('height',0)
print ("WIDTH",self.width,self.height)
self.regleft = tkinter.Frame(self,width=int(0.2*self.width),height=int(self.height))
self.regright = tkinter.PanedWindow(self,width=int(0.8*self.width),height=self.height,orient=tkinter.VERTICAL)
self.regleft.pack( side=tkinter.LEFT,fill=tkinter.Y)
self.regright.pack(side=tkinter.LEFT,expand=tkinter.TRUE,fill=tkinter.BOTH)
self.regtop = tkinter.Frame(self.regright,width=0.8*self.width,height=0.0*self.height)
self.regmodel = tkinter.Frame(self.regtop)
# self.reginfo = procpy.graphinfo.Graphinfo(self.regtop)
# self.reginfo.pack( side=Tkinter.BOTTOM,fill=Tkinter.X) # TOP: put it on the top of the right side
self.regmodel.pack(side=tkinter.TOP,expand=tkinter.TRUE,fill=tkinter.BOTH)
self.regbottom = tkinter.Canvas(self.regright,width=int(0.8*self.width),height=int(0.35*self.height))
self.regtop.pack( side=tkinter.TOP,expand=tkinter.TRUE,fill=tkinter.BOTH)
self.regbottom.pack(side=tkinter.TOP,fill=tkinter.X)
self.regright.add(self.regtop)
self.regright.add(self.regbottom)
self.graphmodel = procpy.graphmodel.Graphmodel(self,self.regmodel)
self.txscroll = tkinter.Scrollbar(self.regmodel,orient=tkinter.HORIZONTAL,
command=self.graphmodel.xview,width=8)
self.tyscroll = tkinter.Scrollbar(self.regmodel,orient=tkinter.VERTICAL,
command=self.graphmodel.yview,width=8)
self.graphmodel.config(xscrollcommand=self.txscroll.set)
self.graphmodel.config(yscrollcommand=self.tyscroll.set)
self.txscroll.pack(side=tkinter.BOTTOM,fill=tkinter.X)
self.tyscroll.pack(side=tkinter.RIGHT,fill=tkinter.Y)
self.graphmodel.pack(side=tkinter.LEFT,expand=True,fill=tkinter.BOTH)
self.reportitem = tkinter.Canvas(self.regmodel)
self.graphreport = procpy.graphreport.Graphreport(self,self.regbottom)
self.bxscroll = tkinter.Scrollbar(self.regbottom,orient=tkinter.HORIZONTAL,
command=lambda x,y: (self.graphreport.header.xview(x,y),
self.graphreport.report.xview(x,y)),width=8)
self.byscroll = tkinter.Scrollbar(self.regbottom,orient=tkinter.VERTICAL,
command=self.graphreport.report.yview,width=8)
self.graphreport.header.config(xscrollcommand=self.bxscroll.set)
self.graphreport.report.config(xscrollcommand=self.bxscroll.set)
self.graphreport.report.config(yscrollcommand=self.byscroll.set)
self.bxscroll.pack(side=tkinter.BOTTOM,fill=tkinter.X)
self.byscroll.pack(side=tkinter.RIGHT,fill=tkinter.Y)
self.graphreport.pack(side=tkinter.LEFT,expand=True,fill=tkinter.BOTH)
self.buttonframe_top = tkinter.Frame(self.regleft)
self.buttonframe_bottom = tkinter.Frame(self.regleft)
self.buttonframe_top.pack(side=tkinter.TOP,expand=tkinter.FALSE,fill=tkinter.Y)
self.buttonframe_bottom.pack(side=tkinter.BOTTOM)
self.buttonframe_left = tkinter.Frame(self.buttonframe_top)
self.buttonframe_right = tkinter.Frame(self.buttonframe_top)
self.buttonframe_left.pack(side=tkinter.LEFT,expand=tkinter.TRUE,fill=tkinter.Y)
self.buttonframe_right.pack(side=tkinter.LEFT,expand=tkinter.TRUE,fill=tkinter.Y)
self.runcounter = tkinter.Entry(self.buttonframe_right,width=6)
self.runcounter.insert(0,"1")
self.runcounter.pack()
self.startbutton = tkinter.Button(self.buttonframe_right,text="Start",width=6,
command=self.process_start,font=("Arial",10))
self.startbutton.pack()
# self.forecastbutton = Tkinter.Button(self.buttonframe_right,text="Forecast",width=6,
# command=self.process_start,font=("Arial",10))
# self.forecastbutton.pack()
self.stopbutton = tkinter.Button(self.buttonframe_right,text="Stop",width=6,
command=self.process_stop,font=("Arial",10))
self.stopbutton.pack()
self.resetbutton = tkinter.Button(self.buttonframe_right,text="0",width=6,bg="yellow",
command=self.storeproc_clear,font=("Arial",10))
self.resetbutton.pack()
self.speedruler = tkinter.Scale(self.buttonframe_left,from_=1000,to=0,length=20,showvalue=True,
command=self.set_speed)
self.speedruler.set(500)
self.speedruler.pack(expand=tkinter.TRUE,fill=tkinter.Y)
self.anzahl = "0"
#**************************************************************************
def scroll_command (self,x,y):
self.graphreport.header.xview(x,y)
self.graphreport.report.xview(x,y)
#**************************************************************************
def toggle_regmodel (self,zielwert=None):
o = self.pack_slaves()[0]
if zielwert == None:
if o == self.graphmodel:
zielwert = self.reportitem
else:
zielwert = self.graphmodel
if not o == zielwert:
o.pack_forget()
zielwert.pack(side=tkinter.LEFT,expand=True,fill=tkinter.BOTH)
#**************************************************************************
def set_speed (self,x):
fac = 2
dif = 1.0
nr = 500
speedfactor0 = (10**fac)**((float(nr)/1000)**dif-1)
speedfactor = speedfactor0 / (10**fac)**((float(x)/1000)**dif-1)
self.storeproc.speedup = speedfactor
self.graphmodel.run_delay = speedfactor * procpy.config.RUN_DELAY
# self.storeproc.speedup = 10.0/float(x)
print(self.storeproc.speedup)
# self.storeproc.period = 300
#**************************************************************************
def config (self,*pars,**args):
for par in ["classname","storeproc"]:
if par in args:
vars(self)[par] = args[par]
del args[par]
tkinter.Frame.config(self,*pars,**args)
#**************************************************************************
def process_start (self):
if 'process_runs' in vars(self.graphmodel):
return()
self.graphmodel.repeats = int(self.runcounter.get())
self.graphmodel.tokens = {}
self.graphmodel.run_process(self)
#**************************************************************************
def notify (self):
self.runcounter.delete(0,10)
self.runcounter.insert(0,str(max(1,self.graphmodel.repeats)))
self.anzahl = "%1u" % (int(self.anzahl) + 1)
self.resetbutton.config(text=self.anzahl)
#**************************************************************************
def process_start (self):
print("PROCESS_START")
cln = self.classname
try:
cln = re.search(r".*[\\|/](.*)$",cln).group(1)
except:
pass
o = self.graphmodel.initiate_class(cln)
print("PROCESS_START",self.classname,o,cln)
try:
exec(o)
except Exception as e:
print(e)
print(self.__module__ + "." + cln + " = " + cln)
# print("hier")
exec(self.__module__ + "." + cln + " = " + cln)
# print ("A",cln,sim02)
# print("------------------ooooooooooooooooooooooooooo--------------------------")
exec("self.pobj_exec = " + self.__module__ + "." + cln + "()")
self.pobj_exec.__REPEAT__ = int(self.runcounter.get())
self.old_running_blocks = {}
self.running_proc_objid = self.storeproc.run(self.pobj_exec)
del self.pobj_exec
#**************************************************************************
def process_stop (self):
self.graphmodel.notifier = None
self.graphmodel.repeats = 0
# o = self.storeproc.property(self.running_proc_objid,"__REPEAT__","1")
# self.graphreport.report.rf_show = None
# self.graphreport.report.rf_col = None
# self.graphmodel.hide(0)
#**************************************************************************
def storeproc_clear (self):
# self.storeproc.clear()
# procpy.storeproc.VARS = {}
self.resetbutton.config(text="0")
self.anzahl = "0"
# self.graphreport.clear()
# self.graphreport.report.rf_show = None
# self.graphreport.report.rf_col = None
# self.graphmodel.hide(0)
#**************************************************************************
def save (self):
return(self.graphmodel.save() + "\n\n==================\n\n" + self.graphreport.save())
#**************************************************************************
def load (self,text):
m = re.search(r"^(.*)\n\=+\n(.*)$",text,re.DOTALL)
if m:
self.graphreport.load(m.group(2))
text = m.group(1)
self.graphmodel.load(text)
#**************************************************************************
def actualize_report (self,event=None):
if type(self.storeproc.dbh) == type({}):
return()
# self.graphreport.draw_report_headers() # superfluous!
qy = []
group_string = {}
order_string = []
for col in self.graphreport.actual_report_columns:
col1 = procpy.objpickle.mask( re.sub(r"^ *$","''",col) )
m = re.search(r"^(.+)\((.+)\)$",col1)
fieldname = col1
if m:
fieldname = m.group(2)
func = m.group(1)
if not func in ("AVG","MIN","MAX","SUM","COUNT") or "GROSS" in self.storeproc.store.list_of_variables[fieldname]:
col1 = re.sub(r"^\S+?\((.*?)\)","GROUP_CONCAT(\\1,'---GROUPCONCATSEPARATOR---')",col1)
else:
if not col1 == "''":
group_string[col1] = 1
if not col1 in qy:
qy.append(col1)
if fieldname in self.graphreport.sort_fields and not "GROSS" in self.storeproc.store.list_of_variables[fieldname]:
if self.graphreport.sort_klicks[fieldname] % 2 == 0:
order_string.append([fieldname," asc"])
else:
order_string.append([fieldname," desc"])
for col1 in group_string:
col1_group = "GROUP_CONCAT("+col1+",'---GROUPCONCATSEPARATOR---')"
if col1_group in qy:
qy.remove(col1_group)
if not col1 in qy:
qy.append(col1)
qy = " select " + ",".join(qy) + " from " + self.storeproc.dbtable
qy = qy + " where ____LEVEL____ = '1'"
def sort_order_list (a,b): # the sorting function of the nr'th column by clist
try:
erg = self.graphreport.sort_fields.index(a[0]) - self.graphreport.sort_fields.index(b[0])
if not erg == 0:
return(erg)
except Exception as e:
print(str(e))
return(0)
return(0)
if group_string:
qy = qy + " group by " + ",".join(list(group_string.keys()))
order_string.sort(key=functools.cmp_to_key(sort_order_list))
sort_col = None
order_string.append(["STARTTIME"," asc"])
if order_string: # the group fields now are sorted by sort_fields
sort_col = order_string[0]
order_string = [x[0] + x[1] for x in order_string]
order_string = ",".join(order_string)
qy = qy + " order by " + order_string
qy = qy + " limit 500"
print(qy)
cursor = None
try:
cursor = self.storeproc.dbh.execute(qy)
except Exception as e:
print(str(e))
print(qy)
self.graphreport.draw_report(cursor,sort_col)
#**************************************************************************
def xxactualize_report (self):
report_columns = self.graphreport.column_aggr_funcs
report_columns['__PARENT__'] = ''
report_columns['__LEVEL__'] = ''
report_columns['__LOCKED__'] = ''
cursor = self.storeproc.query_tk(report_columns)
self.graphreport.draw_report(cursor)
#**************************************************************************
def xxnotify (self,objid,running_block=None,parentid=None):
try:
self.old_running_blocks
except:
return()
if objid in self.old_running_blocks:
try:
self.graphmodel.blocks[int(self.old_running_blocks[objid].replace("Block",""))].mark_as_running(-1)
except:
pass
if running_block:
try:
self.graphmodel.blocks[int(running_block.replace("Block",""))].mark_as_running(1)
except:
pass
self.old_running_blocks[objid] = running_block
if parentid in self.old_running_blocks:
self.notify(parentid)
elif objid in self.old_running_blocks:
del self.old_running_blocks[objid]
#**************************************************************************
def mark_end (self):
self.actualize_report()
self.runcounter.delete(0,10)
self.runcounter.insert(0,str(self.storeproc.act_repeats))
self.resetbutton.config(text=str(self.storeproc.act_anzahl))