Skip to content

Commit

Permalink
Cumalative stats handler
Browse files Browse the repository at this point in the history
  • Loading branch information
dustball committed May 24, 2013
1 parent 9a451d7 commit 1e5c0e2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions main.py
Expand Up @@ -400,6 +400,32 @@ def get(self):
self.response.out.write(signin.last_signin) self.response.out.write(signin.last_signin)
self.response.out.write("<br/>") 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/* # Used by /stats/*
class StatsHandler(webapp.RequestHandler): class StatsHandler(webapp.RequestHandler):
def get(self,format): def get(self,format):
Expand Down Expand Up @@ -538,6 +564,7 @@ def receive(self, mail_message):
('/api/charge', ChargeHandler), ('/api/charge', ChargeHandler),
('/sstats/?', StatHandler), ('/sstats/?', StatHandler),
('/sstats/(.+)', StatsHandler), ('/sstats/(.+)', StatsHandler),
('/cstats/(.+)', CStatsHandler),
('/log', LogHandler), ('/log', LogHandler),
# ('/initrecords', InitRecordsHandler), # ('/initrecords', InitRecordsHandler),
('/count', CountHandler), ('/count', CountHandler),
Expand Down

0 comments on commit 1e5c0e2

Please sign in to comment.