Unverified Commit 8875fa77 authored by Lijiaoa's avatar Lijiaoa Committed by GitHub
Browse files

Improve trial intermediate result graph: trials have not intermediate default key (#4171)

parent 69a84cf3
...@@ -55,6 +55,7 @@ interface CompareProps { ...@@ -55,6 +55,7 @@ interface CompareProps {
trials: TableObj[]; trials: TableObj[];
title: string; title: string;
showDetails: boolean; showDetails: boolean;
intermediateKeyList?: string[];
onHideDialog: () => void; onHideDialog: () => void;
changeSelectTrialIds?: () => void; changeSelectTrialIds?: () => void;
} }
...@@ -68,7 +69,9 @@ class Compare extends React.Component<CompareProps, CompareState> { ...@@ -68,7 +69,9 @@ class Compare extends React.Component<CompareProps, CompareState> {
super(props); super(props);
this.state = { this.state = {
intermediateKey: 'default' // intermediate result maybe don't have the 'default' key...
intermediateKey:
this.props.intermediateKeyList !== undefined ? this.props.intermediateKeyList[0] : 'default'
}; };
} }
...@@ -226,10 +229,9 @@ class Compare extends React.Component<CompareProps, CompareState> { ...@@ -226,10 +229,9 @@ class Compare extends React.Component<CompareProps, CompareState> {
}; };
render(): React.ReactNode { render(): React.ReactNode {
const { trials, title, showDetails } = this.props; const { trials, title, showDetails, intermediateKeyList } = this.props;
const { intermediateKey } = this.state; const { intermediateKey } = this.state;
let intermediateAllKeysList: string[] = []; const intermediateAllKeysList: string[] = intermediateKeyList !== undefined ? intermediateKeyList : [];
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]));
}; };
...@@ -243,20 +245,6 @@ class Compare extends React.Component<CompareProps, CompareState> { ...@@ -243,20 +245,6 @@ class Compare extends React.Component<CompareProps, CompareState> {
intermediates: _parseIntermediates(trial, intermediateKey) 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}
...@@ -276,7 +264,8 @@ class Compare extends React.Component<CompareProps, CompareState> { ...@@ -276,7 +264,8 @@ class Compare extends React.Component<CompareProps, CompareState> {
onClick={this.closeCompareModal} onClick={this.closeCompareModal}
/> />
</div> </div>
{intermediateAllKeysList.length > 1 ? ( {intermediateAllKeysList.length > 1 ||
(intermediateAllKeysList.length === 1 && intermediateAllKeysList !== ['default']) ? (
<Stack horizontalAlign='end' className='selectKeys'> <Stack horizontalAlign='end' className='selectKeys'>
<Dropdown <Dropdown
className='select' className='select'
......
...@@ -12,7 +12,7 @@ import { ...@@ -12,7 +12,7 @@ import {
} from '@fluentui/react'; } from '@fluentui/react';
import { EXPERIMENT, TRIALS } from '../../static/datamodel'; import { EXPERIMENT, TRIALS } from '../../static/datamodel';
import { TOOLTIP_BACKGROUND_COLOR } from '../../static/const'; import { TOOLTIP_BACKGROUND_COLOR } from '../../static/const';
import { convertDuration, formatTimestamp, copyAndSort, parametersType } from '../../static/function'; import { convertDuration, formatTimestamp, copyAndSort, parametersType, parseMetrics } from '../../static/function';
import { TableObj, SortInfo, SearchItems } from '../../static/interface'; import { TableObj, SortInfo, SearchItems } from '../../static/interface';
import { getTrialsBySearchFilters } from './search/searchFunction'; import { getTrialsBySearchFilters } from './search/searchFunction';
import { blocked, copy, LineChart, tableListIcon } from '../buttons/Icon'; import { blocked, copy, LineChart, tableListIcon } from '../buttons/Icon';
...@@ -87,6 +87,7 @@ interface TableListState { ...@@ -87,6 +87,7 @@ interface TableListState {
sortInfo: SortInfo; sortInfo: SortInfo;
searchItems: Array<SearchItems>; searchItems: Array<SearchItems>;
relation: Map<string, string>; relation: Map<string, string>;
intermediateKeyList: string[];
} }
class TableList extends React.Component<TableListProps, TableListState> { class TableList extends React.Component<TableListProps, TableListState> {
...@@ -112,7 +113,8 @@ class TableList extends React.Component<TableListProps, TableListState> { ...@@ -112,7 +113,8 @@ class TableList extends React.Component<TableListProps, TableListState> {
copiedTrialId: undefined, copiedTrialId: undefined,
sortInfo: { field: '', isDescend: true }, sortInfo: { field: '', isDescend: true },
searchItems: [], searchItems: [],
relation: parametersType() relation: parametersType(),
intermediateKeyList: []
}; };
this._expandedTrialIds = new Set<string>(); this._expandedTrialIds = new Set<string>();
...@@ -437,7 +439,11 @@ class TableList extends React.Component<TableListProps, TableListState> { ...@@ -437,7 +439,11 @@ class TableList extends React.Component<TableListProps, TableListState> {
onClick={(): void => { onClick={(): void => {
const { tableSource } = this.props; const { tableSource } = this.props;
const trial = tableSource.find(trial => trial.id === record.id) as TableObj; const trial = tableSource.find(trial => trial.id === record.id) as TableObj;
this.setState({ intermediateDialogTrial: trial }); const intermediateKeyListResult = this.getIntermediateAllKeys(trial);
this.setState({
intermediateDialogTrial: trial,
intermediateKeyList: intermediateKeyListResult
});
}} }}
> >
{LineChart} {LineChart}
...@@ -469,6 +475,33 @@ class TableList extends React.Component<TableListProps, TableListState> { ...@@ -469,6 +475,33 @@ class TableList extends React.Component<TableListProps, TableListState> {
})); }));
}; };
private getIntermediateAllKeys = (intermediateDialogTrial: any): string[] => {
let intermediateAllKeysList: string[] = [];
if (
intermediateDialogTrial!.intermediateMetrics !== undefined &&
intermediateDialogTrial!.intermediateMetrics[0]
) {
const parsedMetric = parseMetrics(intermediateDialogTrial!.intermediateMetrics[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;
}
}
if (intermediateAllKeysList.includes('default') && intermediateAllKeysList[0] !== 'default') {
intermediateAllKeysList = intermediateAllKeysList.filter(item => item !== 'default');
intermediateAllKeysList.unshift('default');
}
return intermediateAllKeysList;
};
componentDidUpdate(prevProps: TableListProps): void { componentDidUpdate(prevProps: TableListProps): void {
if (this.props.tableSource !== prevProps.tableSource) { if (this.props.tableSource !== prevProps.tableSource) {
this._updateTableSource(); this._updateTableSource();
...@@ -489,7 +522,8 @@ class TableList extends React.Component<TableListProps, TableListState> { ...@@ -489,7 +522,8 @@ class TableList extends React.Component<TableListProps, TableListState> {
selectedRowIds, selectedRowIds,
intermediateDialogTrial, intermediateDialogTrial,
copiedTrialId, copiedTrialId,
searchItems searchItems,
intermediateKeyList
} = this.state; } = this.state;
return ( return (
...@@ -564,6 +598,7 @@ class TableList extends React.Component<TableListProps, TableListState> { ...@@ -564,6 +598,7 @@ class TableList extends React.Component<TableListProps, TableListState> {
title='Intermediate results' title='Intermediate results'
showDetails={false} showDetails={false}
trials={[intermediateDialogTrial]} trials={[intermediateDialogTrial]}
intermediateKeyList={intermediateKeyList}
onHideDialog={(): void => { onHideDialog={(): void => {
this.setState({ intermediateDialogTrial: undefined }); this.setState({ intermediateDialogTrial: undefined });
}} }}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment