
| 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/viewobj.py |
# coding: utf8
import os,re,sys,random
#**************************************************************************
class Scalar (object):
def __init__ (self,report,graphmodel,val,function1=None):
self.graphmodel = graphmodel
self.report = report
self.val = val
self.func = function1
#**************************************************************************
def evaluate_type (self,nrx,nry,x_pos,x_width): # additional configurations
self.nrx = nrx
self.nry = nry
self.x_pos = x_pos
self.x_width = x_width
if type(self.val) == type([]): # Kurve
if self.func == "GROSS":
self.val = len(self.val)
self.vtype = "val1"
elif type(self.val[0]) == type([]):
if type(self.val[0][0]) == type([]):
self.yxbundle() # yx-Kurvenschar
elif not len(self.val[0]) == 2 or self.func == "TREND":
self.ytbundle()
else:
self.yx()
else:
if self.func == "TREND":
self.valbundle()
else:
self.yt() # yt
else:
self.vtype = "val1"
#**************************************************************************
def positioning (self,x_width,x_pos,y_pos,elem_tag): # additional configurations
self.x_width = x_width
self.x_pos = x_pos
self.y_pos = y_pos
self.tag = elem_tag
if type(self.val) == type([]):
self.height = 30
else:
self.height = 12
#**************************************************************************
def make_gesamt_val (self,gesamt_val): # ,nr):
try:
gesamt_val[0] = max(float(gesamt_val[0]),self.val)
except:
if not self.val in gesamt_val:
gesamt_val.append(self.val)
#**************************************************************************
def curve (self,curve,func):
if func[0] == "X":
aggr_val = [x[0] for x in curve]
elif func[0] == "Y":
aggr_val = [x[1] for x in curve]
else:
aggr_val = curve
try:
if func[len(func)-3:] == "MIN":
return( min(aggr_val) )
if func[len(func)-3:] == "MAX":
return( max(aggr_val) )
if func[len(func)-3:] == "AVG":
return( sum(aggr_val) / float(len(aggr_val)) )
except Exception as e:
self.val = ",".join( list(dict(list(zip(curve,[1]*len(curve)))).keys()) )
#**************************************************************************
def yxbundle (self):
if self.func == "FIRST":
self.val = self.val[0]
self.vtype = "yx"
elif self.func == "LAST":
self.val = self.val[0]
self.vtype = "yx"
elif self.func and self.func[0] in ("X","Y"):
aggr_vals = [self.curve(x,self.func) for x in self.val]
self.val = self.curve(aggr_vals,self.func)
self.vtype = "val1"
else:
self.vtype = "yxbundle"
#**************************************************************************
def ytbundle (self):
if self.func == "FIRST":
self.val = self.val[0]
self.vtype = "yt"
elif self.func == "LAST":
self.val = self.val[0]
self.vtype = "yt"
elif self.func and self.func in ("MIN","MAX","AVG"):
aggr_vals = [self.curve(x,self.func) for x in self.val]
self.val = self.curve(aggr_vals,self.func)
self.vtype = "val1"
else:
self.vtype = "ytbundle"
#**************************************************************************
def yx (self):
if self.func and self.func[0] in ("X","Y"):
self.val = self.curve(self.val,self.func)
self.vtype = "val1"
else:
self.vtype = "ytbundle"
#**************************************************************************
def yt (self):
if self.func in ("MIN","MAX","AVG"):
self.val = self.curve(self.val,self.func)
self.vtype = "val1"
else:
self.vtype = "yt"
#**************************************************************************
def valbundle (self):
if self.func in ("MIN","MAX","AVG"):
self.val = self.curve(self.val,self.func)
self.vtype = "val1"
else:
self.vtype = "valbundle"
#**************************************************************************
def post_fit (self,gesamt_val):
self.__class__.__dict__["post_"+self.vtype](self,gesamt_val)
#**************************************************************************
def press (self,event=None):
try:
self.report.rf_show.unhighlight()
except Exception as e:
print(str(e))
pass
if self.report.rf_show == self:
self.report.rf_show = None
self.report.rf_col = None
self.graphmodel.hide(0)
else:
self.__class__.__dict__["press_"+self.vtype](self,event)
self.highlight()
self.report.rf_show = self
#***************************************************************************
def post_val1 (self,gesamt_val):
self.color = "#ffffdd"
try:
laenge = self.x_width * 0.95 * float(max(self.val,0.0)) / float(gesamt_val[0])
except:
laenge = None
if laenge:
self.hl = self.report.create_rectangle(self.x_pos,self.y_pos,self.x_pos+laenge,
self.y_pos+self.height-2,fill=self.color,tag=self.tag)
self.report.tag_bind(self.hl,"<Double-Button-1>", self.press)
x1 = self.report.create_text(self.x_pos+2,self.y_pos,text=str(self.val),anchor='nw',font=("Arial",8),tag=self.tag)
if not laenge:
self.hl = x1
self.report.tag_bind(x1,"<Double-Button-1>", self.press)
#***************************************************************************
def press_val1 (self,event):
xdim = self.graphmodel.winfo_width()
ydim = self.graphmodel.winfo_height()
self.graphmodel.hide(1)
self.graphmodel.create_text(xdim/2,ydim/2,text=str(self.val),anchor='center',font=("Arial",50),tag="reportitem")
#***************************************************************************
def post_valbundle (self,gesamt_val): # trend blocks
maxval = float(max(self.val))
minval = float(min(self.val))
minval = min(0.0,minval)
xstep = 0.95 * float(self.x_width) / float(len(self.val))
ystep = float(self.height-2) / float(maxval - minval)
zaehler = 0
for val in self.val:
x0 = self.x_pos + int(zaehler * xstep)
y0 = self.y_pos + self.height-2
zaehler = zaehler + 1
x1 = self.x_pos + int(zaehler * xstep)
y1 = y0 - int( (float(val) - minval) * ystep )
self.report.create_rectangle(x0,y0,x1,y1,fill='#bbffff',tag=self.tag)
#**************************************************************************
def post_yt (self,event):
self.color = "#ffffff"
maxval = float(max(self.val))
minval = float(min(self.val))
minval = min(0.0,minval)
xstep = 0.95 * float(self.x_width) / float(len(self.val))
ystep = float(self.height-2) / float(maxval - minval)
line_data = []
zaehler = -0.5
for val in self.val:
zaehler = zaehler + 1
line_data.append( self.x_pos + int(zaehler * xstep) )
line_data.append( self.y_pos + self.height-2 - int( (float(val) - minval) * ystep ) )
self.hl = self.report.create_rectangle(min(line_data[::2]),min(line_data[1::2]),
max(line_data[::2]),max(line_data[1::2]),fill=self.color,tag=self.tag)
self.report.tag_bind(self.hl,"<Double-Button-1>", self.press)
x2 = self.report.create_line( line_data, tag=self.tag )
self.report.tag_bind(x2,"<Double-Button-1>", self.press)
#**************************************************************************
def press_yt (self,gesamt_val):
maxval = float(max(self.val))
minval = float(min(self.val))
minval = min(0.0,minval)
xdim = self.graphmodel.winfo_width()
ydim = self.graphmodel.winfo_height()
xstep = 0.94 * float(xdim) / float(len(self.val))
ystep = 0.94 * float(ydim) / float(maxval - minval)
xoffset = 0.03 * float(xdim)
yoffset = 0.03 * float(ydim)
self.graphmodel.hide(1)
line_data = []
zaehler = -0.5
for val in self.val:
zaehler = zaehler + 1
line_data.append( xoffset + int(zaehler * xstep) )
line_data.append( ydim - yoffset - int( (float(val) - minval) * ystep ) )
self.graphmodel.create_line( line_data, tag="reportitem" )
#**************************************************************************
def post_ytbundle (self,gesamt_val):
maxval = [float(max(x)) for x in self.val]
minval = [float(min(x)) for x in self.val]
maxval = float(max(maxval))
minval = float(min(minval))
minval = min(0.0,minval)
for yt in self.val:
xstep = 0.95 * float(self.x_width) / float(len(yt))
ystep = float(self.height-2) / float(maxval - minval)
line_data = []
zaehler = -0.5
for val in yt:
zaehler = zaehler + 1
line_data.append( self.x_pos + int(zaehler * xstep) )
line_data.append( self.y_pos + self.height-2 - int( (float(val) - minval) * ystep ) )
self.report.create_line( line_data, tag=self.tag )
#***************************************************************************
def post_yx (self,gesamt_val): #
pass # TODO
#***************************************************************************
def post_yxbundle (self,gesamt_val): #
pass # TODO
#***************************************************************************
def highlight(self):
try:
self.report.itemconfig(self.hl,fill="yellow")
except:
pass
#***************************************************************************
def unhighlight(self):
self.report.itemconfig(self.hl,fill=self.color)
#***************************************************************************