From 42a3a8e24579610ab2c2006024db2d535a1403df Mon Sep 17 00:00:00 2001 From: Lijiao <15910218274@163.com> Date: Sun, 16 Feb 2020 12:56:08 +0000 Subject: [PATCH 1/4] Use JSON5 to parse json --- src/webui/src/components/trial-detail/TableList.tsx | 5 +++-- src/webui/src/static/function.ts | 6 ++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/webui/src/components/trial-detail/TableList.tsx b/src/webui/src/components/trial-detail/TableList.tsx index 28e5d76aa0..9f245207fe 100644 --- a/src/webui/src/components/trial-detail/TableList.tsx +++ b/src/webui/src/components/trial-detail/TableList.tsx @@ -5,6 +5,7 @@ import { Stack, Dropdown, DetailsList, IDetailsListProps, DetailsListLayoutMode, PrimaryButton, Modal, IDropdownOption, IColumn, Selection, SelectionMode, IconButton } from 'office-ui-fabric-react'; +import * as JSON5 from 'json5'; import { LineChart, blocked, copy } from '../Buttons/Icon'; import { MANAGER_IP, COLUMNPro } from '../../static/const'; import { convertDuration, formatTimestamp, intermediateGraphOption, parseMetrics } from '../../static/function'; @@ -377,7 +378,7 @@ class TableList extends React.Component { // trial parameters & dict final keys & Trial No. Id ... private getAllColumnKeys = (): string[] => { - const tableSource: Array = JSON.parse(JSON.stringify(this.props.tableSource)); + const tableSource: Array = JSON5.parse(JSON5.stringify(this.props.tableSource)); // parameter as table column const parameterStr: string[] = []; if (tableSource.length > 0) { @@ -545,7 +546,7 @@ class TableList extends React.Component { isShowCustomizedModal, copyTrialId, intermediateOption } = this.state; const { columnList } = this.props; - const tableSource: Array = JSON.parse(JSON.stringify(this.state.tableSourceForSort)); + const tableSource: Array = JSON5.parse(JSON5.stringify(this.state.tableSourceForSort)); return ( diff --git a/src/webui/src/static/function.ts b/src/webui/src/static/function.ts index 32f64a78c8..71848cef20 100644 --- a/src/webui/src/static/function.ts +++ b/src/webui/src/static/function.ts @@ -43,7 +43,7 @@ const getFinalResult = (final?: MetricDataRecord[]): number => { let acc; let showDefault = 0; if (final) { - acc = JSON.parse(final[final.length - 1].data); + acc = JSON5.parse(final[final.length - 1].data); if (typeof (acc) === 'object') { if (acc.default) { showDefault = acc.default; @@ -61,7 +61,7 @@ const getFinalResult = (final?: MetricDataRecord[]): number => { const getFinal = (final?: MetricDataRecord[]): FinalType | undefined => { let showDefault: FinalType; if (final) { - showDefault = JSON.parse(final[final.length - 1].data); + showDefault = JSON5.parse(final[final.length - 1].data); if (typeof showDefault === 'number') { showDefault = { default: showDefault }; } @@ -182,8 +182,6 @@ function formatTimestamp(timestamp?: number, placeholder?: string): string { function parseMetrics(metricData: string): any { if (metricData.includes('NaN')) { return JSON5.parse(metricData) - } else { - return JSON.parse(metricData) } } From 5a8e56e7e18361c4cbaa3e382dd2995f81bd940b Mon Sep 17 00:00:00 2001 From: Lijiao <15910218274@163.com> Date: Mon, 17 Feb 2020 09:28:29 +0000 Subject: [PATCH 2/4] fix chengmin comments --- src/webui/src/static/function.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/webui/src/static/function.ts b/src/webui/src/static/function.ts index 71848cef20..df3ae40992 100644 --- a/src/webui/src/static/function.ts +++ b/src/webui/src/static/function.ts @@ -43,7 +43,7 @@ const getFinalResult = (final?: MetricDataRecord[]): number => { let acc; let showDefault = 0; if (final) { - acc = JSON5.parse(final[final.length - 1].data); + acc = parseMetrics(final[final.length - 1].data); if (typeof (acc) === 'object') { if (acc.default) { showDefault = acc.default; @@ -181,7 +181,9 @@ function formatTimestamp(timestamp?: number, placeholder?: string): string { function parseMetrics(metricData: string): any { if (metricData.includes('NaN')) { - return JSON5.parse(metricData) + return JSON5.parse(metricData); + } else { + return JSON.parse(metricData); } } From 6626efe323bb9ab4a2590106f6441c145dba007b Mon Sep 17 00:00:00 2001 From: Lijiao <15910218274@163.com> Date: Mon, 17 Feb 2020 12:15:35 +0000 Subject: [PATCH 3/4] update --- src/webui/src/components/trial-detail/TableList.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/webui/src/components/trial-detail/TableList.tsx b/src/webui/src/components/trial-detail/TableList.tsx index 9f245207fe..8738841f47 100644 --- a/src/webui/src/components/trial-detail/TableList.tsx +++ b/src/webui/src/components/trial-detail/TableList.tsx @@ -547,6 +547,7 @@ class TableList extends React.Component { } = this.state; const { columnList } = this.props; const tableSource: Array = JSON5.parse(JSON5.stringify(this.state.tableSourceForSort)); + console.info(tableSource); // eslint-disable-line return ( From 3ab9e0c69c10032ee00e185423d62915b0724892 Mon Sep 17 00:00:00 2001 From: Lijiao <15910218274@163.com> Date: Mon, 17 Feb 2020 12:36:29 +0000 Subject: [PATCH 4/4] change json5 to json --- .../src/components/trial-detail/TableList.tsx | 6 ++---- src/webui/src/static/function.ts | 18 +++++++++--------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/webui/src/components/trial-detail/TableList.tsx b/src/webui/src/components/trial-detail/TableList.tsx index 8738841f47..28e5d76aa0 100644 --- a/src/webui/src/components/trial-detail/TableList.tsx +++ b/src/webui/src/components/trial-detail/TableList.tsx @@ -5,7 +5,6 @@ import { Stack, Dropdown, DetailsList, IDetailsListProps, DetailsListLayoutMode, PrimaryButton, Modal, IDropdownOption, IColumn, Selection, SelectionMode, IconButton } from 'office-ui-fabric-react'; -import * as JSON5 from 'json5'; import { LineChart, blocked, copy } from '../Buttons/Icon'; import { MANAGER_IP, COLUMNPro } from '../../static/const'; import { convertDuration, formatTimestamp, intermediateGraphOption, parseMetrics } from '../../static/function'; @@ -378,7 +377,7 @@ class TableList extends React.Component { // trial parameters & dict final keys & Trial No. Id ... private getAllColumnKeys = (): string[] => { - const tableSource: Array = JSON5.parse(JSON5.stringify(this.props.tableSource)); + const tableSource: Array = JSON.parse(JSON.stringify(this.props.tableSource)); // parameter as table column const parameterStr: string[] = []; if (tableSource.length > 0) { @@ -546,8 +545,7 @@ class TableList extends React.Component { isShowCustomizedModal, copyTrialId, intermediateOption } = this.state; const { columnList } = this.props; - const tableSource: Array = JSON5.parse(JSON5.stringify(this.state.tableSourceForSort)); - console.info(tableSource); // eslint-disable-line + const tableSource: Array = JSON.parse(JSON.stringify(this.state.tableSourceForSort)); return ( diff --git a/src/webui/src/static/function.ts b/src/webui/src/static/function.ts index df3ae40992..8177ec1f54 100644 --- a/src/webui/src/static/function.ts +++ b/src/webui/src/static/function.ts @@ -37,6 +37,14 @@ const convertDuration = (num: number): string => { return result.join(' '); }; +function parseMetrics(metricData: string): any { + if (metricData.includes('NaN')) { + return JSON5.parse(JSON5.parse(metricData)); + } else { + return JSON.parse(JSON.parse(metricData)); + } +} + // get final result value // draw Accuracy point graph const getFinalResult = (final?: MetricDataRecord[]): number => { @@ -61,7 +69,7 @@ const getFinalResult = (final?: MetricDataRecord[]): number => { const getFinal = (final?: MetricDataRecord[]): FinalType | undefined => { let showDefault: FinalType; if (final) { - showDefault = JSON5.parse(final[final.length - 1].data); + showDefault = parseMetrics(final[final.length - 1].data); if (typeof showDefault === 'number') { showDefault = { default: showDefault }; } @@ -179,14 +187,6 @@ function formatTimestamp(timestamp?: number, placeholder?: string): string { return timestamp ? new Date(timestamp).toLocaleString('en-US') : placeholder; } -function parseMetrics(metricData: string): any { - if (metricData.includes('NaN')) { - return JSON5.parse(metricData); - } else { - return JSON.parse(metricData); - } -} - function metricAccuracy(metric: MetricDataRecord): number { const data = parseMetrics(metric.data); return typeof data === 'number' ? data : NaN;