Add depth and maxdepth columns to the RogueGame tables.

This commit is contained in:
John "Elwin" Edwards 2014-01-11 10:45:33 -05:00
parent 291d5d4ffc
commit 48c1b168bc
2 changed files with 26 additions and 4 deletions

View file

@ -2,6 +2,7 @@
# Module for the Roguelike Gallery, using a postgres database
# Requires Python 3.3
import re
import os
import psycopg2
from datetime import datetime
@ -303,9 +304,9 @@ class RogueGame(Game):
self.uname = uname
self.scores = logdir + uname + ".log"
self.logspec = ["endt", "score", "name", "xl", "fate"]
self.sqltypes = {"endt": "timestamptz", "score": "int",
"name": "varchar(20)", "xl": "int", "fate": "text",
"ttyrecs": "text ARRAY", "startt": "timestamptz"}
self.sqltypes = {"endt": "timestamptz", "score": "int", "name": "text",
"xl": "int", "fate": "text", "ttyrecs": "text ARRAY",
"startt": "timestamptz", "depth": "int", "maxdepth": "int"}
self.logdelim = " "
self.lookback = -1500
# Construct the insert query
@ -375,6 +376,27 @@ class RogueGame(Game):
conn.commit()
cur.close()
return
def postprocess(self, gamelist):
lre = re.compile("^(quit|killed by (.*)) on level ([0-9]*)( \\[max ([0-9]*)\\] with the Amulet)?$")
wre = re.compile("^escaped with the Amulet \\[deepest level: ([0-9]*)\\]$")
for d in gamelist:
m = lre.match(d["fate"])
if m:
d["depth"] = int(m.group(3))
if m.group(4):
d["maxdepth"] = int(m.group(5))
else:
d["maxdepth"] = d["depth"]
else:
m = wre.match(d["fate"])
if m:
d["depth"] = 0
d["maxdepth"] = int(m.group(1))
else:
# Something went wrong
d["depth"] = -1
d["maxdepth"] = -1
Game.postprocess(self, gamelist)
# End RogueGame class definition
class ARogueGame(Game):