inline HTML, result viewer
This commit is contained in:
72
manager.py
72
manager.py
@@ -135,77 +135,17 @@ 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)
|
||||
cur = db.cursor()
|
||||
questions, answers = get_summary(db, options.name)
|
||||
tokens = get_token_counts(db, options.name)
|
||||
|
||||
cur.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name=?;",
|
||||
( options.name, )
|
||||
)
|
||||
matching_tables = cur.fetchall()
|
||||
if len(matching_tables) == 0:
|
||||
return "No votes yet"
|
||||
|
||||
token_table = get_voter_table_name(options.name)
|
||||
cur.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name=?;",
|
||||
( token_table, )
|
||||
)
|
||||
matching_tables = cur.fetchall()
|
||||
if len(matching_tables) == 0:
|
||||
used_tokens = 0
|
||||
unused_tokens = 0
|
||||
if options.tsv:
|
||||
out = summary_tsv(questions, answers, tokens)
|
||||
else:
|
||||
cur.execute(
|
||||
"SELECT count(*) FROM `%s` WHERE answered = 'true'"%(
|
||||
token_table,
|
||||
)
|
||||
)
|
||||
used_tokens = cur.fetchall()[0][0]
|
||||
cur.execute(
|
||||
"SELECT count(*) FROM `%s` WHERE answered = 'false'"%(
|
||||
token_table,
|
||||
)
|
||||
)
|
||||
unused_tokens = cur.fetchall()[0][0]
|
||||
tokens = {
|
||||
'unused': unused_tokens,
|
||||
'used': used_tokens,
|
||||
'total': used_tokens + unused_tokens
|
||||
}
|
||||
|
||||
questions = []
|
||||
answers = {}
|
||||
cur.execute(
|
||||
"SELECT question, answer, answer_type FROM `%s`"%(
|
||||
options.name,
|
||||
)
|
||||
)
|
||||
for row in cur:
|
||||
if row[0] not in answers.keys():
|
||||
questions.append(row[0])
|
||||
answers[row[0]] = {
|
||||
'answers': {},
|
||||
'answer_type': row[2]
|
||||
}
|
||||
|
||||
if row[1] not in answers[row[0]]['answers'].keys():
|
||||
answers[row[0]]['answers'][row[1]] = 0
|
||||
answers[row[0]]['answers'][row[1]] += 1
|
||||
|
||||
try:
|
||||
if options.tsv:
|
||||
return summary_tsv(questions, answers, tokens)
|
||||
else:
|
||||
return summary_list(questions, answers, tokens)
|
||||
except AttributeError:
|
||||
return summary_list(questions, answers, tokens)
|
||||
out = summary_list(questions, answers, tokens)
|
||||
print(out)
|
||||
|
||||
def summary_list(questions, answers, tokens):
|
||||
s = """# Tokens for this question set:
|
||||
|
||||
Reference in New Issue
Block a user