Esempio n. 1
0
def _create_responses(question_parts, submission, is_single):
    """
  Creates `Response` models for this `submission` and sets
  the correct answer pages for it
  """
    for question_part in question_parts:
        answer_pages = ''

        for page in question_part.pages.split(','):
            page = int(page)

            if is_single:
                if page < submission.page_count:
                    answer_pages = answer_pages + str(page) + ','
                elif answer_pages == '':
                    answer_pages = str(submission.page_count) + ','
            else:
                # When the PDF of the exam was uploaded, we assumed it had no blank
                # pages whereas there were blank pages during upload. Hence, the 2x - 1
                if 2 * page - 1 <= submission.page_count:
                    answer_pages = answer_pages + str(2 * page - 1) + ','
                elif answer_pages == '':
                    # If the page is out of bounds, and we have no pages associated
                    # with this question part, the last page is our best guess.
                    answer_pages = str(submission.page_count) + ','
                    break

        # remove the trailing comma (,) from the end of answer_pages
        answer_pages = answer_pages[:-1]
        response = models.Response(question_part=question_part,
                                   submission=submission,
                                   pages=answer_pages)
        response.save()
Esempio n. 2
0
        def create_course_user_exam_answer(c, exam, num_pages, question_parts,
                                           rubric, course_user):
            pdf = open('scorystapp/static/development/exam.pdf', 'r')
            exam_answer = models.Submission(exam=exam,
                                            course_user=c,
                                            page_count=num_pages)
            exam_answer.pdf.save('new', File(pdf))
            exam_answer.save()
            pdf.close()

            for i in range(num_pages):
                f = open(
                    'scorystapp/static/development/img' + str(i) + '.jpeg',
                    'r')
                exam_answer_page = models.SubmissionPage(
                    exam_answer=exam_answer, page_number=i + 1)
                exam_answer_page.page_jpeg.save('new', File(f))
                exam_answer_page.save()
                f.close()

            for i in range(num_pages):
                response = models.Response(exam_answer=exam_answer,
                                           question_part=question_parts[i],
                                           pages=i + 1)
                response.save()

            response.grader = course_user
            response.rubrics.add(rubric)
            response.save()
Esempio n. 3
0
def _create_empty_responses(submission):
    """ Creates empty responses for the given submission. """
    question_parts = submission.assessment.questionpart_set.all()
    for qp in question_parts:
        response = models.Response(submission=submission,
                                   question_part=qp,
                                   pages=None,
                                   grader_comments=None,
                                   grader=None,
                                   custom_points=None)
        response.save()
Esempio n. 4
0
        def create_unmapped_exam_answers(exam, folder, name_prefix,
                                         num_pages_per_exam, num_students):
            question_parts = models.QuestionPart.objects.filter(exam=exam)

            for cur_student in range(num_students):
                exam_answer = models.Submission(course_user=None,
                                                exam=exam,
                                                page_count=num_pages_per_exam)
                temp_pdf_name = '%s/%s%d.pdf' % (folder, name_prefix,
                                                 cur_student)

                temp_pdf = file(temp_pdf_name, 'rb')
                exam_answer.pdf.save('new', files.File(temp_pdf))
                exam_answer.save()
                os.remove(temp_pdf_name)

                for cur_page in range(num_pages_per_exam):
                    exam_answer_page = models.SubmissionPage(
                        exam_answer=exam_answer, page_number=cur_page + 1)

                    cur_page_num = cur_student * num_pages_per_exam + cur_page
                    temp_jpeg_name = '%s/%s%d.jpeg' % (folder, name_prefix,
                                                       cur_page_num)
                    temp_jpeg = file(temp_jpeg_name, 'rb')
                    exam_answer_page.page_jpeg.save('new',
                                                    files.File(temp_jpeg))

                    # Doing this because this script is a worst case scenario and we're probably
                    # short on time so don't want another upload.
                    exam_answer_page.page_jpeg_large = exam_answer_page.page_jpeg

                    exam_answer_page.save()
                    temp_jpeg.close()

                for question_part in question_parts:
                    answer_pages = ''
                    for page in question_part.pages.split(','):
                        page = int(page)
                        answer_pages = answer_pages + str(2 * page - 1) + ','
                    # Remove the trailing comma (,) from the end of answer_pages
                    answer_pages = answer_pages[:-1]
                    response = models.Response(question_part=question_part,
                                               exam_answer=exam_answer,
                                               pages=answer_pages)
                    response.save()

                for cur_page in range(num_pages_per_exam):
                    cur_page_num = cur_student * num_pages_per_exam + cur_page
                    temp_jpeg_name = '%s/%s%d.jpeg' % (folder, name_prefix,
                                                       cur_page_num)
Esempio n. 5
0
  def handle(self, *args, **options):
    # We are in debug mode, so the database can be deleted
    if options['delete'] and settings.DEBUG:
      os.system('python manage.py reset_db --noinput')
      os.system('python manage.py syncdb --all --noinput')
    elif options['delete']:
      responsibility = 'Catherine takes full responsibility for my mistakes'
      self.stdout.write('You are going to delete everything. I mean everything. FROM PRODUCTION.' +
        ' Chances are you will regret this. If you still want to go ahead please type:\n' +
        responsibility)
      text = raw_input('Enter in correct case: ')
      if text == responsibility:
        os.system('python manage.py reset_db --noinput')
        os.system('python manage.py syncdb --all --noinput')
      else:
        self.stdout.write('Incorrect text. Not deleting anything.')
        return

    superuser_data = json.load(open('scorystapp/fixtures/demo/json/superuser.json'))
    superuser = None
    if models.User.objects.filter(email=superuser_data['email']).count():
      superuser = models.User.objects.filter(email=superuser_data['email'])[0]
      self.stdout.write('Super user from superuser.json already exists. Not recreating.')
    else:
      superuser = get_user_model().objects.create_superuser(superuser_data['email'],
        superuser_data['first_name'], superuser_data['last_name'],
        superuser_data['id'], superuser_data['password'])

    class_name = options['classname'] if options['classname'] else 'CS221'
    user = get_user_model().objects.create_user('*****@*****.**' % class_name.lower(),
      'Demo', 'User','12345678', 'demo')

    course = models.Course(name=class_name, term=0)
    course.save()

    # Make the newly created user the instructor for this course
    course_user = models.CourseUser(user=user, course=course, privilege=models.CourseUser.INSTRUCTOR)
    course_user.save()

    # Make the super user an instructor as well
    course_user_super = models.CourseUser(user=superuser, course=course, privilege=models.CourseUser.INSTRUCTOR)
    course_user_super.save()

    questions = json.load(open('scorystapp/fixtures/demo/json/questions.json'))

    users = []
    course_users = []

    user_first_names = sorted(['John', 'Cynthia', 'Arushi', 'Chenyuan',
      'Jose', 'Brett', 'Crystal', 'Jenny', 'Andy',
      'Ben', 'George', 'Sheila', 'Stephanie', 'Kunal',
      'Alp', 'Keith', 'Daryl', 'Neeraj', 'Eileen',
      'Ahmed', 'Keegan', 'Adam', 'Reid', 'Sarah'])

    user_last_names = ['Holmstead', 'Boyle', 'Goel', 'Wong',
      'Sharma', 'White', 'Whittaker', 'Hong', 'Moeur',
      'Turk', 'Wyngar', 'Wong', 'Seth', 'Nguyen',
      'Bourabee', 'Go', 'Jensen', 'Johnson', 'Lockheart']

    # TODO: Not 7
    num_users = 14
    for i in range(num_users):
      email = 'fake_email' + str(i) + '@scoryst.com'

      if models.User.objects.filter(email=email).count():
        user2 = models.User.objects.get(email=email)
      else:
        user2 = get_user_model().objects.create_user(email, user_first_names[i],
          user_last_names[i], '0' + str(5715000 + random.randint(1001,9999)), 'demo')
        user2.save()

      course_user2 = models.CourseUser(user=user2, course=course, privilege=0)
      course_user2.save()
      users.append(user2)
      course_users.append(course_user2)

    num_pages = 6
    pdf = open('scorystapp/fixtures/demo/midterm.pdf', 'r')
    exam = models.Exam(name='Midterm Exam', course=course, page_count=num_pages)
    exam.exam_pdf.save('new', File(pdf))
    solutions_pdf = open('scorystapp/fixtures/demo/midterm_solution.pdf', 'r')
    exam.solutions_pdf.save('new', File(solutions_pdf))
    exam.save()

    for i in range(num_pages):
      f = open('scorystapp/fixtures/demo/midterm' + str(i) + '.jpeg', 'r')
      exam_page = models.ExamPage(exam=exam, page_number=i+1)
      exam_page.page_jpeg.save('new', File(f))
      exam_page.save()
      f.close()

    question_parts = []

    for question_part_data in questions:
      question_part = models.QuestionPart(exam=exam, question_number=question_part_data['question'],
        part_number=question_part_data['part'], max_points=question_part_data['max_points'],
        pages=question_part_data['pages'])
      question_part.save()
      question_parts.append(question_part)

      rubric = models.Rubric(question_part=question_part, description='Correct answer', points=0)
      rubric.save()

      # rubric2 = models.Rubric(question_part=question_part, description='Incorrect answer', points=question_part_data['max_points'])
      # rubric2.save()

      for rubric in question_part_data['rubrics']:
        rubric3 = models.Rubric(question_part=question_part,
            description=rubric['description'], points=rubric['points'])
        rubric3.save()

    for i in range(num_users):
      name = users[i].first_name.lower()

      pdf = open('scorystapp/fixtures/demo/%s.pdf' % name, 'r')
      user_question_data = json.load(open('scorystapp/fixtures/demo/json/%s.json' % name, 'r'))

      num_pages = user_question_data[0]['num_pages']

      exam_answer = models.Submission(exam=exam, course_user=course_users[i],
        page_count=num_pages)
      exam_answer.pdf.save('new', File(pdf))
      exam_answer.save()
      pdf.close()


      for j in range(num_pages):
        f = open('scorystapp/fixtures/demo/' + name + str(j) + '.jpeg', 'r')

        exam_answer_page = models.SubmissionPage(exam_answer=exam_answer, page_number=j+1)
        exam_answer_page.page_jpeg.save('new', File(f))
        exam_answer_page.save()

        f.close()

      for j in range(len(question_parts)):
        response = models.Response(exam_answer=exam_answer,
          question_part=question_parts[j], pages=user_question_data[j]['pages'])
        response.save()

    self.stdout.write('Successfully initialized database')
Esempio n. 6
0
    def handle(self, *args, **options):
        os.system('python manage.py reset_db --noinput')
        os.system('python manage.py syncdb --noinput')

        superuser_data = json.load(
            open('scorystapp/fixtures/development/superuser.json'))
        get_user_model().objects.create_superuser(superuser_data['email'],
                                                  superuser_data['first_name'],
                                                  superuser_data['last_name'],
                                                  superuser_data['id'],
                                                  superuser_data['password'])

        rubrics_data = json.load(
            open('scorystapp/fixtures/development/rubrics.json'))

        course = models.Course(name='CS144', term=0)
        course.save()

        # Make the superuser the Instructor for this course
        user = models.User.objects.get(pk=1)
        course_user = models.CourseUser(user=user, course=course, privilege=2)
        course_user.save()

        users = []
        course_users = []
        num_rubrics = 5

        user_first_names = sorted([
            'John', 'Cynthia', 'Albert', 'Arushi', 'Chenyuan', 'Jose', 'Brett',
            'Crystal', 'Jenny', 'Andy', 'Benjamin', 'George', 'Sheila',
            'Stephanie', 'Kunal', 'Alp', 'Keith', 'Daryl', 'Neeraj', 'Eileen',
            'Ahmed', 'Keegan', 'Adam', 'Reid', 'Sarah'
        ])

        user_last_names = [
            'Holmstead', 'Boyle', 'Wu', 'Goel', 'Wong', 'Garcia', 'White',
            'Whittaker', 'Hong', 'Moeur', 'Turk', 'Wyngar', 'Wong', 'Seth',
            'Nguyen', 'Bourabee', 'Go', 'Jensen', 'Johnson', 'Lockheart'
        ]

        for i in range(len(user_last_names)):
            email = 'fake_email' + str(i) + '@gmail.com'
            user2 = models.User(email=email,
                                first_name=user_first_names[i],
                                last_name=user_last_names[i],
                                student_id='0' +
                                str(5715000 + random.randint(1001, 9999)),
                                is_signed_up=True)
            user2.save()
            course_user2 = models.CourseUser(user=user2,
                                             course=course,
                                             privilege=0)
            course_user2.save()
            users.append(user2)
            course_users.append(course_user2)

        num_pages = 8
        pdf = open('scorystapp/fixtures/demo/kv.pdf', 'r')
        exam = models.Exam(name='Midterm Exam',
                           course=course,
                           page_count=num_pages)
        exam.exam_pdf.save('new', File(pdf))
        solutions_pdf = open('scorystapp/fixtures/demo/solutions.pdf', 'r')
        exam.solutions_pdf.save('new', File(solutions_pdf))
        exam.save()

        for i in range(num_pages):
            f = open('scorystapp/fixtures/demo/kv' + str(i) + '.jpeg', 'r')
            exam_page = models.ExamPage(exam=exam, page_number=i + 1)
            exam_page.page_jpeg.save('new', File(f))
            exam_page.save()
            f.close()

        question_parts = []

        # i is for questions, j is for parts
        # Requires: i*j = num_pages
        for i in range(num_pages / 2):
            for j in range(2):
                question_part = models.QuestionPart(exam=exam,
                                                    question_number=i + 1,
                                                    part_number=j + 1,
                                                    max_points=10,
                                                    pages=2 * i + j + 1)
                question_part.save()
                question_parts.append(question_part)

                rubric = models.Rubric(question_part=question_part,
                                       description='Correct answer',
                                       points=0)
                rubric.save()

                rubric2 = models.Rubric(question_part=question_part,
                                        description='Incorrect answer',
                                        points=10)
                rubric2.save()

                random.shuffle(rubrics_data)

                for k in range(num_rubrics - 2):
                    rubric3 = models.Rubric(
                        question_part=question_part,
                        description=rubrics_data[k]['description'],
                        points=rubrics_data[k]['points'])
                    rubric3.save()

        course_user_a = course_users[0]
        course_user_b = course_users[1]

        # Exam for first course user - uses karanveer's exam
        pdf = open('scorystapp/fixtures/demo/kv.pdf', 'r')
        exam_answer = models.Submission(exam=exam,
                                        course_user=course_user_a,
                                        page_count=num_pages)
        exam_answer.pdf.save('new', File(pdf))
        exam_answer.save()
        pdf.close()

        for i in range(num_pages):
            f = open('scorystapp/fixtures/demo/kv' + str(i) + '.jpeg', 'r')
            exam_answer_page = models.SubmissionPage(exam_answer=exam_answer,
                                                     page_number=i + 1)
            exam_answer_page.page_jpeg.save('new', File(f))
            exam_answer_page.save()
            f.close()

        for i in range(num_pages):
            response = models.Response(exam_answer=exam_answer,
                                       question_part=question_parts[i],
                                       pages=i + 1)
            response.save()

        # Exam for second course user - uses squishy's exam
        pdf = open('scorystapp/fixtures/demo/cglu.pdf', 'r')
        exam_answer = models.Submission(exam=exam,
                                        course_user=course_user_b,
                                        page_count=num_pages)
        exam_answer.pdf.save('new', File(pdf))
        exam_answer.save()
        pdf.close()

        for i in range(num_pages):
            f = open('scorystapp/fixtures/demo/cglu' + str(i) + '.jpeg', 'r')
            exam_answer_page = models.SubmissionPage(exam_answer=exam_answer,
                                                     page_number=i + 1)
            exam_answer_page.page_jpeg.save('new', File(f))
            exam_answer_page.save()
            f.close()

        for i in range(num_pages):
            response = models.Response(exam_answer=exam_answer,
                                       question_part=question_parts[i],
                                       pages=i + 1)
            response.save()

        self.stdout.write('Successfully initialized database')

        # Create another exam that has no students mapped so can be editted
        num_pages = 5
        exam = models.Exam(name='Final Exam',
                           course=course,
                           page_count=num_pages)
        pdf = open('scorystapp/fixtures/demo/cs221.pdf', 'r')
        exam.exam_pdf.save('new', File(pdf))
        exam.save()

        for i in range(num_pages):
            f = open('scorystapp/fixtures/demo/cs221' + str(i) + '.jpeg', 'r')
            exam_page = models.ExamPage(exam=exam, page_number=i + 1)
            exam_page.page_jpeg.save('new', File(f))
            exam_page.save()
            f.close()

        question_parts = []

        # i is for questions, j is for parts
        # Requires: i*j = num_pages
        for i in range(2):
            for j in range(2):
                question_part = models.QuestionPart(exam=exam,
                                                    question_number=i + 1,
                                                    part_number=j + 1,
                                                    max_points=10,
                                                    pages=2 * i + j + 2)
                question_part.save()

                rubric = models.Rubric(question_part=question_part,
                                       description='Correct answer',
                                       points=0)
                rubric.save()

                rubric2 = models.Rubric(question_part=question_part,
                                        description='Incorrect answer',
                                        points=10)
                rubric2.save()

                random.shuffle(rubrics_data)

                for k in range(num_rubrics - 2):
                    rubric3 = models.Rubric(
                        question_part=question_part,
                        description=rubrics_data[k]['description'],
                        points=rubrics_data[k]['points'])
                    rubric3.save()