diff py/rlgall.py @ 50:4549b3c0cd28

rlgall.py: add time selection to Game.getHigh(). Optional inittime and finaltime parameters set the range of time over which to calculate high scores.
author John "Elwin" Edwards
date Fri, 28 Mar 2014 09:33:49 -0700
parents 6138c27d1950
children df7acc5653b3
line wrap: on
line diff
--- a/py/rlgall.py	Mon Mar 24 16:01:28 2014 -0700
+++ b/py/rlgall.py	Fri Mar 28 09:33:49 2014 -0700
@@ -257,7 +257,7 @@
     else:
       printTable(newest, self.fields, of)
     return
-  def getHigh(self, n=10, offset=0):
+  def getHigh(self, n=10, offset=0, inittime=None, finaltime=None):
     "Gets the n highest scores (starting at offset) from the database, \
      returning a list of dicts."
     qfields = []
@@ -266,8 +266,19 @@
         qfields.append("rank(*) OVER (ORDER BY score DESC)")
       else:
         qfields.append(f)
-    qstr = "SELECT " + ", ".join(qfields) + " FROM {0} ".format(self.uname)
+    qstr = "SELECT " + ", ".join(qfields) + " FROM {0}".format(self.uname)
     qvals = []
+    if isinstance(inittime, datetime):
+      qstr += " WHERE endt >= %s"
+      qvals.append(inittime)
+      if isinstance(finaltime, datetime):
+        if finaltime < inittime:
+          return []
+        qstr += " AND endt < %s"
+        qvals.append(finaltime)
+    elif isinstance(finaltime, datetime):
+      qstr += " WHERE endt < %s"
+      qvals.append(finaltime)
     try:
       n = int(n)
     except (ValueError, TypeError):