# HG changeset patch # User John "Elwin" Edwards # Date 1389455133 18000 # Node ID e1de8aeb5ed46a3adbc1c1ad2d635d77f728a0e1 # Parent d3ccdc195796ae76a419840015560f67efd762b8 Add depth and maxdepth columns to the RogueGame tables. diff -r d3ccdc195796 -r e1de8aeb5ed4 py/rlgall.py --- a/py/rlgall.py Fri Jan 10 17:01:11 2014 -0500 +++ b/py/rlgall.py Sat Jan 11 10:45:33 2014 -0500 @@ -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 @@ 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 @@ 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): diff -r d3ccdc195796 -r e1de8aeb5ed4 py/setupdb.py --- a/py/setupdb.py Fri Jan 10 17:01:11 2014 -0500 +++ b/py/setupdb.py Sat Jan 11 10:45:33 2014 -0500 @@ -11,7 +11,7 @@ dbcur = dbconn.cursor() dbcur.execute("CREATE TABLE games ( gname varchar(20), offbytes int );") -dbcur.execute("CREATE TABLE players (pname varchar(20) PRIMARY KEY);") +dbcur.execute("CREATE TABLE players (pname text PRIMARY KEY);") dbconn.commit() for game in rlgall.gamelist: