aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorentin Chary <corentin.chary@gmail.com>2012-11-26 23:39:34 +0100
committerCorentin Chary <corentin.chary@gmail.com>2012-11-26 23:39:34 +0100
commitc6a0c29401a7e26f7f7481254c27844aa022c9fd (patch)
tree5437bdf59d71487a6cc85a9d0df07509c3ffb865
parenteuscanwww: reorder some settings (diff)
downloadeuscan-c6a0c29401a7e26f7f7481254c27844aa022c9fd.tar.gz
euscan-c6a0c29401a7e26f7f7481254c27844aa022c9fd.tar.bz2
euscan-c6a0c29401a7e26f7f7481254c27844aa022c9fd.zip
euscanwww: tweak the new handler code
Signed-off-by: Corentin Chary <corentin.chary@gmail.com>
-rw-r--r--euscanwww/djeuscan/managers.py9
-rw-r--r--euscanwww/djeuscan/models.py2
-rw-r--r--euscanwww/djeuscan/templates/euscan/statistics.html64
-rw-r--r--euscanwww/djeuscan/urls.py2
-rw-r--r--euscanwww/djeuscan/views.py30
5 files changed, 72 insertions, 35 deletions
diff --git a/euscanwww/djeuscan/managers.py b/euscanwww/djeuscan/managers.py
index 33d7ee8..6c04b85 100644
--- a/euscanwww/djeuscan/managers.py
+++ b/euscanwww/djeuscan/managers.py
@@ -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
diff --git a/euscanwww/djeuscan/models.py b/euscanwww/djeuscan/models.py
index 2c7f6c2..5a0991c 100644
--- a/euscanwww/djeuscan/models.py
+++ b/euscanwww/djeuscan/models.py
@@ -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)
diff --git a/euscanwww/djeuscan/templates/euscan/statistics.html b/euscanwww/djeuscan/templates/euscan/statistics.html
index 8e03c3e..8372be0 100644
--- a/euscanwww/djeuscan/templates/euscan/statistics.html
+++ b/euscanwww/djeuscan/templates/euscan/statistics.html
@@ -2,26 +2,64 @@
{% 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>
{% for handler in handlers %}
<tr>
<td>
- <a href="{% url "statistics_handler" handler.handler %}">
- {{ handler.handler }}
+ <a href="{% url "statistics_handler" handler.handler %}">
+ {{ handler.handler }}
</a>
</td>
<td>{{ handler.n }}</td>
@@ -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 %}
diff --git a/euscanwww/djeuscan/urls.py b/euscanwww/djeuscan/urls.py
index 57cc08e..8e1e087 100644
--- a/euscanwww/djeuscan/urls.py
+++ b/euscanwww/djeuscan/urls.py
@@ -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"),
diff --git a/euscanwww/djeuscan/views.py b/euscanwww/djeuscan/views.py
index e09b82f..1b128a4 100644
--- a/euscanwww/djeuscan/views.py
+++ b/euscanwww/djeuscan/views.py
@@ -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}