from datetime import datetime
import sqlalchemy as sa
import sqlalchemy.sql.functions as func
+from sqlalchemy import distinct
from pyramid.paster import bootstrap
from xonstat.models import *
# maximal number of query results (for testing, set to 0 to get all)
#NUM_PLAYERS = 100
+# we look for players who have activity within the past DELTA hours
+DELTA = 6
+
skin_classic = Skin(
bg = "asfalt",
)
req.matchdict = {'id':3}
print "Requesting player data from db ..."
+cutoff_dt = datetime.utcnow() - timedelta(hours=DELTA)
start = datetime.now()
players = []
if locals().has_key('NUM_PLAYERS'):
- players = DBSession.query(Player).\
+ players = DBSession.query(distinct(Player.player_id)).\
filter(Player.player_id == PlayerElo.player_id).\
+ filter(Player.player_id == PlayerGameStat.player_id).\
+ filter(PlayerGameStat.create_dt > cutoff_dt).\
filter(Player.nick != None).\
filter(Player.player_id > 2).\
filter(Player.active_ind == True).\
limit(NUM_PLAYERS).all()
else:
- players = DBSession.query(Player).\
+ players = DBSession.query(distinct(Player.player_id)).\
filter(Player.player_id == PlayerElo.player_id).\
+ filter(Player.player_id == PlayerGameStat.player_id).\
+ filter(PlayerGameStat.create_dt > cutoff_dt).\
filter(Player.nick != None).\
filter(Player.player_id > 2).\
filter(Player.active_ind == True).\
print "Creating badges for %d players ..." % len(players)
start = datetime.now()
data_time, render_time = 0,0
-for player in players:
- req.matchdict['id'] = player.player_id
+for player_id in players:
+ req.matchdict['id'] = player_id
sstart = datetime.now()
- skin.get_data(player)
+ skin.get_data(player_id)
sstop = datetime.now()
td = sstop-sstart
total_seconds = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6
data_time += total_seconds
sstart = datetime.now()
- skin.render_image("output/%d.png" % player.player_id)
+ skin.render_image("output/%d.png" % player_id)
sstop = datetime.now()
td = sstop-sstart
total_seconds = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6
ctx.select_font_face(font, C.FONT_SLANT_NORMAL, C.FONT_WEIGHT_NORMAL)
ctx.set_font_size(self.deaths_fontsize)
ctx.set_source_rgb(self.deaths_color[0], self.deaths_color[1], self.deaths_color[2])
- txt = "%d death" % deaths
- if deaths != 1:
- txt += "s"
+ if deaths is not None:
+ txt = "%d death" % deaths
+ if deaths != 1:
+ txt += "s"
+ else:
+ txt = ""
xoff, yoff, tw, th = ctx.text_extents(txt)[:4]
ctx.move_to(self.deaths_pos[0]-xoff-tw/2, self.deaths_pos[1]+yoff)
ctx.show_text(txt)
writepng(output_filename, imgdata, self.width, self.height)
- def get_data(self, player):
+ def get_data(self, player_id):
"""Return player data as dict.
This function is similar to the function in player.py but more optimized
# wins/losses
# kills/deaths
# duel/dm/tdm/ctf elo + rank
-
- player_id = player.player_id
+ player = DBSession.query(Player).filter(Player.player_id == player_id).one()
games_played = DBSession.query(
Game.game_type_cd, func.count(), func.sum(PlayerGameStat.alivetime)).\