Skip to content

Commit

Permalink
applied comments
Browse files Browse the repository at this point in the history
  • Loading branch information
klakhov committed Mar 15, 2024
1 parent d1a951f commit ecf8606
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 24 deletions.
2 changes: 1 addition & 1 deletion cvat-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-core",
"version": "15.1.0",
"version": "15.0.1",
"type": "module",
"description": "Part of Computer Vision Tool which presents an interface for client-side integration",
"main": "src/api.ts",
Expand Down
10 changes: 2 additions & 8 deletions cvat-core/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,8 @@ function build(): CVATCore {
const result = await PluginRegistry.apiWrapper(cvat.lambda.cancel, requestID, functionID);
return result;
},
async listen(requestID, functionID, onChange, options) {
const result = await PluginRegistry.apiWrapper(
cvat.lambda.listen,
requestID,
functionID,
onChange,
options,
);
async listen(requestID, functionID, onChange) {
const result = await PluginRegistry.apiWrapper(cvat.lambda.listen, requestID, functionID, onChange);
return result;
},
async requests() {
Expand Down
8 changes: 2 additions & 6 deletions cvat-core/src/lambda-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,15 @@ class LambdaManager {
requestID: string,
functionID: string | number,
callback: (status: RQStatus, progress: number, message?: string) => void,
options: { includeListening: boolean } = { includeListening: true },
): Promise<void> {
const model = this.cachedList.find((_model) => _model.id === functionID);
if (!model) {
throw new ArgumentError('Incorrect function Id provided');
}

// already listening, avoid sending extra requests
if (requestID in this.listening) {
const { includeListening } = options;
if (includeListening) {
this.listening[requestID].onUpdate.push(callback);
}
this.listening[requestID].onUpdate.push(callback);
// already listening, avoid sending extra requests
return;
}
const timeoutCallback = (): void => {
Expand Down
2 changes: 1 addition & 1 deletion cvat-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-ui",
"version": "1.63.1",
"version": "1.63.3",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down
25 changes: 19 additions & 6 deletions cvat-ui/src/actions/models-actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2020-2022 Intel Corporation
// Copyright (C) 2022-2023 CVAT.ai Corporation
// Copyright (C) 2022-2024 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -20,6 +20,7 @@ export enum ModelsActionTypes {
DELETE_MODEL = 'DELETE_MODEL',
DELETE_MODEL_SUCCESS = 'DELETE_MODEL_SUCCESS',
DELETE_MODEL_FAILED = 'DELETE_MODEL_FAILED',
GET_INFERENCES_SUCCESS = 'GET_INFERENCES_SUCCESS',
START_INFERENCE_FAILED = 'START_INFERENCE_FAILED',
GET_INFERENCE_STATUS_SUCCESS = 'GET_INFERENCE_STATUS_SUCCESS',
GET_INFERENCE_STATUS_FAILED = 'GET_INFERENCE_STATUS_FAILED',
Expand All @@ -45,6 +46,9 @@ export const modelsActions = {
error,
}),
fetchMetaFailed: (error: any) => createAction(ModelsActionTypes.FETCH_META_FAILED, { error }),
getInferencesSuccess: (requestedInferenceIDs: Record<string, boolean>) => (
createAction(ModelsActionTypes.GET_INFERENCES_SUCCESS, { requestedInferenceIDs })
),
getInferenceStatusSuccess: (taskID: number, activeInference: ActiveInference) => (
createAction(ModelsActionTypes.GET_INFERENCE_STATUS_SUCCESS, {
taskID,
Expand All @@ -64,9 +68,10 @@ export const modelsActions = {
error,
})
),
cancelInferenceSuccess: (taskID: number) => (
cancelInferenceSuccess: (taskID: number, activeInference: ActiveInference) => (
createAction(ModelsActionTypes.CANCEL_INFERENCE_SUCCESS, {
taskID,
activeInference,
})
),
cancelInferenceFailed: (taskID: number, error: any) => (
Expand Down Expand Up @@ -149,7 +154,7 @@ function listen(inferenceMeta: InferenceMeta, dispatch: (action: ModelsActions)
id: requestID,
}),
);
}, { includeListening: false })
})
.catch((error: Error) => {
dispatch(
modelsActions.getInferenceStatusFailed(taskID, {
Expand All @@ -164,22 +169,29 @@ function listen(inferenceMeta: InferenceMeta, dispatch: (action: ModelsActions)
}

export function getInferenceStatusAsync(): ThunkAction {
return async (dispatch): Promise<void> => {
return async (dispatch, getState): Promise<void> => {
const dispatchCallback = (action: ModelsActions): void => {
dispatch(action);
};

const { requestedInferenceIDs } = getState().models;

try {
const requests = await core.lambda.requests();
const newListenedIDs: Record<string, boolean> = {};
requests
.map((request: any): object => ({
taskID: +request.function.task,
requestID: request.id,
functionID: request.function.id,
}))
.forEach((inferenceMeta: InferenceMeta): void => {
listen(inferenceMeta, dispatchCallback);
if (!(inferenceMeta.requestID in requestedInferenceIDs)) {
listen(inferenceMeta, dispatchCallback);
newListenedIDs[inferenceMeta.requestID] = true;
}
});
dispatch(modelsActions.getInferencesSuccess(newListenedIDs));
} catch (error) {
dispatch(modelsActions.fetchMetaFailed(error));
}
Expand All @@ -202,6 +214,7 @@ export function startInferenceAsync(taskId: number, model: MLModel, body: object
},
dispatchCallback,
);
dispatch(modelsActions.getInferencesSuccess({ [requestID]: true }));
} catch (error) {
dispatch(modelsActions.startInferenceFailed(taskId, error));
}
Expand All @@ -213,7 +226,7 @@ export function cancelInferenceAsync(taskID: number): ThunkAction {
try {
const inference = getState().models.inferences[taskID];
await core.lambda.cancel(inference.id, inference.functionID);
dispatch(modelsActions.cancelInferenceSuccess(taskID));
dispatch(modelsActions.cancelInferenceSuccess(taskID, inference));
} catch (error) {
dispatch(modelsActions.cancelInferenceFailed(taskID, error));
}
Expand Down
3 changes: 3 additions & 0 deletions cvat-ui/src/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ export interface ModelsState {
reid: MLModel[];
classifiers: MLModel[];
totalCount: number;
requestedInferenceIDs: {
[index: string]: boolean;
};
inferences: {
[index: number]: ActiveInference;
};
Expand Down
18 changes: 16 additions & 2 deletions cvat-ui/src/reducers/models-reducer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2020-2022 Intel Corporation
// Copyright (C) 2022-2023 CVAT.ai Corporation
// Copyright (C) 2022-2024 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -20,6 +20,7 @@ const defaultState: ModelsState = {
classifiers: [],
modelRunnerIsVisible: false,
modelRunnerTask: null,
requestedInferenceIDs: {},
inferences: {},
totalCount: 0,
query: {
Expand Down Expand Up @@ -88,6 +89,17 @@ export default function (state = defaultState, action: ModelsActions | AuthActio
modelRunnerTask: null,
};
}
case ModelsActionTypes.GET_INFERENCES_SUCCESS: {
const { requestedInferenceIDs } = state;

return {
...state,
requestedInferenceIDs: {
...requestedInferenceIDs,
...action.payload.requestedInferenceIDs,
},
};
}
case ModelsActionTypes.GET_INFERENCE_STATUS_SUCCESS: {
const { inferences } = state;

Expand Down Expand Up @@ -123,12 +135,14 @@ export default function (state = defaultState, action: ModelsActions | AuthActio
};
}
case ModelsActionTypes.CANCEL_INFERENCE_SUCCESS: {
const { inferences } = state;
const { inferences, requestedInferenceIDs } = state;
delete inferences[action.payload.taskID];
delete requestedInferenceIDs[action.payload.activeInference.id];

return {
...state,
inferences: { ...inferences },
requestedInferenceIDs: { ...requestedInferenceIDs },
};
}
case ModelsActionTypes.GET_MODEL_PREVIEW: {
Expand Down

0 comments on commit ecf8606

Please sign in to comment.