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
15
py/rlgall.py
15
py/rlgall.py
|
|
@ -257,7 +257,7 @@ class Game:
|
||||||
else:
|
else:
|
||||||
printTable(newest, self.fields, of)
|
printTable(newest, self.fields, of)
|
||||||
return
|
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, \
|
"Gets the n highest scores (starting at offset) from the database, \
|
||||||
returning a list of dicts."
|
returning a list of dicts."
|
||||||
qfields = []
|
qfields = []
|
||||||
|
|
@ -266,8 +266,19 @@ class Game:
|
||||||
qfields.append("rank(*) OVER (ORDER BY score DESC)")
|
qfields.append("rank(*) OVER (ORDER BY score DESC)")
|
||||||
else:
|
else:
|
||||||
qfields.append(f)
|
qfields.append(f)
|
||||||
qstr = "SELECT " + ", ".join(qfields) + " FROM {0} ".format(self.uname)
|
qstr = "SELECT " + ", ".join(qfields) + " FROM {0}".format(self.uname)
|
||||||
qvals = []
|
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:
|
try:
|
||||||
n = int(n)
|
n = int(n)
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue