From 9aed500db2af917d700a2e64dd2e30b3da61804a Mon Sep 17 00:00:00 2001 From: Lijiao <35484733+lvybriage@users.noreply.github.com> Date: Tue, 26 Nov 2019 10:26:44 +0800 Subject: [PATCH] Fix table sort issue (#1773) --- .../src/components/trial-detail/TableList.tsx | 11 +++++------ src/webui/src/static/function.ts | 2 +- src/webui/src/static/interface.ts | 3 ++- src/webui/src/static/model/trial.ts | 19 ++++++++++++++++++- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/webui/src/components/trial-detail/TableList.tsx b/src/webui/src/components/trial-detail/TableList.tsx index 4b4856c50e..e048d24cbe 100644 --- a/src/webui/src/components/trial-detail/TableList.tsx +++ b/src/webui/src/components/trial-detail/TableList.tsx @@ -586,17 +586,16 @@ const AccuracyColumnConfig: ColumnProps = { dataIndex: 'accuracy', width: 120, sorter: (a, b, sortOrder) => { - if (a.accuracy === undefined) { - return sortOrder === 'ascend' ? -1 : 1; - } else if (b.accuracy === undefined) { + if (a.latestAccuracy === undefined) { return sortOrder === 'ascend' ? 1 : -1; + } else if (b.latestAccuracy === undefined) { + return sortOrder === 'ascend' ? -1 : 1; } else { - return a.accuracy - b.accuracy; + return a.latestAccuracy - b.latestAccuracy; } }, render: (text, record) => ( - // TODO: is this needed? -
{record.latestAccuracy}
+
{record.formattedLatestAccuracy}
) }; diff --git a/src/webui/src/static/function.ts b/src/webui/src/static/function.ts index be352ff35c..2c7b7283e5 100644 --- a/src/webui/src/static/function.ts +++ b/src/webui/src/static/function.ts @@ -186,5 +186,5 @@ function formatAccuracy(accuracy: number): string { export { convertTime, convertDuration, getFinalResult, getFinal, downFile, intermediateGraphOption, killJob, filterByStatus, filterDuration, - formatAccuracy, formatTimestamp, metricAccuracy, + formatAccuracy, formatTimestamp, metricAccuracy }; diff --git a/src/webui/src/static/interface.ts b/src/webui/src/static/interface.ts index 6e6f5a2620..99b06c7e68 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..e0a399c46d 100644 --- a/src/webui/src/static/model/trial.ts +++ b/src/webui/src/static/model/trial.ts @@ -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(), }; }