[mirrorbrain-commits] [mod_stats] r64 - in /trunk/downloadstats/stats: urls.py views.py

From: <poeml_at_mirrorbrain.org>
Date: Thu, 17 Dec 2009 15:37:41 -0000
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
@@ -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
@@ -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
 
@@ -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.org
Received on Thu Dec 17 2009 - 15:37:43 GMT

This archive was generated by hypermail 2.2.0 : Thu Dec 17 2009 - 15:45:11 GMT