diff --git a/readthedocs/projects/views/private.py b/readthedocs/projects/views/private.py index 2b699c9e971..5d9940ff68f 100644 --- a/readthedocs/projects/views/private.py +++ b/readthedocs/projects/views/private.py @@ -940,12 +940,6 @@ def search_analytics_view(request, project_slug): query_count_of_1_month = SearchQuery.generate_queries_count_of_one_month( project_slug ) - # data for plotting the doughnut-chart - distribution_of_top_queries = SearchQuery.generate_distribution_of_top_queries( - project_slug, - 10, - ) - now = timezone.now() queries = [] qs = SearchQuery.objects.filter(project=project) @@ -968,7 +962,6 @@ def search_analytics_view(request, project_slug): 'queries': queries, 'show_analytics': True, 'query_count_of_1_month': query_count_of_1_month, - 'distribution_of_top_queries': distribution_of_top_queries, } ) diff --git a/readthedocs/rtd_tests/tests/test_views.py b/readthedocs/rtd_tests/tests/test_views.py index 027a34880c5..66ae8f97ca9 100644 --- a/readthedocs/rtd_tests/tests/test_views.py +++ b/readthedocs/rtd_tests/tests/test_views.py @@ -304,23 +304,6 @@ def test_top_queries(self): list(resp.context['queries']), ) - def test_distribution_of_top_queries(self): - with mock.patch('django.utils.timezone.now') as test_time: - test_time.return_value = self.test_time - - expected_result = { - 'labels': ['hello world', 'documentation', 'read the docs', 'advertising', - 'elasticsearch', 'sphinx', 'github', 'hello', 'search'], - 'int_data': [5, 4, 4, 3, 2, 2, 1, 1, 1], - } - resp = self.client.get(self.analyics_page, {'version': self.version.slug}) - - self.assertEqual(resp.status_code, 200) - self.assertDictEqual( - expected_result, - resp.context['distribution_of_top_queries'], - ) - def test_query_count_of_1_month(self): with mock.patch('django.utils.timezone.now') as test_time: test_time.return_value = self.test_time diff --git a/readthedocs/search/models.py b/readthedocs/search/models.py index 45f13640294..53fedecaf96 100644 --- a/readthedocs/search/models.py +++ b/readthedocs/search/models.py @@ -92,48 +92,3 @@ def generate_queries_count_of_one_month(cls, project_slug): } return final_data - - @classmethod - def generate_distribution_of_top_queries(cls, project_slug, n): - """ - Returns top `n` most searched queries with their count. - - Structure of returned data is compatible to make graphs. - Sample returned data:: - { - 'labels': ['read the docs', 'documentation', 'sphinx'], - 'int_data': [150, 200, 143] - } - This data shows that `read the docs` was searched 150 times, - `documentation` was searched 200 times and `sphinx` was searched 143 times. - """ - qs = cls.objects.filter(project__slug=project_slug) - - # total searches ever made - total_count = len(qs) - - # search queries with their count - # Eg. [('read the docs', 150), ('documentation', 200), ('sphinx', 143')] - count_of_each_query = ( - qs.values('query') - .annotate(count=Count('id')) - .order_by('-count') - .values_list('query', 'count') - ) - - # total number of searches made for top `n` queries - count_of_top_n = sum([value[1] for value in count_of_each_query][:n]) - - # total number of remaining searches - count_of_other = total_count - count_of_top_n - - final_data = { - 'labels': [value[0] for value in count_of_each_query][:n], - 'int_data': [value[1] for value in count_of_each_query][:n], - } - - if count_of_other: - final_data['labels'].append('Other queries') - final_data['int_data'].append(count_of_other) - - return final_data diff --git a/readthedocs/templates/projects/projects_search_analytics.html b/readthedocs/templates/projects/projects_search_analytics.html index b84129c6275..e162fd21e03 100644 --- a/readthedocs/templates/projects/projects_search_analytics.html +++ b/readthedocs/templates/projects/projects_search_analytics.html @@ -35,13 +35,6 @@

{% trans "Top queries" %}

-
- - {% if distribution_of_top_queries.labels and distribution_of_top_queries.int_data %} -

{% trans "Distribution of top 10 queries" %}

- - {% endif %} -
{% if query_count_of_1_month.labels and query_count_of_1_month.int_data %}

{% trans "Overview of the past 1 month:" %}

@@ -83,16 +76,6 @@

{% trans "Overview of the past 1 month:" %}

var line_chart_labels = {{ query_count_of_1_month.labels|safe }}; var line_chart_data = {{ query_count_of_1_month.int_data|safe }}; - var ticks_options = { - precision: 0 - } - - // checks if line_chart_data only contains zero. - // if yes, set the minimum value to zero - if(!(/[^0]/).exec(line_chart_data.join(""))){ - ticks_options.min = 0; - } - var line_chart = new Chart(line_chart, { type: "line", data: { @@ -104,56 +87,7 @@

{% trans "Overview of the past 1 month:" %}

borderColor: "rgba(75, 192, 192, 1)", pointBorderColor: "rgba(75, 192, 192, 1)", }] - }, - options: { - scales: { - yAxes: [{ - ticks: ticks_options - }] - } } }); {% endif %} - - {% if distribution_of_top_queries.labels and distribution_of_top_queries.int_data and show_analytics %} - // Doughnut chart - var doughnut_chart = document.getElementById("analytics-doughnut-top-queries").getContext("2d"); - var doughnut_labels = {{ distribution_of_top_queries.labels|safe }}; - var doughnut_data = {{ distribution_of_top_queries.int_data|safe }}; - colors = [ "#81ecec", "#74b9ff", "#a29bfe", "#ffeaa7", "#ff7675", - "#fdcb6e", "#636e72", "#e17055", "#e84393", "#00cec9" ]; - var doughnut_chart = new Chart(doughnut_chart, { - type: "doughnut", - data: { - labels: doughnut_labels, - datasets: [{ - data: doughnut_data, - backgroundColor: colors, - }], - borderAlign: "center", - }, - options: { - responsive: true, - legend: { - position: "right", - }, - tooltips: { - callbacks: { - label: function(tooltipItem, data) { - var dataset = data.datasets[tooltipItem.datasetIndex]; - var meta = dataset._meta[Object.keys(dataset._meta)[0]]; - var total = meta.total; - var currentValue = dataset.data[tooltipItem.index]; - var percentage = parseFloat((currentValue/total*100).toFixed(1)); - return percentage + '%'; - }, - title: function(tooltipItem, data) { - return data.labels[tooltipItem[0].index]; - } - } - } - } - }); - {% endif %} - {% endblock %}