Skip to content

Commit

Permalink
Replaced get/task/ID by api/v1/tasks/ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Manovich committed Jan 28, 2019
1 parent fdd99ad commit 6ca3c6f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 36 deletions.
42 changes: 30 additions & 12 deletions cvat/apps/dashboard/static/dashboard/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,27 @@ function uploadAnnotationRequest() {
function parseFile(e, overlay) {
let xmlText = e.target.result;
overlay.setMessage("Request task data from server..");
$.ajax({
url: "/get/task/" + window.cvat.dashboard.taskID,
success: function(data) {
$.when(
$.get("/api/v1/tasks/" + window.cvat.dashboard.taskID),
$.get("/api/v1/tasks/" + window.cvat.dashboard.taskID + "/frames/meta"),
).then(
function(taskInfo, imageMetaCache) {
let spec = {"labels": {}, "attributes": {}};
for (let label of taskInfo[0].labels) {
spec.labels[label.id] = label.name;
spec.attributes[label.id] = {};
for (let attr of label.attributes) {
spec.attributes[label.id][attr.id] = attr.text;
}
}
let annotationParser = new AnnotationParser(
{
start: 0,
stop: data.size,
image_meta_data: data.image_meta_data,
flipped: data.flipped
stop: taskInfo[0].size,
image_meta_data: imageMetaCache[0],
flipped: taskInfo[0].flipped
},
new LabelsInfo(data.spec),
new LabelsInfo(spec),
new ConstIdGenerator(-1)
);

Expand Down Expand Up @@ -208,13 +218,13 @@ function uploadAnnotationRequest() {
overlay.setMessage("File is being parsed..");
setTimeout(asyncParse);
},
error: function(response) {
function(response) {
overlay.remove();
let message = "Bad task request: " + response.responseText;
showMessage(message);
throw Error(message);
}
});
);
}
}

Expand Down Expand Up @@ -570,9 +580,17 @@ function setupTaskUpdater() {

updateModal[0].loadCurrentLabels = function() {
$.ajax({
url: "/get/task/" + window.cvat.dashboard.taskID,
success: function(data) {
let labels = new LabelsInfo(data.spec);
url: "/api/v1/tasks/" + window.cvat.dashboard.taskID,
success: function(taskInfo) {
let spec = {"labels": {}, "attributes": {}};
for (let label of taskInfo.labels) {
spec.labels[label.id] = label.name;
spec.attributes[label.id] = {};
for (let attr of label.attributes) {
spec.attributes[label.id][attr.id] = attr.text;
}
}
let labels = new LabelsInfo(spec);
oldLabels.attr("value", labels.normalize());
},
error: function(response) {
Expand Down
24 changes: 12 additions & 12 deletions cvat/apps/engine/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ def init_from_client(self, data):
frame_idx = int(box['frame']) if db_task.mode == 'annotation' else 0
xtl, ytl, xbr, ybr = self._clamp_box(float(box['xtl']), float(box['ytl']),
float(box['xbr']), float(box['ybr']),
image_meta['original_size'][frame_idx])
image_meta[frame_idx])

labeled_box = _LabeledBox(
label=label,
Expand All @@ -935,7 +935,7 @@ def init_from_client(self, data):
label = _Label(self.db_labels[int(poly_shape['label_id'])])

frame_idx = int(poly_shape['frame']) if db_task.mode == 'annotation' else 0
points = self._clamp_poly(poly_shape['points'], image_meta['original_size'][frame_idx])
points = self._clamp_poly(poly_shape['points'], image_meta[frame_idx])
labeled_poly_shape = _LabeledPolyShape(
label=label,
points=points,
Expand Down Expand Up @@ -976,7 +976,7 @@ def init_from_client(self, data):
if int(box['frame']) <= self.stop_frame and int(box['frame']) >= self.start_frame:
frame_idx = int(box['frame']) if db_task.mode == 'annotation' else 0
xtl, ytl, xbr, ybr = self._clamp_box(float(box['xtl']), float(box['ytl']),
float(box['xbr']), float(box['ybr']), image_meta['original_size'][frame_idx])
float(box['xbr']), float(box['ybr']), image_meta[frame_idx])
tracked_box = _TrackedBox(
x0=xtl, y0=ytl, x1=xbr, y1=ybr,
frame=int(box['frame']),
Expand Down Expand Up @@ -1039,7 +1039,7 @@ def init_from_client(self, data):
for poly_shape in path['shapes']:
if int(poly_shape['frame']) <= self.stop_frame and int(poly_shape['frame']) >= self.start_frame:
frame_idx = int(poly_shape['frame']) if db_task.mode == 'annotation' else 0
points = self._clamp_poly(poly_shape['points'], image_meta['original_size'][frame_idx])
points = self._clamp_poly(poly_shape['points'], image_meta[frame_idx])
tracked_poly_shape = _TrackedPolyShape(
points=points,
frame=int(poly_shape['frame']),
Expand Down Expand Up @@ -1963,8 +1963,8 @@ def _flip_shape(shape, im_w, im_h):

if db_task.mode == "interpolation":
meta["task"]["original_size"] = OrderedDict([
("width", str(im_meta_data["original_size"][0]["width"])),
("height", str(im_meta_data["original_size"][0]["height"]))
("width", str(im_meta_data[0]["width"])),
("height", str(im_meta_data[0]["height"]))
])

dump_path = db_task.get_dump_path()
Expand Down Expand Up @@ -2014,14 +2014,14 @@ def _flip_shape(shape, im_w, im_h):
rpath = path.split(os.path.sep)
rpath = os.path.sep.join(rpath[rpath.index(".upload")+1:])

im_w = im_meta_data['original_size'][frame]['width']
im_h = im_meta_data['original_size'][frame]['height']
im_w = im_meta_data[frame]['width']
im_h = im_meta_data[frame]['height']

dumper.open_image(OrderedDict([
("id", str(frame)),
("name", rpath),
("width", str(im_meta_data['original_size'][frame]["width"])),
("height", str(im_meta_data['original_size'][frame]["height"]))
("width", str(im_meta_data[frame]["width"])),
("height", str(im_meta_data[frame]["height"]))
]))

for shape_type in ["boxes", "polygons", "polylines", "points"]:
Expand Down Expand Up @@ -2095,8 +2095,8 @@ def _flip_shape(shape, im_w, im_h):
paths["polylines"] = self.to_polyline_paths()
paths["points"] = self.to_points_paths()

im_w = im_meta_data['original_size'][0]['width']
im_h = im_meta_data['original_size'][0]['height']
im_w = im_meta_data[0]['width']
im_h = im_meta_data[0]['height']

counter = 0
for shape_type in ["boxes", "polygons", "polylines", "points"]:
Expand Down
12 changes: 6 additions & 6 deletions cvat/apps/engine/static/engine/js/annotationParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class AnnotationParser {
}

_getBoxPosition(box, frame) {
frame = Math.min(frame - this._startFrame, this._im_meta['original_size'].length - 1);
let im_w = this._im_meta['original_size'][frame].width;
let im_h = this._im_meta['original_size'][frame].height;
frame = Math.min(frame - this._startFrame, this._im_meta.length - 1);
let im_w = this._im_meta[frame].width;
let im_h = this._im_meta[frame].height;

let xtl = +box.getAttribute('xtl');
let ytl = +box.getAttribute('ytl');
Expand Down Expand Up @@ -56,9 +56,9 @@ class AnnotationParser {
}

_getPolyPosition(shape, frame) {
frame = Math.min(frame - this._startFrame, this._im_meta['original_size'].length - 1);
let im_w = this._im_meta['original_size'][frame].width;
let im_h = this._im_meta['original_size'][frame].height;
frame = Math.min(frame - this._startFrame, this._im_meta.length - 1);
let im_w = this._im_meta[frame].width;
let im_h = this._im_meta[frame].height;
let points = shape.getAttribute('points').split(';').join(' ');
points = PolyShapeModel.convertStringToNumberArray(points);

Expand Down
7 changes: 3 additions & 4 deletions cvat/apps/engine/static/engine/js/qunitTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,7 @@ function makePlayerModel() {

// stub data
window.job = {
"image_meta_data": {
"original_size": [{
"image_meta_data": [{
"height": 1280,
"width": 1920
}, {
Expand Down Expand Up @@ -567,8 +566,8 @@ window.job = {
}, {
"height": 1280,
"width": 1920
}]
},
}
],
"z_order": true,
"start": 0,
"slug": "QUnitTests",
Expand Down
2 changes: 1 addition & 1 deletion cvat/apps/engine/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def get_job(jid):

# Truncate extra image sizes
if db_task.mode == 'annotation':
im_meta_data['original_size'] = im_meta_data['original_size'][db_segment.start_frame:db_segment.stop_frame + 1]
im_meta_data = im_meta_data['original_size'][db_segment.start_frame:db_segment.stop_frame + 1]

db_labels = db_task.label_set.prefetch_related('attributespec_set').order_by('-pk').all()
attributes = {}
Expand Down
1 change: 0 additions & 1 deletion cvat/apps/engine/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
path('delete/task/<int:tid>', views.delete_task), ####
path('update/task/<int:tid>', views.update_task), ####
path('get/job/<int:jid>', views.get_job), ###
path('get/task/<int:tid>', views.get_task), ####
path('dump/annotation/task/<int:tid>', views.dump_annotation), ###
path('check/annotation/task/<int:tid>', views.check_annotation), ###
path('download/annotation/task/<int:tid>', views.download_annotation), ###
Expand Down

0 comments on commit 6ca3c6f

Please sign in to comment.