open voting, without tokens
This commit is contained in:
44
manager.py
44
manager.py
@@ -135,6 +135,10 @@ def list_question_sets(options):
|
||||
|
||||
|
||||
def summary(options):
|
||||
print(get_summary(options))
|
||||
|
||||
|
||||
def get_summary(options):
|
||||
if not is_key(options.name, options):
|
||||
raise Exception("%s does not exist, or is not a valid question set name"%( options.name, ))
|
||||
db = open_db(options.db)
|
||||
@@ -146,8 +150,8 @@ def summary(options):
|
||||
)
|
||||
matching_tables = cur.fetchall()
|
||||
if len(matching_tables) == 0:
|
||||
print("No votes yet")
|
||||
return
|
||||
return "No votes yet"
|
||||
|
||||
token_table = get_voter_table_name(options.name)
|
||||
cur.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name=?;",
|
||||
@@ -197,21 +201,20 @@ def summary(options):
|
||||
|
||||
try:
|
||||
if options.tsv:
|
||||
summary_tsv(questions, answers, tokens)
|
||||
return summary_tsv(questions, answers, tokens)
|
||||
else:
|
||||
summary_list(questions, answers, tokens)
|
||||
return summary_list(questions, answers, tokens)
|
||||
except AttributeError:
|
||||
summary_list(questions, answers, tokens)
|
||||
return summary_list(questions, answers, tokens)
|
||||
|
||||
def summary_list(questions, answers, tokens):
|
||||
print(
|
||||
"""# Tokens for this question set:
|
||||
# used: {used}, unused: {unused}, total: {total}""".format_map(tokens)
|
||||
)
|
||||
s = """# Tokens for this question set:
|
||||
# used: {used}, unused: {unused}, total: {total}
|
||||
""".format_map(tokens)
|
||||
|
||||
for q,a in zip(questions, answers):
|
||||
sum_answers = sum([answers[q]['answers'][x] for x in answers[q]['answers']])
|
||||
print("\n%s\n# Answers total: %d"%( q, sum_answers, ))
|
||||
s += "\n%s\n# Answers total: %d\n"%( q, sum_answers, )
|
||||
sorted_answers = sorted(
|
||||
[(x, answers[q]['answers'][x]) for x in answers[q]['answers']],
|
||||
key = lambda i: -i[1]
|
||||
@@ -229,33 +232,34 @@ def summary_list(questions, answers, tokens):
|
||||
prefix = "----\n> "
|
||||
postfix = ""
|
||||
|
||||
print("%s%s%s"%(
|
||||
s += "%s%s%s\n"%(
|
||||
prefix,
|
||||
answer[0],
|
||||
postfix
|
||||
))
|
||||
)
|
||||
return s
|
||||
|
||||
|
||||
def summary_tsv(questions, answers, tokens):
|
||||
print(
|
||||
'''Tokens\tUsed\tUnused\tTotal
|
||||
""\t"{used}"\t"{unused}"\t"{total}"'''.format_map(tokens)
|
||||
)
|
||||
print('"Question"\t"Question type"\t"Answer"\t"Count"')
|
||||
s = '''Tokens\tUsed\tUnused\tTotal
|
||||
""\t"{used}"\t"{unused}"\t"{total}"
|
||||
'''.format_map(tokens)
|
||||
s += '"Question"\t"Question type"\t"Answer"\t"Count"\n'
|
||||
good_characters = dict.fromkeys(range(32))
|
||||
for q,a in zip(questions, answers):
|
||||
sum_answers = sum([answers[q]['answers'][x] for x in answers[q]['answers']])
|
||||
print('"%s"\t"%s"\t""\t"%d"'%( q, answers[q]['answer_type'], sum_answers, ))
|
||||
s += '"%s"\t"%s"\t""\t"%d"\n'%( q, answers[q]['answer_type'], sum_answers, )
|
||||
sorted_answers = sorted(
|
||||
[(x, answers[q]['answers'][x]) for x in answers[q]['answers']],
|
||||
key = lambda i: -i[1]
|
||||
)
|
||||
for answer in sorted_answers:
|
||||
|
||||
print('""\t""\t""%s\t"%d"'%(
|
||||
s += '""\t""\t""%s\t"%d"\n'%(
|
||||
answer[0].translate(good_characters),
|
||||
answer[1],
|
||||
))
|
||||
)
|
||||
return s
|
||||
|
||||
|
||||
def clear_votes(options):
|
||||
|
||||
Reference in New Issue
Block a user