Commit 62304e3a authored by carlosribas's avatar carlosribas
Browse files

Fix pie chart

parent 9394a968
......@@ -140,15 +140,9 @@ limitations under the License.
// Set chart values
var data = google.visualization.arrayToDataTable([
['Expert database', 'Number of searches'],
{% for dict in context.expert_db_results %}
{% for dict in context.current_month_pie_chart %}
{% for key, value in dict.items %}
{% if value %}
{% with value|last as last %}
{% for item in last.items %}
['{{ key }}', {{ item.1 }}],
{% endfor %}
{% endwith %}
{% endif %}
['{{ key }}', {{ value }}],
{% endfor %}
{% endfor %}
]);
......@@ -167,15 +161,9 @@ limitations under the License.
// Set chart values
var data = google.visualization.arrayToDataTable([
['Expert database', 'Number of searches'],
{% for dict in context.expert_db_results %}
{% for dict in context.last_month_pie_chart %}
{% for key, value in dict.items %}
{% if value|slice:"-2:-1" %}
{% for item in value|slice:"-2:-1" %}
{% for n in item.items %}
['{{ key }}', {{ n.1 }}],
{% endfor %}
{% endfor %}
{% endif %}
['{{ key }}', {{ value }}],
{% endfor %}
{% endfor %}
]);
......
......@@ -13,6 +13,7 @@ limitations under the License.
import os
import requests
from datetime import date, timedelta
from django.conf import settings
from django.shortcuts import render
from django.views.decorators.cache import never_cache
......@@ -158,6 +159,21 @@ def dashboard(request):
except requests.exceptions.HTTPError as err:
raise err
current_date = date.today()
current_month = current_date.strftime('%Y-%m')
last_month = (current_date.replace(day=1) - timedelta(days=1)).strftime('%Y-%m')
current_month_pie_chart = []
last_month_pie_chart = []
for index in range(len(expert_db_results)):
for key in expert_db_results[index]:
if expert_db_results[index][key][-1].keys()[0] == current_month:
current_month_pie_chart.append({key: expert_db_results[index][key][-1][current_month]})
if expert_db_results[index][key][-1].keys()[0] == last_month:
last_month_pie_chart.append({key: expert_db_results[index][key][-1][last_month]})
if expert_db_results[index][key][-2].keys()[0] == last_month:
last_month_pie_chart.append({key: expert_db_results[index][key][-2][last_month]})
context = {
'all_searches': all_searches,
'searches_last_24_hours': searches_last_24_hours,
......@@ -166,7 +182,9 @@ def dashboard(request):
'average_last_24_hours': average_last_24_hours,
'average_last_week': average_last_week,
'searches_per_month': searches_per_month,
'expert_db_results': expert_db_results
'expert_db_results': expert_db_results,
'current_month_pie_chart': current_month_pie_chart,
'last_month_pie_chart': last_month_pie_chart
}
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