def output(test_data, test_result): test_pid = test_data['source'] db = database.get_connection() with closing(db) as con: all_tasks = Task.loadAll(con) all_problems = Problem.loadAll(con) pid_to_task = { task.problem_id: task for task in all_tasks if task.contest_id.startswith('arc') or task.contest_id.startswith('abc') } pid_to_title = {prob.id: prob.title for prob in all_problems} results = sorted([(pid_to_task[pid], pid_to_title[pid], pid, guessed_score) for pid, guessed_score in zip(test_pid, test_result)]) # CSV output # print('contest', 'symbol', 'title', 'estimated_score', sep=',') # for task, title, pid, guessed_score in results: # print(task.contest_id, task.symbol, '"' + title + '"', int(round(guessed_score / 100)), sep=',') # HTML output env = Environment(loader=FileSystemLoader('./', encoding='utf8')) template = env.get_template('template.html') html = template.render(results=results) print(html)