CSC/ECE 517 Fall 2019 - E1959. Intelligent copying of assignments without topics

From Expertiza_Wiki
Jump to navigation Jump to search

Introduction

Expertiza is an open source web application project developed using Ruby on Rails framework. Let us list some of the functionalities that Expertiza allows us to do under different roles:

As an Instructor:

We can create new assignments, edit the existing assignments, copy the assignments and also delete the assignment. The instructor can also add participants, reviewers to a particular assignment.

As a Student:

They can form teams to work on various projects and also bid for the projects they would like to work on. They can also review other student's work and can give feedback on them. They can also submit various types of documents including the URLs and wiki pages for their project or assignment submission.

Design Pattern

Design patterns are not applicable as our task involved just modification of existing methods.

Problem Statement

Background

When an instructor or a TA logs in to expertiza, s(he) can see a list of assignments under the assignment tab. An instructor or a TA can copy an assignment to use the same event in another course or as another assignment. When the user copies the assignment, the assignment is being copied without providing required flexibility to the users. Majorly, we are focused on implementing two features that shall add flexibility to the copy functionality.

Issues

Issue 1: While copying an assignment, the user (instructor or TA) is not asked whether they wants to copy the topics along with the assignment or not. Currently, it is copying the topics, without providing any choice for user to not have the topics.

Issue 2: While copying an assignment, the teams/students assigned to each topic are not getting copied. The user might want to copy the teams/students mapped to the topics as well.

Steps to generate the issue <Existing system, without our implementation> <Requires Instructor credentials>

1) Login to expertiza.ncsu.edu using instructor credentials.

2) Navigate to Assignments section. (Hover on Manage Tab -> Click on Assignments)

3) Copy the assignment of your choice by clicking copy icon located on the right side of the specific assignment.

Above steps copy the assignment. Remember that this process did not give you the flexibility of choosing whether to copy/not copy.

1) Topics linked to assignment.

2) Students/Teams linked to each topic.

Present system copies the topics but doesn't copy the students, even if you don't want it this way. Our implementation is to provide the user with the functionality to choose to copy/not copy topics linked to an assignment and students/teams linked to each topic.

Solution & Code Modification

We have modified 5 files and mainly we have modified code in two classes they are:

  1. apps/controllers/assignments_controller.rb and
  2. apps/models/assignment_form.rb.

Solution

So before we made any changes, the flow was, when an assignment is copied: def copy in controllers/assignments_controller.rb is called which calls a function def self.copy in models/assignment_form.rb. To solve the issue, we have created a new web page that is triggered on clicking the copy icon for the assignment. The view page is the checktopicscopy.html.erb under the views/assignments folder. This page asks the user to select from 3 options, which are:

  1. Copy without Topics. (Blank Assignment)
  2. Copy with Topics. (Assignment with only topics)
  3. Copy with Topics and Teams. (Assignment with topics and teams)

Based on the option chosen by the user, this option is passed by the def copy in controllers/assignments_controller.rb to def self.copy in models/assignment_form.rb.

def checktopicscopy
    @assignment_id = params[:id]
end
new_assign_id = AssignmentForm.copy(params[:id], params[:copyoption], @user) #Line 115 in original file has been updated to Line 119 in modified file.

The def self.copy in models/assignment_form.rb now receives this value and creates a duplicate of the assignment without copying the teams and topics originally. If the user chosen the option to just copy a blank assignment (i.e. without the topics or teams, the execution does not enter into any of the if conditions. If the user wants to copy the assignment with only the topics (but not the teams), then it goes into the first if (Line 330 [refer code below]) and copies the topics as well but does not enter the next if (Line 335 [refer code below]). If the user wants to copy the assignment with the topics as well as the teams, the code will enter the first as well as the second if condition and copy the topics as well as the teams.

def self.copy(assignment_id, copyoption, user) #Line 313 in the original file has been modified.

..... (Skipped Lines)

if copyoption != 'copyWithoutTopics' #Line 330 in modified file.
  topics = SignUpTopic.where(assignment_id: old_assign.id)
  topics.each do |topic|
    new_sign_up_topic = SignUpTopic.create(
	  topic_name: topic.topic_name,
	  assignment_id: new_assign_id,
	  max_choosers: topic.max_choosers,
	  category: topic.category,
	  topic_identifier: topic.topic_identifier,
	  micropayment: topic.micropayment
    )

  if copyoption == 'copyWithTopicsTeams' #Line 335 in modified file.
	old_signed_up_teams = SignedUpTeam.where(topic_id: topic.id)
	old_signed_up_teams.each do |old_signed_up_team|
	  new_signed_up_team = old_signed_up_team.dup
	  new_signed_up_team.update_attribute('topic_id', new_sign_up_topic.id)
	  new_signed_up_team.save
	end
  end
end

The code modifications and their coverage have been covered in the following section.

Testing (Test Plan)

Automated Testing using RSpec

We have made changes to the test cases and both the models/assignment_form.rb and also the controllers/assignments_controller.rb have passed all the test cases. The tests can be executed rpec spec and the results for the 2 main files we have modified are shown below:

#rspec ./spec/models/assignment_form_spec.rb
Finished in 1 minute 32.18 seconds (files took 20.22 seconds to load)
29 examples, 0 failures
.
.
.
#rspec ./spec/controllers/assignments_controller_spec.rb
Finished in 2 minutes 2.3 seconds (files took 1 minute 13.49 seconds to load)
23 examples, 0 failures

See the detailed coverage report below.

1. models/assignment_form.rb
In this file, the coverage has increased from 61.39% to 85.65% after modification.

Original file:

Modified file:

In the modified file, the following code has been added,

def self.copy(assignment_id, copyoption, user) #Line 313 in the original file has been modified.
if copyoption != 'copyWithoutTopics' #Line 330 in modified file.
  topics = SignUpTopic.where(assignment_id: old_assign.id)
  topics.each do |topic|
    new_sign_up_topic = SignUpTopic.create(
	  topic_name: topic.topic_name,
	  assignment_id: new_assign_id,
	  max_choosers: topic.max_choosers,
	  category: topic.category,
	  topic_identifier: topic.topic_identifier,
	  micropayment: topic.micropayment
    )

  if copyoption == 'copyWithTopicsTeams'
	old_signed_up_teams = SignedUpTeam.where(topic_id: topic.id)
	old_signed_up_teams.each do |old_signed_up_team|
	  new_signed_up_team = old_signed_up_team.dup
	  new_signed_up_team.update_attribute('topic_id', new_sign_up_topic.id)
	  new_signed_up_team.save
	end
  end
end


2. controllers/assignments_controller.rb
In this file, the coverage has increased from 88.66% to 88.8% after modification.

Original file:

Modified file:

In the modified file, the following code has been added,

def checktopicscopy
    @assignment_id = params[:id]
end
new_assign_id = AssignmentForm.copy(params[:id], params[:copyoption], @user) #Line 115 in original file has been updated to Line 119 in modified file.

Manual Testing from UI (For Reviewers)

By following the below stated process, you can test the implementation that we worked on, which is: Target 1: Provide the user with the option to select copy/not copy topics linked to an assignment. Target 2: Provide the user with the option to select copy/not copy students/teams linked to a topic.

Step 1: Visit http://152.46.17.204:8080/ . Enter the credentials:
Username: instructor6
Password: password

Step 2: On the top, hover on Manage tab. Click Assignments.

Step 3: Choose an assignment that you want to copy. We would recommend you choosing a robust assignment that has Topics and students/teams associated with topics. OSS Projects generally have these. [Please make sure that you are under the Assignments tab or select the assignment besides the course]

If you want to check and see if an assignment has topics or not, click on Edit (pencil icon) on the right. - If this assignment has topics, you will see a tab named Topics on the right of General tab. If there are no topics, you won't see Topics tab. - On clicking the Topics tab, you can see the list of topics. If students/teams are assigned to topics, you will see student names (alias representations, like student1234 student2343) under each Topic name in 'Topic name(s) column'. If you don't see any such, it means that teams/students are not assigned to topics.

Step 4: After you chose the assignment that you want to copy, click on the copy icon on the right of the corresponding assignment.

Where is the copy button located? Check the image below.


Step 5: Clicking the copy button will take you to copy options page, where you can select the options for copying. The page looks like this:


Step 6: Choose the option you wish to test. Click create. Now the assignment shall be copied with the options you provided.


Step 7: After copying, the application takes you to 'Edit' page for the assignment where you can edit/view the details pertaining to the assignment. Here, you can test our implementation. In step 6, if you chose to

- copy without topics: You won't see 'Topics' tab near General tab.

- copy with topics: You will see 'Topics' tab near General tab(As shown in image below). Navigate to Topics tab where you can see and check that the respective topics have been copied. You won't see students under each topic in 'Topic Name(s)' column(If there are topics under Topics tab in original assignment from which you created this copy).

- copy with topics and students: You will see 'Topics' tab near General tab(As shown in image below). Navigate to Topics tab where you can see and check that the respective topics have been copied. You will see students under each topic in 'Topic Name(s)' column(If there are topics and students under Topics tab in original assignment from which you created this copy).

Step 8: Please rename the assignment to some random string of your choice. Having it as 'Copy of'.. is creating issues of duplicate names when creating a new copy (more details in the section below, named 'Our Recommendation for a separate issue'. Not required for students). If not changed, the next tester might face difficulty while testing(which we don't want to see happening :)).

Step 9: This completes the testing. Reiterate from step 2, if you wish to test again.

Our Work

The code we created can be found below.

The project could be run locally by cloning the GitHub Repository and then running the following commands sequentially.

bundle install
rake db:create:all
rake db:migrate
rails s

Our Recommendation for a Separate Issue (For Instructors only)

In the current system, we identified an issue and would like to bring it to your notice.

Existing System

When a user attempts to copy an assignment, the code creates a duplicate ‘assignment’ object, renames it as ‘copy of’ + <name of existing assignment>, saves the object and redirects to the ‘edit’ page where user is supposed to rename the assignment to something meaningful.

Issue

The current naming scheme as ‘copy of’ + <name of existing assignment> is creating an issue. Say you are creating a copy for some assignment named ‘OSS Project’, the copy object will be named as ‘copy of OSS Project’, saved and redirected to edit page. Had there been an existing assignment names ‘copy of OSS Project’ (which is likely), the copy attempt shall fail, putting a flash message on the screen like:

The assignment was not able to be copied. Please check the original assignment for missing information.

The above error message is in no relevance to the real reason for the error. Even though the save attempt failed, a copy is being inserted into the assignments table in the database.

Proposed Recommendation

Current naming scheme must be changed to have randomness. The name of the assignment can be given a random string, or a string like ‘copy of ’ + <name of existing assignment> + <5 digit random code>.

The user is anyway supposed to edit the information in the edit page (where the application is redirected after copying is successful). So, here, he can change the name to have some meaningful string.

Team Information

  1. Sai Vishnu Muvvala (smuvval)
  2. Rohan Pillai (rspillai)
  3. Subha Sekhar Reddy Pereddy (speredd)

Mentor: Yashad Trivedi (ytrived)
Professor: Dr. Edward F. Gehringer (efg)
Special shoutout to TA Suraj Siddharudh (ssiddha) for clearing my doubts regarding RSpec Tests.

References

  1. Expertiza on GitHub
  2. RSpec Documentation