|
|
Line 9: |
Line 9: |
|
| |
|
| == What it does == | | == What it does == |
| #It handles the display, submission, deletion of hyperlinks and files by the teams.
| | It does stuff |
|
| |
|
| == What is wrong with it == | | == 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).
| | things are wrong |
| #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 == | | == What needs to be done == |
Line 42: |
Line 41: |
|
| |
|
| = Scope = | | = Scope = |
| #This project can be divided into four major work items:
| | This project can be divided into major work items: |
| #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. | | #thing 1 |
| #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. | | #thing 2 |
| #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. | | #thing 3 |
| #Write test cases to verify student-submitted hyperlinks and files. | | #thing 4 |
|
| |
|
| = Implementation = | | = Implementation = |
| #Expertiza files that will be modified for each work item along with the description:
| | implementation details |
| {| class="wikitable"
| |
| ! scope="col" style="width: 50px;" | Work Item #
| |
| ! scope="col" style="width: 225px;" | Files to be modified
| |
| ! scope="col" style="width: 500px;" | Description
| |
| |-
| |
| | 1 || assignment_participant.rb<br>assignment_team.rb<br>db:participants table<br>db:teams table || - Create a new column '''hyperlinks''' in '''teams''' table<br>- Write db migration, move all the participants’ submitted hyperlinks from '''participants''' table into '''teams''' table. All duplicated hyperlinks have to be removed.<br>- Write db migration, remove the '''hyperlinks''' field from '''participants''' table.<br>- 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<br>teams_controller.rb<br>db:participants table<br>db:teams table || - Write db migration, move the '''directory_num''' field (also the content) to '''teams''' table.<br>- Move the '''set_student_directory_num''' from '''participant_controller''' to '''team_controller''', then refactor this method into smaller methods.<br>- 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.<br>- 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 = | | = 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.
| | design |
| | |
| [[File:db.jpg]]
| |
| | |
| Finally, we need to merge the results before displaying it.
| |
| | |
| <pre>
| |
| def hyperlinks
| |
| links = Array.new
| |
| self.participants.each { |team_member|
| |
| links.concat(team_member.hyperlinks_array) if team_member.hyperlinks_array}
| |
| links
| |
| end
| |
| </pre>
| |
| | |
| 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'''.
| |
| | |
| <pre>
| |
| # 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
| |
| </pre>
| |
| | |
| 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 Cases == |
| '''Use Case 1:''' Submit hyperlink for an assignment by student.
| | use cases |
|
| |
| '''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:'''
| |
| #The submitted hyperlink is visible every time the student views the “Your work” section for the Assignment.
| |
| #All other team members should be able to view the submitted hyperlink.
| |
| #A reviewer should be able to see the submitted hyperlink.
| |
| #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:'''
| |
| #The submitted file is visible every time the student views the “Your work” section for the Assignment.
| |
| #All other team members should be able to view the submitted file.
| |
| #A reviewer should be able to see the submitted file.
| |
| #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:'''
| |
| #The deleted hyperlink should not be visible the next time the student clicks on “Your work” section.
| |
| #All other team members should not see the deleted hyperlink.
| |
| #A reviewer should not be able to see the deleted hyperlink.
| |
| #An instructor should not be able to see the deleted hyperlink.
| |
| | |
|
| |
|
| = Accomplishments = | | = Accomplishments = |
|
| |
|
| The project was divided into 4 categories:
| | Video demo of our work can be found at https://www.youtube.com/<br> |
| # Database migrations
| | GitHub repository containing the refactoring changes can be found at https://github.com/<br> |
| # Refactor ''submitted_hyperlink'' related methods
| | Link to the pull request to Expertiza is https://github.com/expertiza/expertiza/pull/ |
| # Refactor ''directory_num'' related methods
| |
| # Testing
| |
| <br>
| |
| | |
| We followed the steps listed below in the process of refactoring the submitted content controller:
| |
| | |
| * Writing database migrations to move the ''submitted_hyperlinks'' and ''directory_num'' attributes from the Participants table to the Teams table.
| |
| * Rewriting ''submitted_hyperlinks'' related methods in the Participants model to read from and write to the Teams table.
| |
| * Modifying the corresponding views to read ''hyperlinks_array'' instead of ''hyperlinks''. ''hyperlinks_array'' stores the the submissions of all the team members of a team.
| |
| * Removing ''directory_num'' related methods from the participant model.
| |
| * Rewriting ''directory_num'' related methods in the team model.
| |
| * Rewriting the corresponding views to read ''directory_num'' from the teams table instead of the participants table.
| |
| * For testing, we first created fixtures for all required tables.
| |
| * We tested our changes by writing functional tests to test the SubmittedContentController.
| |
| * Our test suite included the following tests:
| |
| ** Testing submission of a hyperlink by one student - Check the count of submmited hyperlinks, verify that the hyperlink is stored properly in the database and displayed correctly from the UI.
| |
| ** Testing submission of two hyperlinks by two students in a team - Check the count of submmited hyperlinks, verify that the hyperlink is stored properly in the database and displayed correctly from the UI.
| |
| ** Testing submission of the same hyperlink by two students in a team - Check that the duplicate hyperlinks does not get stored.
| |
| ** Testing deletion of a hyperlink - Check the count of submmited hyperlinks and the updated list is displayed correctly from the UI.
| |
| ** Testing submission of one file by one student - Check the submission of a file and check the updated count of submitted files.
| |
| ** Testing deletion of one file by one student - Check the deletion of a submitted file and check the updated count of submitted files.
| |
| ** Testing submission of multiple files by multiple students - Check the submission of multiple files and check the updated count of submitted files.
| |
| ** Testing deletion of multiple files by multiple students - Check the deletion of multiple submitted files and check the updated count of submitted files.
| |
| | |
| <br>
| |
| We can conclusively say that, after refactoring the submitted content controller, the query time for retrieving submissions will improve significantly as they are stored together on a team-basis rather than for each participant.
| |
| | |
| Video demo of our work can be found at https://www.youtube.com/watch?v=VHVWF_UKgOc&feature=youtu.be <br> | |
| GitHub repository containing the refactoring changes can be found at https://github.com/nitinnagaraja/expertiza/ <br> | |
| Link to the pull request to Expertiza is https://github.com/expertiza/expertiza/pull/629 | |
|
| |
|
| = Future Work = | | = 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.
| | things to do in the future |
| | |
|
| |
|
| = References = | | = References = |
| <references/> | | <references/> |