Skip to content

Commit

Permalink
Store the number of points for each annotation in the database.
Browse files Browse the repository at this point in the history
Recording and store a drawing time after creating an annotation
Update the drawing time when subtracting annotations
  • Loading branch information
lullulalal committed May 8, 2024
1 parent 7177c42 commit ef97aa7
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 19 deletions.
4 changes: 4 additions & 0 deletions exact/exact/annotations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 4 additions & 2 deletions exact/exact/annotations/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -169,7 +171,7 @@ class Meta:
'deleted',
'description',
'unique_identifier',
'meta_data'
'meta_data',
)
read_only_fields = fields

Expand Down
27 changes: 19 additions & 8 deletions exact/exact/annotations/static/annotations/js/boundingboxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -360,16 +369,18 @@ 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),
user: { id: null, username: "you" },
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()
Expand Down Expand Up @@ -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),
Expand All @@ -434,7 +445,7 @@ class BoundingBoxes {
image: this.imageid,
unique_identifier: new_path.name,
deleted: false
});
}]);

}

Expand Down Expand Up @@ -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),
Expand All @@ -663,7 +674,7 @@ class BoundingBoxes {
image: this.imageid,
unique_identifier: new_path.name,
deleted: false
});
}]);

polys[id].remove()
lines[id].remove()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ class EXACTViewerLocalAnnotations extends EXACTViewer {

this.actionStack = [];
this.actionMemory = 50;
this.currentAction = undefined
this.currentAction = undefined;

this.pressedDigits = {
1 : false,
Expand All @@ -859,7 +859,7 @@ class EXACTViewerLocalAnnotations extends EXACTViewer {
9 : false
}

this.insertNewAnno = false
this.insertNewAnno = false;

this.initUiEvents(this.annotationTypes);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)

Expand Down
16 changes: 10 additions & 6 deletions exact/exact/annotations/static/annotations/js/exact-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ef97aa7

Please sign in to comment.