Skip to content

Remove pie-chart from search analytics page #6192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions readthedocs/projects/views/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
}
)

Expand Down
17 changes: 0 additions & 17 deletions readthedocs/rtd_tests/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 0 additions & 45 deletions readthedocs/search/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
66 changes: 0 additions & 66 deletions readthedocs/templates/projects/projects_search_analytics.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ <h3>{% trans "Top queries" %}</h3>
</div>
</div>

<br/>

{% if distribution_of_top_queries.labels and distribution_of_top_queries.int_data %}
<h2>{% trans "Distribution of top 10 queries" %}</h2>
<canvas id="analytics-doughnut-top-queries" width="400" height="150"></canvas>
{% endif %}

<br/>
{% if query_count_of_1_month.labels and query_count_of_1_month.int_data %}
<h2>{% trans "Overview of the past 1 month:" %}</h2>
Expand Down Expand Up @@ -83,16 +76,6 @@ <h2>{% trans "Overview of the past 1 month:" %}</h2>
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: {
Expand All @@ -104,56 +87,7 @@ <h2>{% trans "Overview of the past 1 month:" %}</h2>
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 %}