Skip to content

Commit 1ce3166

Browse files
authored
Merge pull request #6192 from dojutsu-user/remove-pie-chart
Remove pie-chart from search analytics page
2 parents 9b2bf5a + 03b3eac commit 1ce3166

File tree

4 files changed

+0
-135
lines changed

4 files changed

+0
-135
lines changed

readthedocs/projects/views/private.py

-7
Original file line numberDiff line numberDiff line change
@@ -947,12 +947,6 @@ def search_analytics_view(request, project_slug):
947947
query_count_of_1_month = SearchQuery.generate_queries_count_of_one_month(
948948
project_slug
949949
)
950-
# data for plotting the doughnut-chart
951-
distribution_of_top_queries = SearchQuery.generate_distribution_of_top_queries(
952-
project_slug,
953-
10,
954-
)
955-
now = timezone.now()
956950

957951
queries = []
958952
qs = SearchQuery.objects.filter(project=project)
@@ -975,7 +969,6 @@ def search_analytics_view(request, project_slug):
975969
'queries': queries,
976970
'show_analytics': True,
977971
'query_count_of_1_month': query_count_of_1_month,
978-
'distribution_of_top_queries': distribution_of_top_queries,
979972
}
980973
)
981974

readthedocs/rtd_tests/tests/test_views.py

-17
Original file line numberDiff line numberDiff line change
@@ -304,23 +304,6 @@ def test_top_queries(self):
304304
list(resp.context['queries']),
305305
)
306306

307-
def test_distribution_of_top_queries(self):
308-
with mock.patch('django.utils.timezone.now') as test_time:
309-
test_time.return_value = self.test_time
310-
311-
expected_result = {
312-
'labels': ['hello world', 'documentation', 'read the docs', 'advertising',
313-
'elasticsearch', 'sphinx', 'github', 'hello', 'search'],
314-
'int_data': [5, 4, 4, 3, 2, 2, 1, 1, 1],
315-
}
316-
resp = self.client.get(self.analyics_page, {'version': self.version.slug})
317-
318-
self.assertEqual(resp.status_code, 200)
319-
self.assertDictEqual(
320-
expected_result,
321-
resp.context['distribution_of_top_queries'],
322-
)
323-
324307
def test_query_count_of_1_month(self):
325308
with mock.patch('django.utils.timezone.now') as test_time:
326309
test_time.return_value = self.test_time

readthedocs/search/models.py

-45
Original file line numberDiff line numberDiff line change
@@ -92,48 +92,3 @@ def generate_queries_count_of_one_month(cls, project_slug):
9292
}
9393

9494
return final_data
95-
96-
@classmethod
97-
def generate_distribution_of_top_queries(cls, project_slug, n):
98-
"""
99-
Returns top `n` most searched queries with their count.
100-
101-
Structure of returned data is compatible to make graphs.
102-
Sample returned data::
103-
{
104-
'labels': ['read the docs', 'documentation', 'sphinx'],
105-
'int_data': [150, 200, 143]
106-
}
107-
This data shows that `read the docs` was searched 150 times,
108-
`documentation` was searched 200 times and `sphinx` was searched 143 times.
109-
"""
110-
qs = cls.objects.filter(project__slug=project_slug)
111-
112-
# total searches ever made
113-
total_count = len(qs)
114-
115-
# search queries with their count
116-
# Eg. [('read the docs', 150), ('documentation', 200), ('sphinx', 143')]
117-
count_of_each_query = (
118-
qs.values('query')
119-
.annotate(count=Count('id'))
120-
.order_by('-count')
121-
.values_list('query', 'count')
122-
)
123-
124-
# total number of searches made for top `n` queries
125-
count_of_top_n = sum([value[1] for value in count_of_each_query][:n])
126-
127-
# total number of remaining searches
128-
count_of_other = total_count - count_of_top_n
129-
130-
final_data = {
131-
'labels': [value[0] for value in count_of_each_query][:n],
132-
'int_data': [value[1] for value in count_of_each_query][:n],
133-
}
134-
135-
if count_of_other:
136-
final_data['labels'].append('Other queries')
137-
final_data['int_data'].append(count_of_other)
138-
139-
return final_data

readthedocs/templates/projects/projects_search_analytics.html

-66
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ <h3>{% trans "Top queries" %}</h3>
3535
</div>
3636
</div>
3737

38-
<br/>
39-
40-
{% if distribution_of_top_queries.labels and distribution_of_top_queries.int_data %}
41-
<h2>{% trans "Distribution of top 10 queries" %}</h2>
42-
<canvas id="analytics-doughnut-top-queries" width="400" height="150"></canvas>
43-
{% endif %}
44-
4538
<br/>
4639
{% if query_count_of_1_month.labels and query_count_of_1_month.int_data %}
4740
<h2>{% trans "Overview of the past 1 month:" %}</h2>
@@ -83,16 +76,6 @@ <h2>{% trans "Overview of the past 1 month:" %}</h2>
8376
var line_chart_labels = {{ query_count_of_1_month.labels|safe }};
8477
var line_chart_data = {{ query_count_of_1_month.int_data|safe }};
8578

86-
var ticks_options = {
87-
precision: 0
88-
}
89-
90-
// checks if line_chart_data only contains zero.
91-
// if yes, set the minimum value to zero
92-
if(!(/[^0]/).exec(line_chart_data.join(""))){
93-
ticks_options.min = 0;
94-
}
95-
9679
var line_chart = new Chart(line_chart, {
9780
type: "line",
9881
data: {
@@ -104,56 +87,7 @@ <h2>{% trans "Overview of the past 1 month:" %}</h2>
10487
borderColor: "rgba(75, 192, 192, 1)",
10588
pointBorderColor: "rgba(75, 192, 192, 1)",
10689
}]
107-
},
108-
options: {
109-
scales: {
110-
yAxes: [{
111-
ticks: ticks_options
112-
}]
113-
}
11490
}
11591
});
11692
{% endif %}
117-
118-
{% if distribution_of_top_queries.labels and distribution_of_top_queries.int_data and show_analytics %}
119-
// Doughnut chart
120-
var doughnut_chart = document.getElementById("analytics-doughnut-top-queries").getContext("2d");
121-
var doughnut_labels = {{ distribution_of_top_queries.labels|safe }};
122-
var doughnut_data = {{ distribution_of_top_queries.int_data|safe }};
123-
colors = [ "#81ecec", "#74b9ff", "#a29bfe", "#ffeaa7", "#ff7675",
124-
"#fdcb6e", "#636e72", "#e17055", "#e84393", "#00cec9" ];
125-
var doughnut_chart = new Chart(doughnut_chart, {
126-
type: "doughnut",
127-
data: {
128-
labels: doughnut_labels,
129-
datasets: [{
130-
data: doughnut_data,
131-
backgroundColor: colors,
132-
}],
133-
borderAlign: "center",
134-
},
135-
options: {
136-
responsive: true,
137-
legend: {
138-
position: "right",
139-
},
140-
tooltips: {
141-
callbacks: {
142-
label: function(tooltipItem, data) {
143-
var dataset = data.datasets[tooltipItem.datasetIndex];
144-
var meta = dataset._meta[Object.keys(dataset._meta)[0]];
145-
var total = meta.total;
146-
var currentValue = dataset.data[tooltipItem.index];
147-
var percentage = parseFloat((currentValue/total*100).toFixed(1));
148-
return percentage + '%';
149-
},
150-
title: function(tooltipItem, data) {
151-
return data.labels[tooltipItem[0].index];
152-
}
153-
}
154-
}
155-
}
156-
});
157-
{% endif %}
158-
15993
{% endblock %}

0 commit comments

Comments
 (0)