diff options
Diffstat (limited to 'npc.py')
-rwxr-xr-x | npc.py | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -190,6 +190,44 @@ def vote(db): finally: session.close() +@route('/getall') +def getall(db): + html = HTML_HEADER + langs = db.query(Langs) + counts = {} + for lang in langs: + counts[lang.name] = db.query(Votes).filter_by(lang_id=lang.lang_id).count() + total = db.query(Votes).count() + html += '<span class="tasklist voteresult">\n' + html += '<span class="task">\n' + html += '<span class="taskname">{}</span>\n'.format("end result") + chd = 't:' + ','.join([ str(val) for val in counts.values() ]) + chl = '|'.join(counts.keys()) + data = { + 'cht': 'p3', + 'chs': '375x150', + 'chd': chd, + 'chl': chl, + } + urlstring = urllib.parse.urlencode(data) + html += ('<img src="http://chart.apis.google.com/chart?{}" ' + 'alt="pie chart" />\n'.format(urlstring)) + html += '<span class="desc">\n' + cntstr = 'vote' if total == 1 else 'votes' + html += '<p>Total {} {}.</p>\n'.format(total, cntstr) + html += '<ul>\n' + for lang in counts.keys(): + val = counts[lang] + cntstr = 'vote' if val == 1 else 'votes' + html += '<li>{} - {} {} ({}%)</li>\n'.format( + lang, val, cntstr, round(100/total*val)) + html += '</ul>\n' + html += '<span class="taskbottom"><a href="/">Go back</a></span>\n' + html += '</span>\n' # task + html += '</span>\n' # tasklist + html += HTML_FOOTER + return html + @route('/getvotes') def getvotes(db): langs = db.query(Langs) |