<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Amishra6</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Amishra6"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Amishra6"/>
	<updated>2026-09-11T17:08:15Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=121397</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=121397"/>
		<updated>2018-12-08T04:14:53Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, self review is basically asking each team member in the group to evaluate their project on the same criteria as peer review, these self-review scores do not have much functionality currently. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score(composite score) between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Make sure that the peer-reviews should not be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Use case Diagram===&lt;br /&gt;
[[File:E1799_design_2.jpg]]&lt;br /&gt;
&lt;br /&gt;
Actors:&lt;br /&gt;
&lt;br /&gt;
    Instructor: This actor is responsible for creating assignments and adding students to the assignment. &lt;br /&gt;
    Student: This actor is responsible for submitting, self-reviewing and viewing the scores. &lt;br /&gt;
&lt;br /&gt;
All the other use cases are implemented except “View Scores with self-review column and composite score”&lt;br /&gt;
&lt;br /&gt;
'''Use Case: View score with self-review column and composite score'''&lt;br /&gt;
&lt;br /&gt;
Preconditions:&lt;br /&gt;
&lt;br /&gt;
   1.The Instructor creates Assignments and checks the Allow Self Review check box in the Assignment&lt;br /&gt;
   2.The Student should submit the assignment and self-review.&lt;br /&gt;
   3.The other students should submit the reviews of the work submitted.&lt;br /&gt;
&lt;br /&gt;
Student Sequence:&lt;br /&gt;
&lt;br /&gt;
   The student should login.&lt;br /&gt;
   The student should browse and upload the assignment.&lt;br /&gt;
   The student should submit the assignment.&lt;br /&gt;
   The student should submit the self-review.&lt;br /&gt;
   The student should choose your scores to view the score.&lt;br /&gt;
   The student should be able to see the peer-review score with the self-review scores and composite score.&lt;br /&gt;
&lt;br /&gt;
Post Conditions:&lt;br /&gt;
&lt;br /&gt;
   The self-review and composite score will be visible on the page.&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
The composite score is calculated using both self-review score and peer-review score (both are graded over 5 points for each criteria). &lt;br /&gt;
The composite score is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
   composite score = [10 - abs(self review score - peer review score)] * peer review score / 10&lt;br /&gt;
&lt;br /&gt;
By using this formula for calculating composite score we are discouraging students from either exaggerating or underrating their performance. The composite score model assigns more weight to the peer review score since the peer review score being used is the average of all peer review scores assigned and hence tends to be more appropriate than a single self review.&lt;br /&gt;
&lt;br /&gt;
Also this composite score formula gives the score on a scale which is identical to the scale of the self and peer review score. Thus this formula is not dependent on the scale of the self-review and peer-review score as it will also return the composite score on the same scale.&lt;br /&gt;
&lt;br /&gt;
For example: If someone gets an average peer review score of 3.5/5 and he gives 3.5/5 (self review score) while reviewing his project, then he will get a composite score of 3.5/5. And instead if the student reviews his project for 2/5 then the student will get a composite score of 2.975/5.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
As stated above the ability to do self reviews has already been implemented. This can be seen from the image shown below. The instructor has this ability to enable self reviews&lt;br /&gt;
.&lt;br /&gt;
&lt;br /&gt;
[[File:Oodd abhisu.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In our project, we were successful in displaying both the self-review score and composite review score on the view scores page. Shown below is an example of the output in the student profile. As we can see the self-review icon has a blue background to indicate that it is different from other peer reviews.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:student view.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The alternate view was also modified to accommodate a pictorial representation of the self review scores. The modified alternate view scores page is shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:alternate view.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same was achieved in the instructor profile too. In the current implementation of expertiza when self-review was not assigned, the instructor would view the scores of the first student in each team( it wouldn't matter much because without self-review all students in a team would have the same scores). But this would be a problem when self-review was enabled so we decided to display all the self-review scores of all students in the team for instructor view. As it can be seen below self-reviews of all students in the team (distinguished by their usernames) are indicated by blue background to differentiate them from peer review scores.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor view.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
This ensures that the student is not able to see his peer-review score before writing his self-review as the composite score takes into account the difference between the student peer-review and self-review score.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores.&lt;br /&gt;
This enables the student and instructor to view all his scores in one place.&lt;br /&gt;
* The composite score must be properly calculated.&lt;br /&gt;
The composite score must be calculated so as to give students more points if their self-review score is closer to the peer review score.&lt;br /&gt;
* Composite score must be visible in both view scores page and Alternate view.&lt;br /&gt;
The scores must be displayed in both the views.&lt;br /&gt;
&lt;br /&gt;
===Files Changed===&lt;br /&gt;
*app/controllers/grades_controller.rb&lt;br /&gt;
*app/models/response_map.rb&lt;br /&gt;
*app/models/vm_question_response.rb&lt;br /&gt;
*app/models/vm_question_response_row.rb&lt;br /&gt;
*app/views/grades/view_team.html.erb&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1326 Pull Request]&lt;br /&gt;
#[https://www.youtube.com/watch?v=TBStYgnWiUI&amp;amp;feature=youtu.be Screencast video]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=121396</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=121396"/>
		<updated>2018-12-08T04:14:14Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, self review is basically asking each team member in the group to evaluate their project on the same criteria as peer review, these self-review scores do not have much functionality currently. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score(composite score) between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Make sure that the peer-reviews should not be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Use case Diagram===&lt;br /&gt;
[[File:E1799_design_2.jpg]]&lt;br /&gt;
&lt;br /&gt;
Actors:&lt;br /&gt;
&lt;br /&gt;
    Instructor: This actor is responsible for creating assignments and adding students to the assignment. &lt;br /&gt;
    Student: This actor is responsible for submitting, self-reviewing and viewing the scores. &lt;br /&gt;
&lt;br /&gt;
All the other use cases are implemented except “View Scores with self-review column and composite score”&lt;br /&gt;
&lt;br /&gt;
'''Use Case: View score with self-review column and composite score'''&lt;br /&gt;
&lt;br /&gt;
Preconditions:&lt;br /&gt;
&lt;br /&gt;
   1.The Instructor creates Assignments and checks the Allow Self Review check box in the Assignment&lt;br /&gt;
   2.The Student should submit the assignment and self-review.&lt;br /&gt;
   3.The other students should submit the reviews of the work submitted.&lt;br /&gt;
&lt;br /&gt;
Student Sequence:&lt;br /&gt;
&lt;br /&gt;
   The student should login.&lt;br /&gt;
   The student should browse and upload the assignment.&lt;br /&gt;
   The student should submit the assignment.&lt;br /&gt;
   The student should submit the self-review.&lt;br /&gt;
   The student should choose your scores to view the score.&lt;br /&gt;
   The student should be able to see the peer-review score with the self-review scores and composite score.&lt;br /&gt;
&lt;br /&gt;
Post Conditions:&lt;br /&gt;
&lt;br /&gt;
   The self-review and composite score will be visible on the page.&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
The composite score is calculated using both self-review score and peer-review score (both are graded over 5 points for each criteria). &lt;br /&gt;
The composite score is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
   composite score = [10 - abs(self review score - peer review score)] * peer review score / 10&lt;br /&gt;
&lt;br /&gt;
By using this formula for calculating composite score we are discouraging students from either exaggerating or underrating their performance. The composite score model assigns more weight to the peer review score since the peer review score being used is the average of all peer review scores assigned and hence tends to be more appropriate than a single self review.&lt;br /&gt;
&lt;br /&gt;
Also this composite score formula gives the score on a scale which is identical to the scale of the self and peer review score. Thus this formula is not dependent on the scale of the self-review and peer-review score as it will also return the composite score on the same scale.&lt;br /&gt;
&lt;br /&gt;
For example: If someone gets an average peer review score of 3.5/5 and he gives 3.5/5 (self review score) while reviewing his project, then he will get a composite score of 3.5/5. And instead if the student reviews his project for 2/5 then the student will get a composite score of 2.975/5.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
As stated above the ability to do self reviews has already been implemented. This can be seen from the image shown below. The instructor has this ability to enable self reviews&lt;br /&gt;
.&lt;br /&gt;
&lt;br /&gt;
[[File:Oodd abhisu.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In our project, we were successful in displaying both the self-review score and composite review score on the view scores page. Shown below is an example of the output in the student profile. As we can see the self-review icon has a blue background to indicate that it is different from other peer reviews.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:student view.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The alternate view was also modified to accommodate a pictorial representation of the self review scores. The modified alternate view scores page is shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:alternate view.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same was achieved in the instructor profile too. In the current implementation of expertiza when self-review was not assigned, the instructor would view the scores of the first student in each team( it wouldn't matter much because without self-review all students in a team would have the same scores). But this would be a problem when self-review was enabled so we decided to display all the self-review scores of all students in the team for instructor view. As it can be seen below self-reviews of all students in the team (distinguished by their usernames) are indicated by blue background to differentiate them from peer review scores.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor view.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
This ensures that the student is not able to see his peer-review score before writing his self-review as the composite score takes into account the difference between the student peer-review and self-review score.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores.&lt;br /&gt;
This enables the student and instructor to view all his scores in one place.&lt;br /&gt;
* The composite score must be properly calculated.&lt;br /&gt;
The composite score must be calculated so as to give students more points if their self-review score is closer to the peer review score.&lt;br /&gt;
* Composite score must be visible in both view scores page and Alternate view.&lt;br /&gt;
The scores must be displayed in both the views.&lt;br /&gt;
&lt;br /&gt;
===Files Changed===&lt;br /&gt;
*app/controllers/grades_controller.rb&lt;br /&gt;
*app/models/response_map.rb&lt;br /&gt;
*app/models/vm_question_response.rb&lt;br /&gt;
*app/models/vm_question_response_row.rb&lt;br /&gt;
*app/views/grades/view_team.html.erb&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1819:_Improve_self_review,_link_self_and_peer_review_to_derive_grades#Score_Formulas Work done in Spring 2018]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1326 Pull Request]&lt;br /&gt;
#[https://www.youtube.com/watch?v=TBStYgnWiUI&amp;amp;feature=youtu.be Screencast video]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=121283</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=121283"/>
		<updated>2018-12-08T01:16:42Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Method to calculate Composite Score */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, self review is basically asking each team member in the group to evaluate their project on the same criteria as peer review, these self-review scores do not have much functionality currently. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score(composite score) between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Make sure that the peer-reviews should not be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Use case Diagram===&lt;br /&gt;
[[File:E1799_design_2.jpg]]&lt;br /&gt;
&lt;br /&gt;
Actors:&lt;br /&gt;
&lt;br /&gt;
    Instructor: This actor is responsible for creating assignments and adding students to the assignment. &lt;br /&gt;
    Student: This actor is responsible for submitting, self-reviewing and viewing the scores. &lt;br /&gt;
&lt;br /&gt;
All the other use cases are implemented except “View Scores with self-review column and composite score”&lt;br /&gt;
&lt;br /&gt;
'''Use Case: View score with self-review column and composite score'''&lt;br /&gt;
&lt;br /&gt;
Preconditions:&lt;br /&gt;
&lt;br /&gt;
   1.The Instructor creates Assignments and checks the Allow Self Review check box in the Assignment&lt;br /&gt;
   2.The Student should submit the assignment and self-review.&lt;br /&gt;
   3.The other students should submit the reviews of the work submitted.&lt;br /&gt;
&lt;br /&gt;
Student Sequence:&lt;br /&gt;
&lt;br /&gt;
   The student should login.&lt;br /&gt;
   The student should browse and upload the assignment.&lt;br /&gt;
   The student should submit the assignment.&lt;br /&gt;
   The student should submit the self-review.&lt;br /&gt;
   The student should choose your scores to view the score.&lt;br /&gt;
   The student should be able to see the peer-review score with the self-review scores and composite score.&lt;br /&gt;
&lt;br /&gt;
Post Conditions:&lt;br /&gt;
&lt;br /&gt;
   The self-review and composite score will be visible on the page.&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
The composite score is calculated using both self-review score and peer-review score (both are graded over 5 points for each criteria). &lt;br /&gt;
The composite score is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
   composite score = [10 - abs(self review score - peer review score)] * peer review score / 10&lt;br /&gt;
&lt;br /&gt;
By using this formula for calculating composite score we are discouraging students from either exaggerating or underrating their performance. The composite score model assigns more weight to the peer review score since the peer review score being used is the average of all peer review scores assigned and hence tends to be more appropriate than a single self review.&lt;br /&gt;
&lt;br /&gt;
Also this composite score formula gives the score on a scale which is identical to the scale of the self and peer review score. Thus this formula is not dependent on the scale of the self-review and peer-review score as it will also return the composite score on the same scale.&lt;br /&gt;
&lt;br /&gt;
For example: If someone gets an average peer review score of 3.5/5 and he gives 3.5/5 (self review score) while reviewing his project, then he will get a composite score of 3.5/5. And instead if the student reviews his project for 2/5 then the student will get a composite score of 2.975/5.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
As stated above the ability to do self reviews has already been implemented. This can be seen from the image shown below. The instructor has this ability to enable self reviews&lt;br /&gt;
.&lt;br /&gt;
&lt;br /&gt;
[[File:Oodd abhisu.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Our project is concerned with calculating the composite score and dispaying it in the view scores page along with other peer reviews and self review scores. We expect our final output to be in the form as shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Oodd document.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
This ensures that the student is not able to see his peer-review score before writing his self-review as the composite score takes into account the difference between the student peer-review and self-review score.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores.&lt;br /&gt;
This enables the student and instructor to view all his scores in one place.&lt;br /&gt;
* The composite score must be properly calculated.&lt;br /&gt;
The composite score must be calculated so as to give students more points if their self-review score is closer to the peer review score.&lt;br /&gt;
* Composite score must be visible in both view scores page and Alternate view.&lt;br /&gt;
The scores must be displayed in both the views.&lt;br /&gt;
&lt;br /&gt;
===Files Changed===&lt;br /&gt;
*app/controllers/grades_controller.rb&lt;br /&gt;
*app/models/response_map.rb&lt;br /&gt;
*app/models/vm_question_response.rb&lt;br /&gt;
*app/models/vm_question_response_row.rb&lt;br /&gt;
*app/views/grades/view_team.html.erb&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1819:_Improve_self_review,_link_self_and_peer_review_to_derive_grades#Score_Formulas Work done in Spring 2018]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1326 Pull Request]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=121281</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=121281"/>
		<updated>2018-12-08T01:15:14Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, self review is basically asking each team member in the group to evaluate their project on the same criteria as peer review, these self-review scores do not have much functionality currently. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score(composite score) between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Make sure that the peer-reviews should not be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Use case Diagram===&lt;br /&gt;
[[File:E1799_design_2.jpg]]&lt;br /&gt;
&lt;br /&gt;
Actors:&lt;br /&gt;
&lt;br /&gt;
    Instructor: This actor is responsible for creating assignments and adding students to the assignment. &lt;br /&gt;
    Student: This actor is responsible for submitting, self-reviewing and viewing the scores. &lt;br /&gt;
&lt;br /&gt;
All the other use cases are implemented except “View Scores with self-review column and composite score”&lt;br /&gt;
&lt;br /&gt;
'''Use Case: View score with self-review column and composite score'''&lt;br /&gt;
&lt;br /&gt;
Preconditions:&lt;br /&gt;
&lt;br /&gt;
   1.The Instructor creates Assignments and checks the Allow Self Review check box in the Assignment&lt;br /&gt;
   2.The Student should submit the assignment and self-review.&lt;br /&gt;
   3.The other students should submit the reviews of the work submitted.&lt;br /&gt;
&lt;br /&gt;
Student Sequence:&lt;br /&gt;
&lt;br /&gt;
   The student should login.&lt;br /&gt;
   The student should browse and upload the assignment.&lt;br /&gt;
   The student should submit the assignment.&lt;br /&gt;
   The student should submit the self-review.&lt;br /&gt;
   The student should choose your scores to view the score.&lt;br /&gt;
   The student should be able to see the peer-review score with the self-review scores and composite score.&lt;br /&gt;
&lt;br /&gt;
Post Conditions:&lt;br /&gt;
&lt;br /&gt;
   The self-review and composite score will be visible on the page.&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
The composite score is calculated using both self-review score and peer-review score (both are graded over 5 points for each criteria). &lt;br /&gt;
The composite score is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
   composite score = [10 - abs(self review score - peer review score)] * peer review score / 10&lt;br /&gt;
&lt;br /&gt;
By using this formula for calculating composite score we are discouraging students from either exaggerating or underrating their performance. The composite score model assigns more weight to the peer review score since the peer review score being used is the average of all peer review scores assigned and hence tends to be more appropriate than a single self review.&lt;br /&gt;
&lt;br /&gt;
Also this composite score formula gives a score on a scale which is identical to the scale of the self and peer review score.&lt;br /&gt;
&lt;br /&gt;
For example: If someone gets an average peer review score of 3.5/5 and he gives 3.5/5 (self review score) while reviewing his project, then he will get a composite score of 3.5/5. And instead if the student reviews his project for 2/5 then the student will get a composite score of 2.975/5.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
As stated above the ability to do self reviews has already been implemented. This can be seen from the image shown below. The instructor has this ability to enable self reviews&lt;br /&gt;
.&lt;br /&gt;
&lt;br /&gt;
[[File:Oodd abhisu.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Our project is concerned with calculating the composite score and dispaying it in the view scores page along with other peer reviews and self review scores. We expect our final output to be in the form as shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Oodd document.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
This ensures that the student is not able to see his peer-review score before writing his self-review as the composite score takes into account the difference between the student peer-review and self-review score.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores.&lt;br /&gt;
This enables the student and instructor to view all his scores in one place.&lt;br /&gt;
* The composite score must be properly calculated.&lt;br /&gt;
The composite score must be calculated so as to give students more points if their self-review score is closer to the peer review score.&lt;br /&gt;
* Composite score must be visible in both view scores page and Alternate view.&lt;br /&gt;
The scores must be displayed in both the views.&lt;br /&gt;
&lt;br /&gt;
===Files Changed===&lt;br /&gt;
*app/controllers/grades_controller.rb&lt;br /&gt;
*app/models/response_map.rb&lt;br /&gt;
*app/models/vm_question_response.rb&lt;br /&gt;
*app/models/vm_question_response_row.rb&lt;br /&gt;
*app/views/grades/view_team.html.erb&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1819:_Improve_self_review,_link_self_and_peer_review_to_derive_grades#Score_Formulas Work done in Spring 2018]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1326 Pull Request]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=121220</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=121220"/>
		<updated>2018-12-07T22:34:08Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, self review is basically asking each team member in the group to evaluate their project on the same criteria as peer review, these self-review scores do not have much functionality currently. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score(composite score) between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Make sure that the peer-reviews should not be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Use case Diagram===&lt;br /&gt;
[[File:E1799_design_2.jpg]]&lt;br /&gt;
&lt;br /&gt;
Actors:&lt;br /&gt;
&lt;br /&gt;
    Instructor: This actor is responsible for creating assignments and adding students to the assignment. &lt;br /&gt;
    Student: This actor is responsible for submitting, self-reviewing and viewing the scores. &lt;br /&gt;
&lt;br /&gt;
All the other use cases are implemented except “View Scores with self-review column and composite score”&lt;br /&gt;
&lt;br /&gt;
'''Use Case: View score with self-review column and composite score'''&lt;br /&gt;
&lt;br /&gt;
Preconditions:&lt;br /&gt;
&lt;br /&gt;
   1.The Instructor creates Assignments and checks the Allow Self Review check box in the Assignment&lt;br /&gt;
   2.The Student should submit the assignment and self-review.&lt;br /&gt;
   3.The other students should submit the reviews of the work submitted.&lt;br /&gt;
&lt;br /&gt;
Student Sequence:&lt;br /&gt;
&lt;br /&gt;
   The student should login.&lt;br /&gt;
   The student should browse and upload the assignment.&lt;br /&gt;
   The student should submit the assignment.&lt;br /&gt;
   The student should submit the self-review.&lt;br /&gt;
   The student should choose your scores to view the score.&lt;br /&gt;
   The student should be able to see the peer-review score with the self-review scores and composite score.&lt;br /&gt;
&lt;br /&gt;
Post Conditions:&lt;br /&gt;
&lt;br /&gt;
   The self-review and composite score will be visible on the page.&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
The composite score is calculated using both self-review score and peer-review score (both are graded over 5 points for each criteria). &lt;br /&gt;
The composite score is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
   composite score = [10 - abs(self review score - peer review score)] * peer review score / 10&lt;br /&gt;
&lt;br /&gt;
By using this formula for calculating composite score we are discouraging students from either exaggerating or underrating their performance. The composite score model assigns more weight to the peer review score since the peer review score being used is the average of all peer review scores assigned and hence tends to be more appropriate than a single self review.&lt;br /&gt;
&lt;br /&gt;
Also this composite score formula gives a score on a scale which is identical to the scale of the self and peer review score.&lt;br /&gt;
&lt;br /&gt;
For example: If someone gets an average peer review score of 3.5/5 and he gives 3.5/5 (self review score) while reviewing his project, then he will get a composite score of 3.5/5. And instead if the student reviews his project for 2/5 then the student will get a composite score of 2.975/5.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
As stated above the ability to do self reviews has already been implemented. This can be seen from the image shown below. The instructor has this ability to enable self reviews&lt;br /&gt;
.&lt;br /&gt;
&lt;br /&gt;
[[File:Oodd abhisu.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Our project is concerned with calculating the composite score and dispaying it in the view scores page along with other peer reviews and self review scores. We expect our final output to be in the form as shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Oodd document.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores.&lt;br /&gt;
* The composite score must be properly calculated.&lt;br /&gt;
* Composite score must be visible in both view scores page and Alternate view.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1819:_Improve_self_review,_link_self_and_peer_review_to_derive_grades#Score_Formulas Work done in Spring 2018]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1326 Pull Request]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=121219</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=121219"/>
		<updated>2018-12-07T22:32:30Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Method to calculate Composite Score */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, self review is basically asking each team member in the group to evaluate their project on the same criteria as peer review, these self-review scores do not have much functionality currently. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score(composite score) between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Make sure that the peer-reviews should not be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Use case Diagram===&lt;br /&gt;
[[File:E1799_design_2.jpg]]&lt;br /&gt;
&lt;br /&gt;
Actors:&lt;br /&gt;
&lt;br /&gt;
    Instructor: This actor is responsible for creating assignments and adding students to the assignment. &lt;br /&gt;
    Student: This actor is responsible for submitting, self-reviewing and viewing the scores. &lt;br /&gt;
&lt;br /&gt;
All the other use cases are implemented except “View Scores with self-review column and composite score”&lt;br /&gt;
&lt;br /&gt;
'''Use Case: View score with self-review column and composite score'''&lt;br /&gt;
&lt;br /&gt;
Preconditions:&lt;br /&gt;
&lt;br /&gt;
   1.The Instructor creates Assignments and checks the Allow Self Review check box in the Assignment&lt;br /&gt;
   2.The Student should submit the assignment and self-review.&lt;br /&gt;
   3.The other students should submit the reviews of the work submitted.&lt;br /&gt;
&lt;br /&gt;
Student Sequence:&lt;br /&gt;
&lt;br /&gt;
   The student should login.&lt;br /&gt;
   The student should browse and upload the assignment.&lt;br /&gt;
   The student should submit the assignment.&lt;br /&gt;
   The student should submit the self-review.&lt;br /&gt;
   The student should choose your scores to view the score.&lt;br /&gt;
   The student should be able to see the peer-review score with the self-review scores and composite score.&lt;br /&gt;
&lt;br /&gt;
Post Conditions:&lt;br /&gt;
&lt;br /&gt;
   The self-review and composite score will be visible on the page.&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
The composite score is calculated using both self-review score and peer-review score (both are graded over 5 points for each criteria). &lt;br /&gt;
The composite score is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
   composite score = [10 - abs(self review score - peer review score)] * peer review score / 10&lt;br /&gt;
&lt;br /&gt;
By using this formula for calculating composite score we are discouraging students from either exaggerating or underrating their performance. The composite score model assigns more weight to the peer review score since the peer review score being used is the average of all peer review scores assigned and hence tends to be more appropriate than a single self review.&lt;br /&gt;
&lt;br /&gt;
Also this composite score formula gives a score on a scale which is identical to the scale of the self and peer review score.&lt;br /&gt;
&lt;br /&gt;
For example: If someone gets an average peer review score of 3.5/5 and he gives 3.5/5 (self review score) while reviewing his project, then he will get a composite score of 3.5/5. And instead if the student reviews his project for 2/5 then the student will get a composite score of 2.975/5.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
As stated above the ability to do self reviews has already been implemented. This can be seen from the image shown below. The instructor has this ability to enable self reviews&lt;br /&gt;
.&lt;br /&gt;
&lt;br /&gt;
[[File:Oodd abhisu.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Our project is concerned with calculating the composite score and dispaying it in the view scores page along with other peer reviews and self review scores. We expect our final output to be in the form as shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Oodd document.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores.&lt;br /&gt;
* The composite score must be properly calculated.&lt;br /&gt;
* Composite score must be visible in both view scores page and Alternate view.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1819:_Improve_self_review,_link_self_and_peer_review_to_derive_grades#Score_Formulas Work done in Spring 2018]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=120479</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=120479"/>
		<updated>2018-11-21T00:41:08Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, self review is basically asking each team member in the group to evaluate their project on the same criteria as peer review, these self-review scores do not have much functionality currently. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score(composite score) between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Make sure that the peer-reviews should not be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Use case Diagram===&lt;br /&gt;
[[File:E1799_design_2.jpg]]&lt;br /&gt;
&lt;br /&gt;
Actors:&lt;br /&gt;
&lt;br /&gt;
    Instructor: This actor is responsible for creating assignments and adding students to the assignment. &lt;br /&gt;
    Student: This actor is responsible for submitting, self-reviewing and viewing the scores. &lt;br /&gt;
&lt;br /&gt;
All the other use cases are implemented except “View Scores with self-review column and composite score”&lt;br /&gt;
&lt;br /&gt;
'''Use Case: View score with self-review column and composite score'''&lt;br /&gt;
&lt;br /&gt;
Preconditions:&lt;br /&gt;
&lt;br /&gt;
   1.The Instructor creates Assignments and checks the Allow Self Review check box in the Assignment&lt;br /&gt;
   2.The Student should submit the assignment and self-review.&lt;br /&gt;
   3.The other students should submit the reviews of the work submitted.&lt;br /&gt;
&lt;br /&gt;
Student Sequence:&lt;br /&gt;
&lt;br /&gt;
   The student should login.&lt;br /&gt;
   The student should browse and upload the assignment.&lt;br /&gt;
   The student should submit the assignment.&lt;br /&gt;
   The student should submit the self-review.&lt;br /&gt;
   The student should choose your scores to view the score.&lt;br /&gt;
   The student should be able to see the peer-review score with the self-review scores and composite score.&lt;br /&gt;
&lt;br /&gt;
Post Conditions:&lt;br /&gt;
&lt;br /&gt;
   The self-review and composite score will be visible on the page.&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
The composite score is calculated using both self-review score and peer-review score (both are graded over 5 points for each criteria). &lt;br /&gt;
The composite score is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
   composite score = [10 - abs(self review score - peer review score)] * peer review score / 10&lt;br /&gt;
&lt;br /&gt;
By using this formula for calculating composite score we are discouraging students from either exaggerating or underrating their performance. The composite score model assigns more weight to the peer review score since the peer review score being used is the average of all peer review scores assigned and hence tends to be more appropriate than a single self review.&lt;br /&gt;
&lt;br /&gt;
For example: If someone gets an average peer review score of 3.5/5 and he gives 3.5/5 (self review score) while reviewing his project, then he will get a composite score of 3.5/5. And instead if the student reviews his project for 2/5 then the student will get a composite score of 2.975/5.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
As stated above the ability to do self reviews has already been implemented. This can be seen from the image shown below. The instructor has this ability to enable self reviews&lt;br /&gt;
.&lt;br /&gt;
&lt;br /&gt;
[[File:Oodd abhisu.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Our project is concerned with calculating the composite score and dispaying it in the view scores page along with other peer reviews and self review scores. We expect our final output to be in the form as shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Oodd document.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores.&lt;br /&gt;
* The composite score must be properly calculated.&lt;br /&gt;
* Composite score must be visible in both view scores page and Alternate view.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1819:_Improve_self_review,_link_self_and_peer_review_to_derive_grades#Score_Formulas Work done in Spring 2018]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=120478</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=120478"/>
		<updated>2018-11-21T00:40:52Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, self review is basically asking each team member in the group to evaluate their project on the same criteria as peer review, these self-review scores do not have much functionality currently. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score(composite score) between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Make sure that the peer-reviews should not be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Use case Diagram===&lt;br /&gt;
[[File:E1799_design_2.jpg]]&lt;br /&gt;
&lt;br /&gt;
Actors:&lt;br /&gt;
&lt;br /&gt;
    Instructor: This actor is responsible for creating assignments and adding students to the assignment. &lt;br /&gt;
    Student: This actor is responsible for submitting, self-reviewing and viewing the scores. &lt;br /&gt;
&lt;br /&gt;
All the other use cases are implemented except “View Scores with self-review column and composite score”&lt;br /&gt;
&lt;br /&gt;
'''Use Case: View score with self-review column and composite score'''&lt;br /&gt;
&lt;br /&gt;
Preconditions:&lt;br /&gt;
&lt;br /&gt;
   1.The Instructor creates Assignments and checks the Allow Self Review check box in the Assignment&lt;br /&gt;
   2.The Student should submit the assignment and self-review.&lt;br /&gt;
   3.The other students should submit the reviews of the work submitted.&lt;br /&gt;
&lt;br /&gt;
Student Sequence:&lt;br /&gt;
&lt;br /&gt;
   The student should login.&lt;br /&gt;
   The student should browse and upload the assignment.&lt;br /&gt;
   The student should submit the assignment.&lt;br /&gt;
   The student should submit the self-review.&lt;br /&gt;
   The student should choose your scores to view the score.&lt;br /&gt;
   The student should be able to see the peer-review score with the self-review scores and composite score.&lt;br /&gt;
&lt;br /&gt;
Post Conditions:&lt;br /&gt;
&lt;br /&gt;
   The self-review and composite score will be visible on the page.&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
The composite score is calculated using both self-review score and peer-review score (both are graded over 5 points for each criteria). &lt;br /&gt;
The composite score is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
   composite score = [10 - abs(self review score - peer review score)] * peer review score / 10&lt;br /&gt;
&lt;br /&gt;
By using this formula for calculating composite score we are discouraging students from either exaggerating or underrating their performance. The composite score model assigns more weight to the peer review score since the peer review score being used is the average of all peer review scores assigned and hence tends to be more appropriate than a single self review.&lt;br /&gt;
&lt;br /&gt;
For example: If someone gets an average peer review score of 3.5/5 and he gives 3.5/5 (self review score) while reviewing his project, then he will get a composite score of 3.5/5. And instead if the student reviews his project for 2/5 then the student will get a composite score of 2.975/5.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
As stated above the ability to do self reviews has already been implemented. This can be seen from the image shown below. The instructor has this ability to enable self reviews&lt;br /&gt;
.&lt;br /&gt;
[[File:Oodd abhisu.PNG]]&lt;br /&gt;
&lt;br /&gt;
Our project is concerned with calculating the composite score and dispaying it in the view scores page along with other peer reviews and self review scores. We expect our final output to be in the form as shown below.&lt;br /&gt;
&lt;br /&gt;
[[File:Oodd document.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores.&lt;br /&gt;
* The composite score must be properly calculated.&lt;br /&gt;
* Composite score must be visible in both view scores page and Alternate view.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1819:_Improve_self_review,_link_self_and_peer_review_to_derive_grades#Score_Formulas Work done in Spring 2018]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=120234</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=120234"/>
		<updated>2018-11-19T23:58:41Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Use case Diagram */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, self review is basically asking each team member in the group to evaluate their project on the same criteria as peer review, these self-review scores do not have much functionality currently. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score(composite score) between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Make sure that the peer-reviews should not be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Use case Diagram===&lt;br /&gt;
[[File:E1799_design_2.jpg]]&lt;br /&gt;
&lt;br /&gt;
Actors:&lt;br /&gt;
&lt;br /&gt;
    Instructor: This actor is responsible for creating assignments and adding students to the assignment. &lt;br /&gt;
    Student: This actor is responsible for submitting, self-reviewing and viewing the scores. &lt;br /&gt;
&lt;br /&gt;
Database:&lt;br /&gt;
&lt;br /&gt;
    The database where all the data of Expertiza is getting stored. &lt;br /&gt;
&lt;br /&gt;
All the other use cases are implemented except “View Scores with self-review column and composite score”&lt;br /&gt;
&lt;br /&gt;
'''Use Case: View score with self-review column and composite score'''&lt;br /&gt;
&lt;br /&gt;
PreConditions:&lt;br /&gt;
&lt;br /&gt;
   1.The Student should submit the assignment and self-review.&lt;br /&gt;
   2.The other students should submit the reviews of the work submitted.&lt;br /&gt;
&lt;br /&gt;
Primary Sequence:&lt;br /&gt;
&lt;br /&gt;
   The student should login.&lt;br /&gt;
   The student should browse and upload the assignment.&lt;br /&gt;
   The student should submit the assignment.&lt;br /&gt;
   The student should submit the self-review.&lt;br /&gt;
   The student should choose your scores to view the score.&lt;br /&gt;
   The student should be able to see the peer-review score with the self-review scores and composite score.&lt;br /&gt;
&lt;br /&gt;
Post Conditions:&lt;br /&gt;
&lt;br /&gt;
   The self-review and composite score will be visible on the page.&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
The composite score is calculated using both self-review score and peer-review score (both are graded over 5 points for each criteria). &lt;br /&gt;
The composite score is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
   composite score = [100 - abs(self review score - peer review score)] * peer review score / 100&lt;br /&gt;
&lt;br /&gt;
By using this formula for calculating composite score we are discouraging students from either exaggerating or underrating their performance. However, the composite score model penalizes students who exaggerate their performance much more compared to students who underrate their work.&lt;br /&gt;
&lt;br /&gt;
For example: If someone gets an average peer review score of 3.5/5 and he reviews his project for 3.5/5, then he will get a full composite score of 5.And if the student reviews his project for 2.5/5 then the student will get a composite score of 4.5,but if the same student reviews his project for 4.5/5 then by using the formulae the student gets a composite score of 4. In this way, students are penalized more for overestimating their score than underestimating their score.&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores.&lt;br /&gt;
* The composite score must be properly calculated.&lt;br /&gt;
* Composite score must be visible in both view scores page and Alternate view.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1819:_Improve_self_review,_link_self_and_peer_review_to_derive_grades#Score_Formulas Work done in Spring 2018]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=120233</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=120233"/>
		<updated>2018-11-19T23:54:02Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Method to calculate Composite Score */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, self review is basically asking each team member in the group to evaluate their project on the same criteria as peer review, these self-review scores do not have much functionality currently. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score(composite score) between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Make sure that the peer-reviews should not be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Use case Diagram===&lt;br /&gt;
[[File:E1854_UseCase_Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
Actors:&lt;br /&gt;
&lt;br /&gt;
    Instructor: This actor is responsible for creating assignments and adding students to the assignment. &lt;br /&gt;
    Student: This actor is responsible for submitting, self-reviewing and viewing the scores. &lt;br /&gt;
&lt;br /&gt;
Database:&lt;br /&gt;
&lt;br /&gt;
    The database where all the data of Expertiza is getting stored. &lt;br /&gt;
&lt;br /&gt;
All the other use cases are implemented except “View Scores with self-review column and composite score”&lt;br /&gt;
&lt;br /&gt;
'''Use Case: View score with self-review column and composite score'''&lt;br /&gt;
&lt;br /&gt;
PreConditions:&lt;br /&gt;
&lt;br /&gt;
   1.The Student should submit the assignment and self-review.&lt;br /&gt;
   2.The other students should submit the reviews of the work submitted.&lt;br /&gt;
&lt;br /&gt;
Primary Sequence:&lt;br /&gt;
&lt;br /&gt;
   The student should login.&lt;br /&gt;
   The student should browse and upload the assignment.&lt;br /&gt;
   The student should submit the assignment.&lt;br /&gt;
   The student should submit the self-review.&lt;br /&gt;
   The student should choose your scores to view the score.&lt;br /&gt;
   The student should be able to see the peer-review score with the self-review scores and composite score.&lt;br /&gt;
&lt;br /&gt;
Post Conditions:&lt;br /&gt;
&lt;br /&gt;
   The self-review and composite score will be visible on the page.&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
The composite score is calculated using both self-review score and peer-review score (both are graded over 5 points for each criteria). &lt;br /&gt;
The composite score is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
   composite score = [100 - abs(self review score - peer review score)] * peer review score / 100&lt;br /&gt;
&lt;br /&gt;
By using this formula for calculating composite score we are discouraging students from either exaggerating or underrating their performance. However, the composite score model penalizes students who exaggerate their performance much more compared to students who underrate their work.&lt;br /&gt;
&lt;br /&gt;
For example: If someone gets an average peer review score of 3.5/5 and he reviews his project for 3.5/5, then he will get a full composite score of 5.And if the student reviews his project for 2.5/5 then the student will get a composite score of 4.5,but if the same student reviews his project for 4.5/5 then by using the formulae the student gets a composite score of 4. In this way, students are penalized more for overestimating their score than underestimating their score.&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores.&lt;br /&gt;
* The composite score must be properly calculated.&lt;br /&gt;
* Composite score must be visible in both view scores page and Alternate view.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1819:_Improve_self_review,_link_self_and_peer_review_to_derive_grades#Score_Formulas Work done in Spring 2018]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=120232</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=120232"/>
		<updated>2018-11-19T23:51:16Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Use case Diagram */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, self review is basically asking each team member in the group to evaluate their project on the same criteria as peer review, these self-review scores do not have much functionality currently. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score(composite score) between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Make sure that the peer-reviews should not be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Use case Diagram===&lt;br /&gt;
[[File:E1854_UseCase_Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
Actors:&lt;br /&gt;
&lt;br /&gt;
    Instructor: This actor is responsible for creating assignments and adding students to the assignment. &lt;br /&gt;
    Student: This actor is responsible for submitting, self-reviewing and viewing the scores. &lt;br /&gt;
&lt;br /&gt;
Database:&lt;br /&gt;
&lt;br /&gt;
    The database where all the data of Expertiza is getting stored. &lt;br /&gt;
&lt;br /&gt;
All the other use cases are implemented except “View Scores with self-review column and composite score”&lt;br /&gt;
&lt;br /&gt;
'''Use Case: View score with self-review column and composite score'''&lt;br /&gt;
&lt;br /&gt;
PreConditions:&lt;br /&gt;
&lt;br /&gt;
   1.The Student should submit the assignment and self-review.&lt;br /&gt;
   2.The other students should submit the reviews of the work submitted.&lt;br /&gt;
&lt;br /&gt;
Primary Sequence:&lt;br /&gt;
&lt;br /&gt;
   The student should login.&lt;br /&gt;
   The student should browse and upload the assignment.&lt;br /&gt;
   The student should submit the assignment.&lt;br /&gt;
   The student should submit the self-review.&lt;br /&gt;
   The student should choose your scores to view the score.&lt;br /&gt;
   The student should be able to see the peer-review score with the self-review scores and composite score.&lt;br /&gt;
&lt;br /&gt;
Post Conditions:&lt;br /&gt;
&lt;br /&gt;
   The self-review and composite score will be visible on the page.&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
The composite score is calculated using both self-review score and peer-review score (both are graded over 5 points for each criteria). &lt;br /&gt;
The composite score is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
   composite score = [100 -abs(self review score - peer review score)] * peer review score / 100&lt;br /&gt;
&lt;br /&gt;
By using this formula for calculating composite score we are discouraging students from either exaggerating or underrating their performance. However, the composite score model penalizes students who exaggerate their performance much more compared to students who underrate their work.&lt;br /&gt;
&lt;br /&gt;
For example: If someone gets an average peer review score of 3.5/5 and he reviews his project for 3.5/5, then he will get a full composite score of 5.And if the student reviews his project for 2.5/5 then the student will get a composite score of 4.5,but if the same student reviews his project for 4.5/5 then by using the formulae the student gets a composite score of 4. In this way, students are penalized more for overestimating their score than underestimating their score.&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores.&lt;br /&gt;
* The composite score must be properly calculated.&lt;br /&gt;
* Composite score must be visible in both view scores page and Alternate view.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1819:_Improve_self_review,_link_self_and_peer_review_to_derive_grades#Score_Formulas Work done in Spring 2018]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=120231</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=120231"/>
		<updated>2018-11-19T23:50:10Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Method to calculate Composite Score */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, self review is basically asking each team member in the group to evaluate their project on the same criteria as peer review, these self-review scores do not have much functionality currently. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score(composite score) between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Make sure that the peer-reviews should not be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Use case Diagram===&lt;br /&gt;
http://wiki.expertiza.ncsu.edu/images/f/fa/E1854_UseCase_Diagram.png&lt;br /&gt;
&lt;br /&gt;
Actors:&lt;br /&gt;
&lt;br /&gt;
    Instructor: This actor is responsible for creating assignments and adding students to the assignment. &lt;br /&gt;
    Student: This actor is responsible for submitting, self-reviewing and viewing the scores. &lt;br /&gt;
&lt;br /&gt;
Database:&lt;br /&gt;
&lt;br /&gt;
    The database where all the data of Expertiza is getting stored. &lt;br /&gt;
&lt;br /&gt;
All the other use cases are implemented except “View Scores with self-review column and composite score”&lt;br /&gt;
&lt;br /&gt;
'''Use Case: View score with self-review column and composite score'''&lt;br /&gt;
&lt;br /&gt;
PreConditions:&lt;br /&gt;
&lt;br /&gt;
   1.The Student should submit the assignment and self-review.&lt;br /&gt;
   2.The other students should submit the reviews of the work submitted.&lt;br /&gt;
&lt;br /&gt;
Primary Sequence:&lt;br /&gt;
&lt;br /&gt;
   The student should login.&lt;br /&gt;
   The student should browse and upload the assignment.&lt;br /&gt;
   The student should submit the assignment.&lt;br /&gt;
   The student should submit the self-review.&lt;br /&gt;
   The student should choose your scores to view the score.&lt;br /&gt;
   The student should be able to see the peer-review score with the self-review scores and composite score.&lt;br /&gt;
&lt;br /&gt;
Post Conditions:&lt;br /&gt;
&lt;br /&gt;
   The self-review and composite score will be visible on the page.&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
The composite score is calculated using both self-review score and peer-review score (both are graded over 5 points for each criteria). &lt;br /&gt;
The composite score is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
   composite score = [100 -abs(self review score - peer review score)] * peer review score / 100&lt;br /&gt;
&lt;br /&gt;
By using this formula for calculating composite score we are discouraging students from either exaggerating or underrating their performance. However, the composite score model penalizes students who exaggerate their performance much more compared to students who underrate their work.&lt;br /&gt;
&lt;br /&gt;
For example: If someone gets an average peer review score of 3.5/5 and he reviews his project for 3.5/5, then he will get a full composite score of 5.And if the student reviews his project for 2.5/5 then the student will get a composite score of 4.5,but if the same student reviews his project for 4.5/5 then by using the formulae the student gets a composite score of 4. In this way, students are penalized more for overestimating their score than underestimating their score.&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores.&lt;br /&gt;
* The composite score must be properly calculated.&lt;br /&gt;
* Composite score must be visible in both view scores page and Alternate view.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1819:_Improve_self_review,_link_self_and_peer_review_to_derive_grades#Score_Formulas Work done in Spring 2018]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=120230</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=120230"/>
		<updated>2018-11-19T23:49:57Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Method to calculate Composite Score */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, self review is basically asking each team member in the group to evaluate their project on the same criteria as peer review, these self-review scores do not have much functionality currently. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score(composite score) between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Make sure that the peer-reviews should not be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Use case Diagram===&lt;br /&gt;
http://wiki.expertiza.ncsu.edu/images/f/fa/E1854_UseCase_Diagram.png&lt;br /&gt;
&lt;br /&gt;
Actors:&lt;br /&gt;
&lt;br /&gt;
    Instructor: This actor is responsible for creating assignments and adding students to the assignment. &lt;br /&gt;
    Student: This actor is responsible for submitting, self-reviewing and viewing the scores. &lt;br /&gt;
&lt;br /&gt;
Database:&lt;br /&gt;
&lt;br /&gt;
    The database where all the data of Expertiza is getting stored. &lt;br /&gt;
&lt;br /&gt;
All the other use cases are implemented except “View Scores with self-review column and composite score”&lt;br /&gt;
&lt;br /&gt;
'''Use Case: View score with self-review column and composite score'''&lt;br /&gt;
&lt;br /&gt;
PreConditions:&lt;br /&gt;
&lt;br /&gt;
   1.The Student should submit the assignment and self-review.&lt;br /&gt;
   2.The other students should submit the reviews of the work submitted.&lt;br /&gt;
&lt;br /&gt;
Primary Sequence:&lt;br /&gt;
&lt;br /&gt;
   The student should login.&lt;br /&gt;
   The student should browse and upload the assignment.&lt;br /&gt;
   The student should submit the assignment.&lt;br /&gt;
   The student should submit the self-review.&lt;br /&gt;
   The student should choose your scores to view the score.&lt;br /&gt;
   The student should be able to see the peer-review score with the self-review scores and composite score.&lt;br /&gt;
&lt;br /&gt;
Post Conditions:&lt;br /&gt;
&lt;br /&gt;
   The self-review and composite score will be visible on the page.&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
The composite score is calculated using both self-review score and peer-review score (both are graded over 5 points for each criteria). &lt;br /&gt;
The composite score is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
   composite score= [100 -abs(self review score - peer review score)] * peer review score / 100&lt;br /&gt;
&lt;br /&gt;
By using this formula for calculating composite score we are discouraging students from either exaggerating or underrating their performance. However, the composite score model penalizes students who exaggerate their performance much more compared to students who underrate their work.&lt;br /&gt;
&lt;br /&gt;
For example: If someone gets an average peer review score of 3.5/5 and he reviews his project for 3.5/5, then he will get a full composite score of 5.And if the student reviews his project for 2.5/5 then the student will get a composite score of 4.5,but if the same student reviews his project for 4.5/5 then by using the formulae the student gets a composite score of 4. In this way, students are penalized more for overestimating their score than underestimating their score.&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores.&lt;br /&gt;
* The composite score must be properly calculated.&lt;br /&gt;
* Composite score must be visible in both view scores page and Alternate view.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1819:_Improve_self_review,_link_self_and_peer_review_to_derive_grades#Score_Formulas Work done in Spring 2018]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=120217</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=120217"/>
		<updated>2018-11-19T23:01:00Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Method to calculate Composite Score */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, however, these self-review scores do not have much functionality. In the current system, self-review scores are created and stored, but are not used afterwards. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Make sure that the peer-reviews should not be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Use case Diagram===&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
The composite score is calculated using both self-review score and peer-review score (both are graded over 5 points for each criteria). &lt;br /&gt;
The composite score is calculated as follows:&lt;br /&gt;
&lt;br /&gt;
If self review score &amp;gt; peer review score&lt;br /&gt;
   composite score= 5 -[self review score - peer review score]&lt;br /&gt;
If self review score &amp;lt;= peer review score&lt;br /&gt;
   composite score= 5 -[(peer review score - self review score)/2]&lt;br /&gt;
By using this formula for calculating composite score we are discouraging students from either exaggerating or underrating their performance. However, the composite score model penalizes students who exaggerate their performance much more compared to students who underrate their work.&lt;br /&gt;
&lt;br /&gt;
For example: If someone gets an average peer review score of 3.5/5 and he reviews his project for 3.5/5, then he will get a full composite score of 5.And if the student reviews his project for 2.5/5 then the student will get a composite score of 4.5,but if the same student reviews his project for 4.5/5 then by using the formulae the student gets a composite score of 4. In this way, students are penalized more for overestimating their score than underestimating their score.&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores.&lt;br /&gt;
* The composite score must be properly calculated.&lt;br /&gt;
* Composite score must be visible in both view scores page and Alternate view.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1819:_Improve_self_review,_link_self_and_peer_review_to_derive_grades#Score_Formulas Work done in Spring 2018]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119764</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119764"/>
		<updated>2018-11-13T21:14:40Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, however, these self-review scores do not have much functionality. In the current system, self-review scores are created and stored, but are not used afterwards. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Make sure that the peer-reviews should not be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores.&lt;br /&gt;
* The composite score must be properly calculated.&lt;br /&gt;
* Composite score must be visible in both view scores page and Alternate view.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1819:_Improve_self_review,_link_self_and_peer_review_to_derive_grades#Score_Formulas Work done in Spring 2018]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119763</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119763"/>
		<updated>2018-11-13T21:12:31Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Problem Statement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, however, these self-review scores do not have much functionality. In the current system, self-review scores are created and stored, but are not used afterwards. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Make sure that the peer-reviews should not be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
* Peer-reviews can be viewed immediately when self-reviews are not required.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1819:_Improve_self_review,_link_self_and_peer_review_to_derive_grades#Score_Formulas Work done in Spring 2018]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119762</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119762"/>
		<updated>2018-11-13T21:09:55Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, however, these self-review scores do not have much functionality. In the current system, self-review scores are created and stored, but are not used afterwards. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Allow instructors to decide if peer-reviews should be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
* Peer-reviews can be viewed immediately when self-reviews are not required.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1819:_Improve_self_review,_link_self_and_peer_review_to_derive_grades#Score_Formulas Work done in Spring 2018]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119761</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119761"/>
		<updated>2018-11-13T21:09:00Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, however, these self-review scores do not have much functionality. In the current system, self-review scores are created and stored, but are not used afterwards. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Allow instructors to decide if peer-reviews should be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Method to calculate Composite Score===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Test Plan===&lt;br /&gt;
Test cases are as follows:&lt;br /&gt;
* Peer-reviews cannot be viewed before a self-review is completed.&lt;br /&gt;
* Peer-reviews can be viewed immediately when self-reviews are not required.&lt;br /&gt;
* The derived scores can be saved to the database.&lt;br /&gt;
* Self-review scores are displayed with peer-review scores&lt;br /&gt;
* Student can only see their own self-review&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Spring_2018-_Project_E1819:_Improve_self_review,_link_self_and_peer_review_to_derive_grades#Score_Formulas Work done in Spring 2018]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119756</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119756"/>
		<updated>2018-11-13T21:02:59Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, however, these self-review scores do not have much functionality. In the current system, self-review scores are created and stored, but are not used afterwards. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Allow instructors to decide if peer-reviews should be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119753</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119753"/>
		<updated>2018-11-13T21:01:40Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Plan of Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Introduction===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, however, these self-review scores do not have much functionality. In the current system, self-review scores are created and stored, but are not used afterwards. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Allow instructors to decide if peer-reviews should be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119752</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119752"/>
		<updated>2018-11-13T20:58:01Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based Semester project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Introduction===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, however, these self-review scores do not have much functionality. In the current system, self-review scores are created and stored, but are not used afterwards. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Allow instructors to decide if peer-reviews should be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Plan of Work===&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119750</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119750"/>
		<updated>2018-11-13T20:57:29Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Introduction===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, however, these self-review scores do not have much functionality. In the current system, self-review scores are created and stored, but are not used afterwards. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Allow instructors to decide if peer-reviews should be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.\&lt;br /&gt;
&lt;br /&gt;
===Plan of Work===&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119749</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119749"/>
		<updated>2018-11-13T20:54:45Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Introduction===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, however, these self-review scores do not have much functionality. In the current system, self-review scores are created and stored, but are not used afterwards. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Allow instructors to decide if peer-reviews should be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;br /&gt;
&lt;br /&gt;
===Application Flow===&lt;br /&gt;
&lt;br /&gt;
[[File:E1799_design_1.jpg]]&lt;br /&gt;
&lt;br /&gt;
The instructor has to login and create an assignment by checking allow self review option. The instructor has to add the topic and assign students to the topic. Now, the student has to login and submit the assignment. The self review link is visible in the page. The student should give the self review. After giving the self review, the student should be able to see the peer review, self review and the composite score.&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119748</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119748"/>
		<updated>2018-11-13T20:53:23Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Introduction===&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, however, these self-review scores do not have much functionality. In the current system, self-review scores are created and stored, but are not used afterwards. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Allow instructors to decide if peer-reviews should be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119747</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119747"/>
		<updated>2018-11-13T20:53:15Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* About Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, however, these self-review scores do not have much functionality. In the current system, self-review scores are created and stored, but are not used afterwards. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Allow instructors to decide if peer-reviews should be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119746</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119746"/>
		<updated>2018-11-13T20:51:37Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* About Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, however, these self-review scores do not have much functionality. In the current system, self-review scores are created and stored, but are not used afterwards. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Allow instructors to decide if peer-reviews should be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119744</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119744"/>
		<updated>2018-11-13T20:50:49Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza has the ability to require self-reviews on projects, however, these self-review scores do not have much functionality. In the current system, self-review scores are created and stored, but are not used afterwards. This project seeks to improve upon the self-review system, and extend its functionality. The main points of this project are as follows:&lt;br /&gt;
*Create a method to calculate a derived score between self and peer-reviews. The closer the self-review is to the peer-review, the greater the score. Display this score on the &amp;quot;View Scores&amp;quot; page.&lt;br /&gt;
*Allow instructors to decide if peer-reviews should be visible before self-review completion. Display the correct review scores accordingly.&lt;br /&gt;
*Display the self-review scores in the &amp;quot;View Scores&amp;quot; and heat map of peer-reviews, denoting that they are a different type of review.&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119743</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119743"/>
		<updated>2018-11-13T20:49:30Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
&lt;br /&gt;
The purpose of the project is to improve self-review, link self review and peer review, to device a strategy to come up with the composite score.&lt;br /&gt;
&lt;br /&gt;
===Problem Definition===&lt;br /&gt;
&lt;br /&gt;
:1. Implementation of the concept to see self-review scores juxtaposed with peer-review scores.  Designing a way to show them in the regular “View Scores” page and the alternate (heat-map) view&lt;br /&gt;
&lt;br /&gt;
:2. Implementation of the methodology to combine self-review and peer-review scores to derive a composite score&lt;br /&gt;
&lt;br /&gt;
:3. Checking if the author has submitted the self-evaluation(s) before seeing the results of their peer evaluations(already implemented).&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119742</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119742"/>
		<updated>2018-11-13T20:47:30Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* E1836. Refactoring quiz_questionnaires_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1854. Improve self-review, Link peer review &amp;amp; self-review to derive grades==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854&amp;diff=119741</id>
		<title>CSC/ECE 517 Fall 2018 E1854</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854&amp;diff=119741"/>
		<updated>2018-11-13T20:45:07Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: moved CSC/ECE 517 Fall 2018 E1854 to CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp;amp; self-review to derive grades&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp;amp; self-review to derive grades]]&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119740</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119740"/>
		<updated>2018-11-13T20:45:07Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: moved CSC/ECE 517 Fall 2018 E1854 to CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp;amp; self-review to derive grades&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1836. Refactoring quiz_questionnaires_controller.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119739</id>
		<title>CSC/ECE 517 Fall 2018 E1854 Improve self-review, Link peer review &amp; self-review to derive grades</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1854_Improve_self-review,_Link_peer_review_%26_self-review_to_derive_grades&amp;diff=119739"/>
		<updated>2018-11-13T20:44:02Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: Created page with &amp;quot;==E1836. Refactoring quiz_questionnaires_controller.rb==  This page provides a description of the Expertiza based OSS project.   __TOC__   ===About Expertiza===  [http://expertiz...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1836. Refactoring quiz_questionnaires_controller.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119226</id>
		<title>CSC/ECE 517 Fall 2018 E1836 Refactor quiz questionnaires controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119226"/>
		<updated>2018-11-10T02:16:57Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Testing from UI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1836. Refactoring quiz_questionnaires_controller.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
* Created quiz_questionnaire_controller.rb&lt;br /&gt;
* Moved view_quiz, new_quiz, create_quiz_questionnaire, edit_quiz and update_quiz from questionnaires_controller.rb, to quiz_questionnaires_controller.rb, and renamed it as view, new, create, edit and update respectively.&lt;br /&gt;
* Refactored the the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* Replaced switch statements in questionnaires_controller.rb with subclass methods.&lt;br /&gt;
* Created models for the subclasses.&lt;br /&gt;
* Removed hardcoded parameters, such as save_choice method.&lt;br /&gt;
* Appropriate tests were written to test the code.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
'''Problem 1''': Create quiz_questionnaire_controller.rb and move some of the methods in the questionnaires_controller.rb to the new file created.&lt;br /&gt;
* '''Solution''': The methods view_quiz, new_quiz, create_quiz, edit_quiz and update_quiz in the questionnaires_controller.rb were the methods identified and moved into the quiz_questionnaire_controller.rb. They were respectively renamed as view, new, create, edit and update. The implementation of the newly created quiz_questionnaire_controller.rb can be seen below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class QuizQuestionnairesController &amp;lt; QuestionnairesController&lt;br /&gt;
&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
   # Separate methods for quiz questionnaire&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
&lt;br /&gt;
   # View a quiz questionnaire&lt;br /&gt;
   def view&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     @participant = Participant.find(params[:pid]) # creating an instance variable since it needs to be sent to submitted_content/edit&lt;br /&gt;
     render :view&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # define a new quiz questionnaire&lt;br /&gt;
   # method invoked by the view&lt;br /&gt;
   def new&lt;br /&gt;
     valid_request = true&lt;br /&gt;
     @assignment_id = params[:aid] # creating an instance variable to hold the assignment id&lt;br /&gt;
     @participant_id = params[:pid] # creating an instance variable to hold the participant id&lt;br /&gt;
     assignment = Assignment.find(@assignment_id)&lt;br /&gt;
     if !assignment.require_quiz? # flash error if this assignment does not require quiz&lt;br /&gt;
       flash[:error] = &amp;quot;This assignment does not support the quizzing feature.&amp;quot;&lt;br /&gt;
       valid_request = false&lt;br /&gt;
     else&lt;br /&gt;
       team = AssignmentParticipant.find(@participant_id).team&lt;br /&gt;
&lt;br /&gt;
       if team.nil? # flash error if this current participant does not have a team&lt;br /&gt;
         flash[:error] = &amp;quot;You should create or join a team first.&amp;quot;&lt;br /&gt;
         valid_request = false&lt;br /&gt;
       else&lt;br /&gt;
         if assignment.topics? &amp;amp;&amp;amp; team.topic.nil? # flash error if this assignment has topic but current team does not have a topic&lt;br /&gt;
           flash[:error] = &amp;quot;Your team should have a topic.&amp;quot;&lt;br /&gt;
           valid_request = false&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
     if valid_request &amp;amp;&amp;amp; Questionnaire::QUESTIONNAIRE_TYPES.include?(params[:model])&lt;br /&gt;
       @questionnaire = Object.const_get(params[:model]).new&lt;br /&gt;
       @questionnaire.private = params[:private]&lt;br /&gt;
       @questionnaire.min_question_score = 0&lt;br /&gt;
       @questionnaire.max_question_score = 1&lt;br /&gt;
&lt;br /&gt;
       render :new&lt;br /&gt;
     else&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # seperate method for creating a quiz questionnaire because of differences in permission&lt;br /&gt;
   def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # edit a quiz questionnaire&lt;br /&gt;
   def edit&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if !@questionnaire.taken_by_anyone?&lt;br /&gt;
       render :edit&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = &amp;quot;Your quiz has been taken by some other students, you cannot edit it anymore.&amp;quot;&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
   # save an updated quiz questionnaire to the database&lt;br /&gt;
   def update&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if @questionnaire.nil?&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
       return&lt;br /&gt;
     end&lt;br /&gt;
     if params['save'] &amp;amp;&amp;amp; params[:question].try(:keys)&lt;br /&gt;
       @questionnaire.update_attributes(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       for qid in params[:question].keys&lt;br /&gt;
         @question = Question.find(qid)&lt;br /&gt;
         @question.txt = params[:question][qid.to_sym][:txt]&lt;br /&gt;
         @question.save&lt;br /&gt;
&lt;br /&gt;
         @quiz_question_choices = QuizQuestionChoice.where(question_id: qid)&lt;br /&gt;
         i = 1&lt;br /&gt;
         for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
     redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 2''': Refactor the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* '''Solution''': &lt;br /&gt;
a. Deleted the create_questionnaire method and replaced the call to it in create_quiz_questionnaire with the code of create_questionnaire and is later moved to quiz_questionnaires_controller.rb and the code snippet below is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b. Moved the large block of for and if statements into method called change_question_types in the quiz_questionnaire model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
&lt;br /&gt;
	if type == &amp;quot;MultipleChoiceCheckbox&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][i.to_s]&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: params[:quiz_question_choices][id.to_s][type][i.to_s][:iscorrect], txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][quiz_question_choice.id.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;MultipleChoiceRadio&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][:correctindex] == i.to_s&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '1', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;TrueFalse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][1.to_s][:iscorrect] == &amp;quot;True&amp;quot; # the statement is correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is correct so &amp;quot;True&amp;quot; is the right answer&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            else # the statement is not correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is not correct so &amp;quot;False&amp;quot; is the right answer&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
c. Replaced large block of for and if statements in update with a call to the new change_question_types method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
d. Moved export, import, copy_questionnaire_details, and assign_instructor_id to questionaire model. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy_questionnaire_details(questions, orig_questionnaire, id)&lt;br /&gt;
    self.instructor_id = self.assign_instructor_id()&lt;br /&gt;
    self.name = 'Copy of ' + orig_questionnaire.name&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      self.created_at = Time.now&lt;br /&gt;
      self.save!&lt;br /&gt;
      questions.each do |question|&lt;br /&gt;
        new_question = question.dup&lt;br /&gt;
        new_question.questionnaire_id = id&lt;br /&gt;
        new_question.size = '50,3' if (new_question.is_a? Criterion or new_question.is_a? TextResponse) and new_question.size.nil?&lt;br /&gt;
        new_question.save!&lt;br /&gt;
        advices = QuestionAdvice.where(question_id: question.id)&lt;br /&gt;
        next if advices.empty?&lt;br /&gt;
        advices.each do |advice|&lt;br /&gt;
          new_advice = advice.dup&lt;br /&gt;
          new_advice.question_id = new_question.id&lt;br /&gt;
          new_advice.save!&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      pFolder = TreeFolder.find_by(name: question.set_display_type(display_type))&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: pFolder.id)&lt;br /&gt;
      QuestionnaireNode.find_or_create_by(parent_id: parent.id, node_object_id: id)&lt;br /&gt;
      undo_link(&amp;quot;Copy of questionnaire #{orig_questionnaire.name} has been created successfully.&amp;quot;)&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'view', id: @questionnaire.id&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'The questionnaire was not able to be copied. Please check the original course for missing information.' + $ERROR_INFO&lt;br /&gt;
      redirect_to action: 'list', controller: 'tree_display'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def export&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    csv_data = QuestionnaireHelper.create_questionnaire_csv @questionnaire, session[:user].name&lt;br /&gt;
    send_data csv_data,&lt;br /&gt;
              type: 'text/csv; charset=iso-8859-1; header=present',&lt;br /&gt;
              disposition: &amp;quot;attachment; filename=questionnaires.csv&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def import&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    file = params['csv']&lt;br /&gt;
    @questionnaire.questions &amp;lt;&amp;lt; QuestionnaireHelper.get_questions_from_csv(@questionnaire, file)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assign_instructor_id&lt;br /&gt;
    # if the user to copy the questionnaire is a TA, the instructor should be the owner instead of the TA&lt;br /&gt;
    if session[:user].role.name != &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      session[:user].id&lt;br /&gt;
    else # for TA we need to get his instructor id and by default add it to his course for which he is the TA&lt;br /&gt;
      Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3''': Replace switch statements with subclasses methods and create models for the subclasses.&lt;br /&gt;
* '''Solution''': Moved the switch-case statement from create in questionaire_controller.rb into a method called set_display_type in questionaire model. The following is the code snippet that shows the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  def set_dispay_type(display_type)&lt;br /&gt;
&lt;br /&gt;
      case display_type&lt;br /&gt;
&lt;br /&gt;
      when 'Review'&lt;br /&gt;
	display_type = 'Review'&lt;br /&gt;
&lt;br /&gt;
      when 'Metareview'&lt;br /&gt;
	display_type = 'Metareview'&lt;br /&gt;
&lt;br /&gt;
      when 'AuthorFeedback'&lt;br /&gt;
        display_type = 'Author%Feedback'&lt;br /&gt;
&lt;br /&gt;
      when 'CourseSurvey'&lt;br /&gt;
        display_type = 'Course%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'TeammateReview'&lt;br /&gt;
        display_type = 'Teammate%Review'&lt;br /&gt;
&lt;br /&gt;
      when 'GlobalSurvey'&lt;br /&gt;
        display_type = 'Global%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'AssignmentSurvey'&lt;br /&gt;
        display_type = 'Assignment%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'Bookmarkrating'&lt;br /&gt;
	display_type = 'Bookmarkrating'&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 4''': Remove hardcoded parameters, such as save_choice method&lt;br /&gt;
* '''Solution''': Hardcoded parameters are removed and necessary constants are defined.&lt;br /&gt;
&lt;br /&gt;
===Test Plans===&lt;br /&gt;
&lt;br /&gt;
Because the purpose of our project was to better arrange our code, it follows that we also needed to rearrange the tests for that code. We first divided the tests for questionnaires_controller into two test files, questionnaires_controller_spec and quiz_questionnaires_controller_spec and separated the tests for CRUD operations of quiz_questionnaires_controller into the quiz_questionnaires_controller_spec, renaming them from view_quiz, create_quiz and the like to view and create. After this separation of CRUD operation testing, we tested the functionality that we moved out of the controllers into the model including the validation method for the quiz questionnaire. We did not include tests to cover the existing model functions, nor did we test the new set_display_type or change_question_types functions as they are setter methods, which, according to our testing instruction are not worth testing. &lt;br /&gt;
&lt;br /&gt;
The setup for testing was particularly troublesome for the deployment of this project. The tests did not run properly in RubyMine, so it was difficult to ensure they were set up properly, and none of the members of our group have any expertise in rspec testing.&lt;br /&gt;
&lt;br /&gt;
===Testing from UI===&lt;br /&gt;
&lt;br /&gt;
*The testing of the export feature is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Export_setup.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Export_completed_successfully.png|center]]&lt;br /&gt;
&lt;br /&gt;
*The successful creation of quiz is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Quiz created sucessfully.png|center]]&lt;br /&gt;
&lt;br /&gt;
*The saving of question in a questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Save question in review successfully.png]]&lt;br /&gt;
&lt;br /&gt;
*The successful updating of questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Updated questionnaire successfully.png]]&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/Riounis/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1271 GitHub Pull Request]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119225</id>
		<title>CSC/ECE 517 Fall 2018 E1836 Refactor quiz questionnaires controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119225"/>
		<updated>2018-11-10T02:16:37Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Testing from UI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1836. Refactoring quiz_questionnaires_controller.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
* Created quiz_questionnaire_controller.rb&lt;br /&gt;
* Moved view_quiz, new_quiz, create_quiz_questionnaire, edit_quiz and update_quiz from questionnaires_controller.rb, to quiz_questionnaires_controller.rb, and renamed it as view, new, create, edit and update respectively.&lt;br /&gt;
* Refactored the the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* Replaced switch statements in questionnaires_controller.rb with subclass methods.&lt;br /&gt;
* Created models for the subclasses.&lt;br /&gt;
* Removed hardcoded parameters, such as save_choice method.&lt;br /&gt;
* Appropriate tests were written to test the code.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
'''Problem 1''': Create quiz_questionnaire_controller.rb and move some of the methods in the questionnaires_controller.rb to the new file created.&lt;br /&gt;
* '''Solution''': The methods view_quiz, new_quiz, create_quiz, edit_quiz and update_quiz in the questionnaires_controller.rb were the methods identified and moved into the quiz_questionnaire_controller.rb. They were respectively renamed as view, new, create, edit and update. The implementation of the newly created quiz_questionnaire_controller.rb can be seen below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class QuizQuestionnairesController &amp;lt; QuestionnairesController&lt;br /&gt;
&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
   # Separate methods for quiz questionnaire&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
&lt;br /&gt;
   # View a quiz questionnaire&lt;br /&gt;
   def view&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     @participant = Participant.find(params[:pid]) # creating an instance variable since it needs to be sent to submitted_content/edit&lt;br /&gt;
     render :view&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # define a new quiz questionnaire&lt;br /&gt;
   # method invoked by the view&lt;br /&gt;
   def new&lt;br /&gt;
     valid_request = true&lt;br /&gt;
     @assignment_id = params[:aid] # creating an instance variable to hold the assignment id&lt;br /&gt;
     @participant_id = params[:pid] # creating an instance variable to hold the participant id&lt;br /&gt;
     assignment = Assignment.find(@assignment_id)&lt;br /&gt;
     if !assignment.require_quiz? # flash error if this assignment does not require quiz&lt;br /&gt;
       flash[:error] = &amp;quot;This assignment does not support the quizzing feature.&amp;quot;&lt;br /&gt;
       valid_request = false&lt;br /&gt;
     else&lt;br /&gt;
       team = AssignmentParticipant.find(@participant_id).team&lt;br /&gt;
&lt;br /&gt;
       if team.nil? # flash error if this current participant does not have a team&lt;br /&gt;
         flash[:error] = &amp;quot;You should create or join a team first.&amp;quot;&lt;br /&gt;
         valid_request = false&lt;br /&gt;
       else&lt;br /&gt;
         if assignment.topics? &amp;amp;&amp;amp; team.topic.nil? # flash error if this assignment has topic but current team does not have a topic&lt;br /&gt;
           flash[:error] = &amp;quot;Your team should have a topic.&amp;quot;&lt;br /&gt;
           valid_request = false&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
     if valid_request &amp;amp;&amp;amp; Questionnaire::QUESTIONNAIRE_TYPES.include?(params[:model])&lt;br /&gt;
       @questionnaire = Object.const_get(params[:model]).new&lt;br /&gt;
       @questionnaire.private = params[:private]&lt;br /&gt;
       @questionnaire.min_question_score = 0&lt;br /&gt;
       @questionnaire.max_question_score = 1&lt;br /&gt;
&lt;br /&gt;
       render :new&lt;br /&gt;
     else&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # seperate method for creating a quiz questionnaire because of differences in permission&lt;br /&gt;
   def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # edit a quiz questionnaire&lt;br /&gt;
   def edit&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if !@questionnaire.taken_by_anyone?&lt;br /&gt;
       render :edit&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = &amp;quot;Your quiz has been taken by some other students, you cannot edit it anymore.&amp;quot;&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
   # save an updated quiz questionnaire to the database&lt;br /&gt;
   def update&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if @questionnaire.nil?&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
       return&lt;br /&gt;
     end&lt;br /&gt;
     if params['save'] &amp;amp;&amp;amp; params[:question].try(:keys)&lt;br /&gt;
       @questionnaire.update_attributes(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       for qid in params[:question].keys&lt;br /&gt;
         @question = Question.find(qid)&lt;br /&gt;
         @question.txt = params[:question][qid.to_sym][:txt]&lt;br /&gt;
         @question.save&lt;br /&gt;
&lt;br /&gt;
         @quiz_question_choices = QuizQuestionChoice.where(question_id: qid)&lt;br /&gt;
         i = 1&lt;br /&gt;
         for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
     redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 2''': Refactor the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* '''Solution''': &lt;br /&gt;
a. Deleted the create_questionnaire method and replaced the call to it in create_quiz_questionnaire with the code of create_questionnaire and is later moved to quiz_questionnaires_controller.rb and the code snippet below is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b. Moved the large block of for and if statements into method called change_question_types in the quiz_questionnaire model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
&lt;br /&gt;
	if type == &amp;quot;MultipleChoiceCheckbox&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][i.to_s]&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: params[:quiz_question_choices][id.to_s][type][i.to_s][:iscorrect], txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][quiz_question_choice.id.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;MultipleChoiceRadio&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][:correctindex] == i.to_s&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '1', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;TrueFalse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][1.to_s][:iscorrect] == &amp;quot;True&amp;quot; # the statement is correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is correct so &amp;quot;True&amp;quot; is the right answer&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            else # the statement is not correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is not correct so &amp;quot;False&amp;quot; is the right answer&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
c. Replaced large block of for and if statements in update with a call to the new change_question_types method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
d. Moved export, import, copy_questionnaire_details, and assign_instructor_id to questionaire model. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy_questionnaire_details(questions, orig_questionnaire, id)&lt;br /&gt;
    self.instructor_id = self.assign_instructor_id()&lt;br /&gt;
    self.name = 'Copy of ' + orig_questionnaire.name&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      self.created_at = Time.now&lt;br /&gt;
      self.save!&lt;br /&gt;
      questions.each do |question|&lt;br /&gt;
        new_question = question.dup&lt;br /&gt;
        new_question.questionnaire_id = id&lt;br /&gt;
        new_question.size = '50,3' if (new_question.is_a? Criterion or new_question.is_a? TextResponse) and new_question.size.nil?&lt;br /&gt;
        new_question.save!&lt;br /&gt;
        advices = QuestionAdvice.where(question_id: question.id)&lt;br /&gt;
        next if advices.empty?&lt;br /&gt;
        advices.each do |advice|&lt;br /&gt;
          new_advice = advice.dup&lt;br /&gt;
          new_advice.question_id = new_question.id&lt;br /&gt;
          new_advice.save!&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      pFolder = TreeFolder.find_by(name: question.set_display_type(display_type))&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: pFolder.id)&lt;br /&gt;
      QuestionnaireNode.find_or_create_by(parent_id: parent.id, node_object_id: id)&lt;br /&gt;
      undo_link(&amp;quot;Copy of questionnaire #{orig_questionnaire.name} has been created successfully.&amp;quot;)&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'view', id: @questionnaire.id&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'The questionnaire was not able to be copied. Please check the original course for missing information.' + $ERROR_INFO&lt;br /&gt;
      redirect_to action: 'list', controller: 'tree_display'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def export&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    csv_data = QuestionnaireHelper.create_questionnaire_csv @questionnaire, session[:user].name&lt;br /&gt;
    send_data csv_data,&lt;br /&gt;
              type: 'text/csv; charset=iso-8859-1; header=present',&lt;br /&gt;
              disposition: &amp;quot;attachment; filename=questionnaires.csv&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def import&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    file = params['csv']&lt;br /&gt;
    @questionnaire.questions &amp;lt;&amp;lt; QuestionnaireHelper.get_questions_from_csv(@questionnaire, file)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assign_instructor_id&lt;br /&gt;
    # if the user to copy the questionnaire is a TA, the instructor should be the owner instead of the TA&lt;br /&gt;
    if session[:user].role.name != &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      session[:user].id&lt;br /&gt;
    else # for TA we need to get his instructor id and by default add it to his course for which he is the TA&lt;br /&gt;
      Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3''': Replace switch statements with subclasses methods and create models for the subclasses.&lt;br /&gt;
* '''Solution''': Moved the switch-case statement from create in questionaire_controller.rb into a method called set_display_type in questionaire model. The following is the code snippet that shows the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  def set_dispay_type(display_type)&lt;br /&gt;
&lt;br /&gt;
      case display_type&lt;br /&gt;
&lt;br /&gt;
      when 'Review'&lt;br /&gt;
	display_type = 'Review'&lt;br /&gt;
&lt;br /&gt;
      when 'Metareview'&lt;br /&gt;
	display_type = 'Metareview'&lt;br /&gt;
&lt;br /&gt;
      when 'AuthorFeedback'&lt;br /&gt;
        display_type = 'Author%Feedback'&lt;br /&gt;
&lt;br /&gt;
      when 'CourseSurvey'&lt;br /&gt;
        display_type = 'Course%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'TeammateReview'&lt;br /&gt;
        display_type = 'Teammate%Review'&lt;br /&gt;
&lt;br /&gt;
      when 'GlobalSurvey'&lt;br /&gt;
        display_type = 'Global%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'AssignmentSurvey'&lt;br /&gt;
        display_type = 'Assignment%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'Bookmarkrating'&lt;br /&gt;
	display_type = 'Bookmarkrating'&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 4''': Remove hardcoded parameters, such as save_choice method&lt;br /&gt;
* '''Solution''': Hardcoded parameters are removed and necessary constants are defined.&lt;br /&gt;
&lt;br /&gt;
===Test Plans===&lt;br /&gt;
&lt;br /&gt;
Because the purpose of our project was to better arrange our code, it follows that we also needed to rearrange the tests for that code. We first divided the tests for questionnaires_controller into two test files, questionnaires_controller_spec and quiz_questionnaires_controller_spec and separated the tests for CRUD operations of quiz_questionnaires_controller into the quiz_questionnaires_controller_spec, renaming them from view_quiz, create_quiz and the like to view and create. After this separation of CRUD operation testing, we tested the functionality that we moved out of the controllers into the model including the validation method for the quiz questionnaire. We did not include tests to cover the existing model functions, nor did we test the new set_display_type or change_question_types functions as they are setter methods, which, according to our testing instruction are not worth testing. &lt;br /&gt;
&lt;br /&gt;
The setup for testing was particularly troublesome for the deployment of this project. The tests did not run properly in RubyMine, so it was difficult to ensure they were set up properly, and none of the members of our group have any expertise in rspec testing.&lt;br /&gt;
&lt;br /&gt;
===Testing from UI===&lt;br /&gt;
&lt;br /&gt;
*The testing of the export feature is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Export_setup.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Export_completed_successfully.png|center]]&lt;br /&gt;
&lt;br /&gt;
*The successful creation of quiz is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Quiz created sucessfully.png|center]]&lt;br /&gt;
&lt;br /&gt;
*The saving of question in a questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Save question in review successfully.png]]&lt;br /&gt;
&lt;br /&gt;
*The successful updating of questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Updated questionnaire successfully.png|upright=0.5]]&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/Riounis/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1271 GitHub Pull Request]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119224</id>
		<title>CSC/ECE 517 Fall 2018 E1836 Refactor quiz questionnaires controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119224"/>
		<updated>2018-11-10T02:16:20Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Testing from UI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1836. Refactoring quiz_questionnaires_controller.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
* Created quiz_questionnaire_controller.rb&lt;br /&gt;
* Moved view_quiz, new_quiz, create_quiz_questionnaire, edit_quiz and update_quiz from questionnaires_controller.rb, to quiz_questionnaires_controller.rb, and renamed it as view, new, create, edit and update respectively.&lt;br /&gt;
* Refactored the the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* Replaced switch statements in questionnaires_controller.rb with subclass methods.&lt;br /&gt;
* Created models for the subclasses.&lt;br /&gt;
* Removed hardcoded parameters, such as save_choice method.&lt;br /&gt;
* Appropriate tests were written to test the code.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
'''Problem 1''': Create quiz_questionnaire_controller.rb and move some of the methods in the questionnaires_controller.rb to the new file created.&lt;br /&gt;
* '''Solution''': The methods view_quiz, new_quiz, create_quiz, edit_quiz and update_quiz in the questionnaires_controller.rb were the methods identified and moved into the quiz_questionnaire_controller.rb. They were respectively renamed as view, new, create, edit and update. The implementation of the newly created quiz_questionnaire_controller.rb can be seen below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class QuizQuestionnairesController &amp;lt; QuestionnairesController&lt;br /&gt;
&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
   # Separate methods for quiz questionnaire&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
&lt;br /&gt;
   # View a quiz questionnaire&lt;br /&gt;
   def view&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     @participant = Participant.find(params[:pid]) # creating an instance variable since it needs to be sent to submitted_content/edit&lt;br /&gt;
     render :view&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # define a new quiz questionnaire&lt;br /&gt;
   # method invoked by the view&lt;br /&gt;
   def new&lt;br /&gt;
     valid_request = true&lt;br /&gt;
     @assignment_id = params[:aid] # creating an instance variable to hold the assignment id&lt;br /&gt;
     @participant_id = params[:pid] # creating an instance variable to hold the participant id&lt;br /&gt;
     assignment = Assignment.find(@assignment_id)&lt;br /&gt;
     if !assignment.require_quiz? # flash error if this assignment does not require quiz&lt;br /&gt;
       flash[:error] = &amp;quot;This assignment does not support the quizzing feature.&amp;quot;&lt;br /&gt;
       valid_request = false&lt;br /&gt;
     else&lt;br /&gt;
       team = AssignmentParticipant.find(@participant_id).team&lt;br /&gt;
&lt;br /&gt;
       if team.nil? # flash error if this current participant does not have a team&lt;br /&gt;
         flash[:error] = &amp;quot;You should create or join a team first.&amp;quot;&lt;br /&gt;
         valid_request = false&lt;br /&gt;
       else&lt;br /&gt;
         if assignment.topics? &amp;amp;&amp;amp; team.topic.nil? # flash error if this assignment has topic but current team does not have a topic&lt;br /&gt;
           flash[:error] = &amp;quot;Your team should have a topic.&amp;quot;&lt;br /&gt;
           valid_request = false&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
     if valid_request &amp;amp;&amp;amp; Questionnaire::QUESTIONNAIRE_TYPES.include?(params[:model])&lt;br /&gt;
       @questionnaire = Object.const_get(params[:model]).new&lt;br /&gt;
       @questionnaire.private = params[:private]&lt;br /&gt;
       @questionnaire.min_question_score = 0&lt;br /&gt;
       @questionnaire.max_question_score = 1&lt;br /&gt;
&lt;br /&gt;
       render :new&lt;br /&gt;
     else&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # seperate method for creating a quiz questionnaire because of differences in permission&lt;br /&gt;
   def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # edit a quiz questionnaire&lt;br /&gt;
   def edit&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if !@questionnaire.taken_by_anyone?&lt;br /&gt;
       render :edit&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = &amp;quot;Your quiz has been taken by some other students, you cannot edit it anymore.&amp;quot;&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
   # save an updated quiz questionnaire to the database&lt;br /&gt;
   def update&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if @questionnaire.nil?&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
       return&lt;br /&gt;
     end&lt;br /&gt;
     if params['save'] &amp;amp;&amp;amp; params[:question].try(:keys)&lt;br /&gt;
       @questionnaire.update_attributes(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       for qid in params[:question].keys&lt;br /&gt;
         @question = Question.find(qid)&lt;br /&gt;
         @question.txt = params[:question][qid.to_sym][:txt]&lt;br /&gt;
         @question.save&lt;br /&gt;
&lt;br /&gt;
         @quiz_question_choices = QuizQuestionChoice.where(question_id: qid)&lt;br /&gt;
         i = 1&lt;br /&gt;
         for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
     redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 2''': Refactor the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* '''Solution''': &lt;br /&gt;
a. Deleted the create_questionnaire method and replaced the call to it in create_quiz_questionnaire with the code of create_questionnaire and is later moved to quiz_questionnaires_controller.rb and the code snippet below is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b. Moved the large block of for and if statements into method called change_question_types in the quiz_questionnaire model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
&lt;br /&gt;
	if type == &amp;quot;MultipleChoiceCheckbox&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][i.to_s]&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: params[:quiz_question_choices][id.to_s][type][i.to_s][:iscorrect], txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][quiz_question_choice.id.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;MultipleChoiceRadio&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][:correctindex] == i.to_s&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '1', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;TrueFalse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][1.to_s][:iscorrect] == &amp;quot;True&amp;quot; # the statement is correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is correct so &amp;quot;True&amp;quot; is the right answer&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            else # the statement is not correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is not correct so &amp;quot;False&amp;quot; is the right answer&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
c. Replaced large block of for and if statements in update with a call to the new change_question_types method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
d. Moved export, import, copy_questionnaire_details, and assign_instructor_id to questionaire model. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy_questionnaire_details(questions, orig_questionnaire, id)&lt;br /&gt;
    self.instructor_id = self.assign_instructor_id()&lt;br /&gt;
    self.name = 'Copy of ' + orig_questionnaire.name&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      self.created_at = Time.now&lt;br /&gt;
      self.save!&lt;br /&gt;
      questions.each do |question|&lt;br /&gt;
        new_question = question.dup&lt;br /&gt;
        new_question.questionnaire_id = id&lt;br /&gt;
        new_question.size = '50,3' if (new_question.is_a? Criterion or new_question.is_a? TextResponse) and new_question.size.nil?&lt;br /&gt;
        new_question.save!&lt;br /&gt;
        advices = QuestionAdvice.where(question_id: question.id)&lt;br /&gt;
        next if advices.empty?&lt;br /&gt;
        advices.each do |advice|&lt;br /&gt;
          new_advice = advice.dup&lt;br /&gt;
          new_advice.question_id = new_question.id&lt;br /&gt;
          new_advice.save!&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      pFolder = TreeFolder.find_by(name: question.set_display_type(display_type))&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: pFolder.id)&lt;br /&gt;
      QuestionnaireNode.find_or_create_by(parent_id: parent.id, node_object_id: id)&lt;br /&gt;
      undo_link(&amp;quot;Copy of questionnaire #{orig_questionnaire.name} has been created successfully.&amp;quot;)&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'view', id: @questionnaire.id&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'The questionnaire was not able to be copied. Please check the original course for missing information.' + $ERROR_INFO&lt;br /&gt;
      redirect_to action: 'list', controller: 'tree_display'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def export&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    csv_data = QuestionnaireHelper.create_questionnaire_csv @questionnaire, session[:user].name&lt;br /&gt;
    send_data csv_data,&lt;br /&gt;
              type: 'text/csv; charset=iso-8859-1; header=present',&lt;br /&gt;
              disposition: &amp;quot;attachment; filename=questionnaires.csv&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def import&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    file = params['csv']&lt;br /&gt;
    @questionnaire.questions &amp;lt;&amp;lt; QuestionnaireHelper.get_questions_from_csv(@questionnaire, file)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assign_instructor_id&lt;br /&gt;
    # if the user to copy the questionnaire is a TA, the instructor should be the owner instead of the TA&lt;br /&gt;
    if session[:user].role.name != &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      session[:user].id&lt;br /&gt;
    else # for TA we need to get his instructor id and by default add it to his course for which he is the TA&lt;br /&gt;
      Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3''': Replace switch statements with subclasses methods and create models for the subclasses.&lt;br /&gt;
* '''Solution''': Moved the switch-case statement from create in questionaire_controller.rb into a method called set_display_type in questionaire model. The following is the code snippet that shows the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  def set_dispay_type(display_type)&lt;br /&gt;
&lt;br /&gt;
      case display_type&lt;br /&gt;
&lt;br /&gt;
      when 'Review'&lt;br /&gt;
	display_type = 'Review'&lt;br /&gt;
&lt;br /&gt;
      when 'Metareview'&lt;br /&gt;
	display_type = 'Metareview'&lt;br /&gt;
&lt;br /&gt;
      when 'AuthorFeedback'&lt;br /&gt;
        display_type = 'Author%Feedback'&lt;br /&gt;
&lt;br /&gt;
      when 'CourseSurvey'&lt;br /&gt;
        display_type = 'Course%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'TeammateReview'&lt;br /&gt;
        display_type = 'Teammate%Review'&lt;br /&gt;
&lt;br /&gt;
      when 'GlobalSurvey'&lt;br /&gt;
        display_type = 'Global%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'AssignmentSurvey'&lt;br /&gt;
        display_type = 'Assignment%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'Bookmarkrating'&lt;br /&gt;
	display_type = 'Bookmarkrating'&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 4''': Remove hardcoded parameters, such as save_choice method&lt;br /&gt;
* '''Solution''': Hardcoded parameters are removed and necessary constants are defined.&lt;br /&gt;
&lt;br /&gt;
===Test Plans===&lt;br /&gt;
&lt;br /&gt;
Because the purpose of our project was to better arrange our code, it follows that we also needed to rearrange the tests for that code. We first divided the tests for questionnaires_controller into two test files, questionnaires_controller_spec and quiz_questionnaires_controller_spec and separated the tests for CRUD operations of quiz_questionnaires_controller into the quiz_questionnaires_controller_spec, renaming them from view_quiz, create_quiz and the like to view and create. After this separation of CRUD operation testing, we tested the functionality that we moved out of the controllers into the model including the validation method for the quiz questionnaire. We did not include tests to cover the existing model functions, nor did we test the new set_display_type or change_question_types functions as they are setter methods, which, according to our testing instruction are not worth testing. &lt;br /&gt;
&lt;br /&gt;
The setup for testing was particularly troublesome for the deployment of this project. The tests did not run properly in RubyMine, so it was difficult to ensure they were set up properly, and none of the members of our group have any expertise in rspec testing.&lt;br /&gt;
&lt;br /&gt;
===Testing from UI===&lt;br /&gt;
&lt;br /&gt;
*The testing of the export feature is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Export_setup.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Export_completed_successfully.png|center]]&lt;br /&gt;
&lt;br /&gt;
*The successful creation of quiz is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Quiz created sucessfully.png|center]]&lt;br /&gt;
&lt;br /&gt;
*The saving of question in a questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Save question in review successfully.png]]&lt;br /&gt;
&lt;br /&gt;
*The successful updating of questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Updated questionnaire successfully.png|upright=0.75]]&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/Riounis/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1271 GitHub Pull Request]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119223</id>
		<title>CSC/ECE 517 Fall 2018 E1836 Refactor quiz questionnaires controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119223"/>
		<updated>2018-11-10T02:13:46Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Testing from UI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1836. Refactoring quiz_questionnaires_controller.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
* Created quiz_questionnaire_controller.rb&lt;br /&gt;
* Moved view_quiz, new_quiz, create_quiz_questionnaire, edit_quiz and update_quiz from questionnaires_controller.rb, to quiz_questionnaires_controller.rb, and renamed it as view, new, create, edit and update respectively.&lt;br /&gt;
* Refactored the the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* Replaced switch statements in questionnaires_controller.rb with subclass methods.&lt;br /&gt;
* Created models for the subclasses.&lt;br /&gt;
* Removed hardcoded parameters, such as save_choice method.&lt;br /&gt;
* Appropriate tests were written to test the code.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
'''Problem 1''': Create quiz_questionnaire_controller.rb and move some of the methods in the questionnaires_controller.rb to the new file created.&lt;br /&gt;
* '''Solution''': The methods view_quiz, new_quiz, create_quiz, edit_quiz and update_quiz in the questionnaires_controller.rb were the methods identified and moved into the quiz_questionnaire_controller.rb. They were respectively renamed as view, new, create, edit and update. The implementation of the newly created quiz_questionnaire_controller.rb can be seen below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class QuizQuestionnairesController &amp;lt; QuestionnairesController&lt;br /&gt;
&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
   # Separate methods for quiz questionnaire&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
&lt;br /&gt;
   # View a quiz questionnaire&lt;br /&gt;
   def view&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     @participant = Participant.find(params[:pid]) # creating an instance variable since it needs to be sent to submitted_content/edit&lt;br /&gt;
     render :view&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # define a new quiz questionnaire&lt;br /&gt;
   # method invoked by the view&lt;br /&gt;
   def new&lt;br /&gt;
     valid_request = true&lt;br /&gt;
     @assignment_id = params[:aid] # creating an instance variable to hold the assignment id&lt;br /&gt;
     @participant_id = params[:pid] # creating an instance variable to hold the participant id&lt;br /&gt;
     assignment = Assignment.find(@assignment_id)&lt;br /&gt;
     if !assignment.require_quiz? # flash error if this assignment does not require quiz&lt;br /&gt;
       flash[:error] = &amp;quot;This assignment does not support the quizzing feature.&amp;quot;&lt;br /&gt;
       valid_request = false&lt;br /&gt;
     else&lt;br /&gt;
       team = AssignmentParticipant.find(@participant_id).team&lt;br /&gt;
&lt;br /&gt;
       if team.nil? # flash error if this current participant does not have a team&lt;br /&gt;
         flash[:error] = &amp;quot;You should create or join a team first.&amp;quot;&lt;br /&gt;
         valid_request = false&lt;br /&gt;
       else&lt;br /&gt;
         if assignment.topics? &amp;amp;&amp;amp; team.topic.nil? # flash error if this assignment has topic but current team does not have a topic&lt;br /&gt;
           flash[:error] = &amp;quot;Your team should have a topic.&amp;quot;&lt;br /&gt;
           valid_request = false&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
     if valid_request &amp;amp;&amp;amp; Questionnaire::QUESTIONNAIRE_TYPES.include?(params[:model])&lt;br /&gt;
       @questionnaire = Object.const_get(params[:model]).new&lt;br /&gt;
       @questionnaire.private = params[:private]&lt;br /&gt;
       @questionnaire.min_question_score = 0&lt;br /&gt;
       @questionnaire.max_question_score = 1&lt;br /&gt;
&lt;br /&gt;
       render :new&lt;br /&gt;
     else&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # seperate method for creating a quiz questionnaire because of differences in permission&lt;br /&gt;
   def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # edit a quiz questionnaire&lt;br /&gt;
   def edit&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if !@questionnaire.taken_by_anyone?&lt;br /&gt;
       render :edit&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = &amp;quot;Your quiz has been taken by some other students, you cannot edit it anymore.&amp;quot;&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
   # save an updated quiz questionnaire to the database&lt;br /&gt;
   def update&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if @questionnaire.nil?&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
       return&lt;br /&gt;
     end&lt;br /&gt;
     if params['save'] &amp;amp;&amp;amp; params[:question].try(:keys)&lt;br /&gt;
       @questionnaire.update_attributes(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       for qid in params[:question].keys&lt;br /&gt;
         @question = Question.find(qid)&lt;br /&gt;
         @question.txt = params[:question][qid.to_sym][:txt]&lt;br /&gt;
         @question.save&lt;br /&gt;
&lt;br /&gt;
         @quiz_question_choices = QuizQuestionChoice.where(question_id: qid)&lt;br /&gt;
         i = 1&lt;br /&gt;
         for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
     redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 2''': Refactor the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* '''Solution''': &lt;br /&gt;
a. Deleted the create_questionnaire method and replaced the call to it in create_quiz_questionnaire with the code of create_questionnaire and is later moved to quiz_questionnaires_controller.rb and the code snippet below is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b. Moved the large block of for and if statements into method called change_question_types in the quiz_questionnaire model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
&lt;br /&gt;
	if type == &amp;quot;MultipleChoiceCheckbox&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][i.to_s]&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: params[:quiz_question_choices][id.to_s][type][i.to_s][:iscorrect], txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][quiz_question_choice.id.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;MultipleChoiceRadio&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][:correctindex] == i.to_s&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '1', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;TrueFalse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][1.to_s][:iscorrect] == &amp;quot;True&amp;quot; # the statement is correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is correct so &amp;quot;True&amp;quot; is the right answer&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            else # the statement is not correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is not correct so &amp;quot;False&amp;quot; is the right answer&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
c. Replaced large block of for and if statements in update with a call to the new change_question_types method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
d. Moved export, import, copy_questionnaire_details, and assign_instructor_id to questionaire model. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy_questionnaire_details(questions, orig_questionnaire, id)&lt;br /&gt;
    self.instructor_id = self.assign_instructor_id()&lt;br /&gt;
    self.name = 'Copy of ' + orig_questionnaire.name&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      self.created_at = Time.now&lt;br /&gt;
      self.save!&lt;br /&gt;
      questions.each do |question|&lt;br /&gt;
        new_question = question.dup&lt;br /&gt;
        new_question.questionnaire_id = id&lt;br /&gt;
        new_question.size = '50,3' if (new_question.is_a? Criterion or new_question.is_a? TextResponse) and new_question.size.nil?&lt;br /&gt;
        new_question.save!&lt;br /&gt;
        advices = QuestionAdvice.where(question_id: question.id)&lt;br /&gt;
        next if advices.empty?&lt;br /&gt;
        advices.each do |advice|&lt;br /&gt;
          new_advice = advice.dup&lt;br /&gt;
          new_advice.question_id = new_question.id&lt;br /&gt;
          new_advice.save!&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      pFolder = TreeFolder.find_by(name: question.set_display_type(display_type))&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: pFolder.id)&lt;br /&gt;
      QuestionnaireNode.find_or_create_by(parent_id: parent.id, node_object_id: id)&lt;br /&gt;
      undo_link(&amp;quot;Copy of questionnaire #{orig_questionnaire.name} has been created successfully.&amp;quot;)&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'view', id: @questionnaire.id&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'The questionnaire was not able to be copied. Please check the original course for missing information.' + $ERROR_INFO&lt;br /&gt;
      redirect_to action: 'list', controller: 'tree_display'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def export&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    csv_data = QuestionnaireHelper.create_questionnaire_csv @questionnaire, session[:user].name&lt;br /&gt;
    send_data csv_data,&lt;br /&gt;
              type: 'text/csv; charset=iso-8859-1; header=present',&lt;br /&gt;
              disposition: &amp;quot;attachment; filename=questionnaires.csv&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def import&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    file = params['csv']&lt;br /&gt;
    @questionnaire.questions &amp;lt;&amp;lt; QuestionnaireHelper.get_questions_from_csv(@questionnaire, file)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assign_instructor_id&lt;br /&gt;
    # if the user to copy the questionnaire is a TA, the instructor should be the owner instead of the TA&lt;br /&gt;
    if session[:user].role.name != &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      session[:user].id&lt;br /&gt;
    else # for TA we need to get his instructor id and by default add it to his course for which he is the TA&lt;br /&gt;
      Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3''': Replace switch statements with subclasses methods and create models for the subclasses.&lt;br /&gt;
* '''Solution''': Moved the switch-case statement from create in questionaire_controller.rb into a method called set_display_type in questionaire model. The following is the code snippet that shows the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  def set_dispay_type(display_type)&lt;br /&gt;
&lt;br /&gt;
      case display_type&lt;br /&gt;
&lt;br /&gt;
      when 'Review'&lt;br /&gt;
	display_type = 'Review'&lt;br /&gt;
&lt;br /&gt;
      when 'Metareview'&lt;br /&gt;
	display_type = 'Metareview'&lt;br /&gt;
&lt;br /&gt;
      when 'AuthorFeedback'&lt;br /&gt;
        display_type = 'Author%Feedback'&lt;br /&gt;
&lt;br /&gt;
      when 'CourseSurvey'&lt;br /&gt;
        display_type = 'Course%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'TeammateReview'&lt;br /&gt;
        display_type = 'Teammate%Review'&lt;br /&gt;
&lt;br /&gt;
      when 'GlobalSurvey'&lt;br /&gt;
        display_type = 'Global%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'AssignmentSurvey'&lt;br /&gt;
        display_type = 'Assignment%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'Bookmarkrating'&lt;br /&gt;
	display_type = 'Bookmarkrating'&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 4''': Remove hardcoded parameters, such as save_choice method&lt;br /&gt;
* '''Solution''': Hardcoded parameters are removed and necessary constants are defined.&lt;br /&gt;
&lt;br /&gt;
===Test Plans===&lt;br /&gt;
&lt;br /&gt;
Because the purpose of our project was to better arrange our code, it follows that we also needed to rearrange the tests for that code. We first divided the tests for questionnaires_controller into two test files, questionnaires_controller_spec and quiz_questionnaires_controller_spec and separated the tests for CRUD operations of quiz_questionnaires_controller into the quiz_questionnaires_controller_spec, renaming them from view_quiz, create_quiz and the like to view and create. After this separation of CRUD operation testing, we tested the functionality that we moved out of the controllers into the model including the validation method for the quiz questionnaire. We did not include tests to cover the existing model functions, nor did we test the new set_display_type or change_question_types functions as they are setter methods, which, according to our testing instruction are not worth testing. &lt;br /&gt;
&lt;br /&gt;
The setup for testing was particularly troublesome for the deployment of this project. The tests did not run properly in RubyMine, so it was difficult to ensure they were set up properly, and none of the members of our group have any expertise in rspec testing.&lt;br /&gt;
&lt;br /&gt;
===Testing from UI===&lt;br /&gt;
&lt;br /&gt;
*The testing of the export feature is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Export_setup.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Export_completed_successfully.png|center]]&lt;br /&gt;
&lt;br /&gt;
*The successful creation of quiz is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Quiz created sucessfully.png|center]]&lt;br /&gt;
&lt;br /&gt;
*The saving of question in a questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Save question in review successfully.png]]&lt;br /&gt;
&lt;br /&gt;
*The successful updating of questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Updated questionnaire successfully.png|1500px]]&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/Riounis/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1271 GitHub Pull Request]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119222</id>
		<title>CSC/ECE 517 Fall 2018 E1836 Refactor quiz questionnaires controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119222"/>
		<updated>2018-11-10T02:13:25Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Testing from UI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1836. Refactoring quiz_questionnaires_controller.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
* Created quiz_questionnaire_controller.rb&lt;br /&gt;
* Moved view_quiz, new_quiz, create_quiz_questionnaire, edit_quiz and update_quiz from questionnaires_controller.rb, to quiz_questionnaires_controller.rb, and renamed it as view, new, create, edit and update respectively.&lt;br /&gt;
* Refactored the the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* Replaced switch statements in questionnaires_controller.rb with subclass methods.&lt;br /&gt;
* Created models for the subclasses.&lt;br /&gt;
* Removed hardcoded parameters, such as save_choice method.&lt;br /&gt;
* Appropriate tests were written to test the code.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
'''Problem 1''': Create quiz_questionnaire_controller.rb and move some of the methods in the questionnaires_controller.rb to the new file created.&lt;br /&gt;
* '''Solution''': The methods view_quiz, new_quiz, create_quiz, edit_quiz and update_quiz in the questionnaires_controller.rb were the methods identified and moved into the quiz_questionnaire_controller.rb. They were respectively renamed as view, new, create, edit and update. The implementation of the newly created quiz_questionnaire_controller.rb can be seen below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class QuizQuestionnairesController &amp;lt; QuestionnairesController&lt;br /&gt;
&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
   # Separate methods for quiz questionnaire&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
&lt;br /&gt;
   # View a quiz questionnaire&lt;br /&gt;
   def view&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     @participant = Participant.find(params[:pid]) # creating an instance variable since it needs to be sent to submitted_content/edit&lt;br /&gt;
     render :view&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # define a new quiz questionnaire&lt;br /&gt;
   # method invoked by the view&lt;br /&gt;
   def new&lt;br /&gt;
     valid_request = true&lt;br /&gt;
     @assignment_id = params[:aid] # creating an instance variable to hold the assignment id&lt;br /&gt;
     @participant_id = params[:pid] # creating an instance variable to hold the participant id&lt;br /&gt;
     assignment = Assignment.find(@assignment_id)&lt;br /&gt;
     if !assignment.require_quiz? # flash error if this assignment does not require quiz&lt;br /&gt;
       flash[:error] = &amp;quot;This assignment does not support the quizzing feature.&amp;quot;&lt;br /&gt;
       valid_request = false&lt;br /&gt;
     else&lt;br /&gt;
       team = AssignmentParticipant.find(@participant_id).team&lt;br /&gt;
&lt;br /&gt;
       if team.nil? # flash error if this current participant does not have a team&lt;br /&gt;
         flash[:error] = &amp;quot;You should create or join a team first.&amp;quot;&lt;br /&gt;
         valid_request = false&lt;br /&gt;
       else&lt;br /&gt;
         if assignment.topics? &amp;amp;&amp;amp; team.topic.nil? # flash error if this assignment has topic but current team does not have a topic&lt;br /&gt;
           flash[:error] = &amp;quot;Your team should have a topic.&amp;quot;&lt;br /&gt;
           valid_request = false&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
     if valid_request &amp;amp;&amp;amp; Questionnaire::QUESTIONNAIRE_TYPES.include?(params[:model])&lt;br /&gt;
       @questionnaire = Object.const_get(params[:model]).new&lt;br /&gt;
       @questionnaire.private = params[:private]&lt;br /&gt;
       @questionnaire.min_question_score = 0&lt;br /&gt;
       @questionnaire.max_question_score = 1&lt;br /&gt;
&lt;br /&gt;
       render :new&lt;br /&gt;
     else&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # seperate method for creating a quiz questionnaire because of differences in permission&lt;br /&gt;
   def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # edit a quiz questionnaire&lt;br /&gt;
   def edit&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if !@questionnaire.taken_by_anyone?&lt;br /&gt;
       render :edit&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = &amp;quot;Your quiz has been taken by some other students, you cannot edit it anymore.&amp;quot;&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
   # save an updated quiz questionnaire to the database&lt;br /&gt;
   def update&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if @questionnaire.nil?&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
       return&lt;br /&gt;
     end&lt;br /&gt;
     if params['save'] &amp;amp;&amp;amp; params[:question].try(:keys)&lt;br /&gt;
       @questionnaire.update_attributes(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       for qid in params[:question].keys&lt;br /&gt;
         @question = Question.find(qid)&lt;br /&gt;
         @question.txt = params[:question][qid.to_sym][:txt]&lt;br /&gt;
         @question.save&lt;br /&gt;
&lt;br /&gt;
         @quiz_question_choices = QuizQuestionChoice.where(question_id: qid)&lt;br /&gt;
         i = 1&lt;br /&gt;
         for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
     redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 2''': Refactor the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* '''Solution''': &lt;br /&gt;
a. Deleted the create_questionnaire method and replaced the call to it in create_quiz_questionnaire with the code of create_questionnaire and is later moved to quiz_questionnaires_controller.rb and the code snippet below is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b. Moved the large block of for and if statements into method called change_question_types in the quiz_questionnaire model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
&lt;br /&gt;
	if type == &amp;quot;MultipleChoiceCheckbox&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][i.to_s]&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: params[:quiz_question_choices][id.to_s][type][i.to_s][:iscorrect], txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][quiz_question_choice.id.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;MultipleChoiceRadio&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][:correctindex] == i.to_s&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '1', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;TrueFalse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][1.to_s][:iscorrect] == &amp;quot;True&amp;quot; # the statement is correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is correct so &amp;quot;True&amp;quot; is the right answer&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            else # the statement is not correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is not correct so &amp;quot;False&amp;quot; is the right answer&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
c. Replaced large block of for and if statements in update with a call to the new change_question_types method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
d. Moved export, import, copy_questionnaire_details, and assign_instructor_id to questionaire model. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy_questionnaire_details(questions, orig_questionnaire, id)&lt;br /&gt;
    self.instructor_id = self.assign_instructor_id()&lt;br /&gt;
    self.name = 'Copy of ' + orig_questionnaire.name&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      self.created_at = Time.now&lt;br /&gt;
      self.save!&lt;br /&gt;
      questions.each do |question|&lt;br /&gt;
        new_question = question.dup&lt;br /&gt;
        new_question.questionnaire_id = id&lt;br /&gt;
        new_question.size = '50,3' if (new_question.is_a? Criterion or new_question.is_a? TextResponse) and new_question.size.nil?&lt;br /&gt;
        new_question.save!&lt;br /&gt;
        advices = QuestionAdvice.where(question_id: question.id)&lt;br /&gt;
        next if advices.empty?&lt;br /&gt;
        advices.each do |advice|&lt;br /&gt;
          new_advice = advice.dup&lt;br /&gt;
          new_advice.question_id = new_question.id&lt;br /&gt;
          new_advice.save!&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      pFolder = TreeFolder.find_by(name: question.set_display_type(display_type))&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: pFolder.id)&lt;br /&gt;
      QuestionnaireNode.find_or_create_by(parent_id: parent.id, node_object_id: id)&lt;br /&gt;
      undo_link(&amp;quot;Copy of questionnaire #{orig_questionnaire.name} has been created successfully.&amp;quot;)&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'view', id: @questionnaire.id&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'The questionnaire was not able to be copied. Please check the original course for missing information.' + $ERROR_INFO&lt;br /&gt;
      redirect_to action: 'list', controller: 'tree_display'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def export&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    csv_data = QuestionnaireHelper.create_questionnaire_csv @questionnaire, session[:user].name&lt;br /&gt;
    send_data csv_data,&lt;br /&gt;
              type: 'text/csv; charset=iso-8859-1; header=present',&lt;br /&gt;
              disposition: &amp;quot;attachment; filename=questionnaires.csv&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def import&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    file = params['csv']&lt;br /&gt;
    @questionnaire.questions &amp;lt;&amp;lt; QuestionnaireHelper.get_questions_from_csv(@questionnaire, file)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assign_instructor_id&lt;br /&gt;
    # if the user to copy the questionnaire is a TA, the instructor should be the owner instead of the TA&lt;br /&gt;
    if session[:user].role.name != &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      session[:user].id&lt;br /&gt;
    else # for TA we need to get his instructor id and by default add it to his course for which he is the TA&lt;br /&gt;
      Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3''': Replace switch statements with subclasses methods and create models for the subclasses.&lt;br /&gt;
* '''Solution''': Moved the switch-case statement from create in questionaire_controller.rb into a method called set_display_type in questionaire model. The following is the code snippet that shows the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  def set_dispay_type(display_type)&lt;br /&gt;
&lt;br /&gt;
      case display_type&lt;br /&gt;
&lt;br /&gt;
      when 'Review'&lt;br /&gt;
	display_type = 'Review'&lt;br /&gt;
&lt;br /&gt;
      when 'Metareview'&lt;br /&gt;
	display_type = 'Metareview'&lt;br /&gt;
&lt;br /&gt;
      when 'AuthorFeedback'&lt;br /&gt;
        display_type = 'Author%Feedback'&lt;br /&gt;
&lt;br /&gt;
      when 'CourseSurvey'&lt;br /&gt;
        display_type = 'Course%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'TeammateReview'&lt;br /&gt;
        display_type = 'Teammate%Review'&lt;br /&gt;
&lt;br /&gt;
      when 'GlobalSurvey'&lt;br /&gt;
        display_type = 'Global%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'AssignmentSurvey'&lt;br /&gt;
        display_type = 'Assignment%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'Bookmarkrating'&lt;br /&gt;
	display_type = 'Bookmarkrating'&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 4''': Remove hardcoded parameters, such as save_choice method&lt;br /&gt;
* '''Solution''': Hardcoded parameters are removed and necessary constants are defined.&lt;br /&gt;
&lt;br /&gt;
===Test Plans===&lt;br /&gt;
&lt;br /&gt;
Because the purpose of our project was to better arrange our code, it follows that we also needed to rearrange the tests for that code. We first divided the tests for questionnaires_controller into two test files, questionnaires_controller_spec and quiz_questionnaires_controller_spec and separated the tests for CRUD operations of quiz_questionnaires_controller into the quiz_questionnaires_controller_spec, renaming them from view_quiz, create_quiz and the like to view and create. After this separation of CRUD operation testing, we tested the functionality that we moved out of the controllers into the model including the validation method for the quiz questionnaire. We did not include tests to cover the existing model functions, nor did we test the new set_display_type or change_question_types functions as they are setter methods, which, according to our testing instruction are not worth testing. &lt;br /&gt;
&lt;br /&gt;
The setup for testing was particularly troublesome for the deployment of this project. The tests did not run properly in RubyMine, so it was difficult to ensure they were set up properly, and none of the members of our group have any expertise in rspec testing.&lt;br /&gt;
&lt;br /&gt;
===Testing from UI===&lt;br /&gt;
&lt;br /&gt;
*The testing of the export feature is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Export_setup.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Export_completed_successfully.png|center]]&lt;br /&gt;
&lt;br /&gt;
*The successful creation of quiz is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Quiz created sucessfully.png|center]]&lt;br /&gt;
&lt;br /&gt;
*The saving of question in a questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Save question in review successfully.png]]&lt;br /&gt;
&lt;br /&gt;
*The successful updating of questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Updated questionnaire successfully.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/Riounis/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1271 GitHub Pull Request]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119220</id>
		<title>CSC/ECE 517 Fall 2018 E1836 Refactor quiz questionnaires controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119220"/>
		<updated>2018-11-10T02:11:18Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1836. Refactoring quiz_questionnaires_controller.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
* Created quiz_questionnaire_controller.rb&lt;br /&gt;
* Moved view_quiz, new_quiz, create_quiz_questionnaire, edit_quiz and update_quiz from questionnaires_controller.rb, to quiz_questionnaires_controller.rb, and renamed it as view, new, create, edit and update respectively.&lt;br /&gt;
* Refactored the the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* Replaced switch statements in questionnaires_controller.rb with subclass methods.&lt;br /&gt;
* Created models for the subclasses.&lt;br /&gt;
* Removed hardcoded parameters, such as save_choice method.&lt;br /&gt;
* Appropriate tests were written to test the code.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
'''Problem 1''': Create quiz_questionnaire_controller.rb and move some of the methods in the questionnaires_controller.rb to the new file created.&lt;br /&gt;
* '''Solution''': The methods view_quiz, new_quiz, create_quiz, edit_quiz and update_quiz in the questionnaires_controller.rb were the methods identified and moved into the quiz_questionnaire_controller.rb. They were respectively renamed as view, new, create, edit and update. The implementation of the newly created quiz_questionnaire_controller.rb can be seen below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class QuizQuestionnairesController &amp;lt; QuestionnairesController&lt;br /&gt;
&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
   # Separate methods for quiz questionnaire&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
&lt;br /&gt;
   # View a quiz questionnaire&lt;br /&gt;
   def view&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     @participant = Participant.find(params[:pid]) # creating an instance variable since it needs to be sent to submitted_content/edit&lt;br /&gt;
     render :view&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # define a new quiz questionnaire&lt;br /&gt;
   # method invoked by the view&lt;br /&gt;
   def new&lt;br /&gt;
     valid_request = true&lt;br /&gt;
     @assignment_id = params[:aid] # creating an instance variable to hold the assignment id&lt;br /&gt;
     @participant_id = params[:pid] # creating an instance variable to hold the participant id&lt;br /&gt;
     assignment = Assignment.find(@assignment_id)&lt;br /&gt;
     if !assignment.require_quiz? # flash error if this assignment does not require quiz&lt;br /&gt;
       flash[:error] = &amp;quot;This assignment does not support the quizzing feature.&amp;quot;&lt;br /&gt;
       valid_request = false&lt;br /&gt;
     else&lt;br /&gt;
       team = AssignmentParticipant.find(@participant_id).team&lt;br /&gt;
&lt;br /&gt;
       if team.nil? # flash error if this current participant does not have a team&lt;br /&gt;
         flash[:error] = &amp;quot;You should create or join a team first.&amp;quot;&lt;br /&gt;
         valid_request = false&lt;br /&gt;
       else&lt;br /&gt;
         if assignment.topics? &amp;amp;&amp;amp; team.topic.nil? # flash error if this assignment has topic but current team does not have a topic&lt;br /&gt;
           flash[:error] = &amp;quot;Your team should have a topic.&amp;quot;&lt;br /&gt;
           valid_request = false&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
     if valid_request &amp;amp;&amp;amp; Questionnaire::QUESTIONNAIRE_TYPES.include?(params[:model])&lt;br /&gt;
       @questionnaire = Object.const_get(params[:model]).new&lt;br /&gt;
       @questionnaire.private = params[:private]&lt;br /&gt;
       @questionnaire.min_question_score = 0&lt;br /&gt;
       @questionnaire.max_question_score = 1&lt;br /&gt;
&lt;br /&gt;
       render :new&lt;br /&gt;
     else&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # seperate method for creating a quiz questionnaire because of differences in permission&lt;br /&gt;
   def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # edit a quiz questionnaire&lt;br /&gt;
   def edit&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if !@questionnaire.taken_by_anyone?&lt;br /&gt;
       render :edit&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = &amp;quot;Your quiz has been taken by some other students, you cannot edit it anymore.&amp;quot;&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
   # save an updated quiz questionnaire to the database&lt;br /&gt;
   def update&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if @questionnaire.nil?&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
       return&lt;br /&gt;
     end&lt;br /&gt;
     if params['save'] &amp;amp;&amp;amp; params[:question].try(:keys)&lt;br /&gt;
       @questionnaire.update_attributes(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       for qid in params[:question].keys&lt;br /&gt;
         @question = Question.find(qid)&lt;br /&gt;
         @question.txt = params[:question][qid.to_sym][:txt]&lt;br /&gt;
         @question.save&lt;br /&gt;
&lt;br /&gt;
         @quiz_question_choices = QuizQuestionChoice.where(question_id: qid)&lt;br /&gt;
         i = 1&lt;br /&gt;
         for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
     redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 2''': Refactor the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* '''Solution''': &lt;br /&gt;
a. Deleted the create_questionnaire method and replaced the call to it in create_quiz_questionnaire with the code of create_questionnaire and is later moved to quiz_questionnaires_controller.rb and the code snippet below is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b. Moved the large block of for and if statements into method called change_question_types in the quiz_questionnaire model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
&lt;br /&gt;
	if type == &amp;quot;MultipleChoiceCheckbox&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][i.to_s]&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: params[:quiz_question_choices][id.to_s][type][i.to_s][:iscorrect], txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][quiz_question_choice.id.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;MultipleChoiceRadio&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][:correctindex] == i.to_s&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '1', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;TrueFalse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][1.to_s][:iscorrect] == &amp;quot;True&amp;quot; # the statement is correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is correct so &amp;quot;True&amp;quot; is the right answer&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            else # the statement is not correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is not correct so &amp;quot;False&amp;quot; is the right answer&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
c. Replaced large block of for and if statements in update with a call to the new change_question_types method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
d. Moved export, import, copy_questionnaire_details, and assign_instructor_id to questionaire model. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy_questionnaire_details(questions, orig_questionnaire, id)&lt;br /&gt;
    self.instructor_id = self.assign_instructor_id()&lt;br /&gt;
    self.name = 'Copy of ' + orig_questionnaire.name&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      self.created_at = Time.now&lt;br /&gt;
      self.save!&lt;br /&gt;
      questions.each do |question|&lt;br /&gt;
        new_question = question.dup&lt;br /&gt;
        new_question.questionnaire_id = id&lt;br /&gt;
        new_question.size = '50,3' if (new_question.is_a? Criterion or new_question.is_a? TextResponse) and new_question.size.nil?&lt;br /&gt;
        new_question.save!&lt;br /&gt;
        advices = QuestionAdvice.where(question_id: question.id)&lt;br /&gt;
        next if advices.empty?&lt;br /&gt;
        advices.each do |advice|&lt;br /&gt;
          new_advice = advice.dup&lt;br /&gt;
          new_advice.question_id = new_question.id&lt;br /&gt;
          new_advice.save!&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      pFolder = TreeFolder.find_by(name: question.set_display_type(display_type))&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: pFolder.id)&lt;br /&gt;
      QuestionnaireNode.find_or_create_by(parent_id: parent.id, node_object_id: id)&lt;br /&gt;
      undo_link(&amp;quot;Copy of questionnaire #{orig_questionnaire.name} has been created successfully.&amp;quot;)&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'view', id: @questionnaire.id&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'The questionnaire was not able to be copied. Please check the original course for missing information.' + $ERROR_INFO&lt;br /&gt;
      redirect_to action: 'list', controller: 'tree_display'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def export&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    csv_data = QuestionnaireHelper.create_questionnaire_csv @questionnaire, session[:user].name&lt;br /&gt;
    send_data csv_data,&lt;br /&gt;
              type: 'text/csv; charset=iso-8859-1; header=present',&lt;br /&gt;
              disposition: &amp;quot;attachment; filename=questionnaires.csv&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def import&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    file = params['csv']&lt;br /&gt;
    @questionnaire.questions &amp;lt;&amp;lt; QuestionnaireHelper.get_questions_from_csv(@questionnaire, file)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assign_instructor_id&lt;br /&gt;
    # if the user to copy the questionnaire is a TA, the instructor should be the owner instead of the TA&lt;br /&gt;
    if session[:user].role.name != &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      session[:user].id&lt;br /&gt;
    else # for TA we need to get his instructor id and by default add it to his course for which he is the TA&lt;br /&gt;
      Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3''': Replace switch statements with subclasses methods and create models for the subclasses.&lt;br /&gt;
* '''Solution''': Moved the switch-case statement from create in questionaire_controller.rb into a method called set_display_type in questionaire model. The following is the code snippet that shows the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  def set_dispay_type(display_type)&lt;br /&gt;
&lt;br /&gt;
      case display_type&lt;br /&gt;
&lt;br /&gt;
      when 'Review'&lt;br /&gt;
	display_type = 'Review'&lt;br /&gt;
&lt;br /&gt;
      when 'Metareview'&lt;br /&gt;
	display_type = 'Metareview'&lt;br /&gt;
&lt;br /&gt;
      when 'AuthorFeedback'&lt;br /&gt;
        display_type = 'Author%Feedback'&lt;br /&gt;
&lt;br /&gt;
      when 'CourseSurvey'&lt;br /&gt;
        display_type = 'Course%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'TeammateReview'&lt;br /&gt;
        display_type = 'Teammate%Review'&lt;br /&gt;
&lt;br /&gt;
      when 'GlobalSurvey'&lt;br /&gt;
        display_type = 'Global%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'AssignmentSurvey'&lt;br /&gt;
        display_type = 'Assignment%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'Bookmarkrating'&lt;br /&gt;
	display_type = 'Bookmarkrating'&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 4''': Remove hardcoded parameters, such as save_choice method&lt;br /&gt;
* '''Solution''': Hardcoded parameters are removed and necessary constants are defined.&lt;br /&gt;
&lt;br /&gt;
===Test Plans===&lt;br /&gt;
&lt;br /&gt;
Because the purpose of our project was to better arrange our code, it follows that we also needed to rearrange the tests for that code. We first divided the tests for questionnaires_controller into two test files, questionnaires_controller_spec and quiz_questionnaires_controller_spec and separated the tests for CRUD operations of quiz_questionnaires_controller into the quiz_questionnaires_controller_spec, renaming them from view_quiz, create_quiz and the like to view and create. After this separation of CRUD operation testing, we tested the functionality that we moved out of the controllers into the model including the validation method for the quiz questionnaire. We did not include tests to cover the existing model functions, nor did we test the new set_display_type or change_question_types functions as they are setter methods, which, according to our testing instruction are not worth testing. &lt;br /&gt;
&lt;br /&gt;
The setup for testing was particularly troublesome for the deployment of this project. The tests did not run properly in RubyMine, so it was difficult to ensure they were set up properly, and none of the members of our group have any expertise in rspec testing.&lt;br /&gt;
&lt;br /&gt;
===Testing from UI===&lt;br /&gt;
&lt;br /&gt;
*The testing of the export feature is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Export_setup.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Export_completed_successfully.png]]&lt;br /&gt;
&lt;br /&gt;
*The successful creation of quiz is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Quiz created sucessfully.png]]&lt;br /&gt;
&lt;br /&gt;
*The saving of question in a questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Save question in review successfully.png]]&lt;br /&gt;
&lt;br /&gt;
*The successful updating of questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Updated questionnaire successfully.png|center]]&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/Riounis/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1271 GitHub Pull Request]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119219</id>
		<title>CSC/ECE 517 Fall 2018 E1836 Refactor quiz questionnaires controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119219"/>
		<updated>2018-11-10T02:11:05Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Testing from UI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1836. Refactoring quiz_questionnaires_controller.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
* Created quiz_questionnaire_controller.rb&lt;br /&gt;
* Moved view_quiz, new_quiz, create_quiz_questionnaire, edit_quiz and update_quiz from questionnaires_controller.rb, to quiz_questionnaires_controller.rb, and renamed it as view, new, create, edit and update respectively.&lt;br /&gt;
* Refactored the the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* Replaced switch statements in questionnaires_controller.rb with subclass methods.&lt;br /&gt;
* Created models for the subclasses.&lt;br /&gt;
* Removed hardcoded parameters, such as save_choice method.&lt;br /&gt;
* Appropriate tests were written to test the code.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
'''Problem 1''': Create quiz_questionnaire_controller.rb and move some of the methods in the questionnaires_controller.rb to the new file created.&lt;br /&gt;
* '''Solution''': The methods view_quiz, new_quiz, create_quiz, edit_quiz and update_quiz in the questionnaires_controller.rb were the methods identified and moved into the quiz_questionnaire_controller.rb. They were respectively renamed as view, new, create, edit and update. The implementation of the newly created quiz_questionnaire_controller.rb can be seen below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class QuizQuestionnairesController &amp;lt; QuestionnairesController&lt;br /&gt;
&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
   # Separate methods for quiz questionnaire&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
&lt;br /&gt;
   # View a quiz questionnaire&lt;br /&gt;
   def view&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     @participant = Participant.find(params[:pid]) # creating an instance variable since it needs to be sent to submitted_content/edit&lt;br /&gt;
     render :view&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # define a new quiz questionnaire&lt;br /&gt;
   # method invoked by the view&lt;br /&gt;
   def new&lt;br /&gt;
     valid_request = true&lt;br /&gt;
     @assignment_id = params[:aid] # creating an instance variable to hold the assignment id&lt;br /&gt;
     @participant_id = params[:pid] # creating an instance variable to hold the participant id&lt;br /&gt;
     assignment = Assignment.find(@assignment_id)&lt;br /&gt;
     if !assignment.require_quiz? # flash error if this assignment does not require quiz&lt;br /&gt;
       flash[:error] = &amp;quot;This assignment does not support the quizzing feature.&amp;quot;&lt;br /&gt;
       valid_request = false&lt;br /&gt;
     else&lt;br /&gt;
       team = AssignmentParticipant.find(@participant_id).team&lt;br /&gt;
&lt;br /&gt;
       if team.nil? # flash error if this current participant does not have a team&lt;br /&gt;
         flash[:error] = &amp;quot;You should create or join a team first.&amp;quot;&lt;br /&gt;
         valid_request = false&lt;br /&gt;
       else&lt;br /&gt;
         if assignment.topics? &amp;amp;&amp;amp; team.topic.nil? # flash error if this assignment has topic but current team does not have a topic&lt;br /&gt;
           flash[:error] = &amp;quot;Your team should have a topic.&amp;quot;&lt;br /&gt;
           valid_request = false&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
     if valid_request &amp;amp;&amp;amp; Questionnaire::QUESTIONNAIRE_TYPES.include?(params[:model])&lt;br /&gt;
       @questionnaire = Object.const_get(params[:model]).new&lt;br /&gt;
       @questionnaire.private = params[:private]&lt;br /&gt;
       @questionnaire.min_question_score = 0&lt;br /&gt;
       @questionnaire.max_question_score = 1&lt;br /&gt;
&lt;br /&gt;
       render :new&lt;br /&gt;
     else&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # seperate method for creating a quiz questionnaire because of differences in permission&lt;br /&gt;
   def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # edit a quiz questionnaire&lt;br /&gt;
   def edit&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if !@questionnaire.taken_by_anyone?&lt;br /&gt;
       render :edit&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = &amp;quot;Your quiz has been taken by some other students, you cannot edit it anymore.&amp;quot;&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
   # save an updated quiz questionnaire to the database&lt;br /&gt;
   def update&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if @questionnaire.nil?&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
       return&lt;br /&gt;
     end&lt;br /&gt;
     if params['save'] &amp;amp;&amp;amp; params[:question].try(:keys)&lt;br /&gt;
       @questionnaire.update_attributes(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       for qid in params[:question].keys&lt;br /&gt;
         @question = Question.find(qid)&lt;br /&gt;
         @question.txt = params[:question][qid.to_sym][:txt]&lt;br /&gt;
         @question.save&lt;br /&gt;
&lt;br /&gt;
         @quiz_question_choices = QuizQuestionChoice.where(question_id: qid)&lt;br /&gt;
         i = 1&lt;br /&gt;
         for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
     redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 2''': Refactor the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* '''Solution''': &lt;br /&gt;
a. Deleted the create_questionnaire method and replaced the call to it in create_quiz_questionnaire with the code of create_questionnaire and is later moved to quiz_questionnaires_controller.rb and the code snippet below is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b. Moved the large block of for and if statements into method called change_question_types in the quiz_questionnaire model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
&lt;br /&gt;
	if type == &amp;quot;MultipleChoiceCheckbox&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][i.to_s]&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: params[:quiz_question_choices][id.to_s][type][i.to_s][:iscorrect], txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][quiz_question_choice.id.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;MultipleChoiceRadio&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][:correctindex] == i.to_s&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '1', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;TrueFalse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][1.to_s][:iscorrect] == &amp;quot;True&amp;quot; # the statement is correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is correct so &amp;quot;True&amp;quot; is the right answer&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            else # the statement is not correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is not correct so &amp;quot;False&amp;quot; is the right answer&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
c. Replaced large block of for and if statements in update with a call to the new change_question_types method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
d. Moved export, import, copy_questionnaire_details, and assign_instructor_id to questionaire model. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy_questionnaire_details(questions, orig_questionnaire, id)&lt;br /&gt;
    self.instructor_id = self.assign_instructor_id()&lt;br /&gt;
    self.name = 'Copy of ' + orig_questionnaire.name&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      self.created_at = Time.now&lt;br /&gt;
      self.save!&lt;br /&gt;
      questions.each do |question|&lt;br /&gt;
        new_question = question.dup&lt;br /&gt;
        new_question.questionnaire_id = id&lt;br /&gt;
        new_question.size = '50,3' if (new_question.is_a? Criterion or new_question.is_a? TextResponse) and new_question.size.nil?&lt;br /&gt;
        new_question.save!&lt;br /&gt;
        advices = QuestionAdvice.where(question_id: question.id)&lt;br /&gt;
        next if advices.empty?&lt;br /&gt;
        advices.each do |advice|&lt;br /&gt;
          new_advice = advice.dup&lt;br /&gt;
          new_advice.question_id = new_question.id&lt;br /&gt;
          new_advice.save!&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      pFolder = TreeFolder.find_by(name: question.set_display_type(display_type))&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: pFolder.id)&lt;br /&gt;
      QuestionnaireNode.find_or_create_by(parent_id: parent.id, node_object_id: id)&lt;br /&gt;
      undo_link(&amp;quot;Copy of questionnaire #{orig_questionnaire.name} has been created successfully.&amp;quot;)&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'view', id: @questionnaire.id&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'The questionnaire was not able to be copied. Please check the original course for missing information.' + $ERROR_INFO&lt;br /&gt;
      redirect_to action: 'list', controller: 'tree_display'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def export&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    csv_data = QuestionnaireHelper.create_questionnaire_csv @questionnaire, session[:user].name&lt;br /&gt;
    send_data csv_data,&lt;br /&gt;
              type: 'text/csv; charset=iso-8859-1; header=present',&lt;br /&gt;
              disposition: &amp;quot;attachment; filename=questionnaires.csv&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def import&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    file = params['csv']&lt;br /&gt;
    @questionnaire.questions &amp;lt;&amp;lt; QuestionnaireHelper.get_questions_from_csv(@questionnaire, file)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assign_instructor_id&lt;br /&gt;
    # if the user to copy the questionnaire is a TA, the instructor should be the owner instead of the TA&lt;br /&gt;
    if session[:user].role.name != &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      session[:user].id&lt;br /&gt;
    else # for TA we need to get his instructor id and by default add it to his course for which he is the TA&lt;br /&gt;
      Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3''': Replace switch statements with subclasses methods and create models for the subclasses.&lt;br /&gt;
* '''Solution''': Moved the switch-case statement from create in questionaire_controller.rb into a method called set_display_type in questionaire model. The following is the code snippet that shows the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  def set_dispay_type(display_type)&lt;br /&gt;
&lt;br /&gt;
      case display_type&lt;br /&gt;
&lt;br /&gt;
      when 'Review'&lt;br /&gt;
	display_type = 'Review'&lt;br /&gt;
&lt;br /&gt;
      when 'Metareview'&lt;br /&gt;
	display_type = 'Metareview'&lt;br /&gt;
&lt;br /&gt;
      when 'AuthorFeedback'&lt;br /&gt;
        display_type = 'Author%Feedback'&lt;br /&gt;
&lt;br /&gt;
      when 'CourseSurvey'&lt;br /&gt;
        display_type = 'Course%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'TeammateReview'&lt;br /&gt;
        display_type = 'Teammate%Review'&lt;br /&gt;
&lt;br /&gt;
      when 'GlobalSurvey'&lt;br /&gt;
        display_type = 'Global%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'AssignmentSurvey'&lt;br /&gt;
        display_type = 'Assignment%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'Bookmarkrating'&lt;br /&gt;
	display_type = 'Bookmarkrating'&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 4''': Remove hardcoded parameters, such as save_choice method&lt;br /&gt;
* '''Solution''': Hardcoded parameters are removed and necessary constants are defined.&lt;br /&gt;
&lt;br /&gt;
===Test Plans===&lt;br /&gt;
&lt;br /&gt;
Because the purpose of our project was to better arrange our code, it follows that we also needed to rearrange the tests for that code. We first divided the tests for questionnaires_controller into two test files, questionnaires_controller_spec and quiz_questionnaires_controller_spec and separated the tests for CRUD operations of quiz_questionnaires_controller into the quiz_questionnaires_controller_spec, renaming them from view_quiz, create_quiz and the like to view and create. After this separation of CRUD operation testing, we tested the functionality that we moved out of the controllers into the model including the validation method for the quiz questionnaire. We did not include tests to cover the existing model functions, nor did we test the new set_display_type or change_question_types functions as they are setter methods, which, according to our testing instruction are not worth testing. &lt;br /&gt;
&lt;br /&gt;
The setup for testing was particularly troublesome for the deployment of this project. The tests did not run properly in RubyMine, so it was difficult to ensure they were set up properly, and none of the members of our group have any expertise in rspec testing.&lt;br /&gt;
&lt;br /&gt;
===Testing from UI===&lt;br /&gt;
&lt;br /&gt;
*The testing of the export feature is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Export_setup.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Export_completed_successfully.png]]&lt;br /&gt;
&lt;br /&gt;
*The successful creation of quiz is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Quiz created sucessfully.png]]&lt;br /&gt;
&lt;br /&gt;
*The saving of question in a questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Save question in review successfully.png]]&lt;br /&gt;
&lt;br /&gt;
*The successful updating of questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Updated questionnaire successfully.png|center]]&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/Riounis/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1271 GitHub Pull Request]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119217</id>
		<title>CSC/ECE 517 Fall 2018 E1836 Refactor quiz questionnaires controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119217"/>
		<updated>2018-11-10T02:07:16Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Testing from UI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1836. Refactoring quiz_questionnaires_controller.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
* Created quiz_questionnaire_controller.rb&lt;br /&gt;
* Moved view_quiz, new_quiz, create_quiz_questionnaire, edit_quiz and update_quiz from questionnaires_controller.rb, to quiz_questionnaires_controller.rb, and renamed it as view, new, create, edit and update respectively.&lt;br /&gt;
* Refactored the the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* Replaced switch statements in questionnaires_controller.rb with subclass methods.&lt;br /&gt;
* Created models for the subclasses.&lt;br /&gt;
* Removed hardcoded parameters, such as save_choice method.&lt;br /&gt;
* Appropriate tests were written to test the code.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
'''Problem 1''': Create quiz_questionnaire_controller.rb and move some of the methods in the questionnaires_controller.rb to the new file created.&lt;br /&gt;
* '''Solution''': The methods view_quiz, new_quiz, create_quiz, edit_quiz and update_quiz in the questionnaires_controller.rb were the methods identified and moved into the quiz_questionnaire_controller.rb. They were respectively renamed as view, new, create, edit and update. The implementation of the newly created quiz_questionnaire_controller.rb can be seen below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class QuizQuestionnairesController &amp;lt; QuestionnairesController&lt;br /&gt;
&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
   # Separate methods for quiz questionnaire&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
&lt;br /&gt;
   # View a quiz questionnaire&lt;br /&gt;
   def view&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     @participant = Participant.find(params[:pid]) # creating an instance variable since it needs to be sent to submitted_content/edit&lt;br /&gt;
     render :view&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # define a new quiz questionnaire&lt;br /&gt;
   # method invoked by the view&lt;br /&gt;
   def new&lt;br /&gt;
     valid_request = true&lt;br /&gt;
     @assignment_id = params[:aid] # creating an instance variable to hold the assignment id&lt;br /&gt;
     @participant_id = params[:pid] # creating an instance variable to hold the participant id&lt;br /&gt;
     assignment = Assignment.find(@assignment_id)&lt;br /&gt;
     if !assignment.require_quiz? # flash error if this assignment does not require quiz&lt;br /&gt;
       flash[:error] = &amp;quot;This assignment does not support the quizzing feature.&amp;quot;&lt;br /&gt;
       valid_request = false&lt;br /&gt;
     else&lt;br /&gt;
       team = AssignmentParticipant.find(@participant_id).team&lt;br /&gt;
&lt;br /&gt;
       if team.nil? # flash error if this current participant does not have a team&lt;br /&gt;
         flash[:error] = &amp;quot;You should create or join a team first.&amp;quot;&lt;br /&gt;
         valid_request = false&lt;br /&gt;
       else&lt;br /&gt;
         if assignment.topics? &amp;amp;&amp;amp; team.topic.nil? # flash error if this assignment has topic but current team does not have a topic&lt;br /&gt;
           flash[:error] = &amp;quot;Your team should have a topic.&amp;quot;&lt;br /&gt;
           valid_request = false&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
     if valid_request &amp;amp;&amp;amp; Questionnaire::QUESTIONNAIRE_TYPES.include?(params[:model])&lt;br /&gt;
       @questionnaire = Object.const_get(params[:model]).new&lt;br /&gt;
       @questionnaire.private = params[:private]&lt;br /&gt;
       @questionnaire.min_question_score = 0&lt;br /&gt;
       @questionnaire.max_question_score = 1&lt;br /&gt;
&lt;br /&gt;
       render :new&lt;br /&gt;
     else&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # seperate method for creating a quiz questionnaire because of differences in permission&lt;br /&gt;
   def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # edit a quiz questionnaire&lt;br /&gt;
   def edit&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if !@questionnaire.taken_by_anyone?&lt;br /&gt;
       render :edit&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = &amp;quot;Your quiz has been taken by some other students, you cannot edit it anymore.&amp;quot;&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
   # save an updated quiz questionnaire to the database&lt;br /&gt;
   def update&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if @questionnaire.nil?&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
       return&lt;br /&gt;
     end&lt;br /&gt;
     if params['save'] &amp;amp;&amp;amp; params[:question].try(:keys)&lt;br /&gt;
       @questionnaire.update_attributes(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       for qid in params[:question].keys&lt;br /&gt;
         @question = Question.find(qid)&lt;br /&gt;
         @question.txt = params[:question][qid.to_sym][:txt]&lt;br /&gt;
         @question.save&lt;br /&gt;
&lt;br /&gt;
         @quiz_question_choices = QuizQuestionChoice.where(question_id: qid)&lt;br /&gt;
         i = 1&lt;br /&gt;
         for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
     redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 2''': Refactor the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* '''Solution''': &lt;br /&gt;
a. Deleted the create_questionnaire method and replaced the call to it in create_quiz_questionnaire with the code of create_questionnaire and is later moved to quiz_questionnaires_controller.rb and the code snippet below is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b. Moved the large block of for and if statements into method called change_question_types in the quiz_questionnaire model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
&lt;br /&gt;
	if type == &amp;quot;MultipleChoiceCheckbox&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][i.to_s]&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: params[:quiz_question_choices][id.to_s][type][i.to_s][:iscorrect], txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][quiz_question_choice.id.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;MultipleChoiceRadio&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][:correctindex] == i.to_s&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '1', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;TrueFalse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][1.to_s][:iscorrect] == &amp;quot;True&amp;quot; # the statement is correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is correct so &amp;quot;True&amp;quot; is the right answer&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            else # the statement is not correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is not correct so &amp;quot;False&amp;quot; is the right answer&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
c. Replaced large block of for and if statements in update with a call to the new change_question_types method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
d. Moved export, import, copy_questionnaire_details, and assign_instructor_id to questionaire model. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy_questionnaire_details(questions, orig_questionnaire, id)&lt;br /&gt;
    self.instructor_id = self.assign_instructor_id()&lt;br /&gt;
    self.name = 'Copy of ' + orig_questionnaire.name&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      self.created_at = Time.now&lt;br /&gt;
      self.save!&lt;br /&gt;
      questions.each do |question|&lt;br /&gt;
        new_question = question.dup&lt;br /&gt;
        new_question.questionnaire_id = id&lt;br /&gt;
        new_question.size = '50,3' if (new_question.is_a? Criterion or new_question.is_a? TextResponse) and new_question.size.nil?&lt;br /&gt;
        new_question.save!&lt;br /&gt;
        advices = QuestionAdvice.where(question_id: question.id)&lt;br /&gt;
        next if advices.empty?&lt;br /&gt;
        advices.each do |advice|&lt;br /&gt;
          new_advice = advice.dup&lt;br /&gt;
          new_advice.question_id = new_question.id&lt;br /&gt;
          new_advice.save!&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      pFolder = TreeFolder.find_by(name: question.set_display_type(display_type))&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: pFolder.id)&lt;br /&gt;
      QuestionnaireNode.find_or_create_by(parent_id: parent.id, node_object_id: id)&lt;br /&gt;
      undo_link(&amp;quot;Copy of questionnaire #{orig_questionnaire.name} has been created successfully.&amp;quot;)&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'view', id: @questionnaire.id&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'The questionnaire was not able to be copied. Please check the original course for missing information.' + $ERROR_INFO&lt;br /&gt;
      redirect_to action: 'list', controller: 'tree_display'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def export&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    csv_data = QuestionnaireHelper.create_questionnaire_csv @questionnaire, session[:user].name&lt;br /&gt;
    send_data csv_data,&lt;br /&gt;
              type: 'text/csv; charset=iso-8859-1; header=present',&lt;br /&gt;
              disposition: &amp;quot;attachment; filename=questionnaires.csv&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def import&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    file = params['csv']&lt;br /&gt;
    @questionnaire.questions &amp;lt;&amp;lt; QuestionnaireHelper.get_questions_from_csv(@questionnaire, file)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assign_instructor_id&lt;br /&gt;
    # if the user to copy the questionnaire is a TA, the instructor should be the owner instead of the TA&lt;br /&gt;
    if session[:user].role.name != &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      session[:user].id&lt;br /&gt;
    else # for TA we need to get his instructor id and by default add it to his course for which he is the TA&lt;br /&gt;
      Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3''': Replace switch statements with subclasses methods and create models for the subclasses.&lt;br /&gt;
* '''Solution''': Moved the switch-case statement from create in questionaire_controller.rb into a method called set_display_type in questionaire model. The following is the code snippet that shows the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  def set_dispay_type(display_type)&lt;br /&gt;
&lt;br /&gt;
      case display_type&lt;br /&gt;
&lt;br /&gt;
      when 'Review'&lt;br /&gt;
	display_type = 'Review'&lt;br /&gt;
&lt;br /&gt;
      when 'Metareview'&lt;br /&gt;
	display_type = 'Metareview'&lt;br /&gt;
&lt;br /&gt;
      when 'AuthorFeedback'&lt;br /&gt;
        display_type = 'Author%Feedback'&lt;br /&gt;
&lt;br /&gt;
      when 'CourseSurvey'&lt;br /&gt;
        display_type = 'Course%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'TeammateReview'&lt;br /&gt;
        display_type = 'Teammate%Review'&lt;br /&gt;
&lt;br /&gt;
      when 'GlobalSurvey'&lt;br /&gt;
        display_type = 'Global%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'AssignmentSurvey'&lt;br /&gt;
        display_type = 'Assignment%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'Bookmarkrating'&lt;br /&gt;
	display_type = 'Bookmarkrating'&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 4''': Remove hardcoded parameters, such as save_choice method&lt;br /&gt;
* '''Solution''': Hardcoded parameters are removed and necessary constants are defined.&lt;br /&gt;
&lt;br /&gt;
===Test Plans===&lt;br /&gt;
&lt;br /&gt;
Because the purpose of our project was to better arrange our code, it follows that we also needed to rearrange the tests for that code. We first divided the tests for questionnaires_controller into two test files, questionnaires_controller_spec and quiz_questionnaires_controller_spec and separated the tests for CRUD operations of quiz_questionnaires_controller into the quiz_questionnaires_controller_spec, renaming them from view_quiz, create_quiz and the like to view and create. After this separation of CRUD operation testing, we tested the functionality that we moved out of the controllers into the model including the validation method for the quiz questionnaire. We did not include tests to cover the existing model functions, nor did we test the new set_display_type or change_question_types functions as they are setter methods, which, according to our testing instruction are not worth testing. &lt;br /&gt;
&lt;br /&gt;
The setup for testing was particularly troublesome for the deployment of this project. The tests did not run properly in RubyMine, so it was difficult to ensure they were set up properly, and none of the members of our group have any expertise in rspec testing.&lt;br /&gt;
&lt;br /&gt;
===Testing from UI===&lt;br /&gt;
&lt;br /&gt;
*The testing of the export feature is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Export_setup.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Export_completed_successfully.png]]&lt;br /&gt;
&lt;br /&gt;
*The successful creation of quiz is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Quiz created sucessfully.png]]&lt;br /&gt;
&lt;br /&gt;
*The saving of question in a questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Save question in review successfully.png]]&lt;br /&gt;
&lt;br /&gt;
*The successful updating of questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Updated questionnaire successfully.png]]&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/Riounis/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1271 GitHub Pull Request]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Updated_questionnaire_successfully.png&amp;diff=119215</id>
		<title>File:Updated questionnaire successfully.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Updated_questionnaire_successfully.png&amp;diff=119215"/>
		<updated>2018-11-10T02:05:53Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Save_question_in_review_successfully.png&amp;diff=119214</id>
		<title>File:Save question in review successfully.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Save_question_in_review_successfully.png&amp;diff=119214"/>
		<updated>2018-11-10T02:05:43Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Quiz_created_sucessfully.png&amp;diff=119213</id>
		<title>File:Quiz created sucessfully.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Quiz_created_sucessfully.png&amp;diff=119213"/>
		<updated>2018-11-10T02:05:29Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119212</id>
		<title>CSC/ECE 517 Fall 2018 E1836 Refactor quiz questionnaires controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119212"/>
		<updated>2018-11-10T02:05:13Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Testing from UI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1836. Refactoring quiz_questionnaires_controller.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
* Created quiz_questionnaire_controller.rb&lt;br /&gt;
* Moved view_quiz, new_quiz, create_quiz_questionnaire, edit_quiz and update_quiz from questionnaires_controller.rb, to quiz_questionnaires_controller.rb, and renamed it as view, new, create, edit and update respectively.&lt;br /&gt;
* Refactored the the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* Replaced switch statements in questionnaires_controller.rb with subclass methods.&lt;br /&gt;
* Created models for the subclasses.&lt;br /&gt;
* Removed hardcoded parameters, such as save_choice method.&lt;br /&gt;
* Appropriate tests were written to test the code.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
'''Problem 1''': Create quiz_questionnaire_controller.rb and move some of the methods in the questionnaires_controller.rb to the new file created.&lt;br /&gt;
* '''Solution''': The methods view_quiz, new_quiz, create_quiz, edit_quiz and update_quiz in the questionnaires_controller.rb were the methods identified and moved into the quiz_questionnaire_controller.rb. They were respectively renamed as view, new, create, edit and update. The implementation of the newly created quiz_questionnaire_controller.rb can be seen below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class QuizQuestionnairesController &amp;lt; QuestionnairesController&lt;br /&gt;
&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
   # Separate methods for quiz questionnaire&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
&lt;br /&gt;
   # View a quiz questionnaire&lt;br /&gt;
   def view&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     @participant = Participant.find(params[:pid]) # creating an instance variable since it needs to be sent to submitted_content/edit&lt;br /&gt;
     render :view&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # define a new quiz questionnaire&lt;br /&gt;
   # method invoked by the view&lt;br /&gt;
   def new&lt;br /&gt;
     valid_request = true&lt;br /&gt;
     @assignment_id = params[:aid] # creating an instance variable to hold the assignment id&lt;br /&gt;
     @participant_id = params[:pid] # creating an instance variable to hold the participant id&lt;br /&gt;
     assignment = Assignment.find(@assignment_id)&lt;br /&gt;
     if !assignment.require_quiz? # flash error if this assignment does not require quiz&lt;br /&gt;
       flash[:error] = &amp;quot;This assignment does not support the quizzing feature.&amp;quot;&lt;br /&gt;
       valid_request = false&lt;br /&gt;
     else&lt;br /&gt;
       team = AssignmentParticipant.find(@participant_id).team&lt;br /&gt;
&lt;br /&gt;
       if team.nil? # flash error if this current participant does not have a team&lt;br /&gt;
         flash[:error] = &amp;quot;You should create or join a team first.&amp;quot;&lt;br /&gt;
         valid_request = false&lt;br /&gt;
       else&lt;br /&gt;
         if assignment.topics? &amp;amp;&amp;amp; team.topic.nil? # flash error if this assignment has topic but current team does not have a topic&lt;br /&gt;
           flash[:error] = &amp;quot;Your team should have a topic.&amp;quot;&lt;br /&gt;
           valid_request = false&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
     if valid_request &amp;amp;&amp;amp; Questionnaire::QUESTIONNAIRE_TYPES.include?(params[:model])&lt;br /&gt;
       @questionnaire = Object.const_get(params[:model]).new&lt;br /&gt;
       @questionnaire.private = params[:private]&lt;br /&gt;
       @questionnaire.min_question_score = 0&lt;br /&gt;
       @questionnaire.max_question_score = 1&lt;br /&gt;
&lt;br /&gt;
       render :new&lt;br /&gt;
     else&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # seperate method for creating a quiz questionnaire because of differences in permission&lt;br /&gt;
   def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # edit a quiz questionnaire&lt;br /&gt;
   def edit&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if !@questionnaire.taken_by_anyone?&lt;br /&gt;
       render :edit&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = &amp;quot;Your quiz has been taken by some other students, you cannot edit it anymore.&amp;quot;&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
   # save an updated quiz questionnaire to the database&lt;br /&gt;
   def update&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if @questionnaire.nil?&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
       return&lt;br /&gt;
     end&lt;br /&gt;
     if params['save'] &amp;amp;&amp;amp; params[:question].try(:keys)&lt;br /&gt;
       @questionnaire.update_attributes(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       for qid in params[:question].keys&lt;br /&gt;
         @question = Question.find(qid)&lt;br /&gt;
         @question.txt = params[:question][qid.to_sym][:txt]&lt;br /&gt;
         @question.save&lt;br /&gt;
&lt;br /&gt;
         @quiz_question_choices = QuizQuestionChoice.where(question_id: qid)&lt;br /&gt;
         i = 1&lt;br /&gt;
         for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
     redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 2''': Refactor the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* '''Solution''': &lt;br /&gt;
a. Deleted the create_questionnaire method and replaced the call to it in create_quiz_questionnaire with the code of create_questionnaire and is later moved to quiz_questionnaires_controller.rb and the code snippet below is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b. Moved the large block of for and if statements into method called change_question_types in the quiz_questionnaire model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
&lt;br /&gt;
	if type == &amp;quot;MultipleChoiceCheckbox&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][i.to_s]&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: params[:quiz_question_choices][id.to_s][type][i.to_s][:iscorrect], txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][quiz_question_choice.id.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;MultipleChoiceRadio&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][:correctindex] == i.to_s&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '1', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;TrueFalse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][1.to_s][:iscorrect] == &amp;quot;True&amp;quot; # the statement is correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is correct so &amp;quot;True&amp;quot; is the right answer&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            else # the statement is not correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is not correct so &amp;quot;False&amp;quot; is the right answer&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
c. Replaced large block of for and if statements in update with a call to the new change_question_types method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
d. Moved export, import, copy_questionnaire_details, and assign_instructor_id to questionaire model. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy_questionnaire_details(questions, orig_questionnaire, id)&lt;br /&gt;
    self.instructor_id = self.assign_instructor_id()&lt;br /&gt;
    self.name = 'Copy of ' + orig_questionnaire.name&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      self.created_at = Time.now&lt;br /&gt;
      self.save!&lt;br /&gt;
      questions.each do |question|&lt;br /&gt;
        new_question = question.dup&lt;br /&gt;
        new_question.questionnaire_id = id&lt;br /&gt;
        new_question.size = '50,3' if (new_question.is_a? Criterion or new_question.is_a? TextResponse) and new_question.size.nil?&lt;br /&gt;
        new_question.save!&lt;br /&gt;
        advices = QuestionAdvice.where(question_id: question.id)&lt;br /&gt;
        next if advices.empty?&lt;br /&gt;
        advices.each do |advice|&lt;br /&gt;
          new_advice = advice.dup&lt;br /&gt;
          new_advice.question_id = new_question.id&lt;br /&gt;
          new_advice.save!&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      pFolder = TreeFolder.find_by(name: question.set_display_type(display_type))&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: pFolder.id)&lt;br /&gt;
      QuestionnaireNode.find_or_create_by(parent_id: parent.id, node_object_id: id)&lt;br /&gt;
      undo_link(&amp;quot;Copy of questionnaire #{orig_questionnaire.name} has been created successfully.&amp;quot;)&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'view', id: @questionnaire.id&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'The questionnaire was not able to be copied. Please check the original course for missing information.' + $ERROR_INFO&lt;br /&gt;
      redirect_to action: 'list', controller: 'tree_display'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def export&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    csv_data = QuestionnaireHelper.create_questionnaire_csv @questionnaire, session[:user].name&lt;br /&gt;
    send_data csv_data,&lt;br /&gt;
              type: 'text/csv; charset=iso-8859-1; header=present',&lt;br /&gt;
              disposition: &amp;quot;attachment; filename=questionnaires.csv&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def import&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    file = params['csv']&lt;br /&gt;
    @questionnaire.questions &amp;lt;&amp;lt; QuestionnaireHelper.get_questions_from_csv(@questionnaire, file)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assign_instructor_id&lt;br /&gt;
    # if the user to copy the questionnaire is a TA, the instructor should be the owner instead of the TA&lt;br /&gt;
    if session[:user].role.name != &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      session[:user].id&lt;br /&gt;
    else # for TA we need to get his instructor id and by default add it to his course for which he is the TA&lt;br /&gt;
      Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3''': Replace switch statements with subclasses methods and create models for the subclasses.&lt;br /&gt;
* '''Solution''': Moved the switch-case statement from create in questionaire_controller.rb into a method called set_display_type in questionaire model. The following is the code snippet that shows the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  def set_dispay_type(display_type)&lt;br /&gt;
&lt;br /&gt;
      case display_type&lt;br /&gt;
&lt;br /&gt;
      when 'Review'&lt;br /&gt;
	display_type = 'Review'&lt;br /&gt;
&lt;br /&gt;
      when 'Metareview'&lt;br /&gt;
	display_type = 'Metareview'&lt;br /&gt;
&lt;br /&gt;
      when 'AuthorFeedback'&lt;br /&gt;
        display_type = 'Author%Feedback'&lt;br /&gt;
&lt;br /&gt;
      when 'CourseSurvey'&lt;br /&gt;
        display_type = 'Course%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'TeammateReview'&lt;br /&gt;
        display_type = 'Teammate%Review'&lt;br /&gt;
&lt;br /&gt;
      when 'GlobalSurvey'&lt;br /&gt;
        display_type = 'Global%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'AssignmentSurvey'&lt;br /&gt;
        display_type = 'Assignment%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'Bookmarkrating'&lt;br /&gt;
	display_type = 'Bookmarkrating'&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 4''': Remove hardcoded parameters, such as save_choice method&lt;br /&gt;
* '''Solution''': Hardcoded parameters are removed and necessary constants are defined.&lt;br /&gt;
&lt;br /&gt;
===Test Plans===&lt;br /&gt;
&lt;br /&gt;
Because the purpose of our project was to better arrange our code, it follows that we also needed to rearrange the tests for that code. We first divided the tests for questionnaires_controller into two test files, questionnaires_controller_spec and quiz_questionnaires_controller_spec and separated the tests for CRUD operations of quiz_questionnaires_controller into the quiz_questionnaires_controller_spec, renaming them from view_quiz, create_quiz and the like to view and create. After this separation of CRUD operation testing, we tested the functionality that we moved out of the controllers into the model including the validation method for the quiz questionnaire. We did not include tests to cover the existing model functions, nor did we test the new set_display_type or change_question_types functions as they are setter methods, which, according to our testing instruction are not worth testing. &lt;br /&gt;
&lt;br /&gt;
The setup for testing was particularly troublesome for the deployment of this project. The tests did not run properly in RubyMine, so it was difficult to ensure they were set up properly, and none of the members of our group have any expertise in rspec testing.&lt;br /&gt;
&lt;br /&gt;
===Testing from UI===&lt;br /&gt;
&lt;br /&gt;
The testing of the export feature is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Export_setup.png]]&lt;br /&gt;
&lt;br /&gt;
[[File:Export_completed_successfully.png]]&lt;br /&gt;
&lt;br /&gt;
The successful creation of quiz is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Quiz created sucessfully.png]]&lt;br /&gt;
&lt;br /&gt;
The saving of question in a questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Save question in review successfully.png]]&lt;br /&gt;
&lt;br /&gt;
The successful updating of questionnaire is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Updated questionnaire successfully.png]]&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/Riounis/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1271 GitHub Pull Request]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119209</id>
		<title>CSC/ECE 517 Fall 2018 E1836 Refactor quiz questionnaires controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119209"/>
		<updated>2018-11-10T02:01:03Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Testing from UI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1836. Refactoring quiz_questionnaires_controller.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
* Created quiz_questionnaire_controller.rb&lt;br /&gt;
* Moved view_quiz, new_quiz, create_quiz_questionnaire, edit_quiz and update_quiz from questionnaires_controller.rb, to quiz_questionnaires_controller.rb, and renamed it as view, new, create, edit and update respectively.&lt;br /&gt;
* Refactored the the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* Replaced switch statements in questionnaires_controller.rb with subclass methods.&lt;br /&gt;
* Created models for the subclasses.&lt;br /&gt;
* Removed hardcoded parameters, such as save_choice method.&lt;br /&gt;
* Appropriate tests were written to test the code.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
'''Problem 1''': Create quiz_questionnaire_controller.rb and move some of the methods in the questionnaires_controller.rb to the new file created.&lt;br /&gt;
* '''Solution''': The methods view_quiz, new_quiz, create_quiz, edit_quiz and update_quiz in the questionnaires_controller.rb were the methods identified and moved into the quiz_questionnaire_controller.rb. They were respectively renamed as view, new, create, edit and update. The implementation of the newly created quiz_questionnaire_controller.rb can be seen below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class QuizQuestionnairesController &amp;lt; QuestionnairesController&lt;br /&gt;
&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
   # Separate methods for quiz questionnaire&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
&lt;br /&gt;
   # View a quiz questionnaire&lt;br /&gt;
   def view&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     @participant = Participant.find(params[:pid]) # creating an instance variable since it needs to be sent to submitted_content/edit&lt;br /&gt;
     render :view&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # define a new quiz questionnaire&lt;br /&gt;
   # method invoked by the view&lt;br /&gt;
   def new&lt;br /&gt;
     valid_request = true&lt;br /&gt;
     @assignment_id = params[:aid] # creating an instance variable to hold the assignment id&lt;br /&gt;
     @participant_id = params[:pid] # creating an instance variable to hold the participant id&lt;br /&gt;
     assignment = Assignment.find(@assignment_id)&lt;br /&gt;
     if !assignment.require_quiz? # flash error if this assignment does not require quiz&lt;br /&gt;
       flash[:error] = &amp;quot;This assignment does not support the quizzing feature.&amp;quot;&lt;br /&gt;
       valid_request = false&lt;br /&gt;
     else&lt;br /&gt;
       team = AssignmentParticipant.find(@participant_id).team&lt;br /&gt;
&lt;br /&gt;
       if team.nil? # flash error if this current participant does not have a team&lt;br /&gt;
         flash[:error] = &amp;quot;You should create or join a team first.&amp;quot;&lt;br /&gt;
         valid_request = false&lt;br /&gt;
       else&lt;br /&gt;
         if assignment.topics? &amp;amp;&amp;amp; team.topic.nil? # flash error if this assignment has topic but current team does not have a topic&lt;br /&gt;
           flash[:error] = &amp;quot;Your team should have a topic.&amp;quot;&lt;br /&gt;
           valid_request = false&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
     if valid_request &amp;amp;&amp;amp; Questionnaire::QUESTIONNAIRE_TYPES.include?(params[:model])&lt;br /&gt;
       @questionnaire = Object.const_get(params[:model]).new&lt;br /&gt;
       @questionnaire.private = params[:private]&lt;br /&gt;
       @questionnaire.min_question_score = 0&lt;br /&gt;
       @questionnaire.max_question_score = 1&lt;br /&gt;
&lt;br /&gt;
       render :new&lt;br /&gt;
     else&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # seperate method for creating a quiz questionnaire because of differences in permission&lt;br /&gt;
   def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # edit a quiz questionnaire&lt;br /&gt;
   def edit&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if !@questionnaire.taken_by_anyone?&lt;br /&gt;
       render :edit&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = &amp;quot;Your quiz has been taken by some other students, you cannot edit it anymore.&amp;quot;&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
   # save an updated quiz questionnaire to the database&lt;br /&gt;
   def update&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if @questionnaire.nil?&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
       return&lt;br /&gt;
     end&lt;br /&gt;
     if params['save'] &amp;amp;&amp;amp; params[:question].try(:keys)&lt;br /&gt;
       @questionnaire.update_attributes(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       for qid in params[:question].keys&lt;br /&gt;
         @question = Question.find(qid)&lt;br /&gt;
         @question.txt = params[:question][qid.to_sym][:txt]&lt;br /&gt;
         @question.save&lt;br /&gt;
&lt;br /&gt;
         @quiz_question_choices = QuizQuestionChoice.where(question_id: qid)&lt;br /&gt;
         i = 1&lt;br /&gt;
         for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
     redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 2''': Refactor the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* '''Solution''': &lt;br /&gt;
a. Deleted the create_questionnaire method and replaced the call to it in create_quiz_questionnaire with the code of create_questionnaire and is later moved to quiz_questionnaires_controller.rb and the code snippet below is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b. Moved the large block of for and if statements into method called change_question_types in the quiz_questionnaire model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
&lt;br /&gt;
	if type == &amp;quot;MultipleChoiceCheckbox&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][i.to_s]&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: params[:quiz_question_choices][id.to_s][type][i.to_s][:iscorrect], txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][quiz_question_choice.id.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;MultipleChoiceRadio&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][:correctindex] == i.to_s&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '1', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;TrueFalse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][1.to_s][:iscorrect] == &amp;quot;True&amp;quot; # the statement is correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is correct so &amp;quot;True&amp;quot; is the right answer&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            else # the statement is not correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is not correct so &amp;quot;False&amp;quot; is the right answer&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
c. Replaced large block of for and if statements in update with a call to the new change_question_types method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
d. Moved export, import, copy_questionnaire_details, and assign_instructor_id to questionaire model. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy_questionnaire_details(questions, orig_questionnaire, id)&lt;br /&gt;
    self.instructor_id = self.assign_instructor_id()&lt;br /&gt;
    self.name = 'Copy of ' + orig_questionnaire.name&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      self.created_at = Time.now&lt;br /&gt;
      self.save!&lt;br /&gt;
      questions.each do |question|&lt;br /&gt;
        new_question = question.dup&lt;br /&gt;
        new_question.questionnaire_id = id&lt;br /&gt;
        new_question.size = '50,3' if (new_question.is_a? Criterion or new_question.is_a? TextResponse) and new_question.size.nil?&lt;br /&gt;
        new_question.save!&lt;br /&gt;
        advices = QuestionAdvice.where(question_id: question.id)&lt;br /&gt;
        next if advices.empty?&lt;br /&gt;
        advices.each do |advice|&lt;br /&gt;
          new_advice = advice.dup&lt;br /&gt;
          new_advice.question_id = new_question.id&lt;br /&gt;
          new_advice.save!&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      pFolder = TreeFolder.find_by(name: question.set_display_type(display_type))&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: pFolder.id)&lt;br /&gt;
      QuestionnaireNode.find_or_create_by(parent_id: parent.id, node_object_id: id)&lt;br /&gt;
      undo_link(&amp;quot;Copy of questionnaire #{orig_questionnaire.name} has been created successfully.&amp;quot;)&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'view', id: @questionnaire.id&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'The questionnaire was not able to be copied. Please check the original course for missing information.' + $ERROR_INFO&lt;br /&gt;
      redirect_to action: 'list', controller: 'tree_display'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def export&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    csv_data = QuestionnaireHelper.create_questionnaire_csv @questionnaire, session[:user].name&lt;br /&gt;
    send_data csv_data,&lt;br /&gt;
              type: 'text/csv; charset=iso-8859-1; header=present',&lt;br /&gt;
              disposition: &amp;quot;attachment; filename=questionnaires.csv&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def import&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    file = params['csv']&lt;br /&gt;
    @questionnaire.questions &amp;lt;&amp;lt; QuestionnaireHelper.get_questions_from_csv(@questionnaire, file)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assign_instructor_id&lt;br /&gt;
    # if the user to copy the questionnaire is a TA, the instructor should be the owner instead of the TA&lt;br /&gt;
    if session[:user].role.name != &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      session[:user].id&lt;br /&gt;
    else # for TA we need to get his instructor id and by default add it to his course for which he is the TA&lt;br /&gt;
      Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3''': Replace switch statements with subclasses methods and create models for the subclasses.&lt;br /&gt;
* '''Solution''': Moved the switch-case statement from create in questionaire_controller.rb into a method called set_display_type in questionaire model. The following is the code snippet that shows the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  def set_dispay_type(display_type)&lt;br /&gt;
&lt;br /&gt;
      case display_type&lt;br /&gt;
&lt;br /&gt;
      when 'Review'&lt;br /&gt;
	display_type = 'Review'&lt;br /&gt;
&lt;br /&gt;
      when 'Metareview'&lt;br /&gt;
	display_type = 'Metareview'&lt;br /&gt;
&lt;br /&gt;
      when 'AuthorFeedback'&lt;br /&gt;
        display_type = 'Author%Feedback'&lt;br /&gt;
&lt;br /&gt;
      when 'CourseSurvey'&lt;br /&gt;
        display_type = 'Course%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'TeammateReview'&lt;br /&gt;
        display_type = 'Teammate%Review'&lt;br /&gt;
&lt;br /&gt;
      when 'GlobalSurvey'&lt;br /&gt;
        display_type = 'Global%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'AssignmentSurvey'&lt;br /&gt;
        display_type = 'Assignment%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'Bookmarkrating'&lt;br /&gt;
	display_type = 'Bookmarkrating'&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 4''': Remove hardcoded parameters, such as save_choice method&lt;br /&gt;
* '''Solution''': Hardcoded parameters are removed and necessary constants are defined.&lt;br /&gt;
&lt;br /&gt;
===Test Plans===&lt;br /&gt;
&lt;br /&gt;
Because the purpose of our project was to better arrange our code, it follows that we also needed to rearrange the tests for that code. We first divided the tests for questionnaires_controller into two test files, questionnaires_controller_spec and quiz_questionnaires_controller_spec and separated the tests for CRUD operations of quiz_questionnaires_controller into the quiz_questionnaires_controller_spec, renaming them from view_quiz, create_quiz and the like to view and create. After this separation of CRUD operation testing, we tested the functionality that we moved out of the controllers into the model including the validation method for the quiz questionnaire. We did not include tests to cover the existing model functions, nor did we test the new set_display_type or change_question_types functions as they are setter methods, which, according to our testing instruction are not worth testing. &lt;br /&gt;
&lt;br /&gt;
The setup for testing was particularly troublesome for the deployment of this project. The tests did not run properly in RubyMine, so it was difficult to ensure they were set up properly, and none of the members of our group have any expertise in rspec testing.&lt;br /&gt;
&lt;br /&gt;
===Testing from UI===&lt;br /&gt;
&lt;br /&gt;
The testing of the export feature is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Export_completed_successfully.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/Riounis/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1271 GitHub Pull Request]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119208</id>
		<title>CSC/ECE 517 Fall 2018 E1836 Refactor quiz questionnaires controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119208"/>
		<updated>2018-11-10T02:00:50Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* E1836. Refactoring quiz_questionnaires_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1836. Refactoring quiz_questionnaires_controller.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
* Created quiz_questionnaire_controller.rb&lt;br /&gt;
* Moved view_quiz, new_quiz, create_quiz_questionnaire, edit_quiz and update_quiz from questionnaires_controller.rb, to quiz_questionnaires_controller.rb, and renamed it as view, new, create, edit and update respectively.&lt;br /&gt;
* Refactored the the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* Replaced switch statements in questionnaires_controller.rb with subclass methods.&lt;br /&gt;
* Created models for the subclasses.&lt;br /&gt;
* Removed hardcoded parameters, such as save_choice method.&lt;br /&gt;
* Appropriate tests were written to test the code.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
'''Problem 1''': Create quiz_questionnaire_controller.rb and move some of the methods in the questionnaires_controller.rb to the new file created.&lt;br /&gt;
* '''Solution''': The methods view_quiz, new_quiz, create_quiz, edit_quiz and update_quiz in the questionnaires_controller.rb were the methods identified and moved into the quiz_questionnaire_controller.rb. They were respectively renamed as view, new, create, edit and update. The implementation of the newly created quiz_questionnaire_controller.rb can be seen below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class QuizQuestionnairesController &amp;lt; QuestionnairesController&lt;br /&gt;
&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
   # Separate methods for quiz questionnaire&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
&lt;br /&gt;
   # View a quiz questionnaire&lt;br /&gt;
   def view&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     @participant = Participant.find(params[:pid]) # creating an instance variable since it needs to be sent to submitted_content/edit&lt;br /&gt;
     render :view&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # define a new quiz questionnaire&lt;br /&gt;
   # method invoked by the view&lt;br /&gt;
   def new&lt;br /&gt;
     valid_request = true&lt;br /&gt;
     @assignment_id = params[:aid] # creating an instance variable to hold the assignment id&lt;br /&gt;
     @participant_id = params[:pid] # creating an instance variable to hold the participant id&lt;br /&gt;
     assignment = Assignment.find(@assignment_id)&lt;br /&gt;
     if !assignment.require_quiz? # flash error if this assignment does not require quiz&lt;br /&gt;
       flash[:error] = &amp;quot;This assignment does not support the quizzing feature.&amp;quot;&lt;br /&gt;
       valid_request = false&lt;br /&gt;
     else&lt;br /&gt;
       team = AssignmentParticipant.find(@participant_id).team&lt;br /&gt;
&lt;br /&gt;
       if team.nil? # flash error if this current participant does not have a team&lt;br /&gt;
         flash[:error] = &amp;quot;You should create or join a team first.&amp;quot;&lt;br /&gt;
         valid_request = false&lt;br /&gt;
       else&lt;br /&gt;
         if assignment.topics? &amp;amp;&amp;amp; team.topic.nil? # flash error if this assignment has topic but current team does not have a topic&lt;br /&gt;
           flash[:error] = &amp;quot;Your team should have a topic.&amp;quot;&lt;br /&gt;
           valid_request = false&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
     if valid_request &amp;amp;&amp;amp; Questionnaire::QUESTIONNAIRE_TYPES.include?(params[:model])&lt;br /&gt;
       @questionnaire = Object.const_get(params[:model]).new&lt;br /&gt;
       @questionnaire.private = params[:private]&lt;br /&gt;
       @questionnaire.min_question_score = 0&lt;br /&gt;
       @questionnaire.max_question_score = 1&lt;br /&gt;
&lt;br /&gt;
       render :new&lt;br /&gt;
     else&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # seperate method for creating a quiz questionnaire because of differences in permission&lt;br /&gt;
   def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # edit a quiz questionnaire&lt;br /&gt;
   def edit&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if !@questionnaire.taken_by_anyone?&lt;br /&gt;
       render :edit&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = &amp;quot;Your quiz has been taken by some other students, you cannot edit it anymore.&amp;quot;&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
   # save an updated quiz questionnaire to the database&lt;br /&gt;
   def update&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if @questionnaire.nil?&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
       return&lt;br /&gt;
     end&lt;br /&gt;
     if params['save'] &amp;amp;&amp;amp; params[:question].try(:keys)&lt;br /&gt;
       @questionnaire.update_attributes(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       for qid in params[:question].keys&lt;br /&gt;
         @question = Question.find(qid)&lt;br /&gt;
         @question.txt = params[:question][qid.to_sym][:txt]&lt;br /&gt;
         @question.save&lt;br /&gt;
&lt;br /&gt;
         @quiz_question_choices = QuizQuestionChoice.where(question_id: qid)&lt;br /&gt;
         i = 1&lt;br /&gt;
         for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
     redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 2''': Refactor the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* '''Solution''': &lt;br /&gt;
a. Deleted the create_questionnaire method and replaced the call to it in create_quiz_questionnaire with the code of create_questionnaire and is later moved to quiz_questionnaires_controller.rb and the code snippet below is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b. Moved the large block of for and if statements into method called change_question_types in the quiz_questionnaire model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
&lt;br /&gt;
	if type == &amp;quot;MultipleChoiceCheckbox&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][i.to_s]&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: params[:quiz_question_choices][id.to_s][type][i.to_s][:iscorrect], txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][quiz_question_choice.id.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;MultipleChoiceRadio&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][:correctindex] == i.to_s&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '1', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;TrueFalse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][1.to_s][:iscorrect] == &amp;quot;True&amp;quot; # the statement is correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is correct so &amp;quot;True&amp;quot; is the right answer&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            else # the statement is not correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is not correct so &amp;quot;False&amp;quot; is the right answer&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
c. Replaced large block of for and if statements in update with a call to the new change_question_types method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
d. Moved export, import, copy_questionnaire_details, and assign_instructor_id to questionaire model. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy_questionnaire_details(questions, orig_questionnaire, id)&lt;br /&gt;
    self.instructor_id = self.assign_instructor_id()&lt;br /&gt;
    self.name = 'Copy of ' + orig_questionnaire.name&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      self.created_at = Time.now&lt;br /&gt;
      self.save!&lt;br /&gt;
      questions.each do |question|&lt;br /&gt;
        new_question = question.dup&lt;br /&gt;
        new_question.questionnaire_id = id&lt;br /&gt;
        new_question.size = '50,3' if (new_question.is_a? Criterion or new_question.is_a? TextResponse) and new_question.size.nil?&lt;br /&gt;
        new_question.save!&lt;br /&gt;
        advices = QuestionAdvice.where(question_id: question.id)&lt;br /&gt;
        next if advices.empty?&lt;br /&gt;
        advices.each do |advice|&lt;br /&gt;
          new_advice = advice.dup&lt;br /&gt;
          new_advice.question_id = new_question.id&lt;br /&gt;
          new_advice.save!&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      pFolder = TreeFolder.find_by(name: question.set_display_type(display_type))&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: pFolder.id)&lt;br /&gt;
      QuestionnaireNode.find_or_create_by(parent_id: parent.id, node_object_id: id)&lt;br /&gt;
      undo_link(&amp;quot;Copy of questionnaire #{orig_questionnaire.name} has been created successfully.&amp;quot;)&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'view', id: @questionnaire.id&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'The questionnaire was not able to be copied. Please check the original course for missing information.' + $ERROR_INFO&lt;br /&gt;
      redirect_to action: 'list', controller: 'tree_display'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def export&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    csv_data = QuestionnaireHelper.create_questionnaire_csv @questionnaire, session[:user].name&lt;br /&gt;
    send_data csv_data,&lt;br /&gt;
              type: 'text/csv; charset=iso-8859-1; header=present',&lt;br /&gt;
              disposition: &amp;quot;attachment; filename=questionnaires.csv&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def import&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    file = params['csv']&lt;br /&gt;
    @questionnaire.questions &amp;lt;&amp;lt; QuestionnaireHelper.get_questions_from_csv(@questionnaire, file)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assign_instructor_id&lt;br /&gt;
    # if the user to copy the questionnaire is a TA, the instructor should be the owner instead of the TA&lt;br /&gt;
    if session[:user].role.name != &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      session[:user].id&lt;br /&gt;
    else # for TA we need to get his instructor id and by default add it to his course for which he is the TA&lt;br /&gt;
      Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3''': Replace switch statements with subclasses methods and create models for the subclasses.&lt;br /&gt;
* '''Solution''': Moved the switch-case statement from create in questionaire_controller.rb into a method called set_display_type in questionaire model. The following is the code snippet that shows the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  def set_dispay_type(display_type)&lt;br /&gt;
&lt;br /&gt;
      case display_type&lt;br /&gt;
&lt;br /&gt;
      when 'Review'&lt;br /&gt;
	display_type = 'Review'&lt;br /&gt;
&lt;br /&gt;
      when 'Metareview'&lt;br /&gt;
	display_type = 'Metareview'&lt;br /&gt;
&lt;br /&gt;
      when 'AuthorFeedback'&lt;br /&gt;
        display_type = 'Author%Feedback'&lt;br /&gt;
&lt;br /&gt;
      when 'CourseSurvey'&lt;br /&gt;
        display_type = 'Course%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'TeammateReview'&lt;br /&gt;
        display_type = 'Teammate%Review'&lt;br /&gt;
&lt;br /&gt;
      when 'GlobalSurvey'&lt;br /&gt;
        display_type = 'Global%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'AssignmentSurvey'&lt;br /&gt;
        display_type = 'Assignment%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'Bookmarkrating'&lt;br /&gt;
	display_type = 'Bookmarkrating'&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 4''': Remove hardcoded parameters, such as save_choice method&lt;br /&gt;
* '''Solution''': Hardcoded parameters are removed and necessary constants are defined.&lt;br /&gt;
&lt;br /&gt;
===Test Plans===&lt;br /&gt;
&lt;br /&gt;
Because the purpose of our project was to better arrange our code, it follows that we also needed to rearrange the tests for that code. We first divided the tests for questionnaires_controller into two test files, questionnaires_controller_spec and quiz_questionnaires_controller_spec and separated the tests for CRUD operations of quiz_questionnaires_controller into the quiz_questionnaires_controller_spec, renaming them from view_quiz, create_quiz and the like to view and create. After this separation of CRUD operation testing, we tested the functionality that we moved out of the controllers into the model including the validation method for the quiz questionnaire. We did not include tests to cover the existing model functions, nor did we test the new set_display_type or change_question_types functions as they are setter methods, which, according to our testing instruction are not worth testing. &lt;br /&gt;
&lt;br /&gt;
The setup for testing was particularly troublesome for the deployment of this project. The tests did not run properly in RubyMine, so it was difficult to ensure they were set up properly, and none of the members of our group have any expertise in rspec testing.&lt;br /&gt;
&lt;br /&gt;
===Testing from UI===&lt;br /&gt;
&lt;br /&gt;
The testing of the export feature is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Export_completed_successfully.png|200px]]&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/Riounis/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1271 GitHub Pull Request]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119207</id>
		<title>CSC/ECE 517 Fall 2018 E1836 Refactor quiz questionnaires controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119207"/>
		<updated>2018-11-10T02:00:09Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Testing from UI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1836. Refactoring quiz_questionnaires_controller.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
* Created quiz_questionnaire_controller.rb&lt;br /&gt;
* Moved view_quiz, new_quiz, create_quiz_questionnaire, edit_quiz and update_quiz from questionnaires_controller.rb, to quiz_questionnaires_controller.rb, and renamed it as view, new, create, edit and update respectively.&lt;br /&gt;
* Refactored the the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* Replaced switch statements in questionnaires_controller.rb with subclass methods.&lt;br /&gt;
* Created models for the subclasses.&lt;br /&gt;
* Removed hardcoded parameters, such as save_choice method.&lt;br /&gt;
* Appropriate tests were written to test the code.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
'''Problem 1''': Create quiz_questionnaire_controller.rb and move some of the methods in the questionnaires_controller.rb to the new file created.&lt;br /&gt;
* '''Solution''': The methods view_quiz, new_quiz, create_quiz, edit_quiz and update_quiz in the questionnaires_controller.rb were the methods identified and moved into the quiz_questionnaire_controller.rb. They were respectively renamed as view, new, create, edit and update. The implementation of the newly created quiz_questionnaire_controller.rb can be seen below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class QuizQuestionnairesController &amp;lt; QuestionnairesController&lt;br /&gt;
&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
   # Separate methods for quiz questionnaire&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
&lt;br /&gt;
   # View a quiz questionnaire&lt;br /&gt;
   def view&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     @participant = Participant.find(params[:pid]) # creating an instance variable since it needs to be sent to submitted_content/edit&lt;br /&gt;
     render :view&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # define a new quiz questionnaire&lt;br /&gt;
   # method invoked by the view&lt;br /&gt;
   def new&lt;br /&gt;
     valid_request = true&lt;br /&gt;
     @assignment_id = params[:aid] # creating an instance variable to hold the assignment id&lt;br /&gt;
     @participant_id = params[:pid] # creating an instance variable to hold the participant id&lt;br /&gt;
     assignment = Assignment.find(@assignment_id)&lt;br /&gt;
     if !assignment.require_quiz? # flash error if this assignment does not require quiz&lt;br /&gt;
       flash[:error] = &amp;quot;This assignment does not support the quizzing feature.&amp;quot;&lt;br /&gt;
       valid_request = false&lt;br /&gt;
     else&lt;br /&gt;
       team = AssignmentParticipant.find(@participant_id).team&lt;br /&gt;
&lt;br /&gt;
       if team.nil? # flash error if this current participant does not have a team&lt;br /&gt;
         flash[:error] = &amp;quot;You should create or join a team first.&amp;quot;&lt;br /&gt;
         valid_request = false&lt;br /&gt;
       else&lt;br /&gt;
         if assignment.topics? &amp;amp;&amp;amp; team.topic.nil? # flash error if this assignment has topic but current team does not have a topic&lt;br /&gt;
           flash[:error] = &amp;quot;Your team should have a topic.&amp;quot;&lt;br /&gt;
           valid_request = false&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
     if valid_request &amp;amp;&amp;amp; Questionnaire::QUESTIONNAIRE_TYPES.include?(params[:model])&lt;br /&gt;
       @questionnaire = Object.const_get(params[:model]).new&lt;br /&gt;
       @questionnaire.private = params[:private]&lt;br /&gt;
       @questionnaire.min_question_score = 0&lt;br /&gt;
       @questionnaire.max_question_score = 1&lt;br /&gt;
&lt;br /&gt;
       render :new&lt;br /&gt;
     else&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # seperate method for creating a quiz questionnaire because of differences in permission&lt;br /&gt;
   def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # edit a quiz questionnaire&lt;br /&gt;
   def edit&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if !@questionnaire.taken_by_anyone?&lt;br /&gt;
       render :edit&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = &amp;quot;Your quiz has been taken by some other students, you cannot edit it anymore.&amp;quot;&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
   # save an updated quiz questionnaire to the database&lt;br /&gt;
   def update&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if @questionnaire.nil?&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
       return&lt;br /&gt;
     end&lt;br /&gt;
     if params['save'] &amp;amp;&amp;amp; params[:question].try(:keys)&lt;br /&gt;
       @questionnaire.update_attributes(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       for qid in params[:question].keys&lt;br /&gt;
         @question = Question.find(qid)&lt;br /&gt;
         @question.txt = params[:question][qid.to_sym][:txt]&lt;br /&gt;
         @question.save&lt;br /&gt;
&lt;br /&gt;
         @quiz_question_choices = QuizQuestionChoice.where(question_id: qid)&lt;br /&gt;
         i = 1&lt;br /&gt;
         for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
     redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 2''': Refactor the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* '''Solution''': &lt;br /&gt;
a. Deleted the create_questionnaire method and replaced the call to it in create_quiz_questionnaire with the code of create_questionnaire and is later moved to quiz_questionnaires_controller.rb and the code snippet below is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b. Moved the large block of for and if statements into method called change_question_types in the quiz_questionnaire model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
&lt;br /&gt;
	if type == &amp;quot;MultipleChoiceCheckbox&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][i.to_s]&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: params[:quiz_question_choices][id.to_s][type][i.to_s][:iscorrect], txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][quiz_question_choice.id.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;MultipleChoiceRadio&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][:correctindex] == i.to_s&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '1', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;TrueFalse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][1.to_s][:iscorrect] == &amp;quot;True&amp;quot; # the statement is correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is correct so &amp;quot;True&amp;quot; is the right answer&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            else # the statement is not correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is not correct so &amp;quot;False&amp;quot; is the right answer&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
c. Replaced large block of for and if statements in update with a call to the new change_question_types method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
d. Moved export, import, copy_questionnaire_details, and assign_instructor_id to questionaire model. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy_questionnaire_details(questions, orig_questionnaire, id)&lt;br /&gt;
    self.instructor_id = self.assign_instructor_id()&lt;br /&gt;
    self.name = 'Copy of ' + orig_questionnaire.name&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      self.created_at = Time.now&lt;br /&gt;
      self.save!&lt;br /&gt;
      questions.each do |question|&lt;br /&gt;
        new_question = question.dup&lt;br /&gt;
        new_question.questionnaire_id = id&lt;br /&gt;
        new_question.size = '50,3' if (new_question.is_a? Criterion or new_question.is_a? TextResponse) and new_question.size.nil?&lt;br /&gt;
        new_question.save!&lt;br /&gt;
        advices = QuestionAdvice.where(question_id: question.id)&lt;br /&gt;
        next if advices.empty?&lt;br /&gt;
        advices.each do |advice|&lt;br /&gt;
          new_advice = advice.dup&lt;br /&gt;
          new_advice.question_id = new_question.id&lt;br /&gt;
          new_advice.save!&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      pFolder = TreeFolder.find_by(name: question.set_display_type(display_type))&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: pFolder.id)&lt;br /&gt;
      QuestionnaireNode.find_or_create_by(parent_id: parent.id, node_object_id: id)&lt;br /&gt;
      undo_link(&amp;quot;Copy of questionnaire #{orig_questionnaire.name} has been created successfully.&amp;quot;)&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'view', id: @questionnaire.id&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'The questionnaire was not able to be copied. Please check the original course for missing information.' + $ERROR_INFO&lt;br /&gt;
      redirect_to action: 'list', controller: 'tree_display'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def export&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    csv_data = QuestionnaireHelper.create_questionnaire_csv @questionnaire, session[:user].name&lt;br /&gt;
    send_data csv_data,&lt;br /&gt;
              type: 'text/csv; charset=iso-8859-1; header=present',&lt;br /&gt;
              disposition: &amp;quot;attachment; filename=questionnaires.csv&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def import&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    file = params['csv']&lt;br /&gt;
    @questionnaire.questions &amp;lt;&amp;lt; QuestionnaireHelper.get_questions_from_csv(@questionnaire, file)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assign_instructor_id&lt;br /&gt;
    # if the user to copy the questionnaire is a TA, the instructor should be the owner instead of the TA&lt;br /&gt;
    if session[:user].role.name != &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      session[:user].id&lt;br /&gt;
    else # for TA we need to get his instructor id and by default add it to his course for which he is the TA&lt;br /&gt;
      Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3''': Replace switch statements with subclasses methods and create models for the subclasses.&lt;br /&gt;
* '''Solution''': Moved the switch-case statement from create in questionaire_controller.rb into a method called set_display_type in questionaire model. The following is the code snippet that shows the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  def set_dispay_type(display_type)&lt;br /&gt;
&lt;br /&gt;
      case display_type&lt;br /&gt;
&lt;br /&gt;
      when 'Review'&lt;br /&gt;
	display_type = 'Review'&lt;br /&gt;
&lt;br /&gt;
      when 'Metareview'&lt;br /&gt;
	display_type = 'Metareview'&lt;br /&gt;
&lt;br /&gt;
      when 'AuthorFeedback'&lt;br /&gt;
        display_type = 'Author%Feedback'&lt;br /&gt;
&lt;br /&gt;
      when 'CourseSurvey'&lt;br /&gt;
        display_type = 'Course%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'TeammateReview'&lt;br /&gt;
        display_type = 'Teammate%Review'&lt;br /&gt;
&lt;br /&gt;
      when 'GlobalSurvey'&lt;br /&gt;
        display_type = 'Global%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'AssignmentSurvey'&lt;br /&gt;
        display_type = 'Assignment%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'Bookmarkrating'&lt;br /&gt;
	display_type = 'Bookmarkrating'&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 4''': Remove hardcoded parameters, such as save_choice method&lt;br /&gt;
* '''Solution''': Hardcoded parameters are removed and necessary constants are defined.&lt;br /&gt;
&lt;br /&gt;
===Test Plans===&lt;br /&gt;
&lt;br /&gt;
Because the purpose of our project was to better arrange our code, it follows that we also needed to rearrange the tests for that code. We first divided the tests for questionnaires_controller into two test files, questionnaires_controller_spec and quiz_questionnaires_controller_spec and separated the tests for CRUD operations of quiz_questionnaires_controller into the quiz_questionnaires_controller_spec, renaming them from view_quiz, create_quiz and the like to view and create. After this separation of CRUD operation testing, we tested the functionality that we moved out of the controllers into the model including the validation method for the quiz questionnaire. We did not include tests to cover the existing model functions, nor did we test the new set_display_type or change_question_types functions as they are setter methods, which, according to our testing instruction are not worth testing. &lt;br /&gt;
&lt;br /&gt;
The setup for testing was particularly troublesome for the deployment of this project. The tests did not run properly in RubyMine, so it was difficult to ensure they were set up properly, and none of the members of our group have any expertise in rspec testing.&lt;br /&gt;
&lt;br /&gt;
===Testing from UI===&lt;br /&gt;
&lt;br /&gt;
The testing of the export feature is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Export_completed_successfully.png|upright]]&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/Riounis/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1271 GitHub Pull Request]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119206</id>
		<title>CSC/ECE 517 Fall 2018 E1836 Refactor quiz questionnaires controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119206"/>
		<updated>2018-11-10T01:58:24Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Testing from UI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1836. Refactoring quiz_questionnaires_controller.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
* Created quiz_questionnaire_controller.rb&lt;br /&gt;
* Moved view_quiz, new_quiz, create_quiz_questionnaire, edit_quiz and update_quiz from questionnaires_controller.rb, to quiz_questionnaires_controller.rb, and renamed it as view, new, create, edit and update respectively.&lt;br /&gt;
* Refactored the the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* Replaced switch statements in questionnaires_controller.rb with subclass methods.&lt;br /&gt;
* Created models for the subclasses.&lt;br /&gt;
* Removed hardcoded parameters, such as save_choice method.&lt;br /&gt;
* Appropriate tests were written to test the code.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
'''Problem 1''': Create quiz_questionnaire_controller.rb and move some of the methods in the questionnaires_controller.rb to the new file created.&lt;br /&gt;
* '''Solution''': The methods view_quiz, new_quiz, create_quiz, edit_quiz and update_quiz in the questionnaires_controller.rb were the methods identified and moved into the quiz_questionnaire_controller.rb. They were respectively renamed as view, new, create, edit and update. The implementation of the newly created quiz_questionnaire_controller.rb can be seen below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class QuizQuestionnairesController &amp;lt; QuestionnairesController&lt;br /&gt;
&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
   # Separate methods for quiz questionnaire&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
&lt;br /&gt;
   # View a quiz questionnaire&lt;br /&gt;
   def view&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     @participant = Participant.find(params[:pid]) # creating an instance variable since it needs to be sent to submitted_content/edit&lt;br /&gt;
     render :view&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # define a new quiz questionnaire&lt;br /&gt;
   # method invoked by the view&lt;br /&gt;
   def new&lt;br /&gt;
     valid_request = true&lt;br /&gt;
     @assignment_id = params[:aid] # creating an instance variable to hold the assignment id&lt;br /&gt;
     @participant_id = params[:pid] # creating an instance variable to hold the participant id&lt;br /&gt;
     assignment = Assignment.find(@assignment_id)&lt;br /&gt;
     if !assignment.require_quiz? # flash error if this assignment does not require quiz&lt;br /&gt;
       flash[:error] = &amp;quot;This assignment does not support the quizzing feature.&amp;quot;&lt;br /&gt;
       valid_request = false&lt;br /&gt;
     else&lt;br /&gt;
       team = AssignmentParticipant.find(@participant_id).team&lt;br /&gt;
&lt;br /&gt;
       if team.nil? # flash error if this current participant does not have a team&lt;br /&gt;
         flash[:error] = &amp;quot;You should create or join a team first.&amp;quot;&lt;br /&gt;
         valid_request = false&lt;br /&gt;
       else&lt;br /&gt;
         if assignment.topics? &amp;amp;&amp;amp; team.topic.nil? # flash error if this assignment has topic but current team does not have a topic&lt;br /&gt;
           flash[:error] = &amp;quot;Your team should have a topic.&amp;quot;&lt;br /&gt;
           valid_request = false&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
     if valid_request &amp;amp;&amp;amp; Questionnaire::QUESTIONNAIRE_TYPES.include?(params[:model])&lt;br /&gt;
       @questionnaire = Object.const_get(params[:model]).new&lt;br /&gt;
       @questionnaire.private = params[:private]&lt;br /&gt;
       @questionnaire.min_question_score = 0&lt;br /&gt;
       @questionnaire.max_question_score = 1&lt;br /&gt;
&lt;br /&gt;
       render :new&lt;br /&gt;
     else&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # seperate method for creating a quiz questionnaire because of differences in permission&lt;br /&gt;
   def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # edit a quiz questionnaire&lt;br /&gt;
   def edit&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if !@questionnaire.taken_by_anyone?&lt;br /&gt;
       render :edit&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = &amp;quot;Your quiz has been taken by some other students, you cannot edit it anymore.&amp;quot;&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
   # save an updated quiz questionnaire to the database&lt;br /&gt;
   def update&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if @questionnaire.nil?&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
       return&lt;br /&gt;
     end&lt;br /&gt;
     if params['save'] &amp;amp;&amp;amp; params[:question].try(:keys)&lt;br /&gt;
       @questionnaire.update_attributes(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       for qid in params[:question].keys&lt;br /&gt;
         @question = Question.find(qid)&lt;br /&gt;
         @question.txt = params[:question][qid.to_sym][:txt]&lt;br /&gt;
         @question.save&lt;br /&gt;
&lt;br /&gt;
         @quiz_question_choices = QuizQuestionChoice.where(question_id: qid)&lt;br /&gt;
         i = 1&lt;br /&gt;
         for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
     redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 2''': Refactor the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* '''Solution''': &lt;br /&gt;
a. Deleted the create_questionnaire method and replaced the call to it in create_quiz_questionnaire with the code of create_questionnaire and is later moved to quiz_questionnaires_controller.rb and the code snippet below is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b. Moved the large block of for and if statements into method called change_question_types in the quiz_questionnaire model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
&lt;br /&gt;
	if type == &amp;quot;MultipleChoiceCheckbox&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][i.to_s]&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: params[:quiz_question_choices][id.to_s][type][i.to_s][:iscorrect], txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][quiz_question_choice.id.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;MultipleChoiceRadio&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][:correctindex] == i.to_s&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '1', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;TrueFalse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][1.to_s][:iscorrect] == &amp;quot;True&amp;quot; # the statement is correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is correct so &amp;quot;True&amp;quot; is the right answer&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            else # the statement is not correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is not correct so &amp;quot;False&amp;quot; is the right answer&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
c. Replaced large block of for and if statements in update with a call to the new change_question_types method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
d. Moved export, import, copy_questionnaire_details, and assign_instructor_id to questionaire model. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy_questionnaire_details(questions, orig_questionnaire, id)&lt;br /&gt;
    self.instructor_id = self.assign_instructor_id()&lt;br /&gt;
    self.name = 'Copy of ' + orig_questionnaire.name&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      self.created_at = Time.now&lt;br /&gt;
      self.save!&lt;br /&gt;
      questions.each do |question|&lt;br /&gt;
        new_question = question.dup&lt;br /&gt;
        new_question.questionnaire_id = id&lt;br /&gt;
        new_question.size = '50,3' if (new_question.is_a? Criterion or new_question.is_a? TextResponse) and new_question.size.nil?&lt;br /&gt;
        new_question.save!&lt;br /&gt;
        advices = QuestionAdvice.where(question_id: question.id)&lt;br /&gt;
        next if advices.empty?&lt;br /&gt;
        advices.each do |advice|&lt;br /&gt;
          new_advice = advice.dup&lt;br /&gt;
          new_advice.question_id = new_question.id&lt;br /&gt;
          new_advice.save!&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      pFolder = TreeFolder.find_by(name: question.set_display_type(display_type))&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: pFolder.id)&lt;br /&gt;
      QuestionnaireNode.find_or_create_by(parent_id: parent.id, node_object_id: id)&lt;br /&gt;
      undo_link(&amp;quot;Copy of questionnaire #{orig_questionnaire.name} has been created successfully.&amp;quot;)&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'view', id: @questionnaire.id&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'The questionnaire was not able to be copied. Please check the original course for missing information.' + $ERROR_INFO&lt;br /&gt;
      redirect_to action: 'list', controller: 'tree_display'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def export&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    csv_data = QuestionnaireHelper.create_questionnaire_csv @questionnaire, session[:user].name&lt;br /&gt;
    send_data csv_data,&lt;br /&gt;
              type: 'text/csv; charset=iso-8859-1; header=present',&lt;br /&gt;
              disposition: &amp;quot;attachment; filename=questionnaires.csv&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def import&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    file = params['csv']&lt;br /&gt;
    @questionnaire.questions &amp;lt;&amp;lt; QuestionnaireHelper.get_questions_from_csv(@questionnaire, file)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assign_instructor_id&lt;br /&gt;
    # if the user to copy the questionnaire is a TA, the instructor should be the owner instead of the TA&lt;br /&gt;
    if session[:user].role.name != &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      session[:user].id&lt;br /&gt;
    else # for TA we need to get his instructor id and by default add it to his course for which he is the TA&lt;br /&gt;
      Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3''': Replace switch statements with subclasses methods and create models for the subclasses.&lt;br /&gt;
* '''Solution''': Moved the switch-case statement from create in questionaire_controller.rb into a method called set_display_type in questionaire model. The following is the code snippet that shows the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  def set_dispay_type(display_type)&lt;br /&gt;
&lt;br /&gt;
      case display_type&lt;br /&gt;
&lt;br /&gt;
      when 'Review'&lt;br /&gt;
	display_type = 'Review'&lt;br /&gt;
&lt;br /&gt;
      when 'Metareview'&lt;br /&gt;
	display_type = 'Metareview'&lt;br /&gt;
&lt;br /&gt;
      when 'AuthorFeedback'&lt;br /&gt;
        display_type = 'Author%Feedback'&lt;br /&gt;
&lt;br /&gt;
      when 'CourseSurvey'&lt;br /&gt;
        display_type = 'Course%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'TeammateReview'&lt;br /&gt;
        display_type = 'Teammate%Review'&lt;br /&gt;
&lt;br /&gt;
      when 'GlobalSurvey'&lt;br /&gt;
        display_type = 'Global%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'AssignmentSurvey'&lt;br /&gt;
        display_type = 'Assignment%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'Bookmarkrating'&lt;br /&gt;
	display_type = 'Bookmarkrating'&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 4''': Remove hardcoded parameters, such as save_choice method&lt;br /&gt;
* '''Solution''': Hardcoded parameters are removed and necessary constants are defined.&lt;br /&gt;
&lt;br /&gt;
===Test Plans===&lt;br /&gt;
&lt;br /&gt;
Because the purpose of our project was to better arrange our code, it follows that we also needed to rearrange the tests for that code. We first divided the tests for questionnaires_controller into two test files, questionnaires_controller_spec and quiz_questionnaires_controller_spec and separated the tests for CRUD operations of quiz_questionnaires_controller into the quiz_questionnaires_controller_spec, renaming them from view_quiz, create_quiz and the like to view and create. After this separation of CRUD operation testing, we tested the functionality that we moved out of the controllers into the model including the validation method for the quiz questionnaire. We did not include tests to cover the existing model functions, nor did we test the new set_display_type or change_question_types functions as they are setter methods, which, according to our testing instruction are not worth testing. &lt;br /&gt;
&lt;br /&gt;
The setup for testing was particularly troublesome for the deployment of this project. The tests did not run properly in RubyMine, so it was difficult to ensure they were set up properly, and none of the members of our group have any expertise in rspec testing.&lt;br /&gt;
&lt;br /&gt;
===Testing from UI===&lt;br /&gt;
&lt;br /&gt;
The testing of the export feature is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Export_completed_successfully.png]]&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/Riounis/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1271 GitHub Pull Request]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119205</id>
		<title>CSC/ECE 517 Fall 2018 E1836 Refactor quiz questionnaires controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119205"/>
		<updated>2018-11-10T01:57:21Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* Testing from UI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1836. Refactoring quiz_questionnaires_controller.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
* Created quiz_questionnaire_controller.rb&lt;br /&gt;
* Moved view_quiz, new_quiz, create_quiz_questionnaire, edit_quiz and update_quiz from questionnaires_controller.rb, to quiz_questionnaires_controller.rb, and renamed it as view, new, create, edit and update respectively.&lt;br /&gt;
* Refactored the the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* Replaced switch statements in questionnaires_controller.rb with subclass methods.&lt;br /&gt;
* Created models for the subclasses.&lt;br /&gt;
* Removed hardcoded parameters, such as save_choice method.&lt;br /&gt;
* Appropriate tests were written to test the code.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
'''Problem 1''': Create quiz_questionnaire_controller.rb and move some of the methods in the questionnaires_controller.rb to the new file created.&lt;br /&gt;
* '''Solution''': The methods view_quiz, new_quiz, create_quiz, edit_quiz and update_quiz in the questionnaires_controller.rb were the methods identified and moved into the quiz_questionnaire_controller.rb. They were respectively renamed as view, new, create, edit and update. The implementation of the newly created quiz_questionnaire_controller.rb can be seen below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class QuizQuestionnairesController &amp;lt; QuestionnairesController&lt;br /&gt;
&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
   # Separate methods for quiz questionnaire&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
&lt;br /&gt;
   # View a quiz questionnaire&lt;br /&gt;
   def view&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     @participant = Participant.find(params[:pid]) # creating an instance variable since it needs to be sent to submitted_content/edit&lt;br /&gt;
     render :view&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # define a new quiz questionnaire&lt;br /&gt;
   # method invoked by the view&lt;br /&gt;
   def new&lt;br /&gt;
     valid_request = true&lt;br /&gt;
     @assignment_id = params[:aid] # creating an instance variable to hold the assignment id&lt;br /&gt;
     @participant_id = params[:pid] # creating an instance variable to hold the participant id&lt;br /&gt;
     assignment = Assignment.find(@assignment_id)&lt;br /&gt;
     if !assignment.require_quiz? # flash error if this assignment does not require quiz&lt;br /&gt;
       flash[:error] = &amp;quot;This assignment does not support the quizzing feature.&amp;quot;&lt;br /&gt;
       valid_request = false&lt;br /&gt;
     else&lt;br /&gt;
       team = AssignmentParticipant.find(@participant_id).team&lt;br /&gt;
&lt;br /&gt;
       if team.nil? # flash error if this current participant does not have a team&lt;br /&gt;
         flash[:error] = &amp;quot;You should create or join a team first.&amp;quot;&lt;br /&gt;
         valid_request = false&lt;br /&gt;
       else&lt;br /&gt;
         if assignment.topics? &amp;amp;&amp;amp; team.topic.nil? # flash error if this assignment has topic but current team does not have a topic&lt;br /&gt;
           flash[:error] = &amp;quot;Your team should have a topic.&amp;quot;&lt;br /&gt;
           valid_request = false&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
     if valid_request &amp;amp;&amp;amp; Questionnaire::QUESTIONNAIRE_TYPES.include?(params[:model])&lt;br /&gt;
       @questionnaire = Object.const_get(params[:model]).new&lt;br /&gt;
       @questionnaire.private = params[:private]&lt;br /&gt;
       @questionnaire.min_question_score = 0&lt;br /&gt;
       @questionnaire.max_question_score = 1&lt;br /&gt;
&lt;br /&gt;
       render :new&lt;br /&gt;
     else&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # seperate method for creating a quiz questionnaire because of differences in permission&lt;br /&gt;
   def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # edit a quiz questionnaire&lt;br /&gt;
   def edit&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if !@questionnaire.taken_by_anyone?&lt;br /&gt;
       render :edit&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = &amp;quot;Your quiz has been taken by some other students, you cannot edit it anymore.&amp;quot;&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
   # save an updated quiz questionnaire to the database&lt;br /&gt;
   def update&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if @questionnaire.nil?&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
       return&lt;br /&gt;
     end&lt;br /&gt;
     if params['save'] &amp;amp;&amp;amp; params[:question].try(:keys)&lt;br /&gt;
       @questionnaire.update_attributes(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       for qid in params[:question].keys&lt;br /&gt;
         @question = Question.find(qid)&lt;br /&gt;
         @question.txt = params[:question][qid.to_sym][:txt]&lt;br /&gt;
         @question.save&lt;br /&gt;
&lt;br /&gt;
         @quiz_question_choices = QuizQuestionChoice.where(question_id: qid)&lt;br /&gt;
         i = 1&lt;br /&gt;
         for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
     redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 2''': Refactor the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* '''Solution''': &lt;br /&gt;
a. Deleted the create_questionnaire method and replaced the call to it in create_quiz_questionnaire with the code of create_questionnaire and is later moved to quiz_questionnaires_controller.rb and the code snippet below is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b. Moved the large block of for and if statements into method called change_question_types in the quiz_questionnaire model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
&lt;br /&gt;
	if type == &amp;quot;MultipleChoiceCheckbox&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][i.to_s]&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: params[:quiz_question_choices][id.to_s][type][i.to_s][:iscorrect], txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][quiz_question_choice.id.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;MultipleChoiceRadio&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][:correctindex] == i.to_s&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '1', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;TrueFalse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][1.to_s][:iscorrect] == &amp;quot;True&amp;quot; # the statement is correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is correct so &amp;quot;True&amp;quot; is the right answer&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            else # the statement is not correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is not correct so &amp;quot;False&amp;quot; is the right answer&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
c. Replaced large block of for and if statements in update with a call to the new change_question_types method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
d. Moved export, import, copy_questionnaire_details, and assign_instructor_id to questionaire model. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy_questionnaire_details(questions, orig_questionnaire, id)&lt;br /&gt;
    self.instructor_id = self.assign_instructor_id()&lt;br /&gt;
    self.name = 'Copy of ' + orig_questionnaire.name&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      self.created_at = Time.now&lt;br /&gt;
      self.save!&lt;br /&gt;
      questions.each do |question|&lt;br /&gt;
        new_question = question.dup&lt;br /&gt;
        new_question.questionnaire_id = id&lt;br /&gt;
        new_question.size = '50,3' if (new_question.is_a? Criterion or new_question.is_a? TextResponse) and new_question.size.nil?&lt;br /&gt;
        new_question.save!&lt;br /&gt;
        advices = QuestionAdvice.where(question_id: question.id)&lt;br /&gt;
        next if advices.empty?&lt;br /&gt;
        advices.each do |advice|&lt;br /&gt;
          new_advice = advice.dup&lt;br /&gt;
          new_advice.question_id = new_question.id&lt;br /&gt;
          new_advice.save!&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      pFolder = TreeFolder.find_by(name: question.set_display_type(display_type))&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: pFolder.id)&lt;br /&gt;
      QuestionnaireNode.find_or_create_by(parent_id: parent.id, node_object_id: id)&lt;br /&gt;
      undo_link(&amp;quot;Copy of questionnaire #{orig_questionnaire.name} has been created successfully.&amp;quot;)&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'view', id: @questionnaire.id&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'The questionnaire was not able to be copied. Please check the original course for missing information.' + $ERROR_INFO&lt;br /&gt;
      redirect_to action: 'list', controller: 'tree_display'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def export&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    csv_data = QuestionnaireHelper.create_questionnaire_csv @questionnaire, session[:user].name&lt;br /&gt;
    send_data csv_data,&lt;br /&gt;
              type: 'text/csv; charset=iso-8859-1; header=present',&lt;br /&gt;
              disposition: &amp;quot;attachment; filename=questionnaires.csv&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def import&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    file = params['csv']&lt;br /&gt;
    @questionnaire.questions &amp;lt;&amp;lt; QuestionnaireHelper.get_questions_from_csv(@questionnaire, file)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assign_instructor_id&lt;br /&gt;
    # if the user to copy the questionnaire is a TA, the instructor should be the owner instead of the TA&lt;br /&gt;
    if session[:user].role.name != &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      session[:user].id&lt;br /&gt;
    else # for TA we need to get his instructor id and by default add it to his course for which he is the TA&lt;br /&gt;
      Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3''': Replace switch statements with subclasses methods and create models for the subclasses.&lt;br /&gt;
* '''Solution''': Moved the switch-case statement from create in questionaire_controller.rb into a method called set_display_type in questionaire model. The following is the code snippet that shows the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  def set_dispay_type(display_type)&lt;br /&gt;
&lt;br /&gt;
      case display_type&lt;br /&gt;
&lt;br /&gt;
      when 'Review'&lt;br /&gt;
	display_type = 'Review'&lt;br /&gt;
&lt;br /&gt;
      when 'Metareview'&lt;br /&gt;
	display_type = 'Metareview'&lt;br /&gt;
&lt;br /&gt;
      when 'AuthorFeedback'&lt;br /&gt;
        display_type = 'Author%Feedback'&lt;br /&gt;
&lt;br /&gt;
      when 'CourseSurvey'&lt;br /&gt;
        display_type = 'Course%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'TeammateReview'&lt;br /&gt;
        display_type = 'Teammate%Review'&lt;br /&gt;
&lt;br /&gt;
      when 'GlobalSurvey'&lt;br /&gt;
        display_type = 'Global%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'AssignmentSurvey'&lt;br /&gt;
        display_type = 'Assignment%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'Bookmarkrating'&lt;br /&gt;
	display_type = 'Bookmarkrating'&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 4''': Remove hardcoded parameters, such as save_choice method&lt;br /&gt;
* '''Solution''': Hardcoded parameters are removed and necessary constants are defined.&lt;br /&gt;
&lt;br /&gt;
===Test Plans===&lt;br /&gt;
&lt;br /&gt;
Because the purpose of our project was to better arrange our code, it follows that we also needed to rearrange the tests for that code. We first divided the tests for questionnaires_controller into two test files, questionnaires_controller_spec and quiz_questionnaires_controller_spec and separated the tests for CRUD operations of quiz_questionnaires_controller into the quiz_questionnaires_controller_spec, renaming them from view_quiz, create_quiz and the like to view and create. After this separation of CRUD operation testing, we tested the functionality that we moved out of the controllers into the model including the validation method for the quiz questionnaire. We did not include tests to cover the existing model functions, nor did we test the new set_display_type or change_question_types functions as they are setter methods, which, according to our testing instruction are not worth testing. &lt;br /&gt;
&lt;br /&gt;
The setup for testing was particularly troublesome for the deployment of this project. The tests did not run properly in RubyMine, so it was difficult to ensure they were set up properly, and none of the members of our group have any expertise in rspec testing.&lt;br /&gt;
&lt;br /&gt;
===Testing from UI===&lt;br /&gt;
&lt;br /&gt;
The testing of the export feature is shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Export_completed_successfully.png|center]]&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/Riounis/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1271 GitHub Pull Request]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119204</id>
		<title>CSC/ECE 517 Fall 2018 E1836 Refactor quiz questionnaires controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2018_E1836_Refactor_quiz_questionnaires_controller.rb&amp;diff=119204"/>
		<updated>2018-11-10T01:55:26Z</updated>

		<summary type="html">&lt;p&gt;Amishra6: /* E1836. Refactoring quiz_questionnaires_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1836. Refactoring quiz_questionnaires_controller.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
* Created quiz_questionnaire_controller.rb&lt;br /&gt;
* Moved view_quiz, new_quiz, create_quiz_questionnaire, edit_quiz and update_quiz from questionnaires_controller.rb, to quiz_questionnaires_controller.rb, and renamed it as view, new, create, edit and update respectively.&lt;br /&gt;
* Refactored the the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* Replaced switch statements in questionnaires_controller.rb with subclass methods.&lt;br /&gt;
* Created models for the subclasses.&lt;br /&gt;
* Removed hardcoded parameters, such as save_choice method.&lt;br /&gt;
* Appropriate tests were written to test the code.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
&lt;br /&gt;
'''Problem 1''': Create quiz_questionnaire_controller.rb and move some of the methods in the questionnaires_controller.rb to the new file created.&lt;br /&gt;
* '''Solution''': The methods view_quiz, new_quiz, create_quiz, edit_quiz and update_quiz in the questionnaires_controller.rb were the methods identified and moved into the quiz_questionnaire_controller.rb. They were respectively renamed as view, new, create, edit and update. The implementation of the newly created quiz_questionnaire_controller.rb can be seen below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class QuizQuestionnairesController &amp;lt; QuestionnairesController&lt;br /&gt;
&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
   # Separate methods for quiz questionnaire&lt;br /&gt;
   #=========================================================================================================&lt;br /&gt;
&lt;br /&gt;
   # View a quiz questionnaire&lt;br /&gt;
   def view&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     @participant = Participant.find(params[:pid]) # creating an instance variable since it needs to be sent to submitted_content/edit&lt;br /&gt;
     render :view&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # define a new quiz questionnaire&lt;br /&gt;
   # method invoked by the view&lt;br /&gt;
   def new&lt;br /&gt;
     valid_request = true&lt;br /&gt;
     @assignment_id = params[:aid] # creating an instance variable to hold the assignment id&lt;br /&gt;
     @participant_id = params[:pid] # creating an instance variable to hold the participant id&lt;br /&gt;
     assignment = Assignment.find(@assignment_id)&lt;br /&gt;
     if !assignment.require_quiz? # flash error if this assignment does not require quiz&lt;br /&gt;
       flash[:error] = &amp;quot;This assignment does not support the quizzing feature.&amp;quot;&lt;br /&gt;
       valid_request = false&lt;br /&gt;
     else&lt;br /&gt;
       team = AssignmentParticipant.find(@participant_id).team&lt;br /&gt;
&lt;br /&gt;
       if team.nil? # flash error if this current participant does not have a team&lt;br /&gt;
         flash[:error] = &amp;quot;You should create or join a team first.&amp;quot;&lt;br /&gt;
         valid_request = false&lt;br /&gt;
       else&lt;br /&gt;
         if assignment.topics? &amp;amp;&amp;amp; team.topic.nil? # flash error if this assignment has topic but current team does not have a topic&lt;br /&gt;
           flash[:error] = &amp;quot;Your team should have a topic.&amp;quot;&lt;br /&gt;
           valid_request = false&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
     if valid_request &amp;amp;&amp;amp; Questionnaire::QUESTIONNAIRE_TYPES.include?(params[:model])&lt;br /&gt;
       @questionnaire = Object.const_get(params[:model]).new&lt;br /&gt;
       @questionnaire.private = params[:private]&lt;br /&gt;
       @questionnaire.min_question_score = 0&lt;br /&gt;
       @questionnaire.max_question_score = 1&lt;br /&gt;
&lt;br /&gt;
       render :new&lt;br /&gt;
     else&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # seperate method for creating a quiz questionnaire because of differences in permission&lt;br /&gt;
   def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   # edit a quiz questionnaire&lt;br /&gt;
   def edit&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if !@questionnaire.taken_by_anyone?&lt;br /&gt;
       render :edit&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = &amp;quot;Your quiz has been taken by some other students, you cannot edit it anymore.&amp;quot;&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
   # save an updated quiz questionnaire to the database&lt;br /&gt;
   def update&lt;br /&gt;
     @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
     if @questionnaire.nil?&lt;br /&gt;
       redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
       return&lt;br /&gt;
     end&lt;br /&gt;
     if params['save'] &amp;amp;&amp;amp; params[:question].try(:keys)&lt;br /&gt;
       @questionnaire.update_attributes(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       for qid in params[:question].keys&lt;br /&gt;
         @question = Question.find(qid)&lt;br /&gt;
         @question.txt = params[:question][qid.to_sym][:txt]&lt;br /&gt;
         @question.save&lt;br /&gt;
&lt;br /&gt;
         @quiz_question_choices = QuizQuestionChoice.where(question_id: qid)&lt;br /&gt;
         i = 1&lt;br /&gt;
         for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
     redirect_to controller: 'submitted_content', action: 'view', id: params[:pid]&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 2''': Refactor the long methods in questionnaires_controller.rb, such as create and create_questionnaire, update quiz, valid quiz, etc.&lt;br /&gt;
* '''Solution''': &lt;br /&gt;
a. Deleted the create_questionnaire method and replaced the call to it in create_quiz_questionnaire with the code of create_questionnaire and is later moved to quiz_questionnaires_controller.rb and the code snippet below is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create&lt;br /&gt;
     valid = QuizQuestionnaire.valid&lt;br /&gt;
     if valid.eql?(&amp;quot;valid&amp;quot;)&lt;br /&gt;
       @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
&lt;br /&gt;
       # TODO: check for Quiz Questionnaire?&lt;br /&gt;
       if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
         participant_id = params[:pid] # creating a local variable to send as parameter to submitted content if it is a quiz questionnaire&lt;br /&gt;
         @questionnaire.min_question_score = 0&lt;br /&gt;
         @questionnaire.max_question_score = 1&lt;br /&gt;
         author_team = AssignmentTeam.team(Participant.find(participant_id))&lt;br /&gt;
&lt;br /&gt;
         @questionnaire.instructor_id = author_team.id # for a team assignment, set the instructor id to the team_id&lt;br /&gt;
&lt;br /&gt;
         @successful_create = true&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         save_choices @questionnaire.id&lt;br /&gt;
&lt;br /&gt;
         flash[:note] = &amp;quot;The quiz was successfully created.&amp;quot; if @successful_create == true&lt;br /&gt;
         redirect_to controller: 'submitted_content', action: 'edit', id: participant_id&lt;br /&gt;
       else # if it is not a quiz questionnaire&lt;br /&gt;
         @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
         save&lt;br /&gt;
&lt;br /&gt;
         redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
       end&lt;br /&gt;
     else&lt;br /&gt;
       flash[:error] = valid.to_s&lt;br /&gt;
       redirect_to :back&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b. Moved the large block of for and if statements into method called change_question_types in the quiz_questionnaire model.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
&lt;br /&gt;
	if type == &amp;quot;MultipleChoiceCheckbox&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][i.to_s]&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: params[:quiz_question_choices][id.to_s][type][i.to_s][:iscorrect], txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][quiz_question_choice.id.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;MultipleChoiceRadio&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][:correctindex] == i.to_s&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '1', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
&lt;br /&gt;
            else&lt;br /&gt;
              quiz_question_choice.update_attributes(iscorrect: '0', txt: params[:quiz_question_choices][id.to_s][type][i.to_s][:txt])&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if type == &amp;quot;TrueFalse&amp;quot;&lt;br /&gt;
&lt;br /&gt;
            if params[:quiz_question_choices][id.to_s][type][1.to_s][:iscorrect] == &amp;quot;True&amp;quot; # the statement is correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is correct so &amp;quot;True&amp;quot; is the right answer&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            else # the statement is not correct&lt;br /&gt;
&lt;br /&gt;
              if quiz_question_choice.txt == &amp;quot;True&amp;quot;&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '0')&lt;br /&gt;
&lt;br /&gt;
              else&lt;br /&gt;
                quiz_question_choice.update_attributes(iscorrect: '1') # the statement is not correct so &amp;quot;False&amp;quot; is the right answer&lt;br /&gt;
              end&lt;br /&gt;
            end&lt;br /&gt;
          end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
c. Replaced large block of for and if statements in update with a call to the new change_question_types method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     for quiz_question_choice in @quiz_question_choices&lt;br /&gt;
           type = @question.type&lt;br /&gt;
           id = @question.id&lt;br /&gt;
           QuizQuestionnaire.change_question_types(quiz_question_choice, type, id, i)&lt;br /&gt;
           i += 1&lt;br /&gt;
         end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
d. Moved export, import, copy_questionnaire_details, and assign_instructor_id to questionaire model. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def copy_questionnaire_details(questions, orig_questionnaire, id)&lt;br /&gt;
    self.instructor_id = self.assign_instructor_id()&lt;br /&gt;
    self.name = 'Copy of ' + orig_questionnaire.name&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      self.created_at = Time.now&lt;br /&gt;
      self.save!&lt;br /&gt;
      questions.each do |question|&lt;br /&gt;
        new_question = question.dup&lt;br /&gt;
        new_question.questionnaire_id = id&lt;br /&gt;
        new_question.size = '50,3' if (new_question.is_a? Criterion or new_question.is_a? TextResponse) and new_question.size.nil?&lt;br /&gt;
        new_question.save!&lt;br /&gt;
        advices = QuestionAdvice.where(question_id: question.id)&lt;br /&gt;
        next if advices.empty?&lt;br /&gt;
        advices.each do |advice|&lt;br /&gt;
          new_advice = advice.dup&lt;br /&gt;
          new_advice.question_id = new_question.id&lt;br /&gt;
          new_advice.save!&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      pFolder = TreeFolder.find_by(name: question.set_display_type(display_type))&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: pFolder.id)&lt;br /&gt;
      QuestionnaireNode.find_or_create_by(parent_id: parent.id, node_object_id: id)&lt;br /&gt;
      undo_link(&amp;quot;Copy of questionnaire #{orig_questionnaire.name} has been created successfully.&amp;quot;)&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'view', id: @questionnaire.id&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'The questionnaire was not able to be copied. Please check the original course for missing information.' + $ERROR_INFO&lt;br /&gt;
      redirect_to action: 'list', controller: 'tree_display'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def export&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    csv_data = QuestionnaireHelper.create_questionnaire_csv @questionnaire, session[:user].name&lt;br /&gt;
    send_data csv_data,&lt;br /&gt;
              type: 'text/csv; charset=iso-8859-1; header=present',&lt;br /&gt;
              disposition: &amp;quot;attachment; filename=questionnaires.csv&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def import&lt;br /&gt;
    @questionnaire = Questionnaire.find(params[:id])&lt;br /&gt;
    file = params['csv']&lt;br /&gt;
    @questionnaire.questions &amp;lt;&amp;lt; QuestionnaireHelper.get_questions_from_csv(@questionnaire, file)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def assign_instructor_id&lt;br /&gt;
    # if the user to copy the questionnaire is a TA, the instructor should be the owner instead of the TA&lt;br /&gt;
    if session[:user].role.name != &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      session[:user].id&lt;br /&gt;
    else # for TA we need to get his instructor id and by default add it to his course for which he is the TA&lt;br /&gt;
      Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3''': Replace switch statements with subclasses methods and create models for the subclasses.&lt;br /&gt;
* '''Solution''': Moved the switch-case statement from create in questionaire_controller.rb into a method called set_display_type in questionaire model. The following is the code snippet that shows the same.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  def set_dispay_type(display_type)&lt;br /&gt;
&lt;br /&gt;
      case display_type&lt;br /&gt;
&lt;br /&gt;
      when 'Review'&lt;br /&gt;
	display_type = 'Review'&lt;br /&gt;
&lt;br /&gt;
      when 'Metareview'&lt;br /&gt;
	display_type = 'Metareview'&lt;br /&gt;
&lt;br /&gt;
      when 'AuthorFeedback'&lt;br /&gt;
        display_type = 'Author%Feedback'&lt;br /&gt;
&lt;br /&gt;
      when 'CourseSurvey'&lt;br /&gt;
        display_type = 'Course%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'TeammateReview'&lt;br /&gt;
        display_type = 'Teammate%Review'&lt;br /&gt;
&lt;br /&gt;
      when 'GlobalSurvey'&lt;br /&gt;
        display_type = 'Global%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'AssignmentSurvey'&lt;br /&gt;
        display_type = 'Assignment%Survey'&lt;br /&gt;
&lt;br /&gt;
      when 'Bookmarkrating'&lt;br /&gt;
	display_type = 'Bookmarkrating'&lt;br /&gt;
      end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Problem 4''': Remove hardcoded parameters, such as save_choice method&lt;br /&gt;
* '''Solution''': Hardcoded parameters are removed and necessary constants are defined.&lt;br /&gt;
&lt;br /&gt;
===Test Plans===&lt;br /&gt;
&lt;br /&gt;
Because the purpose of our project was to better arrange our code, it follows that we also needed to rearrange the tests for that code. We first divided the tests for questionnaires_controller into two test files, questionnaires_controller_spec and quiz_questionnaires_controller_spec and separated the tests for CRUD operations of quiz_questionnaires_controller into the quiz_questionnaires_controller_spec, renaming them from view_quiz, create_quiz and the like to view and create. After this separation of CRUD operation testing, we tested the functionality that we moved out of the controllers into the model including the validation method for the quiz questionnaire. We did not include tests to cover the existing model functions, nor did we test the new set_display_type or change_question_types functions as they are setter methods, which, according to our testing instruction are not worth testing. &lt;br /&gt;
&lt;br /&gt;
The setup for testing was particularly troublesome for the deployment of this project. The tests did not run properly in RubyMine, so it was difficult to ensure they were set up properly, and none of the members of our group have any expertise in rspec testing.&lt;br /&gt;
&lt;br /&gt;
===Testing from UI===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/Riounis/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1271 GitHub Pull Request]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Amishra6</name></author>
	</entry>
</feed>