Mercurial > hg > rlgallery-misc
comparison py/rlgall.py @ 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 | 0f4163dbbafc |
comparison
equal
deleted
inserted
replaced
| 41:d3ccdc195796 | 42:e1de8aeb5ed4 |
|---|---|
| 1 # rlgall.py | 1 # rlgall.py |
| 2 # Module for the Roguelike Gallery, using a postgres database | 2 # Module for the Roguelike Gallery, using a postgres database |
| 3 # Requires Python 3.3 | 3 # Requires Python 3.3 |
| 4 | 4 |
| 5 import re | |
| 5 import os | 6 import os |
| 6 import psycopg2 | 7 import psycopg2 |
| 7 from datetime import datetime | 8 from datetime import datetime |
| 8 import pytz | 9 import pytz |
| 9 | 10 |
| 301 def __init__(self, name, uname, suffix): | 302 def __init__(self, name, uname, suffix): |
| 302 self.name = name | 303 self.name = name |
| 303 self.uname = uname | 304 self.uname = uname |
| 304 self.scores = logdir + uname + ".log" | 305 self.scores = logdir + uname + ".log" |
| 305 self.logspec = ["endt", "score", "name", "xl", "fate"] | 306 self.logspec = ["endt", "score", "name", "xl", "fate"] |
| 306 self.sqltypes = {"endt": "timestamptz", "score": "int", | 307 self.sqltypes = {"endt": "timestamptz", "score": "int", "name": "text", |
| 307 "name": "varchar(20)", "xl": "int", "fate": "text", | 308 "xl": "int", "fate": "text", "ttyrecs": "text ARRAY", |
| 308 "ttyrecs": "text ARRAY", "startt": "timestamptz"} | 309 "startt": "timestamptz", "depth": "int", "maxdepth": "int"} |
| 309 self.logdelim = " " | 310 self.logdelim = " " |
| 310 self.lookback = -1500 | 311 self.lookback = -1500 |
| 311 # Construct the insert query | 312 # Construct the insert query |
| 312 fields = self.sqltypes.keys() | 313 fields = self.sqltypes.keys() |
| 313 colspec = ", ".join(fields) | 314 colspec = ", ".join(fields) |
| 373 cur = conn.cursor() | 374 cur = conn.cursor() |
| 374 cur.executemany(self.insertq, [ d for d in dictlist if d["game"] == self ]) | 375 cur.executemany(self.insertq, [ d for d in dictlist if d["game"] == self ]) |
| 375 conn.commit() | 376 conn.commit() |
| 376 cur.close() | 377 cur.close() |
| 377 return | 378 return |
| 379 def postprocess(self, gamelist): | |
| 380 lre = re.compile("^(quit|killed by (.*)) on level ([0-9]*)( \\[max ([0-9]*)\\] with the Amulet)?$") | |
| 381 wre = re.compile("^escaped with the Amulet \\[deepest level: ([0-9]*)\\]$") | |
| 382 for d in gamelist: | |
| 383 m = lre.match(d["fate"]) | |
| 384 if m: | |
| 385 d["depth"] = int(m.group(3)) | |
| 386 if m.group(4): | |
| 387 d["maxdepth"] = int(m.group(5)) | |
| 388 else: | |
| 389 d["maxdepth"] = d["depth"] | |
| 390 else: | |
| 391 m = wre.match(d["fate"]) | |
| 392 if m: | |
| 393 d["depth"] = 0 | |
| 394 d["maxdepth"] = int(m.group(1)) | |
| 395 else: | |
| 396 # Something went wrong | |
| 397 d["depth"] = -1 | |
| 398 d["maxdepth"] = -1 | |
| 399 Game.postprocess(self, gamelist) | |
| 378 # End RogueGame class definition | 400 # End RogueGame class definition |
| 379 | 401 |
| 380 class ARogueGame(Game): | 402 class ARogueGame(Game): |
| 381 def __init__(self, name, uname, suffix): | 403 def __init__(self, name, uname, suffix): |
| 382 self.name = name | 404 self.name = name |
