CSC/ECE 517 Fall 2019 - E1954. Auto-generate submission directory names based on assignment names: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
 
(48 intermediate revisions by 2 users not shown)
Line 4: Line 4:


Expertiza is an educational web application created and maintained by the joint efforts of the students and the faculty at NCSU. It’s an open-source project developed on Ruby on Rails platform and its code is available on Github. It allows students to review each other’s work and improve their work upon this feedback.
Expertiza is an educational web application created and maintained by the joint efforts of the students and the faculty at NCSU. It’s an open-source project developed on Ruby on Rails platform and its code is available on Github. It allows students to review each other’s work and improve their work upon this feedback.
== Need of the current project ==
The following states the needs/issues with the current Expertiza project.
Whenever an instructor/TA adds a new Assignment with the name of already existing assignment in the same course, then the newly created assignment is stored in the same directory as that of the previously created assignment which creates a conflict. Thus, need of a check that should be added to prevent two assignments in the same course from having the same name.
Two assignments can currently be stored in the same directory. Thus, need of a check to stop two assignments from sharing the same directory.
The directory name is not auto-generated from the assignment name. Hence, auto generation is required.


== Description of the current project ==
== Description of the current project ==
Line 14: Line 26:
A check is made to stop two assignments from sharing the same directory. <br/>
A check is made to stop two assignments from sharing the same directory. <br/>


== Files modified in current project ==
== Submitted Work and Demonstration of the Project ==
* [https://github.com/expertiza/expertiza Link to Github Repository of expertiza]
* [https://github.com/anujak30/expertiza-1 Link to Github Repository including our changes related to E1954]
* [http://152.46.19.163:8080 Link to deployed code on NCSU VCL]
* [https://github.com/expertiza/expertiza/pull/1574 Link to Pull Request demonstrating corresponding changes]
* [https://drive.google.com/open?id=1O81Er0QrVceDiVhHVlC57BDToVFuIgDN Link to Video showing the demonstration of the project]
* [https://drive.google.com/file/d/1Xcr7tfVQU9xFmeEcR3iuIWUzuzjVsUNK/view Link to Video showing RSpec tests of the changes]


A controller and a helper file were modified for this project namely:<br/>
== Files modified in Project ==
 
A controllera, helper file and spec were modified for this project namely:<br/>
1. AssignmentsController <br/>
1. AssignmentsController <br/>
2. AssignmentsView - _general.html.erb <br/>
2. AssignmentsView - _general.html.erb <br/>
3. AssignemntsController - assignments_controller_spec.rb </br>


=== AssignmentsController ===
=== AssignmentsController ===
Line 39: Line 60:
       # Do not create an assignment if the assignment name or directory name already present in the course
       # Do not create an assignment if the assignment name or directory name already present in the course
       exist_assignment = Assignment.find_by(name: @assignment_form.assignment.name, course_id: @assignment_form.assignment.course_id)
       exist_assignment = Assignment.find_by(name: @assignment_form.assignment.name, course_id: @assignment_form.assignment.course_id)
       exist_directory = Assignment.find_by(directory_path: assignment_form_params[:assignment][:directory_path], course_id: @assignment_form.assignment.course_id)
       dir_path = assignment_form_params[:assignment][:directory_path]
       if !exist_assignment and !exist_directory
      exist_directory = Assignment.find_by(directory_path: dir_path, course_id: @assignment_form.assignment.course_id)
        if @assignment_form.save
       if !exist_assignment and !exist_directory and @assignment_form.save
          @assignment_form.create_assignment_node
        @assignment_form.create_assignment_node
          # Get the details of the assignment which is saved in current_assignment
        current_assignment = Assignment.find_by(name: @assignment_form.assignment.name, course_id: @assignment_form.assignment.course_id)
          current_assignment = Assignment.find_by(name: @assignment_form.assignment.name, course_id: @assignment_form.assignment.course_id)
        assignment_form_params[:assignment][:id] = current_assignment.id.to_s
          assignment_form_params[:assignment][:id] = current_assignment.id.to_s
        ques_array = assignment_form_params[:assignment_questionnaire]
          ques_array = assignment_form_params[:assignment_questionnaire]
        due_array = assignment_form_params[:due_date]
          due_array = assignment_form_params[:due_date]
        ques_array.each do |cur_questionnaire|
          ques_array.each do |cur_questionnaire|
          cur_questionnaire[:assignment_id] = current_assignment.id.to_s
            cur_questionnaire[:assignment_id] = current_assignment.id.to_s
          end
          due_array.each do |cur_due|
            cur_due[:parent_id] = current_assignment.id.to_s
          end
          assignment_form_params[:assignment_questionnaire] = ques_array
          assignment_form_params[:due_date] = due_array
          @assignment_form.update(assignment_form_params, current_user)
          aid = Assignment.find_by(name: @assignment_form.assignment.name, course_id: @assignment_form.assignment.course_id).id
          ExpertizaLogger.info "Assignment created: #{@assignment_form.as_json}"
          redirect_to edit_assignment_path aid
          undo_link("Assignment \"#{@assignment_form.assignment.name}\" has been created successfully. ")
          return
        else
          flash.now[:error] = "Failed to create assignment"
          render 'new'
         end
         end
        due_array.each do |cur_due|
          cur_due[:parent_id] = current_assignment.id.to_s
        end
        assignment_form_params[:assignment_questionnaire] = ques_array
        assignment_form_params[:due_date] = due_array
        @assignment_form.update(assignment_form_params, current_user)
        aid = Assignment.find_by(name: @assignment_form.assignment.name, course_id: @assignment_form.assignment.course_id).id
        ExpertizaLogger.info "Assignment created: #{@assignment_form.as_json}"
        redirect_to edit_assignment_path aid
        undo_link("Assignment \"#{@assignment_form.assignment.name}\" has been created successfully. ")
        return
       else
       else
         if exist_assignment
         flash.now[:error] = "Failed to create an assignment. Kindly rename."
          flash.now[:error] = "Assignment name already exists in the selected course. Kindly rename the assignment."
        else
          flash.now[:error] = "Directory name already exists in the selected course. Kindly rename the directory."
        end
         render 'new'
         render 'new'
       end
       end
Line 90: Line 102:
<img src="/assets/info.png" title='- DO NOT change this filed for an on-going assignment. This may cause lost of student submitted file.'>
<img src="/assets/info.png" title='- DO NOT change this filed for an on-going assignment. This may cause lost of student submitted file.'>
</td></div>
</td></div>
</tr>


</pre>
</pre>


=== Solutions Implemented and Delivered ===
<pre>
$(function() {
    $("#name_field").change(function() {
        filename = $( "#name_field" ).val().replace(/ /g,"_").replace(/[/\\?%*:|"<>/$&!#%^@]/g, '');;
        $('#directory_field').val(filename);
    });
});


*Refactoring calculate_all_penalties method
</pre>


This is used to calculate various penalty values for each assignment if penalty is applicable.
WI3: Earlier the assignment was getting generated even if the instructor was not giving it any name or submission directory path, now both of these fields have been made mandatory. <br/>


The following changes were made:
== Testing Plans ==
 
1. This method was very complex, performing too many functions within a single method and had to be broken into 3 smaller methods each having a more well defined function.
2. The following 3 methods were created after splitting the first method<br>
  i.  calculate_all_penalties<br>
  ii. calculate_penatly_attributes<br>
  iii. assign_all_penalties<br>
3. Changes were also made to make the code follow ruby style.The language was made more ruby friendly.
4. Finally some redundant code was commented out as it was non-functional.


Testing plan is divided into two - Rspec testing and UI testing
   
   
=== 1) RSpec Test plan ===
As the controller code has been changed now, which does not allows two assignment files to be stored with same name. Thus, in the spec file for assignments controller, a test case has been added for the same.


Refactoring into smaller more specific methods:
<pre>


[[File:Change6_new.png]]
context 'when assignment_form is not saved successfully due to same assignment/auto generated directory exists' do
      it 'renders assignment#new page' do
        allow(Assignment).to receive(:find_by).with(name: 'test assignment', course_id: 1).and_return(assignment)
        allow(Assignment).to receive(:find_by).with(directory_path: 'test_assignment', course_id: 1).and_return(assignment)
        post :create, @params
        expect(flash.now[:error]).to eq("Failed to create an assignment. Kindly rename.")
        expect(response).to render_template(:new)
      end
    end


Removal of non-functional code :
</pre>
 
[[File:Change5_new.png]]
 
 
Change of language to make it more Ruby friendly:
 
[[File:Change1_new.png]]
 
 
*Move the redundant piece of code from conflict_notification & edit methods to a new method list_questions
 
The conflict_notification method is used to help the instructors decide if one of the reviews are unfair or inaccurate.
This was again split into 2 methods with some part of the code which is repeated in another method  refactored into a new method.
 
[[File:Change3_new.png]]
 
 
Refactored #Created a method which was a duplicate in conflict_notification and edit methods
 
[[File:Change4_new.png]]
 
edit method:
 
This method is used to edit the questionnaires. This method again has code which is repeated in the conflict_notification method and thus the repeated section was split into a new method.
 
[[File:Change2_new.png]]
 
New method:
Refactored #Created a method which was a duplicate in conflict_notification and edit methods
 
[[File:Change4_new.png]]
 
Similar refactoring was performed to obtain the retrieve_questions method:
 
[[File:Latest1.png]]
 
This is the new method created after the above refactoring:
 
[[File:Latest2.png]]
 
== Testing Details==


=== RSpec ===
=== 2) UI Testing ===
There were no existing test cases for the GradesController. We have added a new spec file 'grades_spec.rb' which covers testing scenario for the newly added method. The specs were run on the previous and current files and they return the same results implying that the refactored code does not break anything.
Following Steps needs to be performed to test the project from UI:-<br>
As the model was not changed, no test cases were added for the model.
'''Step 1:''' Login as Instructor (Username - instructor6, Password - password). Create an assignment under any of the existing courses with name as "test assignment".<br><br><br>
[[File:Login as instructor.JPG]]  <br><br>
'''Step 2:''' Check if the Submission directory field is automatically getting populated based on the assignment name (replacing spaces with underscores and removing special characters).<br><br><br>
[[File:Directory_name_autopopulate.JPG]] <br><br><br>
'''Step 3:''' Fill in the details for Rubrics and Review Strategy. <br><br><br>
[[File:Rubrics.JPG]] <br><br><br>
'''Step 4:''' Click on create. You should be able to see the assignment you created in the list. <br><br><br>
[[File:Review.JPG]] <br<br><br>
'''Step 5:''' Now, try to create another assignment with the same name in the same course. Also, try to change the submission directory name to any of the existing assignment or same the assignment created in Step 2, Check if the system flashes an error in the creation of this assignment. <br><br><br>
[[File:Assignment directory already exists.JPG]] <br><br>


=== UI Testing ===
== Team Information ==
1) Amit Mandliya (amandli)


Following steps needs to be performed to test this code from UI:<br/>
2) Anuja Kulkarni (apkulka2)
1. Login as instructor. Create a course and an assignment under that course.<br/>
2. Keep the has team checkbox checked while creating the assignment. Add a grading rubric to it. Add at least two students as participants to the assignment.<br/>
3. Create topics for the assignment.<br/>
4. Sign in as one of the students who were added to the assignment.<br/>
5. Go to the assignment and sign up for a topic.<br/>
6. Submit student's work by clicking 'Your work' under that assignment.<br/>
7. Sign in as a different student which is participant of the assignment.<br/>
8. Go to Assignments--><assignment name>-->Others' work (If the link is disabled, login as instructor and change the due date of the assignment to current time).<br/>
9. Give reviews on first student's work.<br/>
10. Login as instructor or first student to look at the review grades.<br/>


3) Samruddhi Khandale (sskhanda)


== Scope for future improvement ==
Mentor : Akanksha Mohan
1. The construct_table method in GradesHelper is not used anywhere. It has no reference in the project. So we feel it can be safely removed.<br/>
2. The has_team_and_metareview? method in GradesHelper can be broken down into separate methods, one each for team and metareview. This will provide improved flexibility. It needs some analysis though, as both the entities(team & metareview) are currently checked in conjuction from all the views they are referenced from.

Latest revision as of 02:20, 7 November 2019

This wiki page is for the description of changes made under E1954. Auto-generate submission directory names based on assignment names for Fall 2019, CSC/ECE 517.

Expertiza Background

Expertiza is an educational web application created and maintained by the joint efforts of the students and the faculty at NCSU. It’s an open-source project developed on Ruby on Rails platform and its code is available on Github. It allows students to review each other’s work and improve their work upon this feedback.


Need of the current project

The following states the needs/issues with the current Expertiza project.

Whenever an instructor/TA adds a new Assignment with the name of already existing assignment in the same course, then the newly created assignment is stored in the same directory as that of the previously created assignment which creates a conflict. Thus, need of a check that should be added to prevent two assignments in the same course from having the same name.

Two assignments can currently be stored in the same directory. Thus, need of a check to stop two assignments from sharing the same directory.

The directory name is not auto-generated from the assignment name. Hence, auto generation is required.


Description of the current project

The following is an Expertiza based OSS project which deals primarily with the AssignmentsController and AssignmentsView - _general.html.erb. Here is the details description of the project:
The directory name is auto-generated from the assignment name. The instructor is allowed to edit
It is done by changing spaces in the names to underscores. E.g., the directory for Program 1 is by default "Program_1".
The special characters like '/','\','$' etc are to be removed from the auto-generated submission directory name.
A check is added to prevent two assignments in the same course from having the same name.
A check is made to stop two assignments from sharing the same directory.

Submitted Work and Demonstration of the Project

Files modified in Project

A controllera, helper file and spec were modified for this project namely:
1. AssignmentsController
2. AssignmentsView - _general.html.erb
3. AssignemntsController - assignments_controller_spec.rb

AssignmentsController

This is a controller that helps instructors create, modify, copy new assignments. Each assignment can be associated with specific Rubrics, Review Strategy and Due dates.


AssignmentsView - _general.html.erb

This the View for creating the new assignments and editing the existing assignments. This view also handles specifications of Rubrics, Review Strategy and Dates.

List of changes

We worked on the following work items(WIs)
WI1: Created exist_assignment and exist_directory to check if the assignment name and directory name already exists in the current course. If any of those are already present then flash the respective error, else save the assignment. Here is the create method of controller -> assignments_controller.rb:

  def create
    @assignment_form = AssignmentForm.new(assignment_form_params)
    if params[:button]
      # Do not create an assignment if the assignment name or directory name already present in the course
      exist_assignment = Assignment.find_by(name: @assignment_form.assignment.name, course_id: @assignment_form.assignment.course_id)
      dir_path = assignment_form_params[:assignment][:directory_path]
      exist_directory = Assignment.find_by(directory_path: dir_path, course_id: @assignment_form.assignment.course_id)
      if !exist_assignment and !exist_directory and @assignment_form.save
        @assignment_form.create_assignment_node
        current_assignment = Assignment.find_by(name: @assignment_form.assignment.name, course_id: @assignment_form.assignment.course_id)
        assignment_form_params[:assignment][:id] = current_assignment.id.to_s
        ques_array = assignment_form_params[:assignment_questionnaire]
        due_array = assignment_form_params[:due_date]
        ques_array.each do |cur_questionnaire|
          cur_questionnaire[:assignment_id] = current_assignment.id.to_s
        end
        due_array.each do |cur_due|
          cur_due[:parent_id] = current_assignment.id.to_s
        end
        assignment_form_params[:assignment_questionnaire] = ques_array
        assignment_form_params[:due_date] = due_array
        @assignment_form.update(assignment_form_params, current_user)
        aid = Assignment.find_by(name: @assignment_form.assignment.name, course_id: @assignment_form.assignment.course_id).id
        ExpertizaLogger.info "Assignment created: #{@assignment_form.as_json}"
        redirect_to edit_assignment_path aid
        undo_link("Assignment \"#{@assignment_form.assignment.name}\" has been created successfully. ")
        return
      else
        flash.now[:error] = "Failed to create an assignment. Kindly rename."
        render 'new'
      end
    else
      render 'new'
      undo_link("Assignment \"#{@assignment_form.assignment.name}\" has been created successfully. ")
    end
  end

WI2: Auto-generate the Submission directory name based on the assignment name. Allow, the Submission Directory name field to be explicitly editable by the instructor. Here is the javascript function introduced in views -> assignments -> edit -> _general.html.erb

<tr><div class="form-inline">
<td style='padding:5px'><%= label_tag('assignment_form[assignment][directory_path]', 'Submission directory:') %></td>
<td style='padding:5px'><%= text_field_tag('assignment_form[assignment][directory_path]', @assignment_form.assignment.directory_path, required: true, 
:id => 'directory_field', :style => 'width:250px', class: 'form-control') %> (Note: Directory name is auto-generated from Assignment Name. You can change it if you wish to.)
<img src="/assets/info.png" title='- DO NOT change this filed for an on-going assignment. This may cause lost of student submitted file.'>
</td></div>
</tr>

$(function() {
    $("#name_field").change(function() {
        filename = $( "#name_field" ).val().replace(/ /g,"_").replace(/[/\\?%*:|"<>/$&!#%^@]/g, '');;
        $('#directory_field').val(filename);
    });
});

WI3: Earlier the assignment was getting generated even if the instructor was not giving it any name or submission directory path, now both of these fields have been made mandatory.

Testing Plans

Testing plan is divided into two - Rspec testing and UI testing

1) RSpec Test plan

As the controller code has been changed now, which does not allows two assignment files to be stored with same name. Thus, in the spec file for assignments controller, a test case has been added for the same.


 context 'when assignment_form is not saved successfully due to same assignment/auto generated directory exists' do
      it 'renders assignment#new page' do
        allow(Assignment).to receive(:find_by).with(name: 'test assignment', course_id: 1).and_return(assignment)
        allow(Assignment).to receive(:find_by).with(directory_path: 'test_assignment', course_id: 1).and_return(assignment)
        post :create, @params
        expect(flash.now[:error]).to eq("Failed to create an assignment. Kindly rename.")
        expect(response).to render_template(:new)
      end
    end

2) UI Testing

Following Steps needs to be performed to test the project from UI:-
Step 1: Login as Instructor (Username - instructor6, Password - password). Create an assignment under any of the existing courses with name as "test assignment".




Step 2: Check if the Submission directory field is automatically getting populated based on the assignment name (replacing spaces with underscores and removing special characters).





Step 3: Fill in the details for Rubrics and Review Strategy.





Step 4: Click on create. You should be able to see the assignment you created in the list.


<br

Step 5: Now, try to create another assignment with the same name in the same course. Also, try to change the submission directory name to any of the existing assignment or same the assignment created in Step 2, Check if the system flashes an error in the creation of this assignment.




Team Information

1) Amit Mandliya (amandli)

2) Anuja Kulkarni (apkulka2)

3) Samruddhi Khandale (sskhanda)

Mentor : Akanksha Mohan