rlgall.py: add time selection to Game.getHigh().
Optional inittime and finaltime parameters set the range of time over which to calculate high scores.
This commit is contained in:
parent
d67561aa42
commit
2eb8cef1c9
1 changed files with 13 additions and 2 deletions
13
py/rlgall.py
13
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 = []
|
||||
|
|
@ -268,6 +268,17 @@ class Game:
|
|||
qfields.append(f)
|
||||
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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue