def matches_per_player( playerid ): print 'not cached: matches_per_player( %s )'% playerid s = db.session() inc = timedelta(days=1) today = datetime.combine(date.today(), time.min ) #datetime( now.year, now.month, now.day ) since = today - timedelta(days=7) - fail_offset now = since data = [] i = 1 while now < datetime.now() - fail_offset: data.append( s.query( Result.id ).filter( Result.player_id == playerid).filter( Result.date < now + inc ).filter( Result.date >= now ).count() ) i += 1 now += inc fn = 'images/plots/player_matches_%i.png'%int(playerid) path = os.path.join(config.get('ladder','base_dir'), fn) url = '%s/%s'%(config.get('ladder','base_url'), fn) mkdir_p(path) with mutex: f = plt.figure(1) plt.plot(range(len(data)),data) plt.ylabel('matches per day') plt.xlabel('days past') plt.savefig(path,transparent=True) plt.close(1) s.close() return url
def get_rss_out(l_id): s = None try: base_url = config.get('ladder','base_url') s = db.session() lad = db.GetLadder( ladder_id ) rank_table = GlobalRankingAlgoSelector.GetWebRepresentation( db.GetRanks( ladder_id ), db ) #template = env.get_template('scoreboard.html') template = env.get_template('rss_scoreboard.html') desc = template.render( rank_table=rank_table, ladder=lad ) url = '%sscoreboard?id=%s'%(base_url,ladder_id) #$postdate = date("Y-m-d H:i", $row['topic_time']); title = "%s -- updated scoreboard"%lad.name item = PyRSS2Gen.RSSItem( title = title, link=url, guid = PyRSS2Gen.Guid( url ), pubDate=datetime.datetime.now(), description = desc ) rss = PyRSS2Gen.RSS2( title = "%s -- Scoreboard"%lad.name, link = "%sfeeds/scores/%s"%(base_url,l_id), description = "DESCRIPTION", lastBuildDate = datetime.datetime.now(), items = [item] ) output = cStringIO.StringIO() rss.write_xml(output) return output.getvalue() except Exception, m: if 's' in locals() and s: s.close() return str(m)
def get_rss_out(l_id): try: base_url = config.get('ladder', 'base_url') s = db.session() limit = 10 matches = s.query( Match ).filter( Match.ladder_id == l_id ) ladder_name = s.query( Ladder.name ).filter( Ladder.id == l_id ).one() items = get_items( matches ) if len(items) == 0: return "" rss = PyRSS2Gen.RSS2( title = "%s -- Latest matches"%ladder_name, link = "%sfeeds/matches/%s"%(base_url,l_id), description = "Latest 10 matches played on a single given ladder", lastBuildDate = datetime.datetime.now(), items = items ) output = cStringIO.StringIO() rss.write_xml(output) response.headers['Content-Type'] = 'text/xml' return output.getvalue() except Exception, m: if 's' in locals() and s: s.close() return str(m)
def get_items(query): items = [] base_url = config.get('ladder', 'base_url') for match in query: url = '%s/%s' % (base_url, urllib.quote('match?id=%s'%(match.id))) #$postdate = date("Y-m-d H:i", $row['topic_time']); title = '%s'%(match.mapname) template = env.get_template('rss_match.html') desc = template.render(ladder=match.ladder, matchinfo=MatchInfoToTableAdapter(match),base_url=base_url ) items.append( PyRSS2Gen.RSSItem( title = title, link=url, guid = PyRSS2Gen.Guid( url ), pubDate=match.date, description = desc ) ) return items
def all_get_rss_out(): try: base_url = config.get('ladder', 'base_url') s = db.session() limit = 10 matches = s.query( Match ) items = get_items( matches ) if len(items) == 0: return "" rss = PyRSS2Gen.RSS2( title = "SpringLadder -- Latest matches", link = "%s/feeds/matches"%(base_url), description = "Latest 10 matches played on any ladder", lastBuildDate = datetime.datetime.now(), items = items ) output = cStringIO.StringIO() rss.write_xml(output) return output.getvalue() except Exception, m: if 's' in locals() and s: s.close() return str(m)