Skip to content

Commit 656ed8c

Browse files
committed
Add statistics for pages in documents, refactoring a bit to share more code
- Legacy-Id: 12639
1 parent 13f3b4e commit 656ed8c

7 files changed

Lines changed: 107 additions & 24 deletions

File tree

ietf/static/ietf/js/document-stats.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
$(document).ready(function () {
22
if (window.chartConf) {
3+
window.chartConf.credits = {
4+
enabled: false
5+
};
6+
window.chartConf.exporting = {
7+
fallbackToExportServer: false
8+
};
9+
10+
if (!window.chartConf.legend)
11+
window.chartConf.legend = {
12+
enabled: false
13+
};
14+
315
var chart = Highcharts.chart('chart', window.chartConf);
416
}
517

ietf/stats/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_document_stats(self):
3131
self.assertTrue(authors_all_url in r["Location"])
3232

3333
# check various stats types
34-
for stats_type in ["authors"]:
34+
for stats_type in ["authors", "pages"]:
3535
for document_type in ["all", "rfc", "draft"]:
3636
url = urlreverse(ietf.stats.views.document_stats, kwargs={ "stats_type": stats_type, "document_type": document_type })
3737
r = self.client.get(url)

ietf/stats/views.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def build_document_stats_url(stats_type_override=Ellipsis, document_type_overrid
6161
# statistics type - one of the tables or the chart
6262
possible_stats_types = [
6363
("authors", "Number of authors"),
64-
# ("pages", "Pages"),
64+
("pages", "Pages"),
6565
# ("format", "Format"),
6666
# ("spectech", "Specification techniques"),
6767
]
@@ -106,7 +106,6 @@ def build_document_stats_url(stats_type_override=Ellipsis, document_type_overrid
106106
stats_title = ""
107107

108108
if stats_type == "authors":
109-
110109
stats_title = "Number of authors for each {}".format(doc_label)
111110

112111
groups = defaultdict(list)
@@ -118,16 +117,39 @@ def build_document_stats_url(stats_type_override=Ellipsis, document_type_overrid
118117

119118
series_data = []
120119
for author_count, names in sorted(groups.iteritems(), key=lambda t: t[0]):
121-
series_data.append((author_count, len(names) * 100.0 / total_docs))
122-
table_data.append((author_count, names))
120+
percentage = len(names) * 100.0 / total_docs
121+
series_data.append((author_count, percentage))
122+
table_data.append((author_count, percentage, names))
123+
124+
chart_data.append({
125+
"data": series_data,
126+
"animation": False,
127+
})
128+
129+
elif stats_type == "pages":
130+
stats_title = "Number of pages for each {}".format(doc_label)
131+
132+
groups = defaultdict(list)
133+
134+
for name, pages in doc_qs.values_list("name", "pages"):
135+
groups[pages].append(name)
136+
137+
total_docs = sum(len(names) for pages, names in groups.iteritems())
138+
139+
series_data = []
140+
for pages, names in sorted(groups.iteritems(), key=lambda t: t[0]):
141+
percentage = len(names) * 100.0 / total_docs
142+
if pages is not None:
143+
series_data.append((pages, len(names)))
144+
table_data.append((pages, percentage, names))
123145

124146
chart_data.append({
125147
"data": series_data,
126-
"name": "Percentage of {}s".format(doc_label),
127148
"animation": False,
128149
})
129150

130151

152+
131153
return render(request, "stats/document_stats.html", {
132154
"chart_data": mark_safe(json.dumps(chart_data)),
133155
"table_data": table_data,

ietf/templates/stats/document_stats.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ <h1>Document statistics</h1>
3737

3838
{% if stats_type == "authors" %}
3939
{% include "stats/document_stats_authors.html" %}
40+
{% elif stats_type == "pages" %}
41+
{% include "stats/document_stats_pages.html" %}
4042
{% endif %}
4143
{% endblock %}
4244

ietf/templates/stats/document_stats_authors.html

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ <h3>{{ stats_title }}</h3>
77
chart: {
88
type: 'column'
99
},
10-
credits: {
11-
enabled: false,
12-
},
13-
exporting: {
14-
fallbackToExportServer: false,
15-
},
1610
title: {
1711
text: '{{ stats_title|escapejs }}'
1812
},
@@ -32,16 +26,12 @@ <h3>{{ stats_title }}</h3>
3226
}
3327
}
3428
},
35-
legend: {
36-
enabled: false,
37-
},
3829
tooltip: {
3930
formatter: function () {
4031
var s = '<b>' + this.x + ' ' + (this.x == 1 ? "author" : 'authors') + '</b>';
4132

4233
$.each(this.points, function () {
43-
s += '<br/>' + this.series.name + ': ' +
44-
this.y.toFixed(1) + '%';
34+
s += '<br/>' + chartConf.yAxis.title.text + ': ' + this.y.toFixed(1) + '%';
4535
});
4636

4737
return s;
@@ -58,18 +48,16 @@ <h3>Data</h3>
5848
<thead>
5949
<tr>
6050
<th>Authors</th>
61-
<th>Documents</th>
51+
<th>Percentage of {{ doc_label }}s</th>
52+
<th>{{ doc_label }}s</th>
6253
</tr>
6354
</thead>
6455
<tbody>
65-
{% for author_count, names in table_data %}
56+
{% for author_count, percentage, names in table_data %}
6657
<tr>
6758
<td>{{ author_count }}</td>
68-
<td><a class="popover-docnames"
69-
href=""
70-
data-docnames="{% for n in names|slice:":20" %}{{ n }}{% if not forloop.last %} {% endif %}{% endfor %}"
71-
data-sliced="{% if names|length > 20 %}1{% endif %}"
72-
>{{ names|length }}</a></td>
59+
<td>{{ percentage|floatformat:2 }}%</td>
60+
<td>{% include "stats/includes/docnames_cell.html" %}</td>
7361
</tr>
7462
{% endfor %}
7563
</tbody>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<h3>{{ stats_title }}</h3>
2+
3+
<div id="chart"></div>
4+
5+
<script>
6+
var chartConf = {
7+
chart: {
8+
type: 'line'
9+
},
10+
title: {
11+
text: '{{ stats_title|escapejs }}'
12+
},
13+
xAxis: {
14+
title: {
15+
text: 'Number of pages'
16+
}
17+
},
18+
yAxis: {
19+
title: {
20+
text: 'Number of {{ doc_label }}s'
21+
}
22+
},
23+
tooltip: {
24+
formatter: function () {
25+
var s = '<b>' + this.x + ' ' + (this.x == 1 ? "page" : 'pages') + '</b>';
26+
27+
$.each(this.points, function () {
28+
s += '<br/>' + chartConf.yAxis.title.text + ': ' + this.y;
29+
});
30+
31+
return s;
32+
},
33+
shared: true
34+
},
35+
series: {{ chart_data }}
36+
};
37+
</script>
38+
39+
<h3>Data</h3>
40+
41+
<table class="table table-condensed stats-data">
42+
<thead>
43+
<tr>
44+
<th>Authors</th>
45+
<th>Percentage of {{ doc_label }}s</th>
46+
<th>{{ doc_label }}s</th>
47+
</tr>
48+
</thead>
49+
<tbody>
50+
{% for pages, percentage, names in table_data %}
51+
<tr>
52+
<td>{{ pages }}</td>
53+
<td>{{ percentage|floatformat:2 }}%</td>
54+
<td>{% include "stats/includes/docnames_cell.html" %}</td>
55+
</tr>
56+
{% endfor %}
57+
</tbody>
58+
</table>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<a class="popover-docnames" href="" data-docnames="{% for n in names|slice:":20" %}{{ n }}{% if not forloop.last %} {% endif %}{% endfor %}" data-sliced="{% if names|length > 20 %}1{% endif %}">{{ names|length }}</a>

0 commit comments

Comments
 (0)