Permalink
Browse files

Cumalative stats handler

  • Loading branch information...
1 parent 9a451d7 commit 1e5c0e2a180ead0b8ecb970377f78031d5f89338 @dustball dustball committed May 24, 2013
Showing with 27 additions and 0 deletions.
  1. +27 −0 main.py
View
27 main.py
@@ -401,6 +401,32 @@ def get(self):
self.response.out.write("<br/>")
# Used by /stats/*
+class CStatsHandler(webapp.RequestHandler):
+ def get(self,format):
+ days = {}
+ formats = {'daily':"%Y-%m-%d", 'weekly':"%Y Week %U", 'monthly':"%Y-%m"}
+ date_format = formats[format]
+ self.response.headers.add_header('Content-Type',"text/csv")
+ self.response.headers.add_header('Content-disposition',"attachment;filename=signin-cstats-"+format+".csv")
+ self.response.out.write("Date,Total Signins")
+ self.response.out.write("\n")
+
+ for signin in DailyCount.all().order("day"):
+ ts = string.replace(signin.day.strftime(date_format),"Week 00","Week 01")
+ if ts not in days:
+ days[ts] = 0
+ days[ts] += signin.count
+
+ ordered_days = days.keys()
+ ordered_days.sort()
+
+ for day in ordered_days:
+ self.response.out.write(day)
+ self.response.out.write(",")
+ self.response.out.write(days[day])
+ self.response.out.write("\n")
+
+# Used by /stats/*
class StatsHandler(webapp.RequestHandler):
def get(self,format):
days = {}
@@ -538,6 +564,7 @@ def receive(self, mail_message):
('/api/charge', ChargeHandler),
('/sstats/?', StatHandler),
('/sstats/(.+)', StatsHandler),
+ ('/cstats/(.+)', CStatsHandler),
('/log', LogHandler),
# ('/initrecords', InitRecordsHandler),
('/count', CountHandler),

0 comments on commit 1e5c0e2

Please sign in to comment.