From c629c282b5220a6485e67688807ed449115cd553 Mon Sep 17 00:00:00 2001
From: Jens Dede
Date: Wed, 20 Sep 2023 12:04:40 +0200
Subject: [PATCH] Show percentage done
---
simplelabel/models.py | 10 +++++++++-
simplelabel/templates/simplelabel/poll.html | 5 ++++-
simplelabel/templates/simplelabel/statistics.html | 2 +-
simplelabel/views.py | 1 +
4 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/simplelabel/models.py b/simplelabel/models.py
index 365d2ac..78a8eb2 100644
--- a/simplelabel/models.py
+++ b/simplelabel/models.py
@@ -55,13 +55,21 @@ def get_number_polls(self):
def get_percentage_done(self):
if self.dataset_max_polls > 0 and self.get_number_images() > 0:
- return round((self.get_number_polls() / (self.dataset_max_polls * self.get_number_images()))*100.0)
+ return (self.get_number_polls() / (self.dataset_max_polls * self.get_number_images()))*100.0
return 0.0
get_percentage_done.short_description = "Percentage done"
def __str__(self):
return self.dataset_name + " " + (u"✓" if self.dataset_active else u"✗")
+ @staticmethod
+ def get_average_percentage_done():
+ ds = Dataset.objects.filter(dataset_active=True).all()
+ s = 0.0
+ for d in ds:
+ s += d.get_percentage_done()
+ return s / len(ds)
+
class Image(models.Model):
image = models.ImageField(
upload_to="images/%Y/%m/%d/",
diff --git a/simplelabel/templates/simplelabel/poll.html b/simplelabel/templates/simplelabel/poll.html
index 9742932..380fe90 100644
--- a/simplelabel/templates/simplelabel/poll.html
+++ b/simplelabel/templates/simplelabel/poll.html
@@ -42,9 +42,12 @@ What do you see?
+
{% if user.is_authenticated %}
-
Details
+ Details ·
{% endif %}
+ {{ percent_done|floatformat }} % done
+
diff --git a/simplelabel/templates/simplelabel/statistics.html b/simplelabel/templates/simplelabel/statistics.html
index bb7b800..1864ce2 100644
--- a/simplelabel/templates/simplelabel/statistics.html
+++ b/simplelabel/templates/simplelabel/statistics.html
@@ -80,7 +80,7 @@ Active Datasets
{{ entry.dataset_name }} |
{{ entry.get_number_images }} |
{{ entry.dataset_max_polls }} |
- {{ entry.get_percentage_done }}% |
+ {{ entry.get_percentage_done|floatformat }}% |
{% endfor %}
diff --git a/simplelabel/views.py b/simplelabel/views.py
index f663de8..d88f5dd 100644
--- a/simplelabel/views.py
+++ b/simplelabel/views.py
@@ -224,6 +224,7 @@ def get_context_data(self, **kwargs):
classes = Class.objects.filter(class_is_visible=True)
context["classes"] = classes
context["image"] = random_img
+ context["percent_done"] = Dataset.get_average_percentage_done()
return context
def get_success_url(self):