From 04d0e7aad5ef06d7e35e3bcba22d6b70e7cc4058 Mon Sep 17 00:00:00 2001 From: Gui Date: Wed, 17 Apr 2024 16:58:01 -0400 Subject: [PATCH] chore: Set Number of cycle with test Profile + Integrity check (#1166) * chore: Set Number of cycle with test Profile + Integrity check * chore: formatting * chore: safe way to reset integrity * chore: formatting --- captain/routes/cloud.py | 2 ++ src/renderer/hooks/useTestSequencerProject.ts | 9 ++++- src/renderer/lib/api.ts | 1 + .../components/CloudPanel.tsx | 34 +++++++++++++++---- src/renderer/stores/sequencer.ts | 7 ++-- 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/captain/routes/cloud.py b/captain/routes/cloud.py index 5d4fae934..de329a92e 100644 --- a/captain/routes/cloud.py +++ b/captain/routes/cloud.py @@ -103,6 +103,7 @@ class Project(CloudModel): updated_at: Optional[datetime.datetime] = Field(..., alias="updatedAt") part_variation_id: str = Field(..., alias="partVariationId") repo_url: Optional[str] = Field(..., alias="repoUrl") + num_cycles: int = Field(..., alias="numCycles") class Part(CloudModel): @@ -221,6 +222,7 @@ async def get_cloud_projects(): "value": p.id, "part": part_var.model_dump(by_alias=True), "repoUrl": p.repo_url, + "numCycles": p.num_cycles, "productName": part.product_name, } ) diff --git a/src/renderer/hooks/useTestSequencerProject.ts b/src/renderer/hooks/useTestSequencerProject.ts index 5e5938aa6..14bc58454 100644 --- a/src/renderer/hooks/useTestSequencerProject.ts +++ b/src/renderer/hooks/useTestSequencerProject.ts @@ -122,10 +122,14 @@ export const useLoadTestProfile = () => { const manager = usePrepareStateManager(); const { isAdmin } = useWithPermission(); const clearState = useSequencerStore(useShallow((state) => state.clearState)); + const setCycleCount = useSequencerStore( + useShallow((state) => state.setCycleCount), + ); + const setCommitHash = useSequencerStore( useShallow((state) => state.setCommitHash), ); - const handleImport = async (gitRepoUrlHttp: string) => { + const handleImport = async (gitRepoUrlHttp: string, numberCycles: number) => { async function importSequences(): Promise> { // Confirmation if admin if (isAdmin()) { @@ -144,6 +148,9 @@ export const useLoadTestProfile = () => { return err(Error("No sequences associated with the test profile")); } + // Set number of cycles + setCycleCount(numberCycles); + // Load test profile const res = await installTestProfile(gitRepoUrlHttp); if (res.isErr()) { diff --git a/src/renderer/lib/api.ts b/src/renderer/lib/api.ts index e8049c9e8..2a60fad49 100644 --- a/src/renderer/lib/api.ts +++ b/src/renderer/lib/api.ts @@ -185,6 +185,7 @@ const Project = z.object({ .transform((value) => value ?? ""), part: Part, productName: z.string(), + numCycles: z.number(), }); export type Project = z.infer; export const getCloudProjects = () => diff --git a/src/renderer/routes/test_sequencer_panel/components/CloudPanel.tsx b/src/renderer/routes/test_sequencer_panel/components/CloudPanel.tsx index c726f56c6..0d6f154d0 100644 --- a/src/renderer/routes/test_sequencer_panel/components/CloudPanel.tsx +++ b/src/renderer/routes/test_sequencer_panel/components/CloudPanel.tsx @@ -27,7 +27,10 @@ import { import { toastQueryError } from "@/renderer/utils/report-error"; import { useQuery, useQueryClient } from "@tanstack/react-query"; import { Spinner } from "@/renderer/components/ui/spinner"; -import { TestSequenceContainer } from "@/renderer/types/test-sequencer"; +import { + CycleConfig, + TestSequenceContainer, +} from "@/renderer/types/test-sequencer"; import { Badge } from "@/renderer/components/ui/badge"; import { Checkbox } from "@/renderer/components/ui/checkbox"; import useWithPermission from "@/renderer/hooks/useWithPermission"; @@ -51,6 +54,7 @@ export function CloudPanel() { const { sequences, handleUpload } = useSequencerState(); const handleLoadProfile = useLoadTestProfile(); const [testProfileUrl, setTestProfileUrl] = useState(null); + const [numberCycles, setNumberCycles] = useState(null); const { serialNumber, isUploaded, @@ -59,6 +63,7 @@ export function CloudPanel() { setStationId, uploadAfterRun, setUploadAfterRun, + cycleConfig, } = useSequencerStore( useShallow((state) => ({ serialNumber: state.serialNumber, @@ -68,6 +73,7 @@ export function CloudPanel() { setStationId: state.setStationId, uploadAfterRun: state.uploadAfterRun, setUploadAfterRun: state.setUploadAfterRun, + cycleConfig: state.cycleConfig, })), ); @@ -87,11 +93,15 @@ export function CloudPanel() { setUploadAfterRun(!isAdmin()); }, [isAdmin]); - const getIntegrity = (sequences: TestSequenceContainer[]): boolean => { + const getIntegrity = ( + sequences: TestSequenceContainer[], + cycleConf: CycleConfig, + ): boolean => { let integrity = true; sequences.forEach((seq) => { integrity = integrity && seq.runable; }); + integrity = integrity && cycleConf.cycleCount === numberCycles; setIntegrity(integrity); return integrity; }; @@ -188,6 +198,12 @@ export function CloudPanel() { enabled: projectsQuery.isSuccess, // Enable only when projectsQuery is successful }); + const loadProfile = () => { + if (testProfileUrl !== null && numberCycles !== null) { + handleLoadProfile(testProfileUrl, numberCycles); + } + }; + useEffect(() => { if (projectId !== "") { stationsQuery.refetch(); @@ -200,9 +216,7 @@ export function CloudPanel() { }, [partVarId]); useEffect(() => { - if (testProfileUrl !== null) { - handleLoadProfile(testProfileUrl); - } + loadProfile(); }, [testProfileUrl]); useEffect(() => { @@ -220,6 +234,7 @@ export function CloudPanel() { setPartNumber(newValue.part.partNumber); setPartVarId(newValue.part.partVariationId); setTestProfileUrl(newValue.repoUrl); + setNumberCycles(newValue.numCycles); setProductName(newValue.productName); }; @@ -381,10 +396,15 @@ export function CloudPanel() {

Sequencer: {"TS-" + packageJson.version}

Integrity:{" "} - {getIntegrity(sequences) ? ( + {getIntegrity(sequences, cycleConfig) ? ( Pass ) : ( - Fail + loadProfile()} + > + Fail + )}

diff --git a/src/renderer/stores/sequencer.ts b/src/renderer/stores/sequencer.ts index 1aafa83c5..5a9d2178d 100644 --- a/src/renderer/stores/sequencer.ts +++ b/src/renderer/stores/sequencer.ts @@ -333,6 +333,7 @@ export const useSequencerStore = create()( }, // Cycles state management =================================== + setCycleCount: (val: number) => { if (val < 1) { set((state) => { @@ -347,10 +348,12 @@ export const useSequencerStore = create()( } }, - setInfinite: (val: boolean) => + setInfinite: (val: boolean) => { set((state) => { state.cycleConfig.infinite = val; - }), + state.cycleConfig.cycleCount = val ? -1 : 1; + }); + }, saveCycle: () => { if ( get().cycleRuns.length > get().cycleConfig.cycleCount &&