Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
nni
Commits
64cf397c
Unverified
Commit
64cf397c
authored
Jul 07, 2021
by
Lijiaoa
Committed by
GitHub
Jul 07, 2021
Browse files
[webui] Support dict intermediate metrics(only for number type) (#3895)
parent
e50270cc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
6 deletions
+56
-6
ts/webui/src/components/modals/Compare.tsx
ts/webui/src/components/modals/Compare.tsx
+54
-5
ts/webui/src/static/style/search.scss
ts/webui/src/static/style/search.scss
+2
-1
No files found.
ts/webui/src/components/modals/Compare.tsx
View file @
64cf397c
import
*
as
React
from
'
react
'
;
import
*
as
React
from
'
react
'
;
import
{
renderToString
}
from
'
react-dom/server
'
;
import
{
renderToString
}
from
'
react-dom/server
'
;
import
{
Stack
,
Modal
,
IconButton
,
IDragOptions
,
ContextualMenu
}
from
'
@fluentui/react
'
;
import
{
Stack
,
Modal
,
IconButton
,
IDragOptions
,
ContextualMenu
,
Dropdown
,
IDropdownOption
}
from
'
@fluentui/react
'
;
import
ReactEcharts
from
'
echarts-for-react
'
;
import
ReactEcharts
from
'
echarts-for-react
'
;
import
{
TooltipForIntermediate
,
TableObj
,
SingleAxis
}
from
'
../../static/interface
'
;
import
{
TooltipForIntermediate
,
TableObj
,
SingleAxis
}
from
'
../../static/interface
'
;
import
{
contentStyles
,
iconButtonStyles
}
from
'
../buttons/ModalTheme
'
;
import
{
contentStyles
,
iconButtonStyles
}
from
'
../buttons/ModalTheme
'
;
...
@@ -8,6 +8,11 @@ import { convertDuration, parseMetrics } from '../../static/function';
...
@@ -8,6 +8,11 @@ import { convertDuration, parseMetrics } from '../../static/function';
import
{
EXPERIMENT
,
TRIALS
}
from
'
../../static/datamodel
'
;
import
{
EXPERIMENT
,
TRIALS
}
from
'
../../static/datamodel
'
;
import
'
../../static/style/compare.scss
'
;
import
'
../../static/style/compare.scss
'
;
/***
* Compare file is design for [each trial intermediate result and trials compare function]
* if trial has dict intermediate result, graph support shows all keys that type is number
*/
function
_getWebUIWidth
():
number
{
function
_getWebUIWidth
():
number
{
return
window
.
innerWidth
;
return
window
.
innerWidth
;
}
}
...
@@ -20,7 +25,7 @@ const dragOptions: IDragOptions = {
...
@@ -20,7 +25,7 @@ const dragOptions: IDragOptions = {
// TODO: this should be refactored to the common modules
// TODO: this should be refactored to the common modules
// copied from trial.ts
// copied from trial.ts
function
_parseIntermediates
(
trial
:
TableObj
):
number
[]
{
function
_parseIntermediates
(
trial
:
TableObj
,
key
:
string
):
number
[]
{
const
intermediates
:
number
[]
=
[];
const
intermediates
:
number
[]
=
[];
for
(
const
metric
of
trial
.
intermediates
)
{
for
(
const
metric
of
trial
.
intermediates
)
{
if
(
metric
===
undefined
)
{
if
(
metric
===
undefined
)
{
...
@@ -29,7 +34,7 @@ function _parseIntermediates(trial: TableObj): number[] {
...
@@ -29,7 +34,7 @@ function _parseIntermediates(trial: TableObj): number[] {
const
parsedMetric
=
parseMetrics
(
metric
.
data
);
const
parsedMetric
=
parseMetrics
(
metric
.
data
);
if
(
typeof
parsedMetric
===
'
object
'
)
{
if
(
typeof
parsedMetric
===
'
object
'
)
{
// TODO: should handle more types of metric keys
// TODO: should handle more types of metric keys
intermediates
.
push
(
parsedMetric
.
default
);
intermediates
.
push
(
parsedMetric
[
key
]
);
}
else
{
}
else
{
intermediates
.
push
(
parsedMetric
);
intermediates
.
push
(
parsedMetric
);
}
}
...
@@ -54,9 +59,17 @@ interface CompareProps {
...
@@ -54,9 +59,17 @@ interface CompareProps {
changeSelectTrialIds
?:
()
=>
void
;
changeSelectTrialIds
?:
()
=>
void
;
}
}
class
Compare
extends
React
.
Component
<
CompareProps
,
{}
>
{
interface
CompareState
{
intermediateKey
:
string
;
// default, dict other keys
}
class
Compare
extends
React
.
Component
<
CompareProps
,
CompareState
>
{
constructor
(
props
:
CompareProps
)
{
constructor
(
props
:
CompareProps
)
{
super
(
props
);
super
(
props
);
this
.
state
=
{
intermediateKey
:
'
default
'
};
}
}
private
_generateTooltipSummary
=
(
row
:
Item
,
value
:
string
):
string
=>
private
_generateTooltipSummary
=
(
row
:
Item
,
value
:
string
):
string
=>
...
@@ -206,8 +219,17 @@ class Compare extends React.Component<CompareProps, {}> {
...
@@ -206,8 +219,17 @@ class Compare extends React.Component<CompareProps, {}> {
onHideDialog
();
onHideDialog
();
};
};
private
selectOtherKeys
=
(
_event
:
React
.
FormEvent
<
HTMLDivElement
>
,
item
?:
IDropdownOption
):
void
=>
{
if
(
item
!==
undefined
)
{
this
.
setState
(()
=>
({
intermediateKey
:
item
.
text
}));
}
};
render
():
React
.
ReactNode
{
render
():
React
.
ReactNode
{
const
{
trials
,
title
,
showDetails
}
=
this
.
props
;
const
{
trials
,
title
,
showDetails
}
=
this
.
props
;
const
{
intermediateKey
}
=
this
.
state
;
let
intermediateAllKeysList
:
string
[]
=
[];
const
flatten
=
(
m
:
Map
<
SingleAxis
,
any
>
):
Map
<
string
,
any
>
=>
{
const
flatten
=
(
m
:
Map
<
SingleAxis
,
any
>
):
Map
<
string
,
any
>
=>
{
return
new
Map
(
Array
.
from
(
m
).
map
(([
key
,
value
])
=>
[
key
.
baseName
,
value
]));
return
new
Map
(
Array
.
from
(
m
).
map
(([
key
,
value
])
=>
[
key
.
baseName
,
value
]));
};
};
...
@@ -218,9 +240,23 @@ class Compare extends React.Component<CompareProps, {}> {
...
@@ -218,9 +240,23 @@ class Compare extends React.Component<CompareProps, {}> {
duration
:
convertDuration
(
trial
.
duration
),
duration
:
convertDuration
(
trial
.
duration
),
parameters
:
flatten
(
trial
.
parameters
(
inferredSearchSpace
)),
parameters
:
flatten
(
trial
.
parameters
(
inferredSearchSpace
)),
metrics
:
flatten
(
trial
.
metrics
(
TRIALS
.
inferredMetricSpace
())),
metrics
:
flatten
(
trial
.
metrics
(
TRIALS
.
inferredMetricSpace
())),
intermediates
:
_parseIntermediates
(
trial
)
intermediates
:
_parseIntermediates
(
trial
,
intermediateKey
)
}));
}));
if
(
trials
[
0
].
intermediates
!==
undefined
&&
trials
[
0
].
intermediates
[
0
])
{
const
parsedMetric
=
parseMetrics
(
trials
[
0
].
intermediates
[
0
].
data
);
if
(
parsedMetric
!==
undefined
&&
typeof
parsedMetric
===
'
object
'
)
{
const
allIntermediateKeys
:
string
[]
=
[];
// just add type=number keys
for
(
const
key
in
parsedMetric
)
{
if
(
typeof
parsedMetric
[
key
]
===
'
number
'
)
{
allIntermediateKeys
.
push
(
key
);
}
}
intermediateAllKeysList
=
allIntermediateKeys
;
}
}
return
(
return
(
<
Modal
<
Modal
isOpen
=
{
true
}
isOpen
=
{
true
}
...
@@ -240,6 +276,19 @@ class Compare extends React.Component<CompareProps, {}> {
...
@@ -240,6 +276,19 @@ class Compare extends React.Component<CompareProps, {}> {
onClick
=
{
this
.
closeCompareModal
}
onClick
=
{
this
.
closeCompareModal
}
/>
/>
</
div
>
</
div
>
{
intermediateAllKeysList
.
length
>
1
?
(
<
Stack
horizontalAlign
=
'end'
className
=
'selectKeys'
>
<
Dropdown
className
=
'select'
selectedKey
=
{
intermediateKey
}
options
=
{
intermediateAllKeysList
.
map
((
key
,
item
)
=>
({
key
:
key
,
text
:
intermediateAllKeysList
[
item
]
}))
}
onChange
=
{
this
.
selectOtherKeys
}
/>
</
Stack
>
)
:
null
}
<
Stack
className
=
'compare-modal-intermediate'
>
<
Stack
className
=
'compare-modal-intermediate'
>
{
this
.
_intermediates
(
items
)
}
{
this
.
_intermediates
(
items
)
}
<
Stack
className
=
'compare-yAxis'
>
# Intermediate result
</
Stack
>
<
Stack
className
=
'compare-yAxis'
>
# Intermediate result
</
Stack
>
...
...
ts/webui/src/static/style/search.scss
View file @
64cf397c
...
@@ -20,7 +20,8 @@
...
@@ -20,7 +20,8 @@
.selectKeys
{
.selectKeys
{
/* intermediate result is dict, select box for keys */
/* intermediate result is dict, select box for keys */
.select
{
.select
{
margin-right
:
12%
;
margin-right
:
6%
;
margin-bottom
:
15px
;
}
}
.ms-Dropdown
{
.ms-Dropdown
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment