コード例 #1
0
ファイル: admin.py プロジェクト: rcoder/vrfy
    def reassess(self, request, queryset):
        for obj in queryset:
            files = []
            for sf in obj.studentproblemfile_set.filter(attempt_num=obj.attempt_num):
                if (
                    sf.required_problem_filename == None or not sf.required_problem_filename.force_rename
                ):  # if it's not renamed, we can use the given name
                    name = str(sf)
                else:  # if it is we have to lookup the required name
                    name = str(sf.required_problem_filename)
                # localfile has username appended to it
                localFile = name + "-" + str(sf.student_problem_solution.student_problem_set.user)
                files.append({"localFile": localFile, "destFile": name})
            jsonlocalFile = "data.json" + "-" + str(sf.student_problem_solution.student_problem_set.user)
            files.append({"localFile": jsonlocalFile, "destFile": "data.json"})

            for f in chain(
                obj.problem.problemsolutionfile_set.all(),
                models.GraderLib.objects.all(),
                [obj.problem.grade_script.name.split("/")[-1]],
            ):
                files.append({"localFile": str(f), "destFile": str(f)})

            jobName = tango.get_jobName(
                obj.problem,
                obj.student_problem_set.problem_set,
                str(sf.student_problem_solution.student_problem_set.user),
            )
            tango.addJob(obj.problem, obj.student_problem_set.problem_set, files, jobName, jobName)
コード例 #2
0
ファイル: admin.py プロジェクト: Gastove/vrfy
    def reassess(self, request, queryset):
        for obj in queryset:
            log.info("REASSESS: {!s}".format(str(obj)))
            files = []
            for sf in obj.studentproblemfile_set.filter(
                    attempt_num=obj.attempt_num):
                # if it's not renamed, we can use the given name
                if sf.required_problem_filename is None or not sf.required_problem_filename.force_rename:
                    name = str(sf)
                else:  # if it is we have to lookup the required name
                    name = str(sf.required_problem_filename)
                # localfile has username appended to it
                localFile = name + "-" + \
                    str(sf.student_problem_solution.student_problem_set.user)
                files.append({'localFile': localFile, 'destFile': name})
            jsonlocalFile = "data.json" + "-" + \
                str(sf.student_problem_solution.student_problem_set.user)
            files.append({'localFile': jsonlocalFile, 'destFile': "data.json"})

            for f in chain(obj.problem.problemsolutionfile_set.all(),
                           models.GraderLib.objects.all(),
                           [obj.problem.grade_script.name.split("/")[-1]]):
                files.append({'localFile': str(f), 'destFile': str(f)})

            jobName = tango.get_jobName(
                obj.problem, obj.get_problemset(), str(
                    sf.student_problem_solution.get_user()))
            r = tango.addJob(
                obj.problem,
                obj.get_problemset(),
                files,
                jobName,
                jobName)
            if r.status_code is not 200:
                return redirect('500.html')
            else:
                # create a new problem result
                response = r.json()
                job_id = response["jobId"]
                obj.job_id = job_id
                prob_result = models.ProblemResult.objects.create(
                    job_id=job_id,
                    attempt_num=obj.attempt_num,
                    sp_sol=obj,
                    sp_set=obj.student_problem_set,
                    user=obj.get_user(),
                    problem=obj.problem,
                    timestamp=obj.submitted)
                obj.save()
                prob_result.save()
                self._update_result(obj)
コード例 #3
0
ファイル: tasks.py プロジェクト: ifjorissen/vrfy
def submit_job_to_tango(self, results, spsol_id, prob_result_id, files, jobName, timeout):
  student_psol = StudentProblemSolution.objects.get(pk=spsol_id)
  ps = student_psol.student_problem_set.problem_set
  problem = student_psol.problem
  tango_callback_url = "http://localhost:8000/notifyURL/student-solution{}/problem-result{}/".format(spsol_id, prob_result_id)
  r = tango.addJob(
                problem,
                ps,
                files,
                jobName,
                jobName,
                timeout=timeout,
                callback_url=tango_callback_url)
  if r.status_code is not 200:
    message = "Failed to submit job"
    self.retry(message=message, countdown=1)
  else:
    response = r.json()
    job_id = response["jobId"]
  return job_id
コード例 #4
0
ファイル: tasks.py プロジェクト: matthewlboyd/vrfy
def submit_job_to_tango(self, results, spsol_id, prob_result_id, files,
                        jobName, timeout):
    student_psol = StudentProblemSolution.objects.get(pk=spsol_id)
    ps = student_psol.student_problem_set.problem_set
    problem = student_psol.problem
    tango_callback_url = "http://localhost:8000/notifyURL/student-solution{}/problem-result{}/".format(
        spsol_id, prob_result_id)
    r = tango.addJob(problem,
                     ps,
                     files,
                     jobName,
                     jobName,
                     timeout=timeout,
                     callback_url=tango_callback_url)
    if r.status_code is not 200:
        message = "Failed to submit job"
        self.retry(message=message, countdown=1)
    else:
        response = r.json()
        job_id = response["jobId"]
    return job_id
コード例 #5
0
ファイル: views.py プロジェクト: rcoder/vrfy
def problem_submit(request, ps_id, p_id):
  if request.method == 'POST':#make sure the user doesn't type this into the address bar
    ps = _get_problem_set(ps_id, request.user.reedie)
    problem = get_object_or_404(Problem, pk=p_id)

    #create / get the student problem set and update the submission time (reflects latest attempt)
    student_ps_sol, sp_set_created = StudentProblemSet.objects.get_or_create(problem_set=ps, user=request.user.reedie, defaults={'submitted': timezone.now()})
    student_ps_sol.save()

    student_psol, sp_sol_created = StudentProblemSolution.objects.get_or_create(problem=problem, student_problem_set=student_ps_sol)
    student_psol.submitted = timezone.now()
    student_psol.attempt_num += 1 
    student_psol.save()

    #create the student result set & problem
    # result_set, prs_created = ProblemResultSet.objects.get_or_create(sp_set = student_ps_sol, user=request.user, problem_set=ps)
    mytimestamp = None
    if not problem.autograde_problem: #if its not being autograded, we should set the timestamp here; if it is, tango will set it
      mytimestamp = timezone.now()
    prob_result = ProblemResult.objects.create(attempt_num=student_psol.attempt_num, sp_sol=student_psol, sp_set=student_ps_sol, user=request.user.reedie, problem=problem, timestamp=mytimestamp)
    
    additional_files = 0
    files = []#for the addJob
    #getting all the submitted files
    for name, f in request.FILES.items():
      print(name, ADDITIONAL_FILE_NAME)
      if ADDITIONAL_FILE_NAME in name:
        required_pf = None
        print(additional_files)
        if additional_files < MAX_ADDITIONAL_FILES:
          additional_files += 1
        else:
          return render(request, '403.html', {'exception': "You can't upload more than " + str(MAX_ADDITIONAL_FILES) + " additional files."}, status=403)
          #raise PermissionDenied()
        
      else:
        required_pf = RequiredProblemFilename.objects.get(problem=problem, file_title=name)

      if required_pf == None or not required_pf.force_rename: 
        name = f.name#if the file should not be renamed, give it the name as it was uploaded
        
        #we also need to check if it has the same name as any of the grader files
        for gfile in chain(problem.problemsolutionfile_set.all(), GraderLib.objects.all(),[problem.grade_script.name.split("/")[-1]]):
          if name == str(gfile):
            return render(request, '403.html', {'exception': name + " is an invalid filename."}, status=403)
            #raise PermissionDenied(name + " is an invalid filename.")
        
      localfile = name + "-"+ request.user.username
      if problem.autograde_problem:
        r = tango.upload(problem, ps, localfile, f.read())
        files.append({"localFile" : localfile, "destFile":name})#for the addJob command

      attempts = student_psol.attempt_num
      new_prob_file = StudentProblemFile.objects.create(required_problem_filename=required_pf, student_problem_solution = student_psol, submitted_file=f, attempt_num = attempts)
      new_prob_file.save()

    if problem.autograde_problem:#these operatons are only required for autograding
      #add grader libraries
      for lib in GraderLib.objects.all():
        name = lib.lib_upload.name.split("/")[-1]
        files.append({"localFile" : name, "destFile": name})

      #getting all the grader files
      grading = problem.grade_script
      name = grading.name.split("/")[-1]
      files.append({"localFile" : name, "destFile": name})

      for psfile in ProblemSolutionFile.objects.filter(problem=problem):
        name = psfile.file_upload.name.split("/")[-1]
        files.append({"localFile" : name, "destFile": name})

      #upload the json data object
      tango_data = json.dumps({"attempts": student_psol.attempt_num, "timedelta": student_psol.is_late()})
      data_name = "data.json" + "-" + request.user.username
      tango.upload(problem, ps, data_name, tango_data)
      files.append({"localFile" : data_name, "destFile": "data.json"})

      #making Tango run the files
      jobName = tango.get_jobName(problem, ps, request.user.username)
      r = tango.addJob(problem, ps, files, jobName, jobName)
      if r.status_code is not 200:
        return redirect('500.html')
      else:
        response = r.json()
        student_psol.job_id = response["jobId"]
        prob_result.job_id = response["jobId"]
        student_psol.save()
        prob_result.save()
    return redirect('course:submit_success', ps_id, p_id)
    
  else:
    raise Http404("Don't do that")