Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
bug 1181140 - Add import progress bar
Browse files Browse the repository at this point in the history
The progress bar shows what percentage of pages with data import without
issues, and a breakdown of the issue severity for the other pages. This
makes it easier to see how close we are to the 80% of pages goal, across
all pages or a topic subset.
  • Loading branch information
jwhitlock committed Aug 26, 2015
1 parent 7099219 commit 309557b
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
23 changes: 21 additions & 2 deletions mdn/templates/mdn/feature_page_list.jinja2
Expand Up @@ -45,6 +45,25 @@
</p>

<p><strong>By Status</strong>:
{% if not status %}
<p>
{{ status_counts.no_data }} pages have no compatibility data.
{{ status_counts.data }} pages with data by error status:
<div class="progress">
{% for name, classes, count, percent in data_counts %}
{% if count %}
<div class="progress-bar {% for class in classes %}progress-bar-{{ class }} {% endfor %}"
aria-valuemin="0" aria-valuemax="100" aria-valuenow="{{ percent }}"
style="width: {{ percent }}%;"
data-toggle="tooltip" data-placement="top"
title="{{ count }} ({{ percent }}%) with {{ name }}">
{{ percent }}%
</div>
{% endif %}
{% endfor %}
</div>
</p>
{% endif %}
<div>
{% for status_value, name, class in statuses %}
{% if status == status_value %}
Expand Down Expand Up @@ -124,10 +143,10 @@

{% endblock content %}

{% block block_js_extra %}
{% block body_js_extra %}
<script>
$(function () {
$('#issue-header').tooltip()
$('[data-toggle="tooltip"]').tooltip()
})
</script>
{% endblock %}
26 changes: 26 additions & 0 deletions mdn/tests/test_views.py
Expand Up @@ -36,6 +36,32 @@ def test_populated_list(self):
self.assertEqual(1, len(pages.object_list))
obj = pages.object_list[0]
self.assertEqual(obj.id, feature_page.id)
data_counts = [
('Critical errors', ('danger', 'striped'), 0, 0),
('Errors', ('danger',), 0, 0),
('Warnings', ('warning',), 0, 0),
('No Errors', ('success',), 0, 0),
]
self.assertEqual(data_counts, response.context_data['data_counts'])
status_counts = {'total': 1, 'data': 0, 'no_data': 0, 'other': 1}
self.assertEqual(status_counts, response.context_data['status_counts'])

def test_with_issue(self):
feature_page = self.add_page()
feature_page.issues.create(slug='halt_import', start=1, end=1)
feature_page.status = FeaturePage.STATUS_PARSED_CRITICAL
feature_page.save()
response = self.client.get(self.url)
self.assertEqual(200, response.status_code)
data_counts = [
('Critical errors', ('danger', 'striped'), 1, '100.0'),
('Errors', ('danger',), 0, 0),
('Warnings', ('warning',), 0, 0),
('No Errors', ('success',), 0, 0),
]
self.assertEqual(data_counts, response.context_data['data_counts'])
status_counts = {'total': 1, 'data': 1, 'no_data': 0, 'other': 0}
self.assertEqual(status_counts, response.context_data['status_counts'])

def test_topic_filter(self):
feature_page = self.add_page()
Expand Down
37 changes: 37 additions & 0 deletions mdn/views.py
Expand Up @@ -5,6 +5,7 @@
from django.contrib.auth.decorators import user_passes_test
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.db.models import Count
from django.http import HttpResponseRedirect, JsonResponse
from django.utils.six.moves.urllib.parse import urlparse, urlunparse
from django.views.generic import DetailView, ListView, TemplateView
Expand Down Expand Up @@ -62,6 +63,13 @@ class FeaturePageListView(ListView):
FeaturePage.STATUS_PARSED_WARNING,
FeaturePage.STATUS_PARSED,
FeaturePage.STATUS_NO_DATA)
progress_bar_order = (
(FeaturePage.STATUS_PARSED_CRITICAL, 'Critical errors',
('danger', 'striped')),
(FeaturePage.STATUS_PARSED_ERROR, 'Errors', ('danger',)),
(FeaturePage.STATUS_PARSED_WARNING, 'Warnings', ('warning',)),
(FeaturePage.STATUS_PARSED, 'No Errors', ('success',)),
)

def get_queryset(self):
qs = FeaturePage.objects.order_by('url')
Expand All @@ -88,6 +96,35 @@ def get_context_data(self, **kwargs):
ctx['status'] = self.request.GET.get('status')
ctx['statuses'] = self.statuses

# Status progress bar
raw_status_counts = self.object_list.order_by(
'status').values('status').annotate(total=Count('status'))
status_counts = {}
total = 0
for item in raw_status_counts:
status_counts[item['status']] = item['total']
total += item['total']
have_data_count = sum(
status_counts.get(item[0], 0) for item in self.progress_bar_order)
data_counts_list = []
for status, name, classes in self.progress_bar_order:
count = status_counts.get(status, 0)
if count:
percent = "%0.1f" % (
100.0 * (float(count) / float(have_data_count)))
else:
percent = 0
data_counts_list.append((name, classes, count, percent))
ctx['data_counts'] = data_counts_list
no_data_count = status_counts.get(FeaturePage.STATUS_NO_DATA, 0)
other_count = total - have_data_count - no_data_count
ctx['status_counts'] = {
'total': total,
'data': have_data_count,
'no_data': no_data_count,
'other': other_count
}

return ctx


Expand Down

0 comments on commit 309557b

Please sign in to comment.