euscanwww: tweak the new handler code
Signed-off-by: Corentin Chary <corentin.chary@gmail.com>
This commit is contained in:
parent
a723d30a33
commit
c6a0c29401
@ -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
|
||||
|
@ -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)
|
||||
|
@ -2,36 +2,34 @@
|
||||
|
||||
{% 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>
|
||||
|
||||
<h3>Handlers</h3>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th># of found versions</th>
|
||||
<th>average confidence</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for handler in handlers %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{% url "statistics_handler" handler.handler %}">
|
||||
{{ handler.handler }}
|
||||
</a>
|
||||
</td>
|
||||
<td>{{ handler.n }}</td>
|
||||
<td>{{ handler.avg_conf }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<hr>
|
||||
<hr />
|
||||
|
||||
<h3>Current statistics</h3>
|
||||
<img alt="pie versions" src="{% url "chart" 'pie-versions' %}" />
|
||||
@ -45,4 +43,30 @@
|
||||
<img alt="versions weekly" src="{% url "chart" 'versions-weekly' %}" />
|
||||
<img alt="versions monthly" src="{% url "chart" 'versions-monthly' %}" />
|
||||
|
||||
<hr />
|
||||
|
||||
<h3>Handlers</h3>
|
||||
<table id="table" class="display">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Handler</th>
|
||||
<th># of found versions</th>
|
||||
<th>Average confidence</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for handler in handlers %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{% url "statistics_handler" handler.handler %}">
|
||||
{{ handler.handler }}
|
||||
</a>
|
||||
</td>
|
||||
<td>{{ handler.n }}</td>
|
||||
<td>{{ handler.avg_conf }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% endblock %}
|
||||
|
@ -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"),
|
||||
|
@ -380,25 +380,29 @@ def config(request):
|
||||
|
||||
@render_to("euscan/statistics.html")
|
||||
def statistics(request):
|
||||
handlers = (
|
||||
Version.objects.values("handler", "confidence")
|
||||
.filter(overlay="")
|
||||
.annotate(n=models.Count("handler"),
|
||||
avg_conf=models.Avg("confidence"))
|
||||
.order_by("-n")
|
||||
# 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"))
|
||||
)
|
||||
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}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user