示例#1
0
def _create_solution(solution_code, user_id, code_lang, problem_id):
    """
        Creates instance of Solution model for storing solution code

        Args:
            solution_code (str) :  complete source code submitted by user
            user_id (str) : registration number of user of submitted the code
            code_lang (str) : extension of code language file
            problem_id (int) : id of problem for which solution is submitted

        Note: Solution Model also contains more attributes which will be initialized
        with some default values.
    """
    solution = Solution(solution_code=solution_code,
                        lang_ext=code_lang,
                        time_of_exec=0,
                        timestamp=datetime.datetime.now(),
                        result_code='SE',
                        user_id=user_id,
                        problem_id=problem_id)
    db_session = get_db_session()
    problem = db_session.query(Problem).filter_by(id=problem_id).one()
    problem.attempts += 1
    execution_time = _generate_output_file(solution, problem)
    result = solution.result_code
    if result == ResultCodes.CORRECT_ANSWER:
        problem.successful_submission += 1
    insert_to_db(db_session, solution, dont_close_session=True)
    insert_to_db(db_session, problem)
    return result, execution_time
示例#2
0
def _get_solution_details(solution_id):
    """
        Retrieves solution base on their Id

        Args:
            solution_id(int) : id of the solution to receive
        Returns:
            solution(Solution): solution row obtained from the database
    """
    db_session = get_db_session(create_new_instance=True)
    solution = db_session.query(Solution).filter_by(id=solution_id).one()
    db_session.close()
    return solution