euscanwww: Improved query for aggregating handler's data

Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
volpino 2012-11-27 14:16:56 +01:00
parent c6a0c29401
commit 3f47a08a54
3 changed files with 8 additions and 16 deletions

View File

@ -119,6 +119,7 @@ class PackageMixin(object):
return packages.filter(version__handler=handler, return packages.filter(version__handler=handler,
version__overlay="").distinct() version__overlay="").distinct()
class PackageQuerySet(models.query.QuerySet, PackageMixin): class PackageQuerySet(models.query.QuerySet, PackageMixin):
pass pass

View File

@ -58,8 +58,8 @@
{% for handler in handlers %} {% for handler in handlers %}
<tr> <tr>
<td> <td>
<a href="{% url "statistics_handler" handler.handler %}"> <a href="{% url "statistics_handler" handler.handler %}">
{{ handler.handler }} {{ handler.handler }}
</a> </a>
</td> </td>
<td>{{ handler.n }}</td> <td>{{ handler.n }}</td>

View File

@ -380,21 +380,12 @@ def config(request):
@render_to("euscan/statistics.html") @render_to("euscan/statistics.html")
def statistics(request): def statistics(request):
# Didn't found a way to do: handlers = (
# SELECT COUNT(*), AVG(confidence) FROM Versions Version.objects.values("handler")
# GROUP BY handler .filter(overlay="")
handlers = ( Version.objects.values("handler") .annotate(n=models.Count("handler"),
.filter(overlay="") avg_conf=models.Avg("confidence"))
.annotate(n=models.Count("handler"))
) )
for i in xrange(len(handlers)):
handler_id = handlers[i]['handler']
avg = ( Version.objects.filter(handler=handler_id)
.aggregate(avg=models.Avg("confidence"))
)
if not handler_id:
handlers[i]['handler'] = "None"
handlers[i]['avg_conf'] = avg['avg'] if 'avg' in avg else 0
return {"handlers": handlers} return {"handlers": handlers}