Skip to content

Commit

Permalink
chore: Set Number of cycle with test Profile + Integrity check (flojo…
Browse files Browse the repository at this point in the history
…y-ai#1166)

* chore: Set Number of cycle with test Profile + Integrity check

* chore: formatting

* chore: safe way to reset integrity

* chore: formatting
  • Loading branch information
LatentDream authored Apr 17, 2024
1 parent 67c55d6 commit 04d0e7a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
2 changes: 2 additions & 0 deletions captain/routes/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
}
)
Expand Down
9 changes: 8 additions & 1 deletion src/renderer/hooks/useTestSequencerProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Result<void, Error>> {
// Confirmation if admin
if (isAdmin()) {
Expand All @@ -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()) {
Expand Down
1 change: 1 addition & 0 deletions src/renderer/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ const Project = z.object({
.transform((value) => value ?? ""),
part: Part,
productName: z.string(),
numCycles: z.number(),
});
export type Project = z.infer<typeof Project>;
export const getCloudProjects = () =>
Expand Down
34 changes: 27 additions & 7 deletions src/renderer/routes/test_sequencer_panel/components/CloudPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -51,6 +54,7 @@ export function CloudPanel() {
const { sequences, handleUpload } = useSequencerState();
const handleLoadProfile = useLoadTestProfile();
const [testProfileUrl, setTestProfileUrl] = useState<string | null>(null);
const [numberCycles, setNumberCycles] = useState<number | null>(null);
const {
serialNumber,
isUploaded,
Expand All @@ -59,6 +63,7 @@ export function CloudPanel() {
setStationId,
uploadAfterRun,
setUploadAfterRun,
cycleConfig,
} = useSequencerStore(
useShallow((state) => ({
serialNumber: state.serialNumber,
Expand All @@ -68,6 +73,7 @@ export function CloudPanel() {
setStationId: state.setStationId,
uploadAfterRun: state.uploadAfterRun,
setUploadAfterRun: state.setUploadAfterRun,
cycleConfig: state.cycleConfig,
})),
);

Expand All @@ -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;
};
Expand Down Expand Up @@ -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();
Expand All @@ -200,9 +216,7 @@ export function CloudPanel() {
}, [partVarId]);

useEffect(() => {
if (testProfileUrl !== null) {
handleLoadProfile(testProfileUrl);
}
loadProfile();
}, [testProfileUrl]);

useEffect(() => {
Expand All @@ -220,6 +234,7 @@ export function CloudPanel() {
setPartNumber(newValue.part.partNumber);
setPartVarId(newValue.part.partVariationId);
setTestProfileUrl(newValue.repoUrl);
setNumberCycles(newValue.numCycles);
setProductName(newValue.productName);
};

Expand Down Expand Up @@ -381,10 +396,15 @@ export function CloudPanel() {
<p>Sequencer: {"TS-" + packageJson.version} </p>
<p className="ml-6">
Integrity:{" "}
{getIntegrity(sequences) ? (
{getIntegrity(sequences, cycleConfig) ? (
<Badge className="h-4 bg-green-500">Pass</Badge>
) : (
<Badge className="h-4 bg-red-500">Fail</Badge>
<Badge
className="h-4 cursor-pointer bg-red-500"
onClick={() => loadProfile()}
>
Fail
</Badge>
)}
</p>
</div>
Expand Down
7 changes: 5 additions & 2 deletions src/renderer/stores/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ export const useSequencerStore = create<State & Actions>()(
},

// Cycles state management ===================================

setCycleCount: (val: number) => {
if (val < 1) {
set((state) => {
Expand All @@ -347,10 +348,12 @@ export const useSequencerStore = create<State & Actions>()(
}
},

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 &&
Expand Down

0 comments on commit 04d0e7a

Please sign in to comment.