Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Az/import export tasks #3056

Merged
merged 29 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8dd68f4
initial version of task export/import feature
Apr 2, 2021
9554bf3
Merge remote-tracking branch 'origin/develop' into az/import_export_t…
Apr 2, 2021
24cb227
fixed tests
Apr 2, 2021
cdf2e12
CLI
Apr 5, 2021
c44faec
fix comments
Apr 9, 2021
b156ff2
Merge remote-tracking branch 'origin/develop' into az/import_export_t…
Apr 9, 2021
c2801bf
updated license headers
Apr 9, 2021
b11ed87
fix eslint issues
Apr 9, 2021
e1cabf8
fix comments
Apr 19, 2021
859271b
fixed comments
Apr 20, 2021
958cfd3
Merge remote-tracking branch 'origin/develop' into az/import_export_t…
Apr 20, 2021
b4b0564
reverted changes in *.md files
Apr 20, 2021
11a8bc9
Merge branch 'develop' into az/import_export_tasks
Apr 20, 2021
b57c939
fixed comments
Apr 29, 2021
55999d3
Merge remote-tracking branch 'origin/develop' into az/import_export_t…
Apr 29, 2021
32266f7
fix pylint issues
Apr 29, 2021
ff80d8a
fix import for share case
May 4, 2021
8669ed6
Merge remote-tracking branch 'origin/develop' into az/import_export_t…
May 4, 2021
60df6a9
improved unit tests
May 6, 2021
d972726
Merge remote-tracking branch 'origin/develop' into az/import_export_t…
May 7, 2021
c956914
updated changelog
May 11, 2021
4151d42
Merge remote-tracking branch 'origin/develop' into az/import_export_t…
May 11, 2021
e7438e3
fixed Maria's comments
May 13, 2021
1aae8f9
fixed comments
May 28, 2021
1dc1942
Merge remote-tracking branch 'origin/develop' into az/import_export_t…
May 28, 2021
3a1bd56
Fixed position of create new task button
Jun 3, 2021
78eef66
Fixed span position
Jun 4, 2021
32aacc4
fixed comments
Jun 7, 2021
57d1fb4
Merge remote-tracking branch 'origin/develop' into az/import_export_t…
Jun 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cvat-core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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": "3.12.0",
"version": "3.13.0",
"description": "Part of Computer Vision Tool which presents an interface for client-side integration",
"main": "babel.config.js",
"scripts": {
Expand Down
55 changes: 55 additions & 0 deletions cvat-core/src/server-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,59 @@
});
}

async function exportTask(id) {
const { backendAPI } = config;
const url = `${backendAPI}/tasks/${id}`;

return new Promise((resolve, reject) => {
async function request() {
try {
const response = await Axios.get(`${url}?action=export`, {
proxy: config.proxy,
});
if (response.status === 202) {
setTimeout(request, 3000);
} else {
resolve(`${url}?action=download`);
}
} catch (errorData) {
reject(generateError(errorData));
}
}

setTimeout(request);
});
}

async function importTask(file) {
const { backendAPI } = config;

let annotationData = new FormData();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason behind annotationData name? Should it be payload or something like that?

annotationData.append('task_file', file);

return new Promise((resolve, reject) => {
async function request() {
try {
const response = await Axios.post(`${backendAPI}/tasks?action=import`, annotationData, {
proxy: config.proxy,
});
if (response.status === 202) {
annotationData = new FormData();
annotationData.append('rq_id', response.data.rq_id);
setTimeout(request, 3000);
} else {
const importedTask = await getTasks(`?id=${response.data.id}`);
resolve(importedTask[0]);
}
} catch (errorData) {
reject(generateError(errorData));
}
}

setTimeout(request);
});
}

async function createTask(taskSpec, taskDataSpec, onUpdate) {
const { backendAPI } = config;

Expand Down Expand Up @@ -1161,6 +1214,8 @@
createTask,
deleteTask,
exportDataset,
exportTask,
importTask,
}),
writable: false,
},
Expand Down
40 changes: 40 additions & 0 deletions cvat-core/src/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,36 @@
const result = await PluginRegistry.apiWrapper.call(this, Task.prototype.delete);
return result;
}

/**
* Method makes a backup of a task
* @method export
* @memberof module:API.cvat.classes.Task
* @readonly
* @instance
* @async
* @throws {module:API.cvat.exceptions.ServerError}
* @throws {module:API.cvat.exceptions.PluginError}
*/
async export() {
const result = await PluginRegistry.apiWrapper.call(this, Task.prototype.export);
return result;
}

/**
* Method imports a task from a backup
* @method import
* @memberof module:API.cvat.classes.Task
* @readonly
* @instance
* @async
* @throws {module:API.cvat.exceptions.ServerError}
* @throws {module:API.cvat.exceptions.PluginError}
*/
static async import(file) {
const result = await PluginRegistry.apiWrapper.call(this, Task.import, file);
return result;
}
}

module.exports = {
Expand Down Expand Up @@ -2077,6 +2107,16 @@
return result;
};

Task.prototype.export.implementation = async function () {
const result = await serverProxy.tasks.exportTask(this.id);
return result;
};

Task.import.implementation = async function (file) {
const result = await serverProxy.tasks.importTask(file);
return result;
};

Task.prototype.frames.get.implementation = async function (frame, isPlaying, step) {
if (!Number.isInteger(frame) || frame < 0) {
throw new ArgumentError(`Frame must be a positive integer. Got: "${frame}"`);
Expand Down
24 changes: 16 additions & 8 deletions cvat-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion cvat-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@types/react-color": "^3.0.4",
"@types/react-dom": "^16.9.11",
"@types/react-redux": "^7.1.16",
"@types/react-resizable": "^1.7.2",
"@types/react-router": "^5.1.12",
"@types/react-router-dom": "^5.1.7",
"@types/react-share": "^3.0.3",
Expand All @@ -72,6 +73,7 @@
"mousetrap": "^1.6.5",
"platform": "^1.3.6",
"prop-types": "^15.7.2",
"rc-menu": "^8.10.7",
"react": "^16.14.0",
"react-awesome-query-builder": "^3.0.0",
"react-color": "^2.19.3",
Expand All @@ -80,7 +82,6 @@
"react-moment": "^1.1.1",
"react-redux": "^7.2.2",
"react-resizable": "^1.11.1",
"@types/react-resizable": "^1.7.2",
"react-router": "^5.1.0",
"react-router-dom": "^5.1.0",
"react-share": "^3.0.1",
Expand Down
100 changes: 100 additions & 0 deletions cvat-ui/src/actions/tasks-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export enum TasksActionTypes {
UPDATE_TASK_SUCCESS = 'UPDATE_TASK_SUCCESS',
UPDATE_TASK_FAILED = 'UPDATE_TASK_FAILED',
HIDE_EMPTY_TASKS = 'HIDE_EMPTY_TASKS',
EXPORT_TASK = 'EXPORT_TASK',
EXPORT_TASK_SUCCESS = 'EXPORT_TASK_SUCCESS',
EXPORT_TASK_FAILED = 'EXPORT_TASK_FAILED',
IMPORT_TASK = 'IMPORT_TASK',
IMPORT_TASK_SUCCESS = 'IMPORT_TASK_SUCCESS',
IMPORT_TASK_FAILED = 'IMPORT_TASK_FAILED',
}

function getTasks(): AnyAction {
Expand Down Expand Up @@ -213,6 +219,49 @@ export function loadAnnotationsAsync(
};
}

function importTask(): AnyAction {
const action = {
type: TasksActionTypes.IMPORT_TASK,
payload: {},
};

return action;
}

function importTaskSuccess(task: any): AnyAction {
const action = {
type: TasksActionTypes.IMPORT_TASK_SUCCESS,
payload: {
task,
},
};

return action;
}

function importTaskFailed(error: any): AnyAction {
const action = {
type: TasksActionTypes.IMPORT_TASK_FAILED,
payload: {
error,
},
};

return action;
}

export function importTaskAsync(file: File): ThunkAction<Promise<void>, {}, {}, AnyAction> {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
try {
dispatch(importTask());
const taskInstance = await cvat.classes.Task.import(file);
dispatch(importTaskSuccess(taskInstance));
} catch (error) {
dispatch(importTaskFailed(error));
}
};
}

function exportDataset(task: any, exporter: any): AnyAction {
const action = {
type: TasksActionTypes.EXPORT_DATASET,
Expand Down Expand Up @@ -267,6 +316,57 @@ export function exportDatasetAsync(task: any, exporter: any): ThunkAction<Promis
};
}

function exportTask(taskID: number): AnyAction {
const action = {
type: TasksActionTypes.EXPORT_TASK,
payload: {
taskID,
},
};

return action;
}

function exportTaskSuccess(taskID: number): AnyAction {
const action = {
type: TasksActionTypes.EXPORT_TASK_SUCCESS,
payload: {
taskID,
},
};

return action;
}

function exportTaskFailed(taskID: number, error: Error): AnyAction {
const action = {
type: TasksActionTypes.EXPORT_TASK_FAILED,
payload: {
taskID,
error,
},
};

return action;
}

export function exportTaskAsync(taskInstance: any): ThunkAction<Promise<void>, {}, {}, AnyAction> {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
dispatch(exportTask(taskInstance.id));

try {
const url = await taskInstance.export();
const downloadAnchor = window.document.getElementById('downloadAnchor') as HTMLAnchorElement;
downloadAnchor.href = url;
downloadAnchor.click();
} catch (error) {
dispatch(exportTaskFailed(taskInstance.id, error));
}

dispatch(exportTaskSuccess(taskInstance.id));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably you can put the line under try. It looks more naturally.

};
}

function deleteTask(taskID: number): AnyAction {
const action = {
type: TasksActionTypes.DELETE_TASK,
Expand Down
8 changes: 8 additions & 0 deletions cvat-ui/src/components/actions-menu/actions-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import './styles.scss';
import React from 'react';
import Menu from 'antd/lib/menu';
import Modal from 'antd/lib/modal';
import { LoadingOutlined } from '@ant-design/icons';
// eslint-disable-next-line import/no-extraneous-dependencies
import { MenuInfo } from 'rc-menu/lib/interface';
import DumpSubmenu from './dump-submenu';
Expand All @@ -25,6 +26,7 @@ interface Props {
inferenceIsActive: boolean;
taskDimension: DimensionType;
onClickMenu: (params: MenuInfo, file?: File) => void;
exportIsActive: boolean;
}

export enum Actions {
Expand All @@ -34,6 +36,7 @@ export enum Actions {
DELETE_TASK = 'delete_task',
RUN_AUTO_ANNOTATION = 'run_auto_annotation',
OPEN_BUG_TRACKER = 'open_bug_tracker',
EXPORT_TASK = 'export_task',
}

export default function ActionsMenuComponent(props: Props): JSX.Element {
Expand All @@ -49,6 +52,7 @@ export default function ActionsMenuComponent(props: Props): JSX.Element {
exportActivities,
loadActivity,
taskDimension,
exportIsActive,
} = props;

let latestParams: MenuInfo | null = null;
Expand Down Expand Up @@ -127,6 +131,10 @@ export default function ActionsMenuComponent(props: Props): JSX.Element {
<Menu.Item disabled={inferenceIsActive} key={Actions.RUN_AUTO_ANNOTATION}>
Automatic annotation
</Menu.Item>
<Menu.Item key={Actions.EXPORT_TASK}>
{exportIsActive && <LoadingOutlined id='cvat-export-task-loading' />}
Export Task
</Menu.Item>
<hr />
<Menu.Item key={Actions.DELETE_TASK}>Delete</Menu.Item>
</Menu>
Expand Down
Loading