Skip to content
Snippets Groups Projects
Commit 6c6b67ca authored by Benedikt's avatar Benedikt
Browse files

added dsiVectorGui

parent dc5cf38f
No related branches found
No related tags found
No related merge requests found
from bokeh.models import TabPanel, Tabs,FileInput, Dropdown
from bokeh.models import ColumnDataSource, DataTable,TableColumn,Div
from bokeh.models import TabPanel, Tabs,FileInput, Dropdown,ColumnDataSource, DataTable,TableColumn,Div,Spacer,NumericInput,RadioGroup,Button,TextAreaInput
from bokeh.layouts import column,row
from bokeh.plotting import figure, show, output_file,curdoc
from base64 import b64decode
......@@ -10,39 +9,116 @@ import logging
##FileUploadSide
import os
from datetime import datetime
from pccDccTools import dsiVector
class dsiVectorGui:
def __init__(self,df,controlJoson={}):
self.controlDict=controlJoson
self.df=df
self.colNames=list(self.df.columns)
self.valDropDown=Dropdown(label="Dropdown button", button_type="warning", menu=self.colNames)
self.valDropDown.on_click(self.valSelectCB)
self.uncerDropDown = Dropdown(label="Dropdown button", button_type="warning", menu=['No Uncer']+self.colNames)
self.uncerDropDown.on_click(self.uncerSelectCB)
self.slectButton=Button(label="Create Vector", button_type="primary")
self.slectButton.on_click(self.createDSiVectorInstance)
self.widget=row([self.valDropDown,self.uncerDropDown,self.slectButton])
self.UncerSelected=False
def createDSiVectorInstance(self):
self.controlDict['coverageFactor']=self.coverrageNumIn.value
self.controlDict['kFactor'] = self.expansionNumIn.value
self.controlDict['uncerDistribution']='normal'
pass
def valSelectCB(self,event):
self.controlDict['valColName']=event.item
self.valDropDown.label='Val: '+str(self.controlDict['valColName'])
self.valDropDown.button_type = 'success'
def uncerSelectCB(self,event):
if event.item!=self.controlDict['valColName']:
if not self.UncerSelected:
self.controlDict['uncerColName']=event.item
self.uncerDropDown.label='Uncer: '+str(self.controlDict['uncerColName'])
self.uncerDropDown.button_type = 'success'
self.uncerTyps = ['Absolute', 'Relative', 'Relative %',
'Relative ppm'] # TODO get supported uncer Formats from DSI Vector
self.uncerTypeRadioGroup = RadioGroup(labels=self.uncerTyps, active=0)
self.widget.children.insert(2,self.uncerTypeRadioGroup)
self.uncerTyptextIn = TextAreaInput(value="mormal", rows=1, title="Uncer Distribution:") #
self.widget.children.insert(3,self.uncerTyptextIn)
self.coverrageNumIn = NumericInput(value=0.95, low=0.0, high=1.0, title="Coverrage propability 0.0-1.0")
self.widget.children.insert(4, self.coverrageNumIn)
self.expansionNumIn = NumericInput(value=2.0, low=0.0, title="coverage Factor 0.0-Inf")
self.widget.children.insert(5, self.expansionNumIn)
self.UncerSelected = True
else:
if event.item=='No Uncer':
self.controlDict['uncerColName'] = event.item
self.uncerDropDown.label = str(self.controlDict['uncerColName'])
for item in [self.uncerTyptextIn,self.expansionNumIn,self.coverrageNumIn,self.uncerTypeRadioGroup]:
self.widget.children.remove(item)
del item
self.UncerSelected = False
else:
self.controlDict['uncerColName'] = event.item
self.uncerDropDown.label = 'Uncer: ' + str(self.controlDict['uncerColName'])
self.uncerDropDown.button_type = 'success'
def createDSiVector(self):
# def __init__(self, values : np.ndarray, uncer : Union[np.ndarray,None], quantity : str, unit : str, uncerType: str="absolute",refTypeAndNames:dict={'dummy_xxx':{'EN':'Dummy','DE':'platzhalter'}},uncerParams:dict={'coverageFactor':2.0,'coverageProbability':0.95,'distribution':'normal'}) ->dsiVector:
vals=self.df[self.controlDict['valColName']]
uncers=None
unit=r"\volt"#TODO add unit
if self.UncerSelected:
uncers=self.df[self.controlDict['uncerColName']]
self.controlDict['uncerParams'] = {'coverageFactor':self.expansionNumIn.value,
'coverageProbability':self.coverrageNumIn.value,
'distribution':self.uncerTyptextIn.value_input}
self.controlDict['uncerType']=self.uncerTypeRadioGroup.active
self.DSiVector=dsiVector(vals,uncers,self.controlDict['valColName'],unit,uncerType=self.controlDict['uncerType'],uncerParams=self.controlDict['uncerParams'])
else:
self.DSiVector = dsiVector(vals, uncers, self.controlDict['valColName'], unit,
uncerType='None')
class Page():
def __init__(self):
self.sheetNames=[]
self.controalDict={}
self.dsiVectorGuis=[]
self.dataDf=pd.DataFrame()
self.busyCount=0
####GUI Elements
##Common
self.clock = Div(text="""<h2 style="color:#1f77b4";>This is a test</h2> """, width=400, height=50)
##Tab 1 File upload
self.dataFileInput = FileInput(title="Select Data files:", accept=".csv,.xls,.xlsx,.odf")
self.controalFileImput = FileInput(title="Optional select conversion control file:", accept=".json")
self.controlFileImput = FileInput(title="Optional select conversion control file:", accept=".json")
self.sheetSelectDropDown = Dropdown(label="Dropdown button", button_type="warning", menu=self.sheetNames,disabled=True)
self.dataFileInput.on_change('filename', self.dataFileUploadCallback)
self.sheetSelectDropDown.on_click(self.sheetSelectionCallBack)
self.tab1 = TabPanel(child=column(self.dataFileInput,self.controalFileImput,self.sheetSelectDropDown), title="File Upload")
self.tab1 = TabPanel(child=column(self.dataFileInput, self.controlFileImput, self.sheetSelectDropDown), title="File Upload")
###Tab 2 Data Selection
self.data_table = DataTable(
columns=[TableColumn(field=Ci, title=Ci) for Ci in self.dataDf.columns],
source=ColumnDataSource(self.dataDf),
height=1050,
width=1680
width = 1600,
height = 500
)
self.addDSIVecotrButton= Button(label="Add DSI Vector", button_type="primary")
self.addDSIVecotrButton.on_click(self.addDSiValueSelector)
self.tab2 = TabPanel(child=column([self.data_table,Spacer(height=10),
Div(text="""<body>
<p>Create DSI Vectors:</p>
<hr style="height:2px;border-width:0;color:gray;background-color:gray">
</body>"""),
self.addDSIVecotrButton],width_policy='max'), title="TableView",disabled=False,name='DatatabelVectorBuilder')#TODO deactivate as default
self.tab2 = TabPanel(child=row(self.data_table), title="TableView",disabled=False)#TODO deactivate as default
self.allTabs=Tabs(tabs=[self.tab1, self.tab2])
# put the button and plot in a layout and add to the document
self.page=column([self.clock,self.allTabs])
def dataFileUploadCallback(self,attr, old, new):
self.xlsData = b64decode(self.dataFileInput.value)
self.dataXLSFile=BytesIO(self.xlsData)
......@@ -78,8 +154,18 @@ class Page():
self.data_table.source.data=self.dataDf
self.data_table.columns=[TableColumn(field=Ci, title=Ci) for Ci in self.dataDf.columns]
self.data_table.update()
#self.tab2.child.children[0]=self.data_table
print("Test")
def addDSiValueSelector(self):
gui=dsiVectorGui(self.dataDf)
self.dsiVectorGuis.append(gui)
self.tab2.child.children.insert(-1,gui.widget)
### Dirty hack reset table colums ... :( otherwise table gets messed up :(
self.data_table.columns = [TableColumn(field=Ci, title=Ci) for Ci in self.dataDf.columns]
pass
# set time and date in the GUI (once per second)
def p_callback(self):
if self.busyCount == 0:
......@@ -104,6 +190,7 @@ def make_doc(doc):
doc.add_root(myPage.page)
doc.title = "DCC table Tool"
doc.add_periodic_callback(myPage.p_callback, 500)
print("Done")
'''
Now the server part
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment