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

From: <poeml_at_mirrorbrain.org>
Date: Wed, 16 Dec 2009 03:27:46 -0000
Author: poeml
Date: Wed Dec 16 04:27:45 2009
New Revision: 59

URL: http://svn.mirrorbrain.org/viewvc/mod_stats?rev=59&view=rev
Log:
in the stats Djanog app, create a little CSV generator to sum up log
results from the database

Added:
    trunk/downloadstats/stats/urls.py
Modified:
    trunk/downloadstats/stats/views.py
    trunk/downloadstats/urls.py

Added: trunk/downloadstats/stats/urls.py
URL: http://svn.mirrorbrain.org/viewvc/mod_stats/trunk/downloadstats/stats/urls.py?rev=59&view=auto
==============================================================================
--- trunk/downloadstats/stats/urls.py (added)
+++ trunk/downloadstats/stats/urls.py Wed Dec 16 04:27:45 2009
_at_@ -1,0 +1,8 @@
+from django.conf.urls.defaults import *
+
+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'),
+)
+

Modified: trunk/downloadstats/stats/views.py
URL: http://svn.mirrorbrain.org/viewvc/mod_stats/trunk/downloadstats/stats/views.py?rev=59&r1=58&r2=59&view=diff
==============================================================================
--- trunk/downloadstats/stats/views.py (original)
+++ trunk/downloadstats/stats/views.py Wed Dec 16 04:27:45 2009
_at_@ -1,1 +1,40 @@
 # 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):
+
+    response = HttpResponse(mimetype='text/csv')
+    response['Content-Disposition'] = 'attachment; filename=%s%s%s.csv' % (year, month, day)
+
+    import csv
+    writer = csv.writer(response)
+    writer.writerow(['Date', 'Product', 'Version', 'OS', 'Language', 'Country', 'Downloads'])
+
+
+    products = Counter.objects.values('product').distinct()
+    for product in products:
+
+        s = Counter.objects.filter(product=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')
+        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']))
+
+    return response
+
+
+
+
+

Modified: trunk/downloadstats/urls.py
URL: http://svn.mirrorbrain.org/viewvc/mod_stats/trunk/downloadstats/urls.py?rev=59&r1=58&r2=59&view=diff
==============================================================================
--- trunk/downloadstats/urls.py (original)
+++ trunk/downloadstats/urls.py Wed Dec 16 04:27:45 2009
_at_@ -7,6 +7,7 @@
 urlpatterns = patterns('',
     # Example:
     # (r'^downloadstats/', include('downloadstats.foo.urls')),
+    (r'^stats/', include('downloadstats.stats.urls')),
 
     # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
     # to INSTALLED_APPS to enable admin documentation:




_______________________________________________
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 Wed Dec 16 2009 - 03:27:49 GMT

This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT