euscanwww: tweak the new handler code

Signed-off-by: Corentin Chary <corentin.chary@gmail.com>
This commit is contained in:
Corentin Chary 2012-11-26 23:39:34 +01:00
parent a723d30a33
commit c6a0c29401
5 changed files with 79 additions and 42 deletions

View File

@ -109,6 +109,15 @@ class PackageMixin(object):
)
return packages.filter(version__overlay=overlay).distinct()
def for_handler(self, handler):
"""
Returns packages that belong to the given handler
"""
packages = self.values(
'id', 'name', 'category', 'n_versions', 'n_packaged', 'n_overlay'
)
return packages.filter(version__handler=handler,
version__overlay="").distinct()
class PackageQuerySet(models.query.QuerySet, PackageMixin):
pass

View File

@ -147,7 +147,7 @@ class Version(models.Model):
alive = models.BooleanField(default=True, db_index=True)
vtype = models.CharField(max_length=128, blank=True)
handler = models.CharField(max_length=128, blank=True)
handler = models.CharField(max_length=128, blank=True, db_index=True)
confidence = models.IntegerField(default=0)
ebuild_path = models.CharField(blank=True, max_length=256)

View File

@ -2,18 +2,56 @@
{% load url from future %}
{% block css %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="{{STATIC_URL}}css/table.css" media="screen" title="Normal" />
{% endblock %}
{% block javascript %}
{{ block.super }}
<script type="text/javascript" language="javascript" src="{{STATIC_URL}}js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="{{STATIC_URL}}js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#table').dataTable( {
"bPaginate": false,
"bInfo": false,
"bStateSave": true,
"sCookiePrefix": "datatables_"
} );
});
</script>
{% endblock %}
{% block content %}
<h2>Statistics</h2>
<hr>
<hr />
<h3>Current statistics</h3>
<img alt="pie versions" src="{% url "chart" 'pie-versions' %}" />
<img alt="pie packages" src="{% url "chart" 'pie-packages' %}" />
<h3>All time statistics</h3>
<img alt="packages weekly" src="{% url "chart" 'packages-weekly' %}" />
<img alt="packages monthly" src="{% url "chart" 'packages-monthly' %}" />
<img alt="versions weekly" src="{% url "chart" 'versions-weekly' %}" />
<img alt="versions monthly" src="{% url "chart" 'versions-monthly' %}" />
<hr />
<h3>Handlers</h3>
<table class="table">
<table id="table" class="display">
<thead>
<tr>
<th></th>
<th>Handler</th>
<th># of found versions</th>
<th>average confidence</th>
<th>Average confidence</th>
</tr>
</thead>
<tbody>
@ -31,18 +69,4 @@
</tbody>
</table>
<hr>
<h3>Current statistics</h3>
<img alt="pie versions" src="{% url "chart" 'pie-versions' %}" />
<img alt="pie packages" src="{% url "chart" 'pie-packages' %}" />
<h3>All time statistics</h3>
<img alt="packages weekly" src="{% url "chart" 'packages-weekly' %}" />
<img alt="packages monthly" src="{% url "chart" 'packages-monthly' %}" />
<img alt="versions weekly" src="{% url "chart" 'versions-weekly' %}" />
<img alt="versions monthly" src="{% url "chart" 'versions-monthly' %}" />
{% endblock %}

View File

@ -88,7 +88,7 @@ urlpatterns = patterns('djeuscan.views',
url(r'^about/feeds$', 'feeds', name="feeds"),
url(r'^about/config$', 'config', name="config"),
url(r'^statistics/$', 'statistics', name="statistics"),
url(r'^statistics/handlers/(?P<handler>\w+)/$', 'statistics_handler',
url(r'^statistics/handlers/(?P<handler>[^/]+)/$', 'statistics_handler',
name="statistics_handler"),
url(r'^statistics/charts/(?P<chart>[\w\-]+).png$', 'chart', name="chart"),
url(r'^world/$', 'world', name="world"),

View File

@ -380,25 +380,29 @@ def config(request):
@render_to("euscan/statistics.html")
def statistics(request):
handlers = (
Version.objects.values("handler", "confidence")
# Didn't found a way to do:
# SELECT COUNT(*), AVG(confidence) FROM Versions
# GROUP BY handler
handlers = ( Version.objects.values("handler")
.filter(overlay="")
.annotate(n=models.Count("handler"),
avg_conf=models.Avg("confidence"))
.order_by("-n")
.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}
@render_to("euscan/statistics_handler.html")
def statistics_handler(request, handler):
package_ids = [
elem["package"] for elem in
Version.objects.filter(handler=handler)
.values("package")
.distinct()
]
packages = Package.objects.filter(pk__in=package_ids)
if handler == "None":
handler = ""
packages = Package.objects.for_handler(handler)
return {"handler": handler, "packages": packages}