From a807bf51fae7314c5724b13fba1375b4281e861c Mon Sep 17 00:00:00 2001 From: v-liguo Date: Fri, 22 Nov 2019 15:43:59 +0800 Subject: [PATCH 1/4] Fix table sort issue --- src/webui/src/components/trial-detail/TableList.tsx | 12 +++++++----- src/webui/src/static/function.ts | 8 +++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/webui/src/components/trial-detail/TableList.tsx b/src/webui/src/components/trial-detail/TableList.tsx index 4b4856c50e..cdffb038b0 100644 --- a/src/webui/src/components/trial-detail/TableList.tsx +++ b/src/webui/src/components/trial-detail/TableList.tsx @@ -6,7 +6,10 @@ import { ColumnProps } from 'antd/lib/table'; const Option = Select.Option; const CheckboxGroup = Checkbox.Group; import { MANAGER_IP, trialJobStatus, COLUMN_INDEX, COLUMNPro } from '../../static/const'; -import { convertDuration, formatTimestamp, intermediateGraphOption, killJob } from '../../static/function'; +import { + convertDuration, formatTimestamp, intermediateGraphOption, + killJob, removeString +} from '../../static/function'; import { EXPERIMENT, TRIALS } from '../../static/datamodel'; import { TableRecord } from '../../static/interface'; import OpenRow from '../public-child/OpenRow'; @@ -586,12 +589,11 @@ const AccuracyColumnConfig: ColumnProps = { dataIndex: 'accuracy', width: 120, sorter: (a, b, sortOrder) => { - if (a.accuracy === undefined) { + if (a.latestAccuracy === '--' || b.latestAccuracy === '') { return sortOrder === 'ascend' ? -1 : 1; - } else if (b.accuracy === undefined) { - return sortOrder === 'ascend' ? 1 : -1; } else { - return a.accuracy - b.accuracy; + // remove (LATEST/FINAL) + return removeString(a.latestAccuracy) - removeString(b.latestAccuracy); } }, render: (text, record) => ( diff --git a/src/webui/src/static/function.ts b/src/webui/src/static/function.ts index be352ff35c..c1419e43cd 100644 --- a/src/webui/src/static/function.ts +++ b/src/webui/src/static/function.ts @@ -183,8 +183,14 @@ function formatAccuracy(accuracy: number): string { return accuracy.toFixed(6).replace(/0+$/, '').replace(/\.$/, ''); } +function removeString(val: string) { + if (val.endsWith('(FINAL)') || val.endsWith('(LATEST)')) { + return JSON.parse(val.replace(/\(FINAL\)|\(LATEST\)/, '')); + } +} + export { convertTime, convertDuration, getFinalResult, getFinal, downFile, intermediateGraphOption, killJob, filterByStatus, filterDuration, - formatAccuracy, formatTimestamp, metricAccuracy, + formatAccuracy, formatTimestamp, metricAccuracy, removeString }; From c0241219d5de9dd72af81b002f4f2d9a13d2a624 Mon Sep 17 00:00:00 2001 From: v-liguo Date: Mon, 25 Nov 2019 15:54:52 +0800 Subject: [PATCH 2/4] fix comments --- .../src/components/trial-detail/TableList.tsx | 15 ++++------ src/webui/src/static/interface.ts | 3 +- src/webui/src/static/model/trial.ts | 29 +++++++++++++++---- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/webui/src/components/trial-detail/TableList.tsx b/src/webui/src/components/trial-detail/TableList.tsx index cdffb038b0..ac6b6a9a67 100644 --- a/src/webui/src/components/trial-detail/TableList.tsx +++ b/src/webui/src/components/trial-detail/TableList.tsx @@ -6,10 +6,7 @@ import { ColumnProps } from 'antd/lib/table'; const Option = Select.Option; const CheckboxGroup = Checkbox.Group; import { MANAGER_IP, trialJobStatus, COLUMN_INDEX, COLUMNPro } from '../../static/const'; -import { - convertDuration, formatTimestamp, intermediateGraphOption, - killJob, removeString -} from '../../static/function'; +import { convertDuration, formatTimestamp, intermediateGraphOption, killJob } from '../../static/function'; import { EXPERIMENT, TRIALS } from '../../static/datamodel'; import { TableRecord } from '../../static/interface'; import OpenRow from '../public-child/OpenRow'; @@ -589,16 +586,16 @@ const AccuracyColumnConfig: ColumnProps = { dataIndex: 'accuracy', width: 120, sorter: (a, b, sortOrder) => { - if (a.latestAccuracy === '--' || b.latestAccuracy === '') { + if (a.latestAccuracy === undefined) { return sortOrder === 'ascend' ? -1 : 1; + } else if (b.latestAccuracy === undefined) { + return sortOrder === 'ascend' ? 1 : -1; } else { - // remove (LATEST/FINAL) - return removeString(a.latestAccuracy) - removeString(b.latestAccuracy); + return a.latestAccuracy - b.latestAccuracy; } }, render: (text, record) => ( - // TODO: is this needed? -
{record.latestAccuracy}
+
{record.formattedLatestAccuracy}
) }; diff --git a/src/webui/src/static/interface.ts b/src/webui/src/static/interface.ts index 44789ab7f0..dcde43da6f 100644 --- a/src/webui/src/static/interface.ts +++ b/src/webui/src/static/interface.ts @@ -24,7 +24,8 @@ interface TableRecord { status: string; intermediateCount: number; accuracy?: number; - latestAccuracy: string; // formatted string + latestAccuracy: number | undefined; + formattedLatestAccuracy: string; // format (LATEST/FINAL) } interface SearchSpace { diff --git a/src/webui/src/static/model/trial.ts b/src/webui/src/static/model/trial.ts index 58be735404..bcc1bc1c55 100644 --- a/src/webui/src/static/model/trial.ts +++ b/src/webui/src/static/model/trial.ts @@ -4,7 +4,7 @@ import { getFinal, formatAccuracy, metricAccuracy } from '../function'; class Trial implements TableObj { private metricsInitialized: boolean = false; private infoField: TrialJobInfo | undefined; - private intermediates: (MetricDataRecord | undefined)[] = [ ]; + private intermediates: (MetricDataRecord | undefined)[] = []; private final: MetricDataRecord | undefined; private finalAcc: number | undefined; @@ -27,7 +27,7 @@ class Trial implements TableObj { } get intermediateMetrics(): MetricDataRecord[] { - const ret: MetricDataRecord[] = [ ]; + const ret: MetricDataRecord[] = []; for (let i = 0; i < this.intermediates.length; i++) { if (this.intermediates[i]) { ret.push(this.intermediates[i]!); @@ -46,6 +46,22 @@ class Trial implements TableObj { return this.metricsInitialized && this.finalAcc !== undefined && !isNaN(this.finalAcc); } + get latestAccuracy(): number | undefined { + if (this.accuracy !== undefined) { + return this.accuracy; + } else if (this.intermediates.length > 0) { + // TODO: support intermeidate result is dict + const temp = this.intermediates[this.intermediates.length - 1]; + if (temp !== undefined) { + return JSON.parse(temp.data); + } else { + return undefined; + } + } else { + return undefined; + } + } + /* table obj start */ get tableRecord(): TableRecord { @@ -62,7 +78,8 @@ class Trial implements TableObj { status: this.info.status, intermediateCount: this.intermediates.length, accuracy: this.finalAcc, - latestAccuracy: this.formatLatestAccuracy(), + latestAccuracy: this.latestAccuracy, + formattedLatestAccuracy: this.formatLatestAccuracy(), }; } @@ -93,8 +110,8 @@ class Trial implements TableObj { get description(): Parameters { let ret: Parameters = { - parameters: { }, - intermediate: [ ], + parameters: {}, + intermediate: [], multiProgress: 1 }; const tempHyper = this.info.hyperParameters; @@ -113,7 +130,7 @@ class Trial implements TableObj { ret.logPath = this.info.logPath; } - const mediate: number[] = [ ]; + const mediate: number[] = []; for (const items of this.intermediateMetrics) { if (typeof JSON.parse(items.data) === 'object') { mediate.push(JSON.parse(items.data).default); From fbfae66968792af4623de41644375c3aa3a280ff Mon Sep 17 00:00:00 2001 From: v-liguo Date: Mon, 25 Nov 2019 15:59:36 +0800 Subject: [PATCH 3/4] format --- src/webui/src/static/function.ts | 8 +------- src/webui/src/static/model/trial.ts | 10 +++++----- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/webui/src/static/function.ts b/src/webui/src/static/function.ts index c1419e43cd..2c7b7283e5 100644 --- a/src/webui/src/static/function.ts +++ b/src/webui/src/static/function.ts @@ -183,14 +183,8 @@ function formatAccuracy(accuracy: number): string { return accuracy.toFixed(6).replace(/0+$/, '').replace(/\.$/, ''); } -function removeString(val: string) { - if (val.endsWith('(FINAL)') || val.endsWith('(LATEST)')) { - return JSON.parse(val.replace(/\(FINAL\)|\(LATEST\)/, '')); - } -} - export { convertTime, convertDuration, getFinalResult, getFinal, downFile, intermediateGraphOption, killJob, filterByStatus, filterDuration, - formatAccuracy, formatTimestamp, metricAccuracy, removeString + formatAccuracy, formatTimestamp, metricAccuracy }; diff --git a/src/webui/src/static/model/trial.ts b/src/webui/src/static/model/trial.ts index bcc1bc1c55..e0a399c46d 100644 --- a/src/webui/src/static/model/trial.ts +++ b/src/webui/src/static/model/trial.ts @@ -4,7 +4,7 @@ import { getFinal, formatAccuracy, metricAccuracy } from '../function'; class Trial implements TableObj { private metricsInitialized: boolean = false; private infoField: TrialJobInfo | undefined; - private intermediates: (MetricDataRecord | undefined)[] = []; + private intermediates: (MetricDataRecord | undefined)[] = [ ]; private final: MetricDataRecord | undefined; private finalAcc: number | undefined; @@ -27,7 +27,7 @@ class Trial implements TableObj { } get intermediateMetrics(): MetricDataRecord[] { - const ret: MetricDataRecord[] = []; + const ret: MetricDataRecord[] = [ ]; for (let i = 0; i < this.intermediates.length; i++) { if (this.intermediates[i]) { ret.push(this.intermediates[i]!); @@ -110,8 +110,8 @@ class Trial implements TableObj { get description(): Parameters { let ret: Parameters = { - parameters: {}, - intermediate: [], + parameters: { }, + intermediate: [ ], multiProgress: 1 }; const tempHyper = this.info.hyperParameters; @@ -130,7 +130,7 @@ class Trial implements TableObj { ret.logPath = this.info.logPath; } - const mediate: number[] = []; + const mediate: number[] = [ ]; for (const items of this.intermediateMetrics) { if (typeof JSON.parse(items.data) === 'object') { mediate.push(JSON.parse(items.data).default); From 09752de15bd38dc18eb66c85ae4080aa082f86c8 Mon Sep 17 00:00:00 2001 From: v-liguo Date: Mon, 25 Nov 2019 17:29:19 +0800 Subject: [PATCH 4/4] fix comments again --- src/webui/src/components/trial-detail/TableList.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/webui/src/components/trial-detail/TableList.tsx b/src/webui/src/components/trial-detail/TableList.tsx index ac6b6a9a67..e048d24cbe 100644 --- a/src/webui/src/components/trial-detail/TableList.tsx +++ b/src/webui/src/components/trial-detail/TableList.tsx @@ -587,9 +587,9 @@ const AccuracyColumnConfig: ColumnProps = { width: 120, sorter: (a, b, sortOrder) => { if (a.latestAccuracy === undefined) { - return sortOrder === 'ascend' ? -1 : 1; - } else if (b.latestAccuracy === undefined) { return sortOrder === 'ascend' ? 1 : -1; + } else if (b.latestAccuracy === undefined) { + return sortOrder === 'ascend' ? -1 : 1; } else { return a.latestAccuracy - b.latestAccuracy; }