Exemplo n.º 1
0
def evaluate_turtle(request, submissionID, testcaseID, program_type):
    '''
    for graphics
    '''
    submission = get_object_or_404(Upload, pk=submissionID)
    assignment = submission.assignment

    # Checking if the user sending the request is either the owner of the submission or the assignment creator
    # (the only people authorized to evaluate).
    is_moderator = isCourseModerator(assignment.course, request.user)
    if not (request.user == submission.owner or is_moderator):
        raise PermissionDenied

    # Evaluating the submission.
    # global lock
    # lock.acquire()
    current_dir = os.getcwd()
    try:
        # remove below return if request is not ajax "work around"
        try:
            x = Evaluate(submission).getResults_turtle(
                request, testcaseID, program_type=program_type)
            return HttpResponse(x, content_type="application/json")
        except Exception as e:
            print e
    except Exception as e:
        print e
    finally:
        os.chdir(current_dir)
    return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
Exemplo n.º 2
0
def showTurtleTestcases(request, submissionID):
    '''this function is to display all testcases in turtle assignment'''
    submission = get_object_or_404(Upload, pk=submissionID)
    assignment = submission.assignment
    course = assignment.course
    # assignment = get_object_or_404(Assignment, pk=assignment_id)
    is_moderator = isCourseModerator(course, request.user)
    programs = ProgramModel.objects.filter(assignment=submission.assignment,
                                           program_type="Practice")
    if is_moderator:
        programs = ProgramModel.objects.filter(
            assignment=submission.assignment)
    testcases = []
    testcasesList = []
    for program in programs:
        testcasesList = Testcase.objects.filter(program=program)
        testcases.append([program, testcasesList])

    return render_to_response('evaluate/showTurtleTestcase.html', {
        'testcases': testcases,
        'assignment': assignment,
        'course': course,
        'submission': submission,
        'is_moderator': is_moderator
    },
                              context_instance=RequestContext(request))
Exemplo n.º 3
0
def showResult(request, submissionID):
    '''
    Function to show results for a submission. This is different from the above functions
    in the sense that the other functions are called to evaluate
    a subsmission while this function is called to retrieve the results for a submission (already evaluated).
    '''
    # Retrieve the submission object and then retrieve the results of that submission using the Results class.
    submission = get_object_or_404(Upload, pk=submissionID)
    try:
        assignment_result = AssignmentResults.objects.filter(
            submission=submission)
    except AssignmentResults.DoesNotExist:
        return HttpResponse("Assignment is not yet evaluated")
    if not assignment_result and not submission.assignment.graphics_program:
        return HttpResponse("Assignment is not yet evaluated")
    results = Results(submission, program_type="Evaluate")
    course = submission.assignment.course
    is_moderator = isCourseModerator(course, request.user)
    # If any results were found then render them.
    is_due = (timezone.now() >= submission.assignment.deadline)
    if results:
        manual_marks = submission.manualmark
        total_marks = results.marks + manual_marks
        assignment = submission.assignment
        is_student = True if (request.user == submission.owner) else False
        is_moderator = isCourseModerator(assignment.course, request.user)
        is_due = (assignment.deadline <= timezone.now())
        return render_to_response('evaluate/result_table.html', {
            'submission': submission,
            'assignment': assignment,
            'error_msg': error_msg,
            'results': results,
            'error_code': error_codes,
            'is_student': is_student,
            'is_due': is_due,
            'is_moderator': is_moderator,
            'manual_marks': manual_marks,
            'total_marks': total_marks
        },
                                  context_instance=RequestContext(request))
    return None
Exemplo n.º 4
0
def evaluateAssignment(request, submissionID):
    '''
    Function to evaluate an assignment submission. Called by either the student who
    submitted the solution or the instructor.
    Takes as input the submission ID and calls evaluate() function above appropriately.
    Compile student's submission run all test cases and display results on html page.
    '''
    submission = get_object_or_404(Upload, pk=submissionID)
    assignment = submission.assignment

    # Checking if the user sending the request is either the owner of the submission or the assignment creator
    # (the only people authorized to evaluate).
    is_moderator = isCourseModerator(assignment.course, request.user)
    if not (request.user == submission.owner or is_moderator):
        raise PermissionDenied

    if submission.to_be_evaluated:
        evaluate_assignment.delay(submissionID, "Evaluate")
        i = app.control.inspect()
        data = i.stats()
        if data is not None:
            node_name = list(data)[0]
            queue_position = len(i.reserved().get(node_name))
        else:
            queue_position = "Unknown"
        return render_to_response('evaluate/evaluate_ajax.html', {
            'submissionID': submissionID,
            'assignment': assignment,
            'position': queue_position,
            'path': request.get_host()
        },
                                  context_instance=RequestContext(request))
    is_student = True if (request.user == submission.owner) else False
    is_due = (assignment.deadline <= timezone.now())

    try:
        results = Results(submission, program_type="Evaluate")
    except Results.DoesNotExist:
        raise Http404("Results not created yet")

    return render_to_response('evaluate/results.html', {
        'submission': submission,
        'assignment': assignment,
        'results': results,
        'error_code': error_codes,
        'is_student': is_student,
        'is_due': is_due,
        'error_msg': error_msg,
        'is_moderator': is_moderator
    },
                              context_instance=RequestContext(request))
Exemplo n.º 5
0
def final_results(request, programType, submissionID):
    '''
    final results
    '''
    submission = get_object_or_404(Upload, pk=submissionID)
    assignment = submission.assignment

    # Checking if the user sending the request is either the owner of the submission or
    # the assignment creator (the only people authorized to evaluate).
    is_moderator = isCourseModerator(assignment.course, request.user)
    if not (request.user == submission.owner or is_moderator):
        raise PermissionDenied

    # Checking if the user is a student. Checking if the assignment is past its due date.
    is_student = True if (request.user == submission.owner) else False
    is_due = (assignment.deadline <= timezone.now())

    if programType == "practice":
        try:
            results = Results(submission, program_type="Practice")
        except Results.DoesNotExist:
            raise Http404("Results not created yet")
        return render_to_response('evaluate/practice_results.html', {
            'submission': submission,
            'assignment': assignment,
            'results': results,
            'error_code': error_codes,
            'is_student': is_student,
            'is_due': is_due,
            'error_msg': error_msg,
            'is_moderator': is_moderator
        },
                                  context_instance=RequestContext(request))
    try:
        results = Results(submission, program_type="Evaluate")
    except Results.DoesNotExist:
        raise Http404("Results not created yet")
    return render_to_response('evaluate/results.html', {
        'submission': submission,
        'assignment': assignment,
        'results': results,
        'error_code': error_codes,
        'is_student': is_student,
        'is_due': is_due,
        'error_msg': error_msg,
        'is_moderator': is_moderator
    },
                              context_instance=RequestContext(request))
Exemplo n.º 6
0
def edit_testcase_comments(request):
    '''
    comments edit
    '''
    if request.method == "POST":
        pk = request.POST["pk"]
        value = request.POST["value"]
        t = Upload.objects.get(id=pk)
        course = t.assignment.course
        is_moderator = isCourseModerator(course, request.user)
        if is_moderator:
            t.comments = value
            t.save()
            return HttpResponse("true")
        else:
            raise Http404
    else:
        raise Http404
Exemplo n.º 7
0
def edit_testcase_marks(request):
    '''
    edit marks
    '''
    if request.method == "POST":
        pk = request.POST["pk"]
        value = request.POST["value"]
        t = TestcaseResult.objects.get(id=pk)
        course = t.test_case.program.assignment.course
        is_moderator = isCourseModerator(course, request.user)
        if is_moderator:
            t.marks = value
            t.save()
            return HttpResponse("true")
        else:
            raise Http404
    else:
        raise Http404
Exemplo n.º 8
0
def evaluate(request, submissionID, program_type):
    '''
    Function to evaluate a submission (passed as submissionID).
    Takes as input the request, submission ID, the section type (evaluate or practice)
    '''
    submission = get_object_or_404(Upload, pk=submissionID)
    assignment = submission.assignment
    # Checking if the user sending the request is either the owner of the submission or
    # the assignment creator (the only people authorized to evaluate).
    is_moderator = isCourseModerator(assignment.course, request.user)
    if not (request.user == submission.owner or is_moderator):
        raise PermissionDenied

    # Evaluating the submission, asynchronously
    evaluate_object = Evaluate(submission)

    # getResults returns the ids of celery groups(each section testcases are grouped and run asynchronously
    # id will help us to track the status of the evaluation which will be rendered to user
    group_id_list, num_tasks = evaluate_object.getResults(
        program_type=program_type)
    return group_id_list, num_tasks
Exemplo n.º 9
0
def downloadInputfile(request, TestcaseID):
    '''
    std in file download
    '''
    testcase = get_object_or_404(Testcase, pk=TestcaseID)
    program = testcase.program
    assignment = program.assignment
    is_due = (timezone.now() >= assignment.deadline)
    course = assignment.course

    if not isEnrolledInCourse(course, request.user):
        return HttpResponseForbidden("Forbidden 403")

    if not testcase.input_files:
        return HttpResponseNotFound("File not found")

    is_moderator = isCourseModerator(course, request.user)

    if (is_moderator or program.program_type == "Practice" or is_due):
        return file_download(testcase.input_files)

    return HttpResponseForbidden("Forbidden 403")
Exemplo n.º 10
0
def edit_manual_marks(request):
    """
    edit manual marks
    """
    if request.method == "POST":
        pk = request.POST["pk"]
        value = request.POST["value"]
        try:
            value = float(value)
        except ValueError:
            return HttpResponse("true")
        row = Upload.objects.get(id=pk)
        course = row.assignment.course
        is_moderator = isCourseModerator(course, request.user)
        if is_moderator:
            row.manualmark = value
            row.save()
            return HttpResponse("true")
        else:
            raise Http404
    else:
        raise Http404
Exemplo n.º 11
0
def evaluate_turtle_testcase(request, submissionID, testcaseID):
    '''function to evaluate simplecpp graphics testcases'''
    if testcaseID == '00':
        request.META['custom_input'] = 1
        testcaseID = None
        programs = ProgramModel.objects.filter(assignment=get_object_or_404(
            Upload, pk=submissionID).assignment,
                                               program_type="Practice")
        for program in programs:
            for testcase in Testcase.objects.filter(program=program):
                testcaseID = testcase.id
                break
            if testcaseID is not None:
                break
    else:
        if not isCourseModerator(
                get_object_or_404(Upload, pk=submissionID).assignment.course,
                request.user):
            if Testcase.objects.filter(id=testcaseID):
                if Testcase.objects.filter(
                        id=testcaseID)[0].program.program_type == 'Evaluate':
                    return Http404("^v^ Forbidden ^o^")
    return evaluate_turtle(request, submissionID, testcaseID, "Practice")
Exemplo n.º 12
0
def complete_evaluation_details(request, assignmentID):
    '''
    Function to retrieve the results of all submissions and render in a good format.
    Takes as input the assignment ID and gathers the results of all submissions.
    '''
    # Gather the assignment object and then all submissions and section of this assignment.
    assignment = get_object_or_404(Assignment, pk=assignmentID)
    all_assignments = Assignment.objects.filter(
        course=assignment.course).filter(
            trash=False).order_by('-serial_number')
    is_moderator = isCourseModerator(assignment.course, request.user)
    if is_moderator:
        assignments = all_assignments
    else:
        assignments = [
            a for a in all_assignments if a.publish_on <= timezone.now()
        ]
    assignment_results = get_all_results_json(assignmentID)
    if assignment_results:
        table_main_headers = [{"name": "Name", "colspan": 1, "rowspan": 2}]
        table_secondary_headers = []
        for ar in assignment_results[0]["programs"]:
            table_main_headers.append({
                "name": ar["name"],
                "colspan": len(ar["testcases"])
            })
            for tc in ar["testcases"]:
                table_secondary_headers.append({"name": tc["name"]})
        content = []
        for ar in assignment_results:
            row = {"name": ar["name"]}
            row["testcases"] = []
            for pr in ar["programs"]:
                for tc in pr["testcases"]:
                    row["testcases"].append({
                        "marks": tc["marks"],
                        "id": tc["id"]
                    })
            row["submissionId"] = ar["submissionId"]
            row["Manual_marks"] = ar["manualmark"]
            row["remarks"] = ar["remarks"]
            content.append(row)
        table_main_headers.append({
            "name": "Manual marks",
            "colspan": 1,
            "rowspan": 2
        })
        table_main_headers.append({
            "name": "remarks",
            "colspan": 1,
            "rowspan": 2
        })
        return render_to_response("evaluate/students_result_table.html", {
            'assignment': assignment,
            "table_main_headers": table_main_headers,
            "table_secondary_headers": table_secondary_headers,
            "content": content,
            'course': assignment.course,
            'assignments': assignments,
            'date_time': timezone.now(),
            'is_moderator': is_moderator,
            'data': True
        },
                                  context_instance=RequestContext(request))
    return render_to_response("evaluate/students_result_table.html", {
        'assignment': assignment,
        'course': assignment.course,
        'assignments': assignments,
        'date_time': timezone.now(),
        'is_moderator': is_moderator
    },
                              context_instance=RequestContext(request))