Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pyDCCandDBTools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benedikt
pyDCCandDBTools
Commits
6c6b67ca
Commit
6c6b67ca
authored
2 years ago
by
Benedikt
Browse files
Options
Downloads
Patches
Plain Diff
added dsiVectorGui
parent
dc5cf38f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
DCCTableTool.py
+96
-9
96 additions, 9 deletions
DCCTableTool.py
with
96 additions
and
9 deletions
DCCTableTool.py
+
96
−
9
View file @
6c6b67ca
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
.
contro
a
lFileImput
=
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
.
contro
a
lFileImput
,
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
=
105
0
,
width
=
168
0
width
=
160
0
,
height
=
50
0
)
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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment