Skip to content

Commit

Permalink
Added HinL task in the SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
souyahia-monk committed Apr 29, 2024
1 parent 831c56f commit d6d4259
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import {
} from '@monkvision/network';
import { useMonitoring } from '@monkvision/monitoring';
import { LoadingState, useAsyncEffect } from '@monkvision/common';
import { ComplianceOptions, Image, Sight, TaskName } from '@monkvision/types';
import { ComplianceOptions, Image, Sight, TaskName, MonkPicture } from '@monkvision/types';
import { sights } from '@monkvision/sights';
import { MonkPicture } from '@monkvision/types';
import { PhotoCaptureErrorName } from '../errors';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { MonkPicture } from '@monkvision/types';
import { TaskName } from '@monkvision/types';
import { MonkPicture, TaskName } from '@monkvision/types';
import { Queue } from '@monkvision/common';
import { useCallback } from 'react';
import { PictureUpload } from './useUploadQueue';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export interface UseStartTasksOnCompleteParams {
*/
export type StartTasksFunction = () => Promise<void>;

const TASKS_NOT_TO_START = [TaskName.HUMAN_IN_THE_LOOP];

function getTasksToStart({
sights,
tasksBySight,
Expand All @@ -52,13 +54,15 @@ function getTasksToStart({
UseStartTasksOnCompleteParams,
'sights' | 'tasksBySight' | 'startTasksOnComplete'
>): TaskName[] {
let tasks = [];
if (Array.isArray(startTasksOnComplete)) {
return startTasksOnComplete;
}
if (tasksBySight) {
return uniq(flatMap(sights, (sight) => tasksBySight[sight.id]));
tasks = startTasksOnComplete;
} else if (tasksBySight) {
tasks = uniq(flatMap(sights, (sight) => tasksBySight[sight.id]));
} else {
tasks = uniq(flatMap(sights, (sight) => sight.tasks));
}
return uniq(flatMap(sights, (sight) => sight.tasks));
return tasks.filter((task) => !TASKS_NOT_TO_START.includes(task));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import '@testing-library/jest-dom';
import { expectPropsOnChildMock } from '@monkvision/test-utils';
import { InteractiveStatus } from '@monkvision/types';
import { MonkPicture } from '@monkvision/types';
import { InteractiveStatus, MonkPicture } from '@monkvision/types';
import { TakePictureButton, Icon } from '@monkvision/common-ui-web';
import { fireEvent, render, screen } from '@testing-library/react';
import { PhotoCaptureHUDButtons } from '../../../src';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { TaskName } from '@monkvision/types';
import { TaskName, MonkPicture } from '@monkvision/types';
import {
AddDamageHandle,
PhotoCaptureMode,
usePictureTaken,
UseTakePictureParams,
} from '../../../src/PhotoCapture/hooks';
import { renderHook } from '@testing-library/react-hooks';
import { MonkPicture } from '@monkvision/types';

function createParams(): UseTakePictureParams {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,23 @@ describe('useStartTasksOnComplete hook', () => {

unmount();
});

it('should not start the Human in the Loop task', () => {
const initialProps = {
...createParams(),
startTasksOnComplete: [TaskName.WHEEL_ANALYSIS, TaskName.HUMAN_IN_THE_LOOP],
};
const { result, unmount } = renderHook(useStartTasksOnComplete, { initialProps });

const startInspectionTasksMock = (useMonkApi as jest.Mock).mock.results[0].value
.startInspectionTasks;
result.current();
expect(startInspectionTasksMock).toHaveBeenCalledWith(
expect.objectContaining({
names: [TaskName.WHEEL_ANALYSIS],
}),
);

unmount();
});
});
29 changes: 14 additions & 15 deletions packages/network/src/api/image/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ import {
import { v4 } from 'uuid';
import { labels, sights } from '@monkvision/sights';
import { getDefaultOptions, MonkApiConfig } from '../config';
import {
ApiBusinessTaskName,
ApiImage,
ApiImageCompliancesTaskPost,
ApiImagePost,
} from '../models';
import { ApiImage, ApiImagePost, ApiImagePostTask } from '../models';
import { MonkApiResponse } from '../types';
import { mapApiImage } from './mappers';

Expand Down Expand Up @@ -123,17 +118,22 @@ function createBeautyShotImageData(
filetype: string,
): { filename: string; body: ApiImagePost } {
const filename = `${options.sightId}-${options.inspectionId}-${Date.now()}.${filetype}`;
const tasks: (ApiBusinessTaskName | ApiImageCompliancesTaskPost)[] = options.tasks.filter(
(task) => task !== TaskName.COMPLIANCES,
);
const tasks = options.tasks.filter(
(task) => ![TaskName.COMPLIANCES, TaskName.HUMAN_IN_THE_LOOP].includes(task),
) as ApiImagePostTask[];
tasks.push({
name: TaskName.COMPLIANCES,
image_details: { sight_id: options.sightId },
wait_for_result: !!(
options.compliance?.enableCompliance && options.compliance?.useLiveCompliance
),
wait_for_result: options.compliance?.enableCompliance && options.compliance?.useLiveCompliance,
});

if (options.tasks.includes(TaskName.HUMAN_IN_THE_LOOP)) {
tasks.push({
name: TaskName.HUMAN_IN_THE_LOOP,
image_details: { sight_label: sights[options.sightId].label },
});
}

const body: ApiImagePost = {
acquisition: {
strategy: 'upload_multipart_form_keys',
Expand Down Expand Up @@ -166,9 +166,8 @@ function createCloseUpImageData(
TaskName.DAMAGE_DETECTION,
{
name: TaskName.COMPLIANCES,
wait_for_result: !!(
options.compliance?.enableCompliance && options.compliance?.useLiveCompliance
),
wait_for_result:
options.compliance?.enableCompliance && options.compliance?.useLiveCompliance,
},
],
additional_data: getAdditionalData(options),
Expand Down
6 changes: 4 additions & 2 deletions packages/network/src/api/models/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ApiAdditionalData, ApiCenterOnElement, ApiLabelPrediction } from '
import type { ApiRenderedOutputs } from './renderedOutput';
import type { ApiImageComplianceResults } from './compliance';
import type { ApiViews } from './view';
import { ApiBusinessTaskName, ApiImageCompliancesTaskPost } from './task';
import { ApiBusinessTaskName, ApiHinlTaskPost, ApiImageCompliancesTaskPost } from './task';

export type ApiImageType = 'unknown' | 'beauty_shot' | 'close_up';

Expand Down Expand Up @@ -78,9 +78,11 @@ export interface ApiCompliance {
zoom_level?: ApiComplianceParameters;
}

export type ApiImagePostTask = ApiBusinessTaskName | ApiImageCompliancesTaskPost | ApiHinlTaskPost;

export interface ApiImagePost {
acquisition: ApiAcquisition;
tasks?: (ApiBusinessTaskName | ApiImageCompliancesTaskPost)[];
tasks?: ApiImagePostTask[];
name?: string;
image_type?: ApiImageType;
image_subtype?: ApiImageSubType;
Expand Down
9 changes: 9 additions & 0 deletions packages/network/src/api/models/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ export interface ApiImageCompliancesTaskPost {
wait_for_result?: boolean;
}

export interface ApiHinlImageDetails {
sight_label: string;
}

export interface ApiHinlTaskPost {
name: 'human_in_the_loop';
image_details: ApiHinlImageDetails;
}

export type ApiTaskProgressStatus =
| 'NOT_STARTED'
| 'TODO'
Expand Down
13 changes: 8 additions & 5 deletions packages/network/test/api/image/requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ function createBeautyShotImageOptions(): AddBeautyShotImageOptions {
mimetype: 'image/jpeg',
},
inspectionId: 'test-inspection-id',
sightId: 'test-sight-id',
tasks: [TaskName.DAMAGE_DETECTION, TaskName.WHEEL_ANALYSIS],
sightId: 'test-sight-1',
tasks: [TaskName.DAMAGE_DETECTION, TaskName.WHEEL_ANALYSIS, TaskName.HUMAN_IN_THE_LOOP],
compliance: {
enableCompliance: true,
complianceIssues: [ComplianceIssue.INTERIOR_NOT_SUPPORTED],
Expand Down Expand Up @@ -168,11 +168,14 @@ describe('Image requests', () => {
},
image_type: ImageType.BEAUTY_SHOT,
tasks: [
...options.tasks,
...options.tasks.filter((task) => task !== TaskName.HUMAN_IN_THE_LOOP),
{
name: TaskName.COMPLIANCES,
image_details: { sight_id: options.sightId },
wait_for_result: false,
},
{
name: TaskName.HUMAN_IN_THE_LOOP,
image_details: { sight_label: sights[options.sightId].label },
},
],
additional_data: {
Expand Down Expand Up @@ -211,7 +214,7 @@ describe('Image requests', () => {
? ImageSubtype.CLOSE_UP_PART
: ImageSubtype.CLOSE_UP_DAMAGE,
image_sibling_key: options.siblingKey,
tasks: [TaskName.DAMAGE_DETECTION, { name: TaskName.COMPLIANCES, wait_for_result: false }],
tasks: [TaskName.DAMAGE_DETECTION, { name: TaskName.COMPLIANCES }],
additional_data: {
label: {
en: options.firstShot ? 'Close Up (part)' : 'Close Up (damage)',
Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/state/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export enum TaskName {
* sight_id of the image for instance).
*/
COMPLIANCES = 'compliances',
/**
* Human in the loop task.
*
* // TODO : Add better doc for this task.
*/
HUMAN_IN_THE_LOOP = 'human_in_the_loop',
}

/**
Expand Down

0 comments on commit d6d4259

Please sign in to comment.