diff options
author | Johannes Krampf <johannes.krampf@gmail.com> | 2011-11-26 14:27:45 +0100 |
---|---|---|
committer | Johannes Krampf <johannes.krampf@gmail.com> | 2011-11-26 14:27:45 +0100 |
commit | 56c773b32fc68639eb55666b6cfaa32bc9618321 (patch) | |
tree | dcc047f0552224facb6d05cddf2fb72b973bd683 /visualize | |
parent | fbd23db51b7160a308cd88e407e676994eb08b10 (diff) | |
parent | 85657db05d7f65604340699cfcb9967c9e81a0ef (diff) |
Merged with archweb trunk
Diffstat (limited to 'visualize')
-rw-r--r-- | visualize/__init__.py | 0 | ||||
-rw-r--r-- | visualize/models.py | 0 | ||||
-rw-r--r-- | visualize/tests.py | 0 | ||||
-rw-r--r-- | visualize/urls.py | 9 | ||||
-rw-r--r-- | visualize/views.py | 69 |
5 files changed, 78 insertions, 0 deletions
diff --git a/visualize/__init__.py b/visualize/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/visualize/__init__.py diff --git a/visualize/models.py b/visualize/models.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/visualize/models.py diff --git a/visualize/tests.py b/visualize/tests.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/visualize/tests.py diff --git a/visualize/urls.py b/visualize/urls.py new file mode 100644 index 00000000..57ee0626 --- /dev/null +++ b/visualize/urls.py @@ -0,0 +1,9 @@ +from django.conf.urls.defaults import patterns + +urlpatterns = patterns('visualize.views', + (r'^$', 'index', {}, 'visualize-index'), + (r'^by_arch/$', 'by_arch', {}, 'visualize-byarch'), + (r'^by_repo/$', 'by_repo', {}, 'visualize-byrepo'), +) + +# vim: set ts=4 sw=4 et: diff --git a/visualize/views.py b/visualize/views.py new file mode 100644 index 00000000..f2b1d63b --- /dev/null +++ b/visualize/views.py @@ -0,0 +1,69 @@ +from django.db.models import Count, Sum +from django.http import HttpResponse +from django.utils import simplejson +from django.views.decorators.cache import cache_page +from django.views.generic.simple import direct_to_template + +from main.models import Package, Arch, Repo + +def index(request): + return direct_to_template(request, 'visualize/index.html', {}) + +def arch_repo_data(): + qs = Package.objects.select_related().values( + 'arch__name', 'repo__name').annotate( + count=Count('pk'), csize=Sum('compressed_size'), + isize=Sum('installed_size'), + flagged=Count('flag_date')).order_by() + arches = Arch.objects.values_list('name', flat=True) + repos = Repo.objects.values_list('name', flat=True) + + def build_map(name, arch, repo): + key = '%s:%s' % (repo or '', arch or '') + return { + 'key': key, + 'name': name, + 'arch': arch, + 'repo': repo, + 'data': [], + } + + # now transform these results into two mappings: one ordered (repo, arch), + # and one ordered (arch, repo). + arch_groups = dict((a, build_map(a, a, None)) for a in arches) + repo_groups = dict((r, build_map(r, None, r)) for r in repos) + for row in qs: + arch = row['arch__name'] + repo = row['repo__name'] + values = { + 'arch': arch, + 'repo': repo, + 'name': '%s (%s)' % (repo, arch), + 'key': '%s:%s' % (repo, arch), + 'csize': row['csize'], + 'isize': row['isize'], + 'count': row['count'], + 'flagged': row['flagged'], + } + arch_groups[arch]['data'].append(values) + repo_groups[repo]['data'].append(values) + + data = { + 'by_arch': { 'name': 'Architectures', 'data': arch_groups.values() }, + 'by_repo': { 'name': 'Repositories', 'data': repo_groups.values() }, + } + return data + +@cache_page(1800) +def by_arch(request): + data = arch_repo_data() + to_json = simplejson.dumps(data['by_arch'], ensure_ascii=False) + return HttpResponse(to_json, mimetype='application/json') + +@cache_page(1800) +def by_repo(request): + data = arch_repo_data() + to_json = simplejson.dumps(data['by_repo'], ensure_ascii=False) + return HttpResponse(to_json, mimetype='application/json') + +# vim: set ts=4 sw=4 et: |