summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2019-05-29 07:02:06 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2019-05-29 07:03:19 (GMT)
commitf0dc0ce1cc4a7a942a50571a1672b77b91efc1f2 (patch)
tree50d857de7ae6c04134fcac3b192c0557e1d24563
parentfdb4165b604bcce8eee452060b0066d9eac52e3f (diff)
downloadcombo-plugin-gnm-f0dc0ce1cc4a7a942a50571a1672b77b91efc1f2.zip
combo-plugin-gnm-f0dc0ce1cc4a7a942a50571a1672b77b91efc1f2.tar.gz
combo-plugin-gnm-f0dc0ce1cc4a7a942a50571a1672b77b91efc1f2.tar.bz2
add api view on tile statistics (#29903)v4.7
-rw-r--r--combo_plugin_gnm/urls.py1
-rw-r--r--combo_plugin_gnm/views.py49
-rw-r--r--debian/50gnm.py6
3 files changed, 54 insertions, 2 deletions
diff --git a/combo_plugin_gnm/urls.py b/combo_plugin_gnm/urls.py
index e36d83b..7a4ac3a 100644
--- a/combo_plugin_gnm/urls.py
+++ b/combo_plugin_gnm/urls.py
@@ -22,4 +22,5 @@ from . import views
urlpatterns = [
url(r'^gnm/plusone/$', views.plusone, name='gnm-plus-one'),
url(r'^gnm/share/$', views.share, name='gnm-share'),
+ url(r'^gnm/stats/$', views.stats, name='gnm-stats'),
]
diff --git a/combo_plugin_gnm/views.py b/combo_plugin_gnm/views.py
index 10f13ed..5d440dc 100644
--- a/combo_plugin_gnm/views.py
+++ b/combo_plugin_gnm/views.py
@@ -17,11 +17,13 @@
from django.conf import settings
from django.contrib import messages
+from django.contrib.auth import get_user_model
from django.core.mail import EmailMultiAlternatives
-from django.http import HttpResponseRedirect
+from django.http import HttpResponseRedirect, JsonResponse
from django.template import RequestContext
from django.template.loader import render_to_string
+from combo.apps.dashboard.models import Tile
from combo.utils import requests, get_templated_url
def plusone(request, *args, **kwargs):
@@ -64,3 +66,48 @@ def share(request, *args, **kwargs):
url = request.POST.get('url')
return HttpResponseRedirect(url)
+
+
+def stats(request, *args, **kwargs):
+ data = {}
+ User = get_user_model()
+ data['users'] = {}
+ data['users']['count'] = User.objects.all().count()
+ data['tiles'] = {}
+ tiles_by_user = {}
+ manual_tiles_by_user = {}
+ for tile in Tile.objects.all().filter(dashboard__isnull=False).select_related():
+ cell = tile.cell
+
+ if cell.key not in settings.JSON_CELL_TYPES:
+ continue
+
+ if tile.user_id not in tiles_by_user:
+ tiles_by_user[tile.user_id] = []
+ tiles_by_user[tile.user_id].append(cell.key)
+
+ if cell.key not in data['tiles']:
+ data['tiles'][cell.key] = {
+ 'name': settings.JSON_CELL_TYPES[cell.key]['name'],
+ 'count': 0,
+ 'manual': 0,
+ }
+
+ data['tiles'][cell.key]['count'] += 1
+
+ if cell.placeholder != '_suggested_tile':
+ data['tiles'][cell.key]['manual'] += 1
+ if tile.user_id not in manual_tiles_by_user:
+ manual_tiles_by_user[tile.user_id] = []
+ manual_tiles_by_user[tile.user_id].append(cell.key)
+
+ data['users']['have-tiles'] = len(tiles_by_user.keys())
+ data['users']['have-more-than-suggested-tiles'] = len(manual_tiles_by_user.keys())
+ data['users']['have-no-tiles'] = data['users']['count'] - data['users']['have-tiles']
+ dashboard_lengths = [len(x) for x in tiles_by_user.values()]
+ dashboard_lengths.sort()
+ data['users']['max-tiles'] = max(dashboard_lengths)
+ if dashboard_lengths:
+ data['users']['median-tiles'] = dashboard_lengths[len(dashboard_lengths) // 2]
+
+ return JsonResponse(data)
diff --git a/debian/50gnm.py b/debian/50gnm.py
index 198f182..224cf86 100644
--- a/debian/50gnm.py
+++ b/debian/50gnm.py
@@ -356,7 +356,11 @@ JSON_CELL_TYPES = {
"label": "Texte"
}
]
- }
+ },
+ "stats": {
+ "name": "Statistiques tuiles",
+ "url": "{{portal_url}}gnm/stats/",
+ },
}
COMBO_ASSET_SLOTS = {