changeset 17:7f7b3da664d6

Begin adding arogue5 support to the recorder script. rlgalldb.py's arogue5 object is a nonfunctional stub, but at least it doesn't crash and the other games still work.
author John "Elwin" Edwards <elwin@sdf.org>
date Sun, 16 Sep 2012 20:44:22 -0700
parents 5297ccba4e70
children 5731d2ecaec4
files py/rlgalldb.py
diffstat 1 files changed, 79 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/py/rlgalldb.py	Sat Sep 15 17:23:13 2012 +0000
+++ b/py/rlgalldb.py	Sun Sep 16 20:44:22 2012 -0700
@@ -143,34 +143,9 @@
   of.write(tblend)
   return
 
-def readentries(entfile, entlist):
-  "Reads a list of entries from a file object"
-  while True:
-    nextentry = entfile.readline()
-    if not nextentry:
-      break
-    if nextentry[-1] != '\n': # The line is incomplete
-      break
-    entlist.append(nextentry.split(None, 4))
-  return
-
 class Game:
-  pass
-
-class RogueGame(Game):
-  def __init__(self, name, uname, suffix):
-    self.name = name
-    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.logdelim = " "
-  # Class variables, used by some methods
-  fields = ["name", "score", "xl", "fate", "endt"]
-  rankfields = ["rank", "score", "name", "xl", "fate", "endt"]
-  pfields = ["score", "xl", "fate", "endt"]
+  def __init__(self, name, uname):
+    pass
   def logtoDict(self, entry):
     "Processes a log entry string, returning a dict."
     ndict = {"game": self}
@@ -178,6 +153,8 @@
     for item, value in zip(self.logspec, entrylist):
       if self.sqltypes[item] == "int":
         ndict[item] = int(value)
+      if self.sqltypes[item] == "bool":
+        ndict[item] = bool(int(value))
       elif self.sqltypes[item] == "timestamptz":
         ndict[item] = datetime.fromtimestamp(int(value), utc)
       else:
@@ -194,6 +171,49 @@
         break
       entlist.append(self.logtoDict(nextentry))
     return
+  # TODO how does this work with postprocess?
+  def loadnew(self):
+    conn = getconn()
+    if conn == None:
+      return []
+    cur = conn.cursor()
+    # Get the previous offset
+    cur.execute(offselstr, [self.uname])
+    offset = cur.fetchone()[0]
+    newlist = []
+    try:
+      scr = open(self.scores)
+      scr.seek(offset)
+      self.getEntryDicts(scr, newlist)
+    except IOError:
+      noffset = offset # Can't read anything, assume no new games
+    else:
+      noffset = scr.tell()
+      scr.close()
+      cur.execute(newoffstr, [noffset, self.uname])
+    # The new players must already be added to the players table.
+    updatenames = set([ e["name"] for e in newlist ])
+    self.postprocess(newlist)
+    self.putIntoDB(newlist, conn)
+    cur.close()
+    conn.close()
+    return updatenames
+# End Game class definition
+
+class RogueGame(Game):
+  def __init__(self, name, uname, suffix):
+    self.name = name
+    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.logdelim = " "
+  # Class variables, used by some methods
+  fields = ["name", "score", "xl", "fate", "endt"]
+  rankfields = ["rank", "score", "name", "xl", "fate", "endt"]
+  pfields = ["score", "xl", "fate", "endt"]
   def getRecent(self, n=20):
     "Gets the n most recent games out of the database, returning a list \
      of dicts."
@@ -325,40 +345,45 @@
         itsEntries[i]["ttyrecs"] = recs
     cur.close()
     conn.close()
-  def loadnew(self):
-    conn = getconn()
-    if conn == None:
-      return []
-    cur = conn.cursor()
-    # Get the previous offset
-    cur.execute(offselstr, [self.uname])
-    offset = cur.fetchone()[0]
-    newlist = []
-    try:
-      scr = open(self.scores)
-      scr.seek(offset)
-      self.getEntryDicts(scr, newlist)
-    except IOError:
-      noffset = offset # Can't read anything, assume no new games
-    else:
-      noffset = scr.tell()
-      scr.close()
-      cur.execute(newoffstr, [noffset, self.uname])
-    # The new players must already be added to the players table.
-    updatenames = set([ e["name"] for e in newlist ])
-    self.postprocess(newlist)
-    self.putIntoDB(newlist, conn)
-    cur.close()
-    conn.close()
-    return updatenames
 # End RogueGame class definition
 
+class ARogueGame(Game):
+  def __init__(self, name, uname, suffix):
+    self.name = name
+    self.uname = uname
+    self.scores = logdir + uname + ".log"
+    self.logspec = ["endt", "score", "name", "xl", "class", "depth", 
+                    "maxdepth", "quest", "hadquest", "fate"]
+    self.sqltypes = {"endt": "timestamptz", "score": "int", 
+            "name": "varchar(20)", "xl": "int", "class": "text", "depth": "int",
+            "maxdepth": "int", "quest": "int", "hadquest": "bool",
+            "fate": "text", "ttyrecs": "text ARRAY", "startt": "timestamptz"}
+    self.logdelim = " "
+  # Class variables
+  fields = ["name", "score", "class", "xl", "fate", "endt"]
+  rankfields = ["rank", "score", "name", "class", "xl", "fate", "endt"]
+  pfields = ["score", "class", "xl", "fate", "endt"]
+  def postprocess(self, gamelist):
+    "Not Implemented"
+    return
+  def putIntoDB(self, dictlist, conn):
+    "Not Implemented"
+    conn.commit()
+    return
+  def getHigh(self, n=10, offset=0):
+    return []
+  def getRecent(self, n=20):
+    return []
+  def getPlayer(self, player):
+    return []
+
 rogue3 = RogueGame("Rogue V3", "rogue3", "r3")
 rogue4 = RogueGame("Rogue V4", "rogue4", "r4")
 rogue5 = RogueGame("Rogue V5", "rogue5", "r5")
 srogue = RogueGame("Super-Rogue", "srogue", "sr")
+arogue5 = ARogueGame("Advanced Rogue 5", "arogue5", "ar5")
 
-gamelist = [rogue3, rogue4, rogue5, srogue]
+gamelist = [rogue3, rogue4, rogue5, srogue, arogue5]
 
 def playerpage(pname):
   "Generate a player's HTML page"