Skip to content

Commit 968bdf7

Browse files
committed
Added time statistics
1 parent 759ad88 commit 968bdf7

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

backend/database/annotations.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from .datasets import DatasetModel
66
from .categories import CategoryModel
7-
7+
from .events import Event
88
from flask_login import current_user
99

1010

@@ -34,6 +34,10 @@ class AnnotationModel(DynamicDocument):
3434
deleted = BooleanField(default=False)
3535
deleted_date = DateTimeField()
3636

37+
milliseconds = IntField(default=0)
38+
events = EmbeddedDocumentListField(Event)
39+
40+
3741
def __init__(self, image_id=None, **data):
3842

3943
from .images import ImageModel

backend/database/images.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from PIL import Image
66
from mongoengine import *
77

8-
from .events import Event
9-
from .annotations import AnnotationModel, DatasetModel
10-
8+
from .events import Event, SessionEvent
9+
from .datasets import DatasetModel
10+
from .annotations import AnnotationModel
1111

1212
class ImageModel(DynamicDocument):
1313

@@ -44,8 +44,8 @@ class ImageModel(DynamicDocument):
4444
deleted = BooleanField(default=False)
4545
deleted_date = DateTimeField()
4646

47+
milliseconds = IntField(default=0)
4748
events = EmbeddedDocumentListField(Event)
48-
4949
regenerate_thumbnail = BooleanField(default=False)
5050

5151
@classmethod
@@ -179,7 +179,13 @@ def permissions(self, user):
179179
}
180180

181181
def add_event(self, e):
182-
self.update(push__events=e)
182+
u = {
183+
'push__events': e,
184+
}
185+
if isinstance(e, SessionEvent):
186+
u['inc__milliseconds'] = e.milliseconds
187+
188+
self.update(**u)
183189

184190

185191
__all__ = ["ImageModel"]

backend/webserver/api/annotator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def post(self):
8080

8181
# Update annotation in database
8282
sessions = []
83+
total_time = 0
8384
for session in annotation.get('sessions', []):
8485
date = datetime.datetime.fromtimestamp(int(session.get('start')) / 1e3)
8586
model = SessionEvent(
@@ -88,10 +89,12 @@ def post(self):
8889
milliseconds=session.get('milliseconds'),
8990
tools_used=session.get('tools')
9091
)
92+
total_time += session.get('milliseconds')
9193
sessions.append(model)
9294

9395
db_annotation.update(
9496
add_to_set__events=sessions,
97+
inc__milliseconds=total_time,
9598
set__keypoints=annotation.get('keypoints', []),
9699
set__metadata=annotation.get('metadata'),
97100
set__color=annotation.get('color')

backend/webserver/api/datasets.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,19 @@ def get(self, dataset_id):
147147
return {"message": "Invalid dataset id"}, 400
148148

149149
images = ImageModel.objects(dataset_id=dataset.id, deleted=False)
150+
annotated_images = images.filter(annotated=True)
150151
annotations = AnnotationModel.objects(dataset_id=dataset_id, deleted=False)
151152
stats = {
152153
'total': {
153154
'Users': dataset.get_users().count(),
154155
'Images': images.count(),
155-
'Annotated Images': images.filter(annotated=True).count(),
156+
'Annotated Images': annotated_images.count(),
156157
'Annotations': annotations.count(),
157-
'Categories': len(dataset.categories)
158+
'Categories': len(dataset.categories),
159+
'Time Annotating (s)': (images.sum('milliseconds') or 0) / 1000
158160
},
159161
'average': {
160-
'Image Width (px)': images.average('width'),
162+
'Image Size (px)': images.average('width'),
161163
'Image Height (px)': images.average('height'),
162164
'Annotation Area (px)': annotations.average('area'),
163165
'Time (ms) per Image': images.average('milliseconds') or 0,

client/src/views/Dataset.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@
9999
<h6 class="border-bottom border-gray pb-2"><b>Total</b></h6>
100100
<div class="row" v-for="stat in Object.keys(stats.total)">
101101
<strong class="col-8">{{stat}}:</strong>
102-
<span class="col-4">{{stats.total[stat]}}</span>
102+
<span class="col-4">{{stats.total[stat].toFixed(0)}}</span>
103103
</div>
104104
</div>
105105

106106
<div v-if="stats.average" class="card my-3 p-3 shadow-sm col-4 mr-2">
107107
<h6 class="border-bottom border-gray pb-2"><b>Average</b></h6>
108108
<div class="row" v-for="stat in Object.keys(stats.average)">
109109
<strong class="col-8">{{stat}}:</strong>
110-
<span class="col-4">{{stats.average[stat].toFixed(2)}}</span>
110+
<span class="col-4">{{stats.average[stat].toFixed(0)}}</span>
111111
</div>
112112
</div>
113113

0 commit comments

Comments
 (0)