Skip to content

Commit

Permalink
working on estimated time progress
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuelef committed Sep 25, 2023
1 parent 0b3b60c commit c7c0abf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
45 changes: 45 additions & 0 deletions website/src/EstimatedTimeProgress.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { useState, useEffect } from "react";
import { LinearProgress, Typography } from "@mui/material";

const EstimatedTimeProgress = ({ totalTime }) => {
const [elapsedTime, setElapsedTime] = useState(0);

useEffect(() => {
let interval;

// Start a timer to update elapsed time every second
if (elapsedTime < totalTime) {
interval = setInterval(() => {
setElapsedTime((prevTime) => prevTime + 1);
}, 1000);
}

// Clear the timer when the component unmounts
return () => clearInterval(interval);
}, [elapsedTime, totalTime]);

const remainingTime = totalTime - elapsedTime;
const progressPercentage = (elapsedTime / totalTime) * 100;

return (
<div>
<Typography variant="h6">
Estimated Time Left: {formatTime(remainingTime)}
</Typography>
<LinearProgress variant="determinate" value={progressPercentage} />
</div>
);
};

// Function to format time in HH:MM:SS format
const formatTime = (timeInSeconds) => {
const hours = Math.floor(timeInSeconds / 3600);
const minutes = Math.floor((timeInSeconds % 3600) / 60);
const seconds = timeInSeconds % 60;

return `${hours.toString().padStart(2, "0")}:${minutes
.toString()
.padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
};

export default EstimatedTimeProgress;
2 changes: 2 additions & 0 deletions website/src/K8sTimeSeriesChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import FusionCharts from "fusioncharts";
import TimeSeries from "fusioncharts/fusioncharts.timeseries";
import ReactFC from "react-fusioncharts";
import schema from "./schema";
import EstimatedTimeProgress from "./EstimatedTimeProgress";

const HOST = import.meta.env.VITE_HOST;

Expand Down Expand Up @@ -147,6 +148,7 @@ function K8sTimeSeriesChart() {
/>
</RadioGroup>
</FormControl>
<EstimatedTimeProgress totalTime={36} />
<ReactFC {...ds.timeseriesDs} />
</div>
);
Expand Down

0 comments on commit c7c0abf

Please sign in to comment.