Commit ce1bc481 authored by Lijiao's avatar Lijiao Committed by fishyds
Browse files

[WebUI] Fix issue#517 & issue#459 (#524)

* [WebUI] Fix issue#517 & issue#459

* update
parent cb83ac0f
import * as React from 'react'; import * as React from 'react';
import axios from 'axios'; import axios from 'axios';
import { MANAGER_IP } from '../static/const'; import { MANAGER_IP } from '../static/const';
import { Row, Col, Button, Tabs, Input } from 'antd'; import { Row, Col, Tabs, Input, Select } from 'antd';
const Search = Input.Search; const Option = Select.Option;
import { TableObj, Parameters, DetailAccurPoint, TooltipForAccuracy } from '../static/interface'; import { TableObj, Parameters, DetailAccurPoint, TooltipForAccuracy } from '../static/interface';
import { getFinalResult } from '../static/function'; import { getFinalResult } from '../static/function';
import Accuracy from './overview/Accuracy'; import Accuracy from './overview/Accuracy';
...@@ -17,8 +17,10 @@ interface TrialDetailState { ...@@ -17,8 +17,10 @@ interface TrialDetailState {
accSource: object; accSource: object;
accNodata: string; accNodata: string;
tableListSource: Array<TableObj>; tableListSource: Array<TableObj>;
tableBaseSource: Array<TableObj>; searchResultSource: Array<TableObj>;
isHasSearch: boolean;
experimentStatus: string; experimentStatus: string;
entriesTable: number;
} }
class TrialsDetail extends React.Component<{}, TrialDetailState> { class TrialsDetail extends React.Component<{}, TrialDetailState> {
...@@ -26,6 +28,7 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> { ...@@ -26,6 +28,7 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> {
public _isMounted = false; public _isMounted = false;
public interAccuracy = 0; public interAccuracy = 0;
public interTableList = 1; public interTableList = 1;
public interAllTableList = 2;
constructor(props: {}) { constructor(props: {}) {
super(props); super(props);
...@@ -34,8 +37,10 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> { ...@@ -34,8 +37,10 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> {
accSource: {}, accSource: {},
accNodata: '', accNodata: '',
tableListSource: [], tableListSource: [],
tableBaseSource: [], searchResultSource: [],
experimentStatus: '' experimentStatus: '',
entriesTable: 20,
isHasSearch: false
}; };
} }
// trial accuracy graph // trial accuracy graph
...@@ -122,6 +127,91 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> { ...@@ -122,6 +127,91 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> {
} }
drawTableList = () => { drawTableList = () => {
this.isOffIntervals();
axios.get(`${MANAGER_IP}/trial-jobs`)
.then(res => {
if (res.status === 200) {
const trialJobs = res.data;
const trialTable: Array<TableObj> = [];
Object.keys(trialJobs).map(item => {
// only succeeded trials have finalMetricData
let desc: Parameters = {
parameters: {}
};
let duration = 0;
const id = trialJobs[item].id !== undefined
? trialJobs[item].id
: '';
const status = trialJobs[item].status !== undefined
? trialJobs[item].status
: '';
const begin = trialJobs[item].startTime;
const end = trialJobs[item].endTime;
if (begin) {
if (end) {
duration = (end - begin) / 1000;
} else {
duration = (new Date().getTime() - begin) / 1000;
}
}
if (trialJobs[item].hyperParameters !== undefined) {
const getPara = JSON.parse(trialJobs[item].hyperParameters[0]).parameters;
if (typeof getPara === 'string') {
desc.parameters = JSON.parse(getPara);
} else {
desc.parameters = getPara;
}
} else {
desc.parameters = { error: 'This trial\'s parameters are not available.' };
}
if (trialJobs[item].logPath !== undefined) {
desc.logPath = trialJobs[item].logPath;
}
const acc = getFinalResult(trialJobs[item].finalMetricData);
trialTable.push({
key: trialTable.length,
sequenceId: trialJobs[item].sequenceId,
id: id,
status: status,
duration: duration,
acc: acc,
description: desc
});
});
// search part data
const { searchResultSource } = this.state;
if (searchResultSource.length !== 0) {
const temp: Array<number> = [];
Object.keys(searchResultSource).map(index => {
temp.push(searchResultSource[index].id);
});
const searchResultList: Array<TableObj> = [];
for (let i = 0; i < temp.length; i++) {
Object.keys(trialTable).map(key => {
const item = trialTable[key];
if (item.id === temp[i]) {
searchResultList.push(item);
}
});
}
if (this._isMounted) {
this.setState(() => ({
searchResultSource: searchResultList
}));
}
}
if (this._isMounted) {
this.setState(() => ({
tableListSource: trialTable
}));
}
}
});
}
// update all data in table
drawAllTableList = () => {
this.isOffIntervals(); this.isOffIntervals();
axios.get(`${MANAGER_IP}/trial-jobs`) axios.get(`${MANAGER_IP}/trial-jobs`)
.then(res => { .then(res => {
...@@ -176,7 +266,7 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> { ...@@ -176,7 +266,7 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> {
if (this._isMounted) { if (this._isMounted) {
this.setState(() => ({ this.setState(() => ({
tableListSource: trialTable, tableListSource: trialTable,
tableBaseSource: trialTable searchResultSource: trialTable
})); }));
} }
} }
...@@ -209,31 +299,29 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> { ...@@ -209,31 +299,29 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> {
} }
} }
// search a specific trial by trial No. // search a trial by trial No. & trial id
searchTrial = (value: string) => { searchTrial = (event: React.ChangeEvent<HTMLInputElement>) => {
window.clearInterval(this.interTableList); const targetValue = event.target.value;
const { tableBaseSource } = this.state; if (targetValue === '' || targetValue === ' ') {
this.drawAllTableList();
this.interAllTableList = window.setInterval(this.drawAllTableList, 10000);
} else {
window.clearInterval(this.interAllTableList);
const { tableListSource } = this.state;
const searchResultList: Array<TableObj> = []; const searchResultList: Array<TableObj> = [];
Object.keys(tableBaseSource).map(key => { Object.keys(tableListSource).map(key => {
const item = tableBaseSource[key]; const item = tableListSource[key];
if (item.sequenceId.toString() === value || item.id.includes(value)) { if (item.sequenceId.toString() === targetValue || item.id.includes(targetValue)) {
searchResultList.push(item); searchResultList.push(item);
} }
}); });
if (this._isMounted) {
this.setState(() => ({ this.setState(() => ({
tableListSource: searchResultList searchResultSource: searchResultList,
isHasSearch: true
})); }));
} }
// reset btn click: rerender table
resetRenderTable = () => {
const searchInput = document.getElementById('searchTrial') as HTMLInputElement;
if (searchInput !== null) {
searchInput.value = '';
} }
this.drawTableList();
this.interTableList = window.setInterval(this.drawTableList, 10000);
} }
isOffIntervals = () => { isOffIntervals = () => {
...@@ -250,6 +338,7 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> { ...@@ -250,6 +338,7 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> {
window.clearInterval(this.interTableList); window.clearInterval(this.interTableList);
window.clearInterval(Duration.intervalDuration); window.clearInterval(Duration.intervalDuration);
window.clearInterval(Para.intervalIDPara); window.clearInterval(Para.intervalIDPara);
window.clearInterval(this.interAllTableList);
break; break;
default: default:
} }
...@@ -257,13 +346,31 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> { ...@@ -257,13 +346,31 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> {
}); });
} }
handleEntriesSelect = (value: string) => {
switch (value) {
case '20':
this.setState(() => ({ entriesTable: 20 }));
break;
case '50':
this.setState(() => ({ entriesTable: 50 }));
break;
case '100':
this.setState(() => ({ entriesTable: 100 }));
break;
case 'all':
this.setState(() => ({ entriesTable: 100000 }));
break;
default:
}
}
componentDidMount() { componentDidMount() {
this._isMounted = true; this._isMounted = true;
this.drawTableList(); this.drawTableList();
this.drawPointGraph(); this.drawPointGraph();
this.interAccuracy = window.setInterval(this.drawPointGraph, 10000);
this.interTableList = window.setInterval(this.drawTableList, 10000); this.interTableList = window.setInterval(this.drawTableList, 10000);
this.interAccuracy = window.setInterval(this.drawPointGraph, 10000);
} }
componentWillUnmount() { componentWillUnmount() {
...@@ -273,11 +380,7 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> { ...@@ -273,11 +380,7 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> {
} }
render() { render() {
const { const { accSource, accNodata, tableListSource, entriesTable, searchResultSource, isHasSearch } = this.state;
accSource, accNodata,
tableListSource
} = this.state;
const titleOfacc = ( const titleOfacc = (
<Title1 text="Default Metric" icon="3.png" /> <Title1 text="Default Metric" icon="3.png" />
); );
...@@ -309,29 +412,38 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> { ...@@ -309,29 +412,38 @@ class TrialsDetail extends React.Component<{}, TrialDetailState> {
</Tabs> </Tabs>
</div> </div>
{/* trial table list */} {/* trial table list */}
<Title1 text="All Trials" icon="6.png" />
<Row className="allList"> <Row className="allList">
<Col span={12}> <Col span={12}>
<Title1 text="All Trials" icon="6.png" /> <span>show</span>
<Select
className="entry"
onSelect={this.handleEntriesSelect}
defaultValue="20"
>
<Option value="20">20</Option>
<Option value="50">50</Option>
<Option value="100">100</Option>
<Option value="all">All</Option>
</Select>
<span>entries</span>
</Col> </Col>
<Col span={12} className="btns"> <Col span={12} className="right">
<Search {/* <span>Search:</span> */}
<Input
type="text"
placeholder="search by Trial No. and id" placeholder="search by Trial No. and id"
onSearch={value => this.searchTrial(value)} onChange={this.searchTrial}
style={{ width: 200 }} style={{ width: 200, marginLeft: 6 }}
id="searchTrial"
/> />
<Button
type="primary"
className="tableButton resetBtn"
onClick={this.resetRenderTable}
>
Reset
</Button>
</Col> </Col>
</Row> </Row>
<TableList <TableList
entries={entriesTable}
tableSource={tableListSource} tableSource={tableListSource}
updateList={this.drawTableList} updateList={this.drawTableList}
searchResult={searchResultSource}
isHasSearch={isHasSearch}
/> />
</div> </div>
); );
......
...@@ -21,8 +21,11 @@ echarts.registerTheme('my_theme', { ...@@ -21,8 +21,11 @@ echarts.registerTheme('my_theme', {
}); });
interface TableListProps { interface TableListProps {
entries: number;
tableSource: Array<TableObj>; tableSource: Array<TableObj>;
searchResult: Array<TableObj>;
updateList: Function; updateList: Function;
isHasSearch: boolean;
} }
interface TableListState { interface TableListState {
...@@ -150,7 +153,7 @@ class TableList extends React.Component<TableListProps, TableListState> { ...@@ -150,7 +153,7 @@ class TableList extends React.Component<TableListProps, TableListState> {
render() { render() {
const { tableSource } = this.props; const { entries, tableSource, searchResult, isHasSearch } = this.props;
const { intermediateOption, modalVisible } = this.state; const { intermediateOption, modalVisible } = this.state;
let bgColor = ''; let bgColor = '';
const trialJob: Array<TrialJob> = []; const trialJob: Array<TrialJob> = [];
...@@ -160,6 +163,7 @@ class TableList extends React.Component<TableListProps, TableListState> { ...@@ -160,6 +163,7 @@ class TableList extends React.Component<TableListProps, TableListState> {
value: item value: item
}); });
}); });
const columns = [{ const columns = [{
title: 'Trial No.', title: 'Trial No.',
dataIndex: 'sequenceId', dataIndex: 'sequenceId',
...@@ -328,7 +332,7 @@ class TableList extends React.Component<TableListProps, TableListState> { ...@@ -328,7 +332,7 @@ class TableList extends React.Component<TableListProps, TableListState> {
<span className="error">'This trial's parameters are not available.'</span> <span className="error">'This trial's parameters are not available.'</span>
</div> </div>
} }
<LogPath logStr={logPathRow}/> <LogPath logStr={logPathRow} />
</pre> </pre>
); );
}; };
...@@ -339,9 +343,9 @@ class TableList extends React.Component<TableListProps, TableListState> { ...@@ -339,9 +343,9 @@ class TableList extends React.Component<TableListProps, TableListState> {
<Table <Table
columns={columns} columns={columns}
expandedRowRender={openRow} expandedRowRender={openRow}
dataSource={tableSource} dataSource={isHasSearch ? searchResult : tableSource}
className="commonTableStyle" className="commonTableStyle"
pagination={{ pageSize: 20 }} pagination={{ pageSize: entries }}
/> />
<Modal <Modal
title="Intermediate Result" title="Intermediate Result"
......
.allList{ .allList{
background-color: #b3b3b3; width: 96%;
padding-right: 14px; margin: 0 auto;
.right{
text-align: right;
}
.entry{
width: 120px;
margin: 0 6px;
}
.btns{ .btns{
height: 32px; height: 32px;
text-align: right; text-align: right;
...@@ -8,12 +15,6 @@ ...@@ -8,12 +15,6 @@
height: 32px; height: 32px;
} }
} }
Button.resetBtn{
height: 32px;
font-size: 15px;
position: relative;
top: 1px;
}
} }
...@@ -66,3 +66,7 @@ ...@@ -66,3 +66,7 @@
margin-bottom: 10px; margin-bottom: 10px;
} }
} }
.allList{
margin-top: 15px;
}
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