CSC/ECE 517 Fall 2015 E1576 Refactoring submitted content (hyperlinks and files): Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 170: Line 170:
<pre>
<pre>
  def participant_params
  def participant_params
- params.require(:participant).permit(:can_submit,:can_review,:user_id,:parent_id,:directory_num,:submitted_at,:permission_granted,:penalty_accumulated,:submitted_hypelinks,:grade,:type,:handle,:time_stamp,:digital_signature,:duty,:can_take_quiz)
- <span style="color:red"> params.require(:participant).permit(:can_submit,:can_review,:user_id,:parent_id,:directory_num,:submitted_at,:permission_granted,:penalty_accumulated,:submitted_hypelinks,:grade,:type,:handle,:time_stamp,:digital_signature,:duty,:can_take_quiz) </span>
<span style="color:green">
+ params.require(:participant).permit(:can_submit,:can_review,:user_id,:parent_id,:submitted_at,:permission_granted,:penalty_accumulated,:grade,:type,:handle,:time_stamp,:digital_signature,:duty,:can_take_quiz)
+ params.require(:participant).permit(:can_submit,:can_review,:user_id,:parent_id,:submitted_at,:permission_granted,:penalty_accumulated,:grade,:type,:handle,:time_stamp,:digital_signature,:duty,:can_take_quiz)
end
end </span>
</pre>
</pre>



Revision as of 00:08, 5 December 2015

Introduction to Expertiza

Expertiza<ref>https://github.com/expertiza/expertiza</ref> is a project developed using Ruby on Rails<ref>http://guides.rubyonrails.org/getting_started.html</ref>. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from GitHub. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large.

Problem Statement

Files involved

  • assignment_participant.rb
  • assignment_team.rb and
  • views related to submitted hyperlinks and files (submitted_content/_hyperlink.html.erb, submitted_content/_submitted_files.html.erb)

What it does

It handles the display, submission, deletion of hyperlinks and files by the teams.

What is wrong with it

The submitted hyperlinks and files are stored in participants table, which means they are associated with individuals instead of team. This is not a good design because in Expertiza, students are always grouped in teams, even when there is only one person in each team (individual assignments). Currently, when a team member wants to see all the submitted hyperlinks of his team, Expertiza needs to load all the submitted hyperlinks from each participant in this team and merge them all before display. Similar overhead happens when a team member wants to delete a submitted hyperlink. Also, the directory_num field needs to be moved from the participants table to the teams table. It signifies the sub-directory which stores all the files submitted by this team. Intuitively it is clear that each team should ideally have only one common copy of directory_num.

What needs to be done

  • Create a new column hyperlinks in the teams table.
  • Write db migration, move all the participants’ submitted hyperlinks from participants table into teams table. Duplicate hyperlinks need to be removed.
  • Write db migration, remove the hyperlinks field from participants table.
  • Rewrite the hyperlink-related methods in both assignment_participant.rb and assignment_team.rb to make sure the new code works with the new db design.
  • Make sure when doing the peer-review, the reviewer can see the submitted content from the reviewees.
  • Make sure when instructor see the peer-review records, they can see the submitted content from the reviewees.
  • Write db migration, move the directory_num field (also the content, of course) to the teams table.
  • Move the set_student_directory_num method from participants_controller to teams_controller, then refactor this method into smaller methods.
    • This method no longer needs to test all the participants.
    • Check if any of them have directory_num. If so, instead, it should just check the directory_num from teams table.
  • Make change to the submitted-file-related code to make it work with the new design.
  • Write test cases to test student-submitted hyperlinks and files.

Problem Description

The main purpose of this project is to improve how submitted hyperlinks are recorded in Expertiza in the current scheme. As of now, the submitted hyperlinks are stored in participants table, which means they are associated with individuals instead of team. This is not a good design because in Expertiza, students are always grouped in teams, even when there is only one person in each team (individual assignments). This results in a lot of redundant data. Currently, when a team member wants to see all the submitted hyperlinks of his team, Expertiza needs to load all the submitted hyperlinks from each participant in this team and merge them all before display. When a team member wants to remove one hyperlink, Expertiza needs to loop over all the participants, which makes the code complicated and results in unnecessary computations. Another aspect of this project requires moving the field directory_num from the participants table to the teams table. The directory_num field signifies the sub-directory which stores all the files submitted by this team. Intuitively it is clear that each team should ideally have only one common copy of directory_num. In the current design, since this field is in the participants table, we are forced to guarantee that all the team members have the same directory_num, which results in redundant code.

Scope

This project can be divided into four major work items:

  1. Moving the hyperlinks field from the participants table to the teams table. After this change, relevant changes are needed in the code to support this database change.
  2. Moving the directory_num field from the participants table to the teams table. After this change, relevant changes are needed in the code to support this database change.
  3. Moving the set_student_directory_num method from the participants_controller to the teams_controller. It just needs to check directory_num from the team table.
  4. Write test cases to verify student-submitted hyperlinks and files.

Implementation

Expertiza files that will be modified for each work item along with the description:

Work Item # Files to be modified Description
1 assignment_participant.rb
assignment_team.rb
db:participants table
db:teams table
- Create a new column hyperlinks in teams table
- Write db migration, move all the participants’ submitted hyperlinks from participants table into teams table. All duplicated hyperlinks have to be removed.
- Write db migration, remove the hyperlinks field from participants table.
- hyperlink-related methods in both assignment_participant.rb and assignment_team.rb have to be rewritten to make sure the new code works with the new db design.
2 participants_controller.rb
teams_controller.rb
db:participants table
db:teams table
- Write db migration, move the directory_num field (also the content) to teams table.
- Move the set_student_directory_num from participant_controller to team_controller, then refactor this method into smaller methods.
- This method no longer needs to test all the participants and see if any of them have directory_num, instead, it just check the directory_num from teams table.
- Make change to the submitted-file-related code to make sure it works with the new design.
3 New files to be added - Write test cases to test student-submitted hyperlinks and files.

Design

Consider a simple use case where we need to retrieve the submitted hyperlinks and files corresponding to team_id, say, 23841. Since there is no existing correlation between teams and submitted content, we will first need to look up the participants in the team using the teams_users table. And then, using those user_id values one at a time, we need to look up the participants table.

Finally, we need to merge the results before displaying it.

def hyperlinks
  links = Array.new
  self.participants.each { |team_member|
    links.concat(team_member.hyperlinks_array) if team_member.hyperlinks_array}
  links
end

So, it becomes a tedious 3-step process. It is evident from this example that the current design is inefficient.

Instead, if the hyperlinks data were available in teams table, we could directly access all the submitted content for a team in one shot, making it much more streamlined.

As a part of this change, we’ll have to move the following routines in assignment_participants.rb, which deal hyperlink handling to assignment_team.rb.

  # Appends the hyperlink to a list that is stored in YAML format in the DB
  # @exception  If is hyperlink was already there
  #             If it is an invalid URL
  def submit_hyperlink(hyperlink)
    hyperlink.strip!
    raise "The hyperlink cannot be empty" if hyperlink.empty?
    url = URI.parse(hyperlink)
    # If not a valid URL, it will throw an exception
    Net::HTTP.start(url.host, url.port)
    hyperlinks = self.hyperlinks_array
    hyperlinks << hyperlink
    self.submitted_hyperlinks = YAML::dump(hyperlinks)
    self.save
  end

  # Note: This method is not used yet. It is here in the case it will be
    needed.
  # @exception  If the index does not exist in the array
  def remove_hyperlink(hyperlink_to_delete)
    hyperlinks = self.hyperlinks_array
    hyperlinks.delete(hyperlink_to_delete)
    self.submitted_hyperlinks = YAML::dump(hyperlinks)
    self.save
  end

  def hyperlinks
    team.try(:hyperlinks) || []
  end
 
  def hyperlinks_array
    self.submitted_hyperlinks.blank? ? [] :YAML::load(self.submitted_hyperlinks)
  end

Similar refactoring work needs to be done for the directory_num field as well. Finally, the refactoring needs to be thoroughly tested by writing test cases for student-submitted hyperlinks and files by making sure that:

  • the submitted hyperlinks and files are correctly displayed on the submitted content page.
  • the reviewer can see the submitted content from the reviewees.
  • the instructor can see the submitted content from the reviewees.

Use Cases

Use Case 1: Submit hyperlink for an assignment by student.

Description: A student who is an assignment participant should be able to submit hyperlink on the “Your work” section of an assignment.

Preconditions: Student should be a participant for the assignment he is trying to submit the hyperlink.

Postconditions: The submitted hyperlink should be stored in the teams table of the database.

Success Scenario:

  1. The submitted hyperlink is visible every time the student views the “Your work” section for the Assignment.
  2. All other team members should be able to view the submitted hyperlink.
  3. A reviewer should be able to see the submitted hyperlink.
  4. An instructor should be able to see the submitted hyperlink.


Use Case 2: Submit file for an assignment by student.

Description: A student who is an assignment participant should be able to submit a file on the “Your work” section of an assignment.

Preconditions: Student should be a participant for the assignment he is trying to submit the file.

Postconditions: The directory_num field which stores the directory number of the directory storing all the submitted files for a team should be stored in the teams table of the database.

Success Scenario:

  1. The submitted file is visible every time the student views the “Your work” section for the Assignment.
  2. All other team members should be able to view the submitted file.
  3. A reviewer should be able to see the submitted file.
  4. An instructor should be able to see the submitted file.


Use Case 3: Delete hyperlink for an assignment by student.

Description: A student who is an assignment participant should be able to delete submitted hyperlink on the “Your work” section of an assignment.

Preconditions: Student should be a participant for the assignment he is trying to delete the hyperlink.

Postconditions: The deleted hyperlink should be removed from the teams table in DB.

Success Scenario:

  1. The deleted hyperlink should not be visible the next time the student clicks on “Your work” section.
  2. All other team members should not see the deleted hyperlink.
  3. A reviewer should not be able to see the deleted hyperlink.
  4. An instructor should not be able to see the deleted hyperlink.

Accomplishments

We made the following changes in the process of refactoring the submitted content controller.

 def participant_params
- <span style="color:red"> params.require(:participant).permit(:can_submit,:can_review,:user_id,:parent_id,:directory_num,:submitted_at,:permission_granted,:penalty_accumulated,:submitted_hypelinks,:grade,:type,:handle,:time_stamp,:digital_signature,:duty,:can_take_quiz) </span>
<span style="color:green">
+ params.require(:participant).permit(:can_submit,:can_review,:user_id,:parent_id,:submitted_at,:permission_granted,:penalty_accumulated,:grade,:type,:handle,:time_stamp,:digital_signature,:duty,:can_take_quiz)
end </span>

Future Work

A proposal for further improvement would be to possibly create a new submitted_content table in the database. This table could include attributes like user_id, team_id, can_submit, hyperlink, directory_num, uploaded_at, updated_at. This approach would resolve the existing hyperlinks issue and more importantly, aid in recording a history of the submitted hyperlinks. There could be a “Show previous submissions” view for a team. So, if ever there’s a scenario where a student or an instructor needs to revert or go back and check a previous submission, he/she can easily access it from this table.


References

<references/>