def get(self): requires_user(self) param = self.request.get('users'); if not param or re.match('(\d+-)*\d+$', param) is None: self.redirect('/') return # construct google charts url userids = re.split('-', param) userids = userids[:6] # keep only forst 6 entries min_score = 10000 max_score = 0 oldest = 0 charts = [] usernames = [] for userid in userids: usernames.append(str(models.get_user(userid).user)) scores = models.get_scores(int(userid)) if not scores is None: x = [] y = [] for score in scores: x.append((date.today() - score.date).days) y.append(round(score.score)) min_score = min(round(score.score), min_score) max_score = max(round(score.score), max_score) oldest = max((date.today() - score.date).days, oldest) if x.count(0) == 0: x.append(0) y.append(y[-1]) charts.append([ x, y ]) def adapt_date(d): return str((oldest - d) * 100 / oldest) def adapt_score(s): return str((s - min_score + 10) * 100 / (max_score - min_score + 10)) def adapt_chart(l): return [ map(adapt_date, l[0]), map(adapt_score, l[1]) ] charts = map(adapt_chart, charts) chart_url = 'http://chart.apis.google.com/chart?chs=600x250&cht=lxy'+\ '&chco=003DF5,F5003D,3DF500,F5F500,FF70B8,CC6600&chd=t:' chart_data = [] for chart in charts: chart_data.append(','.join(chart[0]) + '|' + ','.join(chart[1])) chart_url += '|'.join(chart_data) + '&chdl=' + '|'.join(usernames) template_file = os.path.join(os.path.dirname(__file__), 'templates/compare.html') template_values = { 'greeting': get_greeting(), 'is_admin': is_admin(), 'is_registered': is_registered(), 'chart_url': chart_url } self.response.out.write(Template(filename=template_file,lookup=mylookup).render_unicode(**template_values))
def get(self): param = self.request.get('users'); if not param or re.match('(\d+-)*\d+$', param) is None: self.redirect('/') return # construct google charts url userids = re.split('-', param) userids = userids[:MAX_CHART_ENTRIES] # keep only first n entries min_score = 10000 max_score = 0 oldest = 0 charts = [] usernames = [] for userid in userids: usernames.append(unicode(models.get_user(userid).nickname)) scores = models.get_scores(int(userid)) if not scores is None: x = [] y = [] for score in scores: x.append((date.today() - score.date).days) y.append(round(score.score)) min_score = min(round(score.score), min_score) max_score = max(round(score.score), max_score) oldest = max((date.today() - score.date).days, oldest) if x.count(0) == 0: x.append(0) y.append(y[-1]) charts.append([ x, y ]) def adapt_date(d): return unicode((oldest - d) * 100 / oldest) def adapt_score(s): return unicode((s - min_score + 10) * 100 / (max_score - min_score + 10)) def adapt_chart(l): return [ map(adapt_date, l[0]), map(adapt_score, l[1]) ] charts = map(adapt_chart, charts) chart_url = 'http://chart.apis.google.com/chart?chs=600x250&cht=lxy&chco='+\ ','.join(COLORS[:len(userids)]) + '&chd=t:' chart_data = [] for chart in charts: chart_data.append(','.join(chart[0]) + '|' + ','.join(chart[1])) chart_url += '|'.join(chart_data) + '&chdl=' + '|'.join(usernames) template_file = os.path.join(os.path.dirname(__file__), 'templates/compare.html') template_values = { 'greeting': get_greeting(), 'is_admin': is_admin(), 'is_registered': is_registered(), 'chart_url': chart_url } self.response.out.write(Template(filename=template_file,lookup=mylookup).render_unicode(**template_values))