def fromrow(self, row): if not row: return {} ret = { "teams": {}, "players": {}, "weapons": {}, } # Base dbselectors.rowtodict(ret, row, ["id", "time", "map", "mode", "mutators", "timeplayed"]) ret["version"] = self.db.execute( """SELECT version FROM game_servers WHERE game = %d""" % ret['id']).fetchone()[0] # Server handle if self.flags["server"]: ret["server"] = self.db.execute( """SELECT handle FROM game_servers WHERE game = %d""" % ret['id']).fetchone()[0] # Teams if self.flags["teams"]: for team_row in self.db.execute( "SELECT * FROM game_teams WHERE game = %d" % row[0]): team = {} dbselectors.rowtodict(team, team_row, [None, "team", "score", "name"]) ret["teams"][team["name"]] = team # Affinities captures = [] bombings = [] if self.flags["affinities"]: # Flag Captures for capture_row in self.db.execute( "SELECT * FROM game_captures WHERE game = %d" % row[0]): capture = {} dbselectors.rowtodict(capture, capture_row, [None, "player", "playerhandle", "capturing", "captured"]) captures.append(capture) if captures: ret['captures'] = captures # Base Bombings for bombing_row in self.db.execute( "SELECT * FROM game_bombings WHERE game = %d" % row[0]): bombing = {} dbselectors.rowtodict(bombing, bombing_row, [None, "player", "playerhandle", "bombing", "bombed"]) bombings.append(bombing) if bombings: ret['bombings'] = bombings # FFA Rounds if self.flags["rounds"]: ffarounds = [] for ffaround_row in self.db.execute( "SELECT * FROM game_ffarounds WHERE game = %d" % row[0]): ffaround = {} dbselectors.rowtodict(ffaround, ffaround_row, [None, "player", "playerhandle", "round", "winner"]) ffarounds.append(ffaround) if ffarounds: ret['ffarounds'] = ffarounds # Players if self.flags["players"]: for player_row in self.db.execute( "SELECT * FROM game_players WHERE game = %d" % row[0]): player = { "weapons": {}, "captures": [], "bombings": [], } dbselectors.rowtodict(player, player_row, [None, "name", "handle", "score", "timealive", "frags", "deaths", "id", "timeactive"]) #Player total damage if self.flags["playerdamage"]: player["damage"] = self.db.execute( """SELECT (sum(damage1) + sum(damage2)) FROM game_weapons WHERE game = %d AND player = %s""" % ( row[0], player["id"])).fetchone()[0] or 0 if self.flags["playeraffinities"]: for capture in captures: if capture["player"] == player["id"]: player["captures"].append(capture) for bombing in bombings: if bombing["player"] == player["id"]: player["bombings"].append(bombing) if self.flags["playerweapons"]: cols = ["weapon"] + redeclipse(ret).weapcols for wrow in self.db.execute(""" SELECT %s FROM game_weapons WHERE game = %d AND player = %d""" % ( ','.join(cols), ret['id'], player_row[7] )): weapon = wrow[0] w = {'name': weapon} for colidx in range(len(cols) - 1): colidx += 1 t = cols[colidx] try: w[t] = wrow[colidx] except TypeError: w[t] = 0 player["weapons"][weapon] = w ret["players"][player['id']] = player # Weapons if self.flags["weapons"]: for weapon in redeclipse(ret).weaponlist: w = {'name': weapon} gameweapsum = lambda x: self.db.execute( """SELECT sum(%s) FROM game_weapons WHERE weapon = ? AND game = %d""" % ( x, ret['id']), (weapon,)).fetchone()[0] for t in redeclipse(ret).weapcols: w[t] = gameweapsum(t) ret['weapons'][weapon] = w return ret
def fromrow(self, row): if not row: return {} recentgames = self.q.qint('recentgames', cfg.get('recent')) recentsums = self.recent('recentsums') ret = { "recentgames": {}, } dbselectors.rowtodict(ret, row, [ "name", "handle" ], start=1) handle = ret['handle'] # Games if self.flags['games']: gamerows = list(self.db.execute( """SELECT * FROM games WHERE id in (SELECT game FROM game_players WHERE handle=?)""", (handle,))) ret["games"] = [r[0] for r in gamerows] # Recent Games if self.flags['recentgames']: gs = dbselectors.get("game", self.db) gs.flags_none() gs.weakflags(['players'], True) for row in utils.sliceneg( list(reversed(gamerows)), recentgames): game = gs.fromrow(row) game['player'] = [p for p in list(game["players"].values()) if p["handle"] == handle][0] # Count FFA rounds for this player in a new index ffarounds = [] for ffaround_row in self.db.execute( """SELECT * FROM game_ffarounds WHERE playerhandle = ? AND game = %d""" % game['id'], (handle,)): ffaround = {} dbselectors.rowtodict( ffaround, ffaround_row, ["game", None, None, "round", "winner"]) ffarounds.append(ffaround) if ffarounds: game['player_ffarounds'] = ffarounds ret["recentgames"][game["id"]] = game #Data from games recentsum = lambda x: self.db.execute( """SELECT sum(%s) FROM (SELECT * FROM game_players WHERE game IN (SELECT id FROM games %s) AND %s AND handle = ? %s)""" % (x, "WHERE mode != re_mode(id, 'race')" if x not in ['timeactive'] else "", self.vlimit(), recentsums), (ret['handle'],)).fetchone()[0] recent = { 'weapons': {}, } # Affinity data if self.flags['affinities']: captures = [] for capture_row in self.db.execute( """SELECT * FROM game_captures WHERE playerhandle = ? AND game in (SELECT id FROM games %s)""" % (recentsums), (handle,)): capture = {} dbselectors.rowtodict(capture, capture_row, ["game", None, None, "capturing", "captured"]) captures.append(capture) if captures: ret['captures'] = captures bombings = [] for bombing_row in self.db.execute( """SELECT * FROM game_bombings WHERE playerhandle = ? AND game in (SELECT id FROM games %s)""" % (recentsums), (handle,)): bombing = {} dbselectors.rowtodict(bombing, bombing_row, ["game", None, None, "bombing", "bombed"]) bombings.append(bombing) if bombings: ret['bombings'] = bombings # Sums of data if self.flags['recentsums']: for t in ['frags', 'deaths', 'timealive', 'timeactive']: recent[t] = recentsum(t) # Damage if self.flags['damage']: recent["damage"] = self.db.execute( """SELECT (sum(damage1) + sum(damage2)) FROM game_weapons WHERE %s AND playerhandle = ? AND game IN (SELECT id FROM games WHERE mode != re_mode(id, 'race')) %s""" % (self.vlimit(), recentsums), (ret["handle"],)).fetchone()[0] if self.flags['weapons']: #Weapon Data for weapon in redeclipse().weaponlist: wr = {'name': weapon} recentsum = lambda x: self.db.execute( """SELECT sum(%s) FROM (SELECT * FROM game_weapons WHERE weapon = ? AND playerhandle = ? AND game IN (SELECT id FROM games WHERE mode != re_mode(id, 'race')) AND %s %s)""" % (x, self.vlimit(), recentsums), (weapon, ret['handle'])).fetchone()[0] for t in redeclipse().weapcols: wr[t] = recentsum(t) recent['weapons'][weapon] = wr ret["recent"] = recent return ret