comparison py/rlgalldb.py @ 20:c05050f78d81

Make arogue5 scores appear on the player pages too. This could probably be done in a more structured way.
author John "Elwin" Edwards <elwin@sdf.org>
date Mon, 17 Sep 2012 11:41:11 -0700
parents 78580bffc13d
children 453278a81371
comparison
equal deleted inserted replaced
19:78580bffc13d 20:c05050f78d81
434 conn.close() 434 conn.close()
435 return dictlist 435 return dictlist
436 def getRecent(self, n=20): 436 def getRecent(self, n=20):
437 return [] 437 return []
438 def getPlayer(self, player): 438 def getPlayer(self, player):
439 return [] 439 "Gets all player's games from the database."
440 qstr = "SELECT endt, score, name, xl, class, fate FROM " + self.uname + " WHERE name = %s;"
441 conn = getconn()
442 if conn == None:
443 return []
444 cur = conn.cursor()
445 entries = []
446 cur.execute(qstr, [player])
447 for record in cur:
448 ndict = {"game": self}
449 ndict["endt"] = record[0]
450 ndict["score"] = record[1]
451 ndict["name"] = record[2]
452 ndict["xl"] = record[3]
453 ndict["class"] = record[4]
454 ndict["fate"] = record[5]
455 entries.append(ndict)
456 cur.close()
457 conn.close()
458 return entries
440 459
441 rogue3 = RogueGame("Rogue V3", "rogue3", "r3") 460 rogue3 = RogueGame("Rogue V3", "rogue3", "r3")
442 rogue4 = RogueGame("Rogue V4", "rogue4", "r4") 461 rogue4 = RogueGame("Rogue V4", "rogue4", "r4")
443 rogue5 = RogueGame("Rogue V5", "rogue5", "r5") 462 rogue5 = RogueGame("Rogue V5", "rogue5", "r5")
444 srogue = RogueGame("Super-Rogue", "srogue", "sr") 463 srogue = RogueGame("Super-Rogue", "srogue", "sr")
460 if not entries: 479 if not entries:
461 ppagefi.write("<div>" + pname + " has not yet completed an expedition\ 480 ppagefi.write("<div>" + pname + " has not yet completed an expedition\
462 in this dungeon.</div>\n") 481 in this dungeon.</div>\n")
463 else: 482 else:
464 entries.sort(key=lambda e: e["endt"]) 483 entries.sort(key=lambda e: e["endt"])
465 printTable(entries, RogueGame.pfields, ppagefi) 484 printTable(entries, game.pfields, ppagefi)
466 scoresum = 0 485 scoresum = 0
467 for entry in entries: 486 for entry in entries:
468 scoresum += int(entry["score"]) 487 scoresum += int(entry["score"])
469 avgscr = scoresum / len(entries) 488 avgscr = scoresum / len(entries)
470 ppagefi.write("<p>Average score: {0}</p>\n".format(avgscr)) 489 ppagefi.write("<p>Average score: {0}</p>\n".format(avgscr))