CSC/ECE 517 Fall 2016 E1633. Refactor different question types from quiz feature

From Expertiza_Wiki
Jump to navigation Jump to search

Introduction

About Expertiza

Expertiza is an online system that is used by students to view/submit assignments and review others' work. Expertiza also provides tools to visualize the scores and gauge the improvements made during the course semester. It also facilitates and monitors team projects. It is targeted at educational and non-profit organizations. The project is funded by the National Software Foundation (NSF), NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication. Expertiza is an open-source project with the source code available as a public repository on GitHub. It is developed using Ruby on Rails and is increasingly becoming robust thanks to the innumerable bugs being fixed by the community. The project has a micro-blog on SourceForge where the developer community report bugs and document updates.

Motivation

This project provides an opportunity for students with likeminded interests to collaborate and work as a team to enhance the existing source code of expertiza so as to improve functionality, remove bugs and implement altogether new features.


Task

What it does

Currently, Expertiza has a quizzing feature which allow student authors to create quiz questions and “test" the peer-reviewers. The idea behind this is, if a reviewer can answer the quiz questions which were created by the author correctly, we assume that the reviewer has read the artifact carefully enough and thereby we trust the peer-review. Quiz questionnaire is one sub type of questionnaire, so it should follow the design of other type of questionnaires.

Problems with it

The number one reason that we plan to refactor the quizzing feature is that its design is not consistent with the current questions and questionnaires. Repetition of source code can be observed in quite a few areas of the system, which can be avoided. The system does not adhere to the Rails principle of Convention over Configuration and Ruby naming conventions are violated in certain segments of the code. There are 4 methods which are “edit”, “view_question_text”, “complete” and “view_completed_question” to implement for student_quiz. We need to focus on these for methods.

What needs to be done:

  • There are 3 different types of questions supported in quizzing feature: multiple choice checkbox, multiple choice radio, true/false.
  • Change the views (creating quizzes, viewing quizzes, filling in quizzes and viewing finished quizzes) to call your new model methods accordingly.


Workflow

The picture below shows our logic of the project.


Methodology

Before the refactoring the "edit","complete","view_completed_question" method is written in some view files such as questionnaires and student_quizzes. But all we have to do is to rewrite it in the three models such as multiple choice checkbox, multiple choice radio, true/false. The code below is our truefalse.rb file. There is three methods in this file. Every method will be called if it is needed instead of a new method written in view.

class TrueFalse < QuizQuestion
  def edit
    quiz_question_choices = QuizQuestionChoice.where(question_id: self.id)
    html = '<tr><td>'
    html += '<textarea cols="100" name="question[' + self.id.to_s + '][txt]" '
    html += 'id="question_' + self.id.to_s + '_txt">' + self.txt + '</textarea>'
    html += '</td></tr>'
    html += '<tr><td>'
    html += '<input type="radio" name="quiz_question_choices[' + self.id.to_s + '][TrueFalse][1][iscorrect]" '
    html += 'id="quiz_question_choices_' + self.id.to_s + '_TrueFalse_1_iscorrect_True" value="True" '
    html += 'checked="checked" ' if quiz_question_choices[0].iscorrect
    html += '/>True'
    html += '</td></tr>'
    html += '<tr><td>'
    html += '<input type="radio" name="quiz_question_choices[' + self.id.to_s + '][TrueFalse][1][iscorrect]" '
    html += 'id="quiz_question_choices_' + self.id.to_s + '_TrueFalse_1_iscorrect_True" value="False" '
    html += 'checked="checked" ' if quiz_question_choices[1].iscorrect
    html += '/>False'
    html += '</td></tr>'
    html.html_safe
  end
  def complete
    quiz_question_choices = QuizQuestionChoice.where(question_id: self.id)
    html = ""
    for i in 0..1
      txt = quiz_question_choices[i].txt
      html += "<input name = " + "\"#{self.id}\" "
      html += "id = " + "\"#{self.id}" + "_" + "#{i + 1}\" "
      html += "value = " + "\"#{quiz_question_choices[i].txt}\" "
      html += "type=\"radio\"/>"
      if i == 0
        html += "True"
      else
        html += "False"
      end
      html += "</br>"
    end
    html
  end
  def view_completed_question(user_answer)
    quiz_question_choices = QuizQuestionChoice.where(question_id: self.id)
    html = ''
    html += 'Correct Answer is: <b>'
    if quiz_question_choices[0].iscorrect
      html+='True</b><br/>'
    else
      html+='False</b><br/>'
    end
    html += 'Your answer is: <b>' + user_answer.first.comments.to_s
    if user_answer.first.answer==1
      html += '<img src="/assets/Check-icon.png"/>'
    else
      html += '<img src="/assets/delete_icon.png"/>'
    end
    html +='</b>'
    html += '<br><br><hr>'
    html.html_safe
  end
end


Testing the User Interface

Since this project involved code refactoring, no new functionality was added. But here are tests for each method to verify they are working correctly.

view_question_text

  • Login as a student.
  • Select a quiz assignment.
  • Select "Your Work"
  • First you will have to create a quiz by clicking on the link "Create Quiz".
  • Select "View quiz".
  • You should see each question, followed by the choices. The correct choice(s) will be in Bold.

edit

  • Login as a student.
  • Select a Quiz Assignment.
  • Select "Your Work"
  • If you haven't created a quiz yet, go ahead and create one by clicking the "Create Quiz" link.
  • Select "Edit quiz".
  • You should see each question, followed by the choices, each in an editable text field. The correct choice(s) will be checked.

complete

  • Login as a student.
  • Select an assignment that has quizzing enabled (e.g. Quiz Assignment).
  • Select "Your Work"
  • If you haven't created a quiz yet, go ahead and create one by clicking the "Create Quiz" link.
  • Select "Take Quizzes".
  • Click 'Begin'.
  • You should see each question, followed by the choices. You can record your answers for each questions and then click 'submit'. Your answers will be saved.

view_completed_question

  • Login as a student.
  • Select an assignment that has quizzing enabled (e.g. Quiz Assignment).
  • Select "Your Work"
  • If you haven't created/taken a quiz yet, go ahead and create one by clicking the "Create Quiz" link and take the quiz.
  • Find a finished quiz and click on 'View'.
  • You should see each question, followed by the choices. The correct choice(s) will be in bold and your recorded answer will be shown.