Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More effecient counting, la-te-da

  • Loading branch information...
commit b2c3a40e827547e16639f7317d434972eda140da 1 parent 0bd7d83
@dustball dustball authored
Showing with 26 additions and 4 deletions.
  1. +26 −4 main.py
View
30 main.py
@@ -71,8 +71,31 @@ def post(self):
new_event.put()
self.redirect('/eventmode')
+
+class DailyCount(db.Model):
+ day = db.DateProperty(required=True)
+ count = db.IntegerProperty(required=True)
+ @classmethod
+ def get(cls):
+ count_rec = cls.all().filter('day =', datetime.now(Pacific()).date()).get()
+ if count_rec:
+ count = count_rec.count
+ else:
+ count = 0
+ return count
+
+ @classmethod
+ def increment_and_get(cls):
+ count_rec = cls.all().filter('day =', datetime.now(Pacific()).date()).get()
+ if count_rec:
+ count_rec.count = count_rec.count + 1
+ else:
+ count_rec = DailyCount(day=datetime.now(Pacific()).date(),count=1)
+ count_rec.put()
+ return count_rec.count
+
# A log of all signins. One row per signin.
class Signin(db.Model):
email = db.StringProperty(required=True)
@@ -131,6 +154,7 @@ def signin(cls, email, type):
except:
logging.info("Failed deactivating old Signin object.")
s = Signin(email=email, type=type, image_url=image, name=name)
+ DailyCount.increment_and_get()
s.put()
return s
@@ -195,15 +219,13 @@ def get(self):
# Exports e-mail addresses (usually disabled)
class ExportHandler(webapp.RequestHandler):
def get(self):
- for e in Signin.all():
+ for e in SigninRecord.all():
self.response.out.write(e.email+"\n")
# Renders the main page
class MainHandler(webapp.RequestHandler):
def get(self):
- today_db = db.GqlQuery("SELECT * FROM Signin WHERE created >= DATETIME(:earlier_this_morning) ORDER BY created desc LIMIT 1000",
- earlier_this_morning=(datetime.now(Pacific()).strftime("%Y-%m-%d 00:00:00")))
- today_count = today_db.count()
+ today_count = DailyCount.get()
if today_count > 1:
today_count_signigicant = True
dayofWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

0 comments on commit b2c3a40

Please sign in to comment.
Something went wrong with that request. Please try again.