Skip to content

Commit

Permalink
fix: Correct time conversion in ProfileOverview component
Browse files Browse the repository at this point in the history
  • Loading branch information
Maricaya committed Oct 9, 2024
1 parent b49a97a commit 220d421
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 32 deletions.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@types/react-dom": "^18.3.0",
"antd": "^5.19.1",
"lodash-es": "^4.17.21",
"pretty-ms": "^9.1.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-scripts": "5.0.1",
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/ProfileOverview.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import prettyMilliseconds from 'pretty-ms';

import { IOverview } from '../types/ProfileGraphDashboard';
import { filterMillisecond } from '../utills';

interface ProfileOverviewProps {
overviewInfo?: IOverview;
queryDuration?: number;
Expand All @@ -21,7 +22,7 @@ const ProfileOverview: React.FC<ProfileOverviewProps> = ({
<div className="expensive-nodes-node">
<div className="expensive-nodes-node-name">Total Execution Time</div>
<div className="expensive-nodes-node-percentage">
({filterMillisecond(Math.floor(queryDuration/1000/60/24))})
({prettyMilliseconds(Math.floor(queryDuration/1000/60/24))})
{overviewInfo?.totalTimePercent}
</div>
</div>
Expand Down
30 changes: 0 additions & 30 deletions frontend/src/utills/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,6 @@ export function getPercent(numerator: number, denominator: number): string {
return `${percent.toFixed(1)}%`;
}

/**
* Formats a given millisecond value into a human-readable time format.
* @param {number} milliseconds - The value in milliseconds to be formatted.
* @returns {string} - The formatted time string.
*/
export function filterMillisecond(milliseconds: number): string {
if (typeof milliseconds !== 'number' || isNaN(milliseconds) || milliseconds < 0) {
return "Invalid Input"; // Return error message for invalid input
}

if (milliseconds < 1000) {
// Less than 1 second, show in milliseconds
return `${milliseconds} ms`;
} else if (milliseconds < 60000) {
// Less than 1 minute, show in seconds (up to two decimal places)
const seconds = (milliseconds / 1000).toFixed(2);
return `${seconds} s`;
} else if (milliseconds < 3600000) {
// Less than 1 hour, show in minutes and seconds
const minutes = Math.floor(milliseconds / 60000);
const seconds = ((milliseconds % 60000) / 1000).toFixed(2);
return `${minutes} min ${seconds} s`;
} else {
// More than 1 hour, show in hours, minutes, and seconds
const hours = Math.floor(milliseconds / 3600000);
const minutes = Math.floor((milliseconds % 3600000) / 60000);
const seconds = ((milliseconds % 60000) / 1000).toFixed(2);
return `${hours} h ${minutes} min ${seconds} s`;
}
}

/**
* Transforms the errors array by extracting the error type and merging it with the error details.
Expand Down

0 comments on commit 220d421

Please sign in to comment.