( type: string, account: string, container: string, filePath: string, fftSize: number, // we grab 2x this many floats/ints taps: number[] = [1], pythonScript: string = INITIAL_PYTHON_SNIPPET, fftStepSize: number = 0 )
| 35 | } |
| 36 | |
| 37 | export function useGetIQData( |
| 38 | type: string, |
| 39 | account: string, |
| 40 | container: string, |
| 41 | filePath: string, |
| 42 | fftSize: number, // we grab 2x this many floats/ints |
| 43 | taps: number[] = [1], |
| 44 | pythonScript: string = INITIAL_PYTHON_SNIPPET, |
| 45 | fftStepSize: number = 0 |
| 46 | ) { |
| 47 | const [pyodide, setPyodide] = useState<any>(null); |
| 48 | |
| 49 | async function initPyodide() { |
| 50 | console.log('Loading pyodide...'); |
| 51 | const pyodide = await window.loadPyodide(); |
| 52 | await pyodide.loadPackage('numpy'); |
| 53 | await pyodide.loadPackage('matplotlib'); |
| 54 | return pyodide; |
| 55 | } |
| 56 | |
| 57 | useEffect(() => { |
| 58 | if (!pyodide && pythonScript && pythonScript !== INITIAL_PYTHON_SNIPPET && fftStepSize === 0) { |
| 59 | initPyodide().then((pyodide) => { |
| 60 | setPyodide(pyodide); |
| 61 | }); |
| 62 | } |
| 63 | }, [pythonScript, fftStepSize]); |
| 64 | |
| 65 | const queryClient = useQueryClient(); |
| 66 | const { filesQuery, dataSourcesQuery } = useUserSettings(); |
| 67 | const [fftsRequired, setStateFFTsRequired] = useState<number[]>([]); |
| 68 | |
| 69 | // enforce MAXIMUM_SAMPLES_PER_REQUEST by truncating if need be |
| 70 | function setFFTsRequired(fftsRequired: number[]) { |
| 71 | fftsRequired = fftsRequired.slice( |
| 72 | 0, |
| 73 | fftsRequired.length > Math.ceil(MAXIMUM_SAMPLES_PER_REQUEST / fftSize) |
| 74 | ? Math.ceil(MAXIMUM_SAMPLES_PER_REQUEST / fftSize) |
| 75 | : fftsRequired.length |
| 76 | ); |
| 77 | setStateFFTsRequired(fftsRequired); |
| 78 | } |
| 79 | |
| 80 | const { data: meta } = useMeta(type, account, container, filePath); |
| 81 | |
| 82 | const { instance } = useMsal(); |
| 83 | |
| 84 | const iqDataClient = IQDataClientFactory(type, filesQuery.data, dataSourcesQuery.data, instance); |
| 85 | |
| 86 | // fetches iqData, this happens first, and the iqData is in one big continuous chunk |
| 87 | const { data: iqData } = useQuery({ |
| 88 | queryKey: ['iqData', type, account, container, filePath, fftSize, fftsRequired], |
| 89 | queryFn: async ({ signal }) => { |
| 90 | const iqData = await iqDataClient.getIQDataBlocks(meta, fftsRequired, fftSize, signal); |
| 91 | return iqData; |
| 92 | }, |
| 93 | enabled: !!meta && !!filesQuery.data && !!dataSourcesQuery.data, |
| 94 | }); |
no test coverage detected