Skip to content

Commit

Permalink
[Hotfix] Fix the function that convert ms (#3069)
Browse files Browse the repository at this point in the history
(cherry picked from commit a550103)
Signed-off-by: zhoujinsong <[email protected]>
  • Loading branch information
chouchouji authored and zhoujinsong committed Oct 11, 2024
1 parent b0a1488 commit f3868db
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 52 deletions.
1 change: 1 addition & 0 deletions amoro-ams/amoro-ams-dashboard/src/types/common.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export interface IOptimizeTableItem {
quotaOccupationDesc: string
duration: number
durationDesc: string
durationDisplay: string
fileSizeDesc: string
tableIdentifier: ITableIdentifier
tableNameOnly?: string
Expand Down
70 changes: 26 additions & 44 deletions amoro-ams/amoro-ams-dashboard/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,51 +57,33 @@ export function mbToSize(size: number): string {
/**
* Convert ms to d h min s
*/
export function formatMS2Time(time: number, fromHour?: boolean): string {
if (time === null || time === undefined || Number.isNaN(time)) {
return '-'
}
// 3h 34min 12s
const Second = 1000
const Minute = Second * 60
const Hour = Minute * 60
const Day = Hour * 24
if (time === 0) {
return '0 ms'
}
if (time < Second) {
return fromHour ? '0 min ' : `${time} ms`
}
if (time >= Second && time < Minute) {
const s = Math.floor(time / Second)
if (fromHour) {
return '0 min'
}
return s ? `${s} s` : ''
}
if (time >= Minute && time < Hour) {
const calcMin = Math.floor(time / Minute)
const s = Math.floor((time - calcMin * Minute) / Second)
if (fromHour) {
return `${calcMin} min`
}
else {
return time % Minute === 0 ? `${time / Minute} min` : `${calcMin} min ${s ? `${s} s` : ''}`
}
}
if (time % Hour === 0) {
return `${time / Hour} h`
}
if (time >= Hour && time < Day) {
const calcHour = Math.floor(time / Hour)
return `${calcHour} h ${formatMS2Time(time - calcHour * Hour, true)}`
}
if (time % Day === 0) {
return `${time / Day} d`
}
export function formatMS2Time(ms: number): string {
const secondsInMs = 1000
const minutesInMs = secondsInMs * 60
const hoursInMs = minutesInMs * 60
const daysInMs = hoursInMs * 24

const days = Math.floor(ms / daysInMs)
ms %= daysInMs

const hours = Math.floor(ms / hoursInMs)
ms %= hoursInMs

const minutes = Math.floor(ms / minutesInMs)
ms %= minutesInMs

const seconds = Math.floor(ms / secondsInMs)

const times = [
{ value: days, unit: 'd' },
{ value: hours, unit: 'h' },
{ value: minutes, unit: 'min' },
{ value: seconds, unit: 's' },
]

const calcDay = Math.floor(time / Day)
return `${calcDay} d ${formatMS2Time(time - calcDay * Day, true)}`
return times.reduce((pre: string, cur: { value: number, unit: string }) => {
return cur.value > 0 ? `${pre}${cur.value} ${cur.unit} ` : pre
}, '')
}
/**
* Convert milliseconds to d h min s format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ async function getTableList() {
pagination.total = total;
(list || []).forEach((p: IOptimizeTableItem) => {
p.quotaOccupationDesc = p.quotaOccupation - 0.0005 > 0 ? `${(p.quotaOccupation * 100).toFixed(1)}%` : '0'
p.durationDesc = formatMS2Time(p.duration || 0) as string
(p as any).durationDisplay = formatMS2DisplayTime(p.duration || 0)
p.durationDesc = p.duration ? formatMS2Time(p.duration) : '-'
p.durationDisplay = formatMS2DisplayTime(p.duration || 0)
p.fileSizeDesc = bytesToSize(p.fileSize)
dataSource.push(p)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ const groupRecord = ref<IIOptimizeGroupItem>({
container: '',
resourceOccupation: '',
})
const scaleOutViseble = ref<boolean>(false)
const scaleOutVisible = ref<boolean>(false)
function scaleOutGroup(record: IIOptimizeGroupItem) {
if (record.container === 'external') {
return
}
groupRecord.value = { ...record }
scaleOutViseble.value = true
scaleOutVisible.value = true
}
function changeTable({ current = pagination.current, pageSize = pagination.pageSize }) {
Expand All @@ -221,7 +221,10 @@ onMounted(() => {
<template>
<div class="list-wrap">
<a-table
class="ant-table-common" :columns="columns" :data-source="dataSource" :pagination="pagination"
class="ant-table-common"
:columns="columns"
:data-source="dataSource"
:pagination="pagination"
:loading="loading" @change="changeTable"
>
<template #bodyCell="{ column, record }">
Expand Down Expand Up @@ -262,7 +265,7 @@ onMounted(() => {
</template>
</a-table>
</div>
<ScaleOut v-if="scaleOutViseble" :group-record="groupRecord" @cancel="scaleOutViseble = false" @refresh="refresh" />
<ScaleOut v-if="scaleOutVisible" :group-record="groupRecord" @cancel="scaleOutVisible = false" @refresh="refresh" />
<u-loading v-if="releaseLoading" />
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async function refreshOptimizingProcesses() {
startTime: item.startTime ? dateFormat(item.startTime) : '-',
finishTime: item.finishTime ? dateFormat(item.finishTime) : '-',
optimizingType: item.optimizingType ? item.optimizingType : '-',
duration: formatMS2Time(item.duration || '-'),
duration: item.duration ? formatMS2Time(item.duration) : '-',
inputFiles: `${bytesToSize(inputFiles.totalSize)} / ${inputFiles.fileCnt}`,
outputFiles: `${bytesToSize(outputFiles.totalSize)} / ${outputFiles.fileCnt}`,
tasks: `${item.successTasks || '0'} / ${item.totalTasks || '0'}${item.runningTasks ? ` (${item.runningTasks} running)` : ''}`,
Expand Down Expand Up @@ -186,7 +186,7 @@ async function refreshOptimizingTasks() {
list.forEach((p: BreadcrumbOptimizingItem) => {
p.startTime = p.startTime ? dateFormat(p.startTime) : '-'
p.endTime = p.endTime ? dateFormat(p.endTime) : '-'
p.formatCostTime = formatMS2Time(p.costTime)
p.formatCostTime = p.costTime ? formatMS2Time(p.costTime) : '-'
p.thread = p.optimizerToken ? `(${p.threadId})${p.optimizerToken}` : '-'
p.partitionData = p.partitionData ? p.partitionData : '-'
p.inputFilesDesc = `${bytesToSize(p.inputFiles.totalSize)} / ${p.inputFiles.fileCnt}`
Expand Down

0 comments on commit f3868db

Please sign in to comment.