Commit 879e5f3f authored by carlosribas's avatar carlosribas
Browse files

Show the number of searches per month

parent c32e27ca
......@@ -30,7 +30,44 @@ limitations under the License.
<li>Last 24 hours: {{ context.average_last_24_hours }}</li>
<li>Last 7 days: {{ context.average_last_week }}</li>
</ul>
{% if context.searches_per_month %}
<br>
<p>Number of searches per month:</p>
<div id="chart_div"></div>
{% endif %}
</div>
</div>
{% endblock %}
{% block extra_js_uncompressed %}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
// Set chart values
var data = google.visualization.arrayToDataTable([
['Month', 'Searches'],
{% for dict in context.searches_per_month %}
{% for key, value in dict.items %}
['{{ key }}', {{ value }}],
{% endfor %}
{% endfor %}
]);
// Set chart options
var options = {
vAxis: { title: 'Number of searches' },
legend: { position: "none" },
'width':800,
'height':400
};
// Instantiate and draw the chart.
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
{% endblock extra_js_uncompressed %}
\ No newline at end of file
......@@ -20,9 +20,10 @@ from rest_framework.response import Response
from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import AllowAny
try:
from rnacentral.sequence_search_endpoints import SEQUENCE_SEARCH_ENDPOINT
except ImportError:
if settings.ENVIRONMENT == 'HX':
SEQUENCE_SEARCH_ENDPOINT = 'http://193.62.55.123:8002'
else:
SEQUENCE_SEARCH_ENDPOINT = 'https://search.rnacentral.org'
if settings.ENVIRONMENT == 'DEV':
......@@ -136,6 +137,7 @@ def dashboard(request):
"""Info about searches in rnacentral-sequence-search."""
all_searches, searches_last_24_hours, searches_last_week = 0, 0, 0
average_all_searches, average_last_24_hours, average_last_week = 0, 0, 0
searches_per_month = None
show_searches_url = SEQUENCE_SEARCH_ENDPOINT + '/api/show-searches'
try:
......@@ -144,7 +146,10 @@ def dashboard(request):
data = response_url.json()
for item in data:
if item['search'] == 'all':
if isinstance(item, list):
searches_per_month = item
elif item['search'] == 'all':
all_searches = item['count']
average_all_searches = item['avg_time']
......@@ -165,7 +170,8 @@ def dashboard(request):
'searches_last_week': searches_last_week,
'average_all_searches': average_all_searches,
'average_last_24_hours': average_last_24_hours,
'average_last_week': average_last_week
'average_last_week': average_last_week,
'searches_per_month': searches_per_month
}
return render(request, 'dashboard.html', {'context': context})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment