Skip to content

Commit 759ad88

Browse files
committed
Added basic stats
1 parent d7ef371 commit 759ad88

File tree

3 files changed

+75
-10
lines changed

3 files changed

+75
-10
lines changed

backend/webserver/api/datasets.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,39 @@ def get(self, dataset_id):
134134
return query_util.fix_ids(users)
135135

136136

137+
@api.route('/<int:dataset_id>/stats')
138+
class DatasetStats(Resource):
139+
140+
@login_required
141+
def get(self, dataset_id):
142+
""" All users in the dataset """
143+
args = dataset_generate.parse_args()
144+
145+
dataset = current_user.datasets.filter(id=dataset_id, deleted=False).first()
146+
if dataset is None:
147+
return {"message": "Invalid dataset id"}, 400
148+
149+
images = ImageModel.objects(dataset_id=dataset.id, deleted=False)
150+
annotations = AnnotationModel.objects(dataset_id=dataset_id, deleted=False)
151+
stats = {
152+
'total': {
153+
'Users': dataset.get_users().count(),
154+
'Images': images.count(),
155+
'Annotated Images': images.filter(annotated=True).count(),
156+
'Annotations': annotations.count(),
157+
'Categories': len(dataset.categories)
158+
},
159+
'average': {
160+
'Image Width (px)': images.average('width'),
161+
'Image Height (px)': images.average('height'),
162+
'Annotation Area (px)': annotations.average('area'),
163+
'Time (ms) per Image': images.average('milliseconds') or 0,
164+
'Time (ms) per Annotation': annotations.average('milliseconds') or 0
165+
}
166+
}
167+
return stats
168+
169+
137170
@api.route('/<int:dataset_id>')
138171
class DatasetId(Resource):
139172
@login_required

client/src/models/datasets.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,8 @@ export default {
5151
},
5252
getUsers(id) {
5353
return axios.get(`${baseURL}/${id}/users`);
54+
},
55+
getStats(id) {
56+
return axios.get(`${baseURL}/${id}/stats`);
5457
}
5558
};

client/src/views/Dataset.vue

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@
6464
<div class="container" v-show="tab == 'exports'">Empty</div>
6565
<div class="container" v-show="tab == 'members'">
6666

67-
<div class="my-3 p-3 bg-white rounded shadow-sm">
67+
<div class="card my-3 p-3 shadow-sm mr-2">
6868
<h6 class="border-bottom border-gray pb-2"><b>Invite Members</b></h6>
6969

7070
</div>
7171

72-
<div class="my-3 p-3 bg-white rounded shadow-sm">
72+
<div class="card my-3 p-3 shadow-sm mr-2">
7373
<h6 class="border-bottom border-gray pb-2"><b>Exisiting Memebers</b></h6>
7474

7575
<div class="media text-muted pt-3" v-for="user in users">
@@ -87,7 +87,34 @@
8787
</div>
8888

8989
</div>
90-
<div class="container" v-show="tab == 'statistics'">Stats</div>
90+
<div class="container" v-show="tab == 'statistics'">
91+
<div v-if="stats == null">
92+
Crunching numbers...
93+
</div>
94+
95+
<div v-else>
96+
<div class="row">
97+
98+
<div v-if="stats.total" class="card my-3 p-3 shadow-sm col-3 mr-2">
99+
<h6 class="border-bottom border-gray pb-2"><b>Total</b></h6>
100+
<div class="row" v-for="stat in Object.keys(stats.total)">
101+
<strong class="col-8">{{stat}}:</strong>
102+
<span class="col-4">{{stats.total[stat]}}</span>
103+
</div>
104+
</div>
105+
106+
<div v-if="stats.average" class="card my-3 p-3 shadow-sm col-4 mr-2">
107+
<h6 class="border-bottom border-gray pb-2"><b>Average</b></h6>
108+
<div class="row" v-for="stat in Object.keys(stats.average)">
109+
<strong class="col-8">{{stat}}:</strong>
110+
<span class="col-4">{{stats.average[stat].toFixed(2)}}</span>
111+
</div>
112+
</div>
113+
114+
</div>
115+
116+
</div>
117+
</div>
91118
<div class="container" v-show="tab == 'settings'">settings</div>
92119

93120
</div>
@@ -369,7 +396,8 @@ export default {
369396
panel: {
370397
showAnnotated: true,
371398
showNotAnnotated: true
372-
}
399+
},
400+
stats: null
373401
};
374402
},
375403
methods: {
@@ -419,6 +447,12 @@ export default {
419447
this.users = response.data
420448
});
421449
},
450+
getStats() {
451+
Dataset.getStats(this.dataset.id)
452+
.then(response => {
453+
this.stats = response.data;
454+
});
455+
},
422456
createScanTask() {
423457
if (this.scan.id != null) {
424458
this.$router.push({ path: "/tasks", query: { id: this.scan.id } });
@@ -549,6 +583,7 @@ export default {
549583
tab(tab) {
550584
localStorage.setItem('dataset/tab', tab);
551585
if (tab == 'members') this.getUsers();
586+
if (tab == 'statistics') this.getStats();
552587
},
553588
queryAnnotated() {
554589
this.updatePage();
@@ -671,10 +706,4 @@ export default {
671706
padding: 0 5px 2px 5px;
672707
overflow: auto;
673708
}
674-
675-
.card-header {
676-
padding: 5px 10px;
677-
}
678-
679-
680709
</style>

0 commit comments

Comments
 (0)