Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 98 additions & 2 deletions src/WrapperApp/components/Simulation/Geant4DatasetDownload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Typography,
useTheme
} from '@mui/material';
import { useState } from 'react';
import { useEffect,useState } from 'react';
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after comma in the import statement. Should be import { useEffect, useState } from 'react'; to maintain consistency with the rest of the codebase where all imports have spaces after commas.

Suggested change
import { useEffect,useState } from 'react';
import { useEffect, useState } from 'react';

Copilot uses AI. Check for mistakes.

import {
DatasetDownloadStatus,
Expand All @@ -28,6 +28,21 @@ export enum Geant4DatasetsType {
FULL
}

function formatTime(seconds: number): string {
if (seconds < 1) {
return '<1s';
}

if (seconds < 60) {
return `${Math.ceil(seconds)}s`;
}

const minutes = Math.floor(seconds / 60);
const remainingSeconds = Math.ceil(seconds % 60);

return `${minutes}m ${remainingSeconds}s`;
}

export interface Geant4DatasetsProps {
geant4DownloadManagerState: DownloadManagerStatus;
geant4DatasetStates: DatasetStatus[];
Expand All @@ -36,14 +51,91 @@ export interface Geant4DatasetsProps {
setGeant4DatasetType: (type: Geant4DatasetsType) => void;
}

interface SpeedHistory {
lastDone: number;
lastTime: number;
currentSpeed: number;
}

const SMOOTHING = 0.1;

function DatasetCurrentStatus(props: { status: DatasetStatus }) {
const { status } = props;

const [speedHistory, setSpeedHistory] = useState<SpeedHistory>({
lastDone: status.done ?? 0,
lastTime: Date.now(),
currentSpeed: 0
});

useEffect(() => {
const currentDone = status.done ?? 0;
const currentTime = Date.now();

if (status.status === DatasetDownloadStatus.DOWNLOADING) {
setSpeedHistory(prev => {
const timeDelta = (currentTime - prev.lastTime) / 1000;
const bytesDelta = currentDone - prev.lastDone;

if (bytesDelta > 0 && timeDelta > 0) {
const instSpeed = bytesDelta / timeDelta;

const newSpeed =
prev.currentSpeed === 0
? instSpeed
: prev.currentSpeed * (1 - SMOOTHING) + instSpeed * SMOOTHING;

return {
lastDone: currentDone,
lastTime: currentTime,
currentSpeed: newSpeed
};
}

return {
...prev,
lastTime: currentTime
};
});
}

if (
status.status === DatasetDownloadStatus.DONE ||
status.status === DatasetDownloadStatus.IDLE
) {
setSpeedHistory({
lastDone: status.done ?? 0,
lastTime: Date.now(),
currentSpeed: 0
});
}
}, [status.done, status.status]);

const remainingBytes = (status.total ?? 0) - (status.done ?? 0);
let estimatedTimeRemaining = '';

if (
status.status === DatasetDownloadStatus.DOWNLOADING &&
speedHistory.currentSpeed > 0 &&
remainingBytes > 0
) {
const remainingSeconds = remainingBytes / speedHistory.currentSpeed;
estimatedTimeRemaining = ` (${formatTime(remainingSeconds)})`;
}

return (
<Box sx={{ pb: 1 }}>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
<Typography sx={{ flex: 1 }}>{status.name}</Typography>

{status.status === DatasetDownloadStatus.DONE && <CheckIcon color='success' />}
{status.status === DatasetDownloadStatus.DOWNLOADING && (
<Typography
fontSize={12}
color='text.secondary'>
{estimatedTimeRemaining}
</Typography>
)}
</Box>

<Box sx={{ mt: 1 }}>
Expand All @@ -57,6 +149,7 @@ function DatasetCurrentStatus(props: { status: DatasetStatus }) {
{status.status === DatasetDownloadStatus.PROCESSING && (
<LinearProgress
variant='indeterminate'
value={status.total ? ((status.done ?? 0) / status.total) * 100 : 0}
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value prop should not be set on a LinearProgress component with variant='indeterminate'. When variant is 'indeterminate', the value prop is ignored and has no effect. This prop should only be used with 'determinate' or 'buffer' variants. Remove the value prop from this indeterminate LinearProgress component.

Suggested change
value={status.total ? ((status.done ?? 0) / status.total) * 100 : 0}

Copilot uses AI. Check for mistakes.
color='warning'
/>
)}
Expand Down Expand Up @@ -148,7 +241,10 @@ export function Geant4Datasets(props: Geant4DatasetsProps) {
}}>
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
onClick={() => setOpen(!open)}>
onClick={e => {
e.stopPropagation();
setOpen(!open);
}}>
<Typography
textTransform='none'
fontSize={16}>
Expand Down