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)
def _crawl_task(self, contest_id, row, db_session): cells = row.cssselect('td') symbol = cells[0].text_content() title = cells[1].text_content() link_url = cells[1].find('a').get('href') link_match = re.match(r'/tasks/(.+)$', link_url) if link_match: path = link_match.group(1) else: raise RuntimeError('no task link') submit_url = cells[4].find('a').get('href') submit_match = re.match(r'/submit\?task_id=(\d+)$', submit_url) if submit_match: problem_id = int(submit_match.group(1)) else: raise RuntimeError('no submit link') problem = Problem(problem_id=problem_id, title=title) task = Task(contest_id=contest_id, problem_id=problem_id, symbol=symbol, path=path) logger.info(problem) logger.info(task) db_session.add(problem) db_session.add(task)
def _formulate_problem(a, b, p, q): # Find midpoint deltas = b.coords - a.coords c = a.coords + deltas / 2.0 # Get perpendicular slope v = array([deltas[1], -deltas[0]]) v /= norm(v) s = Slope(v) return Problem(c, s, a, b, p, q)
from view import SudokuScreen from view.widget import * Config.set('graphics', 'width', '320') Config.set('graphics', 'height', '480') Builder.load_file('kv/sudoku.kv') LabelBase.register( 'SeoulNamsan', fn_regular='static/font/SeoulNamsanM.ttf', fn_bold='static/font/SeoulNamsanB.ttf') problem = Problem.loads( "800523910162489075350170420425008009690000" "057700600234037062041540317692016954003", "87452391616248937535917642842573816969324185" "7781695234937862541548317692216954783", 9) board = Board(problem) sm = ScreenManager() sm.switch_to(SudokuScreen(board_model=board)) class SudokuApp(App): def build(self): return sm if __name__ == '__main__': SudokuApp().run()
from model import Board, Problem from view import SudokuScreen from view.widget import * Config.set('graphics', 'width', '320') Config.set('graphics', 'height', '480') Builder.load_file('kv/sudoku.kv') LabelBase.register('SeoulNamsan', fn_regular='static/font/SeoulNamsanM.ttf', fn_bold='static/font/SeoulNamsanB.ttf') problem = Problem.loads( "800523910162489075350170420425008009690000" "057700600234037062041540317692016954003", "87452391616248937535917642842573816969324185" "7781695234937862541548317692216954783", 9) board = Board(problem) sm = ScreenManager() sm.switch_to(SudokuScreen(board_model=board)) class SudokuApp(App): def build(self): return sm if __name__ == '__main__': SudokuApp().run()