From 2eb8cef1c9478d21a2cd701d04683ee40d6806ad Mon Sep 17 00:00:00 2001 From: "John \"Elwin\" Edwards" Date: Fri, 28 Mar 2014 09:33:49 -0700 Subject: [PATCH] rlgall.py: add time selection to Game.getHigh(). Optional inittime and finaltime parameters set the range of time over which to calculate high scores. --- py/rlgall.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/py/rlgall.py b/py/rlgall.py index 42738ce..5994cf8 100644 --- a/py/rlgall.py +++ b/py/rlgall.py @@ -257,7 +257,7 @@ class Game: 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 @@ class Game: 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):