changeset 42:e1de8aeb5ed4

Add depth and maxdepth columns to the RogueGame tables.
author John "Elwin" Edwards
date Sat, 11 Jan 2014 10:45:33 -0500
parents d3ccdc195796
children 3ecbd4fa2a08
files py/rlgall.py py/setupdb.py
diffstat 2 files changed, 26 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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):
--- 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: