From 656ed8c89d79d40114e3010ff41a06e595d681a1 Mon Sep 17 00:00:00 2001 From: Ole Laursen Date: Tue, 10 Jan 2017 18:27:15 +0000 Subject: [PATCH] Add statistics for pages in documents, refactoring a bit to share more code - Legacy-Id: 12639 --- ietf/static/ietf/js/document-stats.js | 12 ++++ ietf/stats/tests.py | 2 +- ietf/stats/views.py | 32 ++++++++-- ietf/templates/stats/document_stats.html | 2 + .../stats/document_stats_authors.html | 24 ++------ .../templates/stats/document_stats_pages.html | 58 +++++++++++++++++++ .../stats/includes/docnames_cell.html | 1 + 7 files changed, 107 insertions(+), 24 deletions(-) create mode 100644 ietf/templates/stats/document_stats_pages.html create mode 100644 ietf/templates/stats/includes/docnames_cell.html diff --git a/ietf/static/ietf/js/document-stats.js b/ietf/static/ietf/js/document-stats.js index f9a08fa2c..922a7205e 100644 --- a/ietf/static/ietf/js/document-stats.js +++ b/ietf/static/ietf/js/document-stats.js @@ -1,5 +1,17 @@ $(document).ready(function () { if (window.chartConf) { + window.chartConf.credits = { + enabled: false + }; + window.chartConf.exporting = { + fallbackToExportServer: false + }; + + if (!window.chartConf.legend) + window.chartConf.legend = { + enabled: false + }; + var chart = Highcharts.chart('chart', window.chartConf); } diff --git a/ietf/stats/tests.py b/ietf/stats/tests.py index af8f5b431..33c76409f 100644 --- a/ietf/stats/tests.py +++ b/ietf/stats/tests.py @@ -31,7 +31,7 @@ class StatisticsTests(TestCase): self.assertTrue(authors_all_url in r["Location"]) # check various stats types - for stats_type in ["authors"]: + for stats_type in ["authors", "pages"]: for document_type in ["all", "rfc", "draft"]: url = urlreverse(ietf.stats.views.document_stats, kwargs={ "stats_type": stats_type, "document_type": document_type }) r = self.client.get(url) diff --git a/ietf/stats/views.py b/ietf/stats/views.py index 77c527157..5e1211daa 100644 --- a/ietf/stats/views.py +++ b/ietf/stats/views.py @@ -61,7 +61,7 @@ def document_stats(request, stats_type=None, document_type=None): # statistics type - one of the tables or the chart possible_stats_types = [ ("authors", "Number of authors"), -# ("pages", "Pages"), + ("pages", "Pages"), # ("format", "Format"), # ("spectech", "Specification techniques"), ] @@ -106,7 +106,6 @@ def document_stats(request, stats_type=None, document_type=None): stats_title = "" if stats_type == "authors": - stats_title = "Number of authors for each {}".format(doc_label) groups = defaultdict(list) @@ -118,15 +117,38 @@ def document_stats(request, stats_type=None, document_type=None): series_data = [] for author_count, names in sorted(groups.iteritems(), key=lambda t: t[0]): - series_data.append((author_count, len(names) * 100.0 / total_docs)) - table_data.append((author_count, names)) + percentage = len(names) * 100.0 / total_docs + series_data.append((author_count, percentage)) + table_data.append((author_count, percentage, names)) chart_data.append({ "data": series_data, - "name": "Percentage of {}s".format(doc_label), "animation": False, }) + elif stats_type == "pages": + stats_title = "Number of pages for each {}".format(doc_label) + + groups = defaultdict(list) + + for name, pages in doc_qs.values_list("name", "pages"): + groups[pages].append(name) + + total_docs = sum(len(names) for pages, names in groups.iteritems()) + + series_data = [] + for pages, names in sorted(groups.iteritems(), key=lambda t: t[0]): + percentage = len(names) * 100.0 / total_docs + if pages is not None: + series_data.append((pages, len(names))) + table_data.append((pages, percentage, names)) + + chart_data.append({ + "data": series_data, + "animation": False, + }) + + return render(request, "stats/document_stats.html", { "chart_data": mark_safe(json.dumps(chart_data)), diff --git a/ietf/templates/stats/document_stats.html b/ietf/templates/stats/document_stats.html index 0ba8e3ccb..576a62ed5 100644 --- a/ietf/templates/stats/document_stats.html +++ b/ietf/templates/stats/document_stats.html @@ -37,6 +37,8 @@ {% if stats_type == "authors" %} {% include "stats/document_stats_authors.html" %} + {% elif stats_type == "pages" %} + {% include "stats/document_stats_pages.html" %} {% endif %} {% endblock %} diff --git a/ietf/templates/stats/document_stats_authors.html b/ietf/templates/stats/document_stats_authors.html index e8d1141fb..143da1114 100644 --- a/ietf/templates/stats/document_stats_authors.html +++ b/ietf/templates/stats/document_stats_authors.html @@ -7,12 +7,6 @@ chart: { type: 'column' }, - credits: { - enabled: false, - }, - exporting: { - fallbackToExportServer: false, - }, title: { text: '{{ stats_title|escapejs }}' }, @@ -32,16 +26,12 @@ } } }, - legend: { - enabled: false, - }, tooltip: { formatter: function () { var s = '' + this.x + ' ' + (this.x == 1 ? "author" : 'authors') + ''; $.each(this.points, function () { - s += '
' + this.series.name + ': ' + - this.y.toFixed(1) + '%'; + s += '
' + chartConf.yAxis.title.text + ': ' + this.y.toFixed(1) + '%'; }); return s; @@ -58,18 +48,16 @@ Authors - Documents + Percentage of {{ doc_label }}s + {{ doc_label }}s - {% for author_count, names in table_data %} + {% for author_count, percentage, names in table_data %} {{ author_count }} - {{ names|length }} + {{ percentage|floatformat:2 }}% + {% include "stats/includes/docnames_cell.html" %} {% endfor %} diff --git a/ietf/templates/stats/document_stats_pages.html b/ietf/templates/stats/document_stats_pages.html new file mode 100644 index 000000000..c9a725d0b --- /dev/null +++ b/ietf/templates/stats/document_stats_pages.html @@ -0,0 +1,58 @@ +

{{ stats_title }}

+ +
+ + + +

Data

+ + + + + + + + + + + {% for pages, percentage, names in table_data %} + + + + + + {% endfor %} + +
AuthorsPercentage of {{ doc_label }}s{{ doc_label }}s
{{ pages }}{{ percentage|floatformat:2 }}%{% include "stats/includes/docnames_cell.html" %}
diff --git a/ietf/templates/stats/includes/docnames_cell.html b/ietf/templates/stats/includes/docnames_cell.html new file mode 100644 index 000000000..fecdbe3a3 --- /dev/null +++ b/ietf/templates/stats/includes/docnames_cell.html @@ -0,0 +1 @@ +{{ names|length }}