comparison py/rlgall.py @ 62:df7acc5653b3

Make the final depth appear in Advanced Rogue 5 tables. Along the way, "SELECT name FROM table WHERE name = ..." was removed from any queries where it had been carelessly placed.
author John "Elwin" Edwards
date Fri, 30 Jan 2015 20:24:47 -0500
parents 4549b3c0cd28
children ad103f9f2e3a
comparison
equal deleted inserted replaced
61:5b4ff5680037 62:df7acc5653b3
52 </body></html> 52 </body></html>
53 """ 53 """
54 54
55 # This would be more useful if we had to do translation 55 # This would be more useful if we had to do translation
56 headerbook = {"endt":"End time", "score":"Score", "name":"Name", "xl":"XL", 56 headerbook = {"endt":"End time", "score":"Score", "name":"Name", "xl":"XL",
57 "fate":"Fate", "rank":"Rank", "game":"Game", "class": "Class"} 57 "fate":"Fate", "rank":"Rank", "game":"Game", "class":"Class",
58 "depth":"Depth"}
58 # Queries for the games table 59 # Queries for the games table
59 offselstr = "SELECT offbytes FROM games WHERE gname = %s;" 60 offselstr = "SELECT offbytes FROM games WHERE gname = %s;"
60 newoffstr = "UPDATE games SET offbytes = %s WHERE gname = %s;" 61 newoffstr = "UPDATE games SET offbytes = %s WHERE gname = %s;"
61 62
62 def getconn(): 63 def getconn():
121 thing = entry[field] 122 thing = entry[field]
122 if field == "game": 123 if field == "game":
123 clist.append((thing.name, cell)) 124 clist.append((thing.name, cell))
124 elif field == "xl" or field == "score" or field == "rank": # Numerics 125 elif field == "xl" or field == "score" or field == "rank": # Numerics
125 clist.append((str(thing), rcell)) 126 clist.append((str(thing), rcell))
127 elif field == "depth" or field == "maxdepth":
128 clist.append((str(thing), cell))
126 elif field == "name": 129 elif field == "name":
127 clist.append((playerlink(thing), cell)) 130 clist.append((playerlink(thing), cell))
128 elif field == "fate": 131 elif field == "fate":
129 clist.append((thing, cell)) 132 clist.append((thing, cell))
130 elif field == "endt": 133 elif field == "endt":
423 cur.close() 426 cur.close()
424 conn.close() 427 conn.close()
425 return dictlist 428 return dictlist
426 def getPlayer(self, player): 429 def getPlayer(self, player):
427 "Gets all player's games from the database." 430 "Gets all player's games from the database."
428 qstr = "SELECT endt, score, name, xl, fate, startt FROM " + self.uname + " WHERE name = %s;" 431 qstr = "SELECT endt, score, xl, fate, startt FROM " + self.uname + " WHERE name = %s;"
429 conn = getconn() 432 conn = getconn()
430 if conn == None: 433 if conn == None:
431 return [] 434 return []
432 cur = conn.cursor() 435 cur = conn.cursor()
433 entries = [] 436 entries = []
434 cur.execute(qstr, [player]) 437 cur.execute(qstr, [player])
435 for record in cur: 438 for record in cur:
436 ndict = {"game": self} 439 ndict = {"game": self}
440 ndict["name"] = self.uname
437 ndict["endt"] = record[0] 441 ndict["endt"] = record[0]
438 ndict["score"] = record[1] 442 ndict["score"] = record[1]
439 ndict["name"] = record[2] 443 ndict["xl"] = record[2]
440 ndict["xl"] = record[3] 444 ndict["fate"] = record[3]
441 ndict["fate"] = record[4] 445 ndict["startt"] = record[4]
442 ndict["startt"] = record[5]
443 entries.append(ndict) 446 entries.append(ndict)
444 cur.close() 447 cur.close()
445 conn.close() 448 conn.close()
446 return entries 449 return entries
447 def putIntoDB(self, dictlist, conn): 450 def putIntoDB(self, dictlist, conn):
493 colspec = ", ".join(fields) 496 colspec = ", ".join(fields)
494 valspec = ", ".join([ "%({})s".format(c) for c in fields ]) 497 valspec = ", ".join([ "%({})s".format(c) for c in fields ])
495 self.insertq = "INSERT INTO {0} ({1}) VALUES ({2});".format(self.uname, 498 self.insertq = "INSERT INTO {0} ({1}) VALUES ({2});".format(self.uname,
496 colspec, valspec) 499 colspec, valspec)
497 # Class variables 500 # Class variables
498 fields = ["name", "score", "class", "xl", "fate", "endt"] 501 fields = ["name", "score", "class", "xl", "fate", "depth", "endt"]
499 rankfields = ["rank", "score", "name", "class", "xl", "fate", "endt"] 502 rankfields = ["rank", "score", "name", "class", "xl", "fate", "depth", "endt"]
500 pfields = ["score", "class", "xl", "fate", "endt"] 503 pfields = ["score", "class", "xl", "fate", "depth", "endt"]
501 def getRecent(self, n=20): 504 def getRecent(self, n=20):
502 return [] 505 return []
503 def getPlayer(self, player): 506 def getPlayer(self, player):
504 "Gets all player's games from the database." 507 "Gets all player's games from the database."
505 qstr = "SELECT endt, score, name, xl, class, fate FROM " + self.uname + " WHERE name = %s;" 508 qstr = "SELECT endt, score, xl, class, fate, depth FROM " + self.uname + " WHERE name = %s;"
506 conn = getconn() 509 conn = getconn()
507 if conn == None: 510 if conn == None:
508 return [] 511 return []
509 cur = conn.cursor() 512 cur = conn.cursor()
510 entries = [] 513 entries = []
511 cur.execute(qstr, [player]) 514 cur.execute(qstr, [player])
512 for record in cur: 515 for record in cur:
513 ndict = {"game": self} 516 ndict = {"game": self}
517 ndict["name"] = self.uname
514 ndict["endt"] = record[0] 518 ndict["endt"] = record[0]
515 ndict["score"] = record[1] 519 ndict["score"] = record[1]
516 ndict["name"] = record[2] 520 ndict["xl"] = record[2]
517 ndict["xl"] = record[3] 521 ndict["class"] = record[3]
518 ndict["class"] = record[4] 522 ndict["fate"] = record[4]
519 ndict["fate"] = record[5] 523 ndict["depth"] = record[5]
520 entries.append(ndict) 524 entries.append(ndict)
521 cur.close() 525 cur.close()
522 conn.close() 526 conn.close()
523 return entries 527 return entries
524 528