Author: poeml Date: Thu Dec 17 16:37:40 2009 New Revision: 64 URL: http://svn.mirrorbrain.org/viewvc/mod_stats?rev=64&view=rev Log: add a view that doesn't split by country Modified: trunk/downloadstats/stats/urls.py trunk/downloadstats/stats/views.py Modified: trunk/downloadstats/stats/urls.py URL: http://svn.mirrorbrain.org/viewvc/mod_stats/trunk/downloadstats/stats/urls.py?rev=64&r1=63&r2=64&view=diff ============================================================================== --- trunk/downloadstats/stats/urls.py (original) +++ trunk/downloadstats/stats/urls.py Thu Dec 17 16:37:40 2009 _at_@ -3,6 +3,9 @@ urlpatterns = patterns('downloadstats.stats.views', (r'^csv/(?P<year>\d{4})(?P<month>\d{2})(?P<day>\d{2})\.csv$', 'stats_csv'), - (r'^csv/(?P<year>\d{4})(?P<month>\d{2})\.csv$', 'stats_csv'), + (r'^csv/(?P<year>\d{4})(?P<month>\d{2})\.csv$', 'stats_csv'), + + (r'^csv/all-countries/(?P<year>\d{4})(?P<month>\d{2})(?P<day>\d{2})\.csv$', 'stats_csv', {'by_country': False}), + (r'^csv/all-countries/(?P<year>\d{4})(?P<month>\d{2})\.csv$', 'stats_csv', {'by_country': False}), ) Modified: trunk/downloadstats/stats/views.py URL: http://svn.mirrorbrain.org/viewvc/mod_stats/trunk/downloadstats/stats/views.py?rev=64&r1=63&r2=64&view=diff ============================================================================== --- trunk/downloadstats/stats/views.py (original) +++ trunk/downloadstats/stats/views.py Thu Dec 17 16:37:40 2009 _at_@ -1,36 +1,42 @@ -# Create your views here. - from django.http import HttpResponse from django.db.models import Sum -#from django.views.decorators.cache import cache_page from downloadstats.stats.models import Counter -#_at_cache_page(60*15) -def stats_csv(request, year, month, day=None): +def stats_csv(request, year, month, day=None, by_country=True): + import csv response = HttpResponse(mimetype='text/plain') #response['Content-Disposition'] = 'attachment; filename=%s%s%s.csv' % (year, month, day or '') - import csv writer = csv.writer(response) - writer.writerow(['Date', 'Product', 'Version', 'OS', 'Language', 'Country', 'Downloads']) + if by_country: + writer.writerow(['Date', 'Product', 'Version', 'OS', 'Language', 'Country', 'Downloads']) + else: + writer.writerow(['Date', 'Product', 'Version', 'OS', 'Language', 'Downloads']) - products = Counter.objects.values('product').distinct() + products = [ i['product'] for i in Counter.objects.values('product').distinct() ] + for product in products: - s = Counter.objects.filter(product=product['product']) + s = Counter.objects.filter(product=product) s = s.filter(date__year=year, date__month=month) if day: s = s.filter(date__day=day) - s = s.values('date', 'product', 'version', 'osname', 'lang', 'country') + if by_country: + s = s.values('date', 'product', 'version', 'osname', 'lang', 'country') + else: + s = s.values('date', 'product', 'version', 'osname', 'lang') s = s.annotate(counter=Sum('count')) s = s.order_by('date', 'product') for i in s: - writer.writerow((i['date'], i['product'], i['version'], i['osname'], i['lang'], i['country'], i['counter'])) + if by_country: + writer.writerow((i['date'], i['product'], i['version'], i['osname'], i['lang'], i['country'], i['counter'])) + else: + writer.writerow((i['date'], i['product'], i['version'], i['osname'], i['lang'], i['counter'])) return response _at_@ -38,3 +44,4 @@ + _______________________________________________ mirrorbrain-commits mailing list Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/ Note: To remove yourself from this list, send a mail with the content unsubscribe to the address mirrorbrain-commits-request_at_mirrorbrain.orgReceived on Thu Dec 17 2009 - 15:37:43 GMT
This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT