Skip to content

Commit

Permalink
Show percentage done
Browse files Browse the repository at this point in the history
  • Loading branch information
jdede committed Sep 20, 2023
1 parent c19bc63 commit c629c28
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
10 changes: 9 additions & 1 deletion simplelabel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
5 changes: 4 additions & 1 deletion simplelabel/templates/simplelabel/poll.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ <h1 class="display-5 fw-bold">What do you see?</h1>
</div>

</form>
<p class="text-muted">
{% if user.is_authenticated %}
<p> <a href="{{ image.get_image_detail_url }}">Details</a></p>
<a href="{{ image.get_image_detail_url }}">Details</a> &centerdot;
{% endif %}
{{ percent_done|floatformat }} &percnt; done
</p>

</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion simplelabel/templates/simplelabel/statistics.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h2 class="display-7 fw-bold">Active Datasets</h2>
<td>{{ entry.dataset_name }}</td>
<td>{{ entry.get_number_images }}</td>
<td>{{ entry.dataset_max_polls }}</td>
<td>{{ entry.get_percentage_done }}&percnt;</td>
<td>{{ entry.get_percentage_done|floatformat }}&percnt;</td>
</tr>
{% endfor %}

Expand Down
1 change: 1 addition & 0 deletions simplelabel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit c629c28

Please sign in to comment.