diff --git a/exact/exact/annotations/models.py b/exact/exact/annotations/models.py index 63249b43..dbc6fd84 100644 --- a/exact/exact/annotations/models.py +++ b/exact/exact/annotations/models.py @@ -88,6 +88,10 @@ class Annotation(models.Model): meta_data = models.JSONField(null=True) + #Minsu + drawing_time = models.IntegerField(default=0) + num_points = models.IntegerField(default=0) + def __str__(self): return 'Annotation: {0}'.format(self.annotation_type.name) diff --git a/exact/exact/annotations/serializers.py b/exact/exact/annotations/serializers.py index b11c97cc..52ae331b 100644 --- a/exact/exact/annotations/serializers.py +++ b/exact/exact/annotations/serializers.py @@ -88,7 +88,9 @@ class Meta: 'unique_identifier', 'uploaded_media_files', 'meta_data', - 'annotationversion_set' + 'annotationversion_set', + 'drawing_time', #Minsu + 'num_points' #Minsu ) expandable_fields = { @@ -169,7 +171,7 @@ class Meta: 'deleted', 'description', 'unique_identifier', - 'meta_data' + 'meta_data', ) read_only_fields = fields diff --git a/exact/exact/annotations/static/annotations/js/boundingboxes.js b/exact/exact/annotations/static/annotations/js/boundingboxes.js index 7c2cb0d5..bf4bac80 100644 --- a/exact/exact/annotations/static/annotations/js/boundingboxes.js +++ b/exact/exact/annotations/static/annotations/js/boundingboxes.js @@ -345,11 +345,20 @@ class BoundingBoxes { el.remove(); this.group.addChild(result) - resultDict.update.push([result.name, org_item]) + //Minsu + //나중에 함수로 만들때는 빼기 결과가 음수일 경우를 고려 + let num_seg_obj1 = result.getIntersections(this.selection.item).length; + let num_seg_obj2 = result._segments.length - num_seg_obj1; + + resultDict.update.push([result.name, org_item, num_seg_obj1, num_seg_obj2]) } } else { result.children.forEach(old_path => { + //Minsu + let num_seg_obj1 = old_path.getIntersections(this.selection.item).length; + let num_seg_obj2 = old_path._segments.length - num_seg_obj1; + // add childs as new elements var new_path = old_path.clone(subOptions) new_path.data = old_path.parent.data @@ -360,7 +369,7 @@ class BoundingBoxes { new_path.name = this.uuidv4(); this.group.addChild(new_path); - resultDict.insert.push({ + resultDict.insert.push([{ annotation_type: el.data.type_id, id: -1, vector: this.getAnnotationVector(new_path.name), @@ -368,8 +377,10 @@ class BoundingBoxes { last_editor: { id: null, username: "you" }, image: this.imageid, unique_identifier: new_path.name, - deleted: false - }); + deleted: false, + drawing_time: 0, + num_points: 0 + }, el.name, num_seg_obj1, num_seg_obj2]); }) result.remove() @@ -425,7 +436,7 @@ class BoundingBoxes { new_path.name = this.uuidv4(); this.group.addChild(new_path); - resultDict.insert.push({ + resultDict.insert.push([{ annotation_type: this.singlePolyOperation.selected.item.data.type_id, id: -1, vector: this.getAnnotationVector(new_path.name), @@ -434,7 +445,7 @@ class BoundingBoxes { image: this.imageid, unique_identifier: new_path.name, deleted: false - }); + }]); } @@ -654,7 +665,7 @@ class BoundingBoxes { new_path.name = this.uuidv4(); this.group.addChild(new_path); - resultDict.insert.push({ + resultDict.insert.push([{ annotation_type: el.data.type_id, id: -1, vector: this.getAnnotationVector(new_path.name), @@ -663,7 +674,7 @@ class BoundingBoxes { image: this.imageid, unique_identifier: new_path.name, deleted: false - }); + }]); polys[id].remove() lines[id].remove() diff --git a/exact/exact/annotations/static/annotations/js/exact-image-viewer.js b/exact/exact/annotations/static/annotations/js/exact-image-viewer.js index dca3e9ff..e1b2c64c 100644 --- a/exact/exact/annotations/static/annotations/js/exact-image-viewer.js +++ b/exact/exact/annotations/static/annotations/js/exact-image-viewer.js @@ -845,7 +845,7 @@ class EXACTViewerLocalAnnotations extends EXACTViewer { this.actionStack = []; this.actionMemory = 50; - this.currentAction = undefined + this.currentAction = undefined; this.pressedDigits = { 1 : false, @@ -859,7 +859,7 @@ class EXACTViewerLocalAnnotations extends EXACTViewer { 9 : false } - this.insertNewAnno = false + this.insertNewAnno = false; this.initUiEvents(this.annotationTypes); } @@ -928,7 +928,12 @@ class EXACTViewerLocalAnnotations extends EXACTViewer { event.userData.cancelEditAnnotation(); }, this); + //Minsu + var startTime = null; viewer.addHandler('selection_onPress', function (event) { + // Minsu start record + startTime = new Date().getTime(); + viewer.canvas.focus() // setup viewport var viewportPoint = viewer.viewport.pointFromPixel(event.position); @@ -1007,6 +1012,14 @@ class EXACTViewerLocalAnnotations extends EXACTViewer { }, this); viewer.addHandler("selection_onRelease", function (event) { + // Minsu + let drawingTime = null; + if (startTime != null) { + let endTime = new Date().getTime(); + drawingTime = endTime - startTime; + startTime = null; + } + viewer.canvas.focus() // setup viewport var viewportPoint = viewer.viewport.pointFromPixel(event.position); @@ -1037,6 +1050,7 @@ class EXACTViewerLocalAnnotations extends EXACTViewer { var last_uuid = tool.selection.item.name; var anno = exact_sync.annotations[last_uuid]; + anno["drawing_time"] = drawingTime event.userData.do_finishAnnotation(anno); // select the new item, if it was not deleted (because it was to small) @@ -1157,6 +1171,14 @@ class EXACTViewerLocalAnnotations extends EXACTViewer { let annotation = exact_sync.getAnnotation(unique_identifier) annotation.vector = event.userData.getAnnotationVector(annotation.unique_identifier); + + //Minsu + let annotation1 = exact_sync.getAnnotation(tool.selection.item.name) + let time1 = Math.round(annotation1.drawing_time / annotation1.num_points) * el[2]; + let time2 = Math.round(annotation.drawing_time / annotation.num_points) * el[3]; + + annotation.drawing_time = time1 + time2 + exact_sync.saveAnnotation(annotation) var action = { @@ -1188,11 +1210,22 @@ class EXACTViewerLocalAnnotations extends EXACTViewer { } } - for (let newAnno of resultDict.insert) + for (let el of resultDict.insert) { + let newAnno = el[0]; + if (Number.isInteger(newAnno.annotation_type)) { newAnno.annotation_type = exact_sync.annotationTypes[newAnno.annotation_type] } + + //Minsu + let annotation1 = exact_sync.getAnnotation(tool.selection.item.name) + let annotation2 = exact_sync.getAnnotation(el[1]) + let time1 = Math.round(annotation1.drawing_time / annotation1.num_points) * el[2]; + let time2 = Math.round(annotation2.drawing_time / annotation2.num_points) * el[3]; + + newAnno.drawing_time = time1 + time2 + exact_sync.addAnnotationToCache(newAnno) exact_sync.saveAnnotation(newAnno) diff --git a/exact/exact/annotations/static/annotations/js/exact-sync.js b/exact/exact/annotations/static/annotations/js/exact-sync.js index b5f2b5cd..1c99da14 100644 --- a/exact/exact/annotations/static/annotations/js/exact-sync.js +++ b/exact/exact/annotations/static/annotations/js/exact-sync.js @@ -572,9 +572,8 @@ class EXACTAnnotationSync { this.API_1_FILTERS += "user=" + user_id + "&" } - this.API_1_ANNOTATION_FIELDS = 'fields=image,annotation_type,id,vector,generated,deleted,description,verified_by_user,uploaded_media_files,unique_identifier,remark,user.id,user.username,last_editor.id,last_editor.username&'; + this.API_1_ANNOTATION_FIELDS = 'fields=image,annotation_type,id,vector,generated,deleted,description,verified_by_user,uploaded_media_files,unique_identifier,remark,user.id,user.username,last_editor.id,last_editor.username,drawing_time,num_points&'; this.API_1_PLUGINRESULTS_FIELDS = 'fields=image,annotation_type,id,vector,score,generated,plugin,description,unique_identifier,pluginresultentry&'; - this.initLoadAnnotations(annotationTypes, imageId) this.refreshAnnotationsFromServer = setInterval(this.refreshAnnotations(this), this.upDateFromServerInterval, this); } @@ -818,13 +817,14 @@ class EXACTAnnotationSync { var action = 'POST'; var url = this.API_1_ANNOTATIONS_BASE_URL + "annotations/"; - var data = { deleted: annotation.deleted, annotation_type: annotation.annotation_type.id, image: annotation.image, vector: annotation.vector, - unique_identifier: annotation.unique_identifier + unique_identifier: annotation.unique_identifier, + drawing_time: annotation.drawing_time, + num_points: Object.keys(annotation.vector).length / 2 }; // edit instead of create @@ -1041,7 +1041,9 @@ class EXACTGlobalAnnotationSync extends EXACTAnnotationSync { annotation_type: annotation.annotation_type.id, image: annotation.image, vector: annotation.vector, - unique_identifier: annotation.unique_identifier + unique_identifier: annotation.unique_identifier, + drawing_time: annotation.drawing_time, + num_points: Object.keys(annotation.vector).length / 2 }; // edit instead of create @@ -1295,7 +1297,9 @@ class EXACTGlobalFrameAnnotationSync extends EXACTGlobalAnnotationSync { annotation_type: annotation.annotation_type.id, image: annotation.image, vector: annotation.vector, - unique_identifier: annotation.unique_identifier + unique_identifier: annotation.unique_identifier, + drawing_time: annotation.drawing_time, + num_points: Object.keys(annotation.vector).length / 2 }; // edit instead of create