-
Notifications
You must be signed in to change notification settings - Fork 5
Add option to download full datasets prior to simulation #2246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7c0019d
port @kmichalik's poc to current worker architecture
lkwinta 5b7959f
Add real downloading of datasets
lkwinta 1a0bc00
improve styling of the progress bars
lkwinta 652f8c0
Fix compilot suggestions
lkwinta d31321a
Refactor
lkwinta 60f336e
Add information modal about datasets
lkwinta b15d8ee
Copilot review
lkwinta 0aec599
rework use callbacks
lkwinta 6f14c2e
Fix bugs and add aditional informations
lkwinta 73b6aa9
add more info for lazy files, rename options
lkwinta 83116c5
Some typos and copilot review
lkwinta 88cd6f5
Update src/WrapperApp/components/Simulation/Modal/DatasetsFullInfoMod…
lkwinta a8cbc18
Update src/WrapperApp/components/Simulation/Geant4DatasetDownload.tsx
lkwinta f6210da
Update src/WrapperApp/components/Simulation/Modal/DatasetsPartialInfo…
lkwinta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| // Additional credits: | ||
| // - @kmichalik | ||
|
|
||
| import { Dispatch, SetStateAction, useCallback, useEffect, useRef, useState } from 'react'; | ||
|
|
||
| import Geant4Worker from './Geant4Worker'; | ||
|
|
||
| export enum DownloadManagerStatus { | ||
| IDLE, | ||
| WORKING, | ||
| FINISHED, | ||
| ERROR | ||
| } | ||
|
|
||
| export enum DatasetDownloadStatus { | ||
| IDLE, | ||
| DOWNLOADING, | ||
| PROCESSING, | ||
| DONE | ||
| } | ||
|
|
||
| const statusTypeMap: Record<string, DatasetDownloadStatus> = { | ||
| downloading: DatasetDownloadStatus.DOWNLOADING, | ||
| preparing: DatasetDownloadStatus.PROCESSING, | ||
| done: DatasetDownloadStatus.DONE | ||
| }; | ||
|
|
||
| export interface DatasetStatus { | ||
| name: string; | ||
| status: DatasetDownloadStatus; | ||
| done?: number; | ||
| total?: number; | ||
| } | ||
|
|
||
| async function fetchProgress( | ||
| worker: Geant4Worker, | ||
| setDatasetStates: Dispatch<SetStateAction<Record<string, DatasetStatus>>> | ||
| ) { | ||
| const progress = await worker.pollDatasetProgress(); | ||
|
|
||
| if (progress) { | ||
| const newDatasetStates: Record<string, DatasetStatus> = {}; | ||
|
|
||
| for (const [datasetName, datasetProgress] of Object.entries(progress)) { | ||
| let status = statusTypeMap[datasetProgress.stage] ?? DatasetDownloadStatus.IDLE; | ||
|
|
||
| newDatasetStates[datasetName] = { | ||
| name: datasetName, | ||
| status, | ||
| done: Math.floor(datasetProgress.progress * 100), | ||
grzanka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| total: 100 | ||
| }; | ||
| } | ||
|
|
||
| setDatasetStates(prev => ({ ...prev, ...newDatasetStates })); | ||
| } | ||
| } | ||
|
|
||
| type StartDownloadArgs = { | ||
| worker: Geant4Worker; | ||
| setManagerState: Dispatch<SetStateAction<DownloadManagerStatus>>; | ||
| setDatasetStates: Dispatch<SetStateAction<Record<string, DatasetStatus>>>; | ||
| setIdle: Dispatch<SetStateAction<boolean>>; | ||
| }; | ||
|
|
||
| function startDownload({ worker, setManagerState, setDatasetStates, setIdle }: StartDownloadArgs) { | ||
| const loadDepsPromise = worker.loadDeps(); | ||
|
|
||
| const interval = setInterval(async () => { | ||
| await fetchProgress(worker, setDatasetStates); | ||
| }, 500); | ||
grzanka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| loadDepsPromise | ||
| .then(async () => { | ||
| clearInterval(interval); | ||
|
|
||
| await fetchProgress(worker, setDatasetStates); | ||
|
|
||
| setManagerState(DownloadManagerStatus.FINISHED); | ||
| worker.destroy(); | ||
| }) | ||
| .catch(error => { | ||
| console.error('Dataset download error:', error); | ||
| setManagerState(DownloadManagerStatus.ERROR); | ||
| clearInterval(interval); | ||
| }); | ||
| setManagerState(DownloadManagerStatus.WORKING); | ||
lkwinta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| setIdle(false); | ||
| } | ||
lkwinta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| export function useDatasetDownloadManager() { | ||
| const [managerState, setManagerState] = useState<DownloadManagerStatus>( | ||
| DownloadManagerStatus.IDLE | ||
| ); | ||
| const [datasetStates, setDatasetStates] = useState<Record<string, DatasetStatus>>({}); | ||
| const [idle, setIdle] = useState<boolean>(false); | ||
| const [worker] = useState<Geant4Worker>(new Geant4Worker()); | ||
lkwinta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const initCalledRef = useRef(false); | ||
|
|
||
| useEffect(() => { | ||
| if (initCalledRef.current) return; | ||
| worker | ||
| .init() | ||
| .then(() => setIdle(true)) | ||
| .catch(error => { | ||
| setManagerState(DownloadManagerStatus.ERROR); | ||
| console.error('Failed to initialize Geant4 worker for dataset download:', error); | ||
| }); | ||
| initCalledRef.current = true; | ||
grzanka marked this conversation as resolved.
Show resolved
Hide resolved
grzanka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, [worker]); | ||
|
|
||
| const startDownloadSimple = useCallback(() => { | ||
| if (!idle) return; | ||
|
|
||
| startDownload({ worker, setManagerState, setDatasetStates, setIdle }); | ||
| }, [worker, idle]); | ||
|
|
||
| return { | ||
| managerState, | ||
| datasetStates: Object.values(datasetStates), | ||
| startDownload: startDownloadSimple | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.