<?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=Vsonthy</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=Vsonthy"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Vsonthy"/>
	<updated>2026-05-08T20:29:56Z</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_2014/final_E1471_asuv&amp;diff=92504</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=92504"/>
		<updated>2014-12-04T05:14:27Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Steps to check the new implementations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Information Display and Student Interaction=&lt;br /&gt;
&lt;br /&gt;
[My main comment is that I would like a mockup of how your screens are going to look, so I can judge if the required info is there and if the UI is intuitive enough.]&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and its codebase is maintained in GitHub.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Our contribution in this project would be to improve the display of questionnaires for all the instructors and also integrating a previous project which provides a new dashboard for students to view and compare their performance of each assignment. &lt;br /&gt;
&lt;br /&gt;
==Current State==&lt;br /&gt;
*In the current state instructor should go through all the questionnaires to find the one they are looking for. &lt;br /&gt;
*The keyword search functionality is not yet implemented for questionnaires.&lt;br /&gt;
*The current student dashboard provides the average score and range of the student’s assignment, review and final score. &lt;br /&gt;
*The system has a limitation where in a student/instructor cannot view and compare the student scores based on the class performance.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
*As a part of our project we will implement the search functionality and also make it possible to click and bring up a list of questionnaires used in the course, expanding only the applicable questionnaires in the list of questionnaires.&lt;br /&gt;
*A project from last year has the implementation for the new student dashboard. We would like to take that project, make the required changes to it and integrate it into expertiza.&lt;br /&gt;
*This new dashboard gives the students a comparative statistics for that particular assignment for the entire class. &lt;br /&gt;
*Giving the min, mean and max gives the student a range to judge where they stand with respect to the class. &lt;br /&gt;
*Other features were part of the project were to show the number of reviews and metareviews he/she has done for this assignment and also based on a threshold what are the number of reviews/metareviews the student still needs to do. &lt;br /&gt;
*A histogram distribution of the scores of the class (all teams) for that assignment would also shown as a part of the dashboard.&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed a significant amount of time ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible and missing parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
We found that while the currently existing code covers most of the functionality, a major part of the functionality is missing. According to definition, the instructor should see the following on his home page:&lt;br /&gt;
*The instructor's courses&lt;br /&gt;
*Assignments for those courses&lt;br /&gt;
*Questionnaire by assignment name&lt;br /&gt;
&lt;br /&gt;
Each of these should be compressed to titles only, and it should be possible to expand them by single mouse click. Each course should have its own list of assignments which can, again, be expanded. Also, there is a search box on the page which allows to search assignments, courses and questionnaires.&lt;br /&gt;
&lt;br /&gt;
The search functionality for assignments and courses is working well, but the search for questionnaires is not implemented.&lt;br /&gt;
&lt;br /&gt;
So, for this specific project, we plan to focus on implementing the search for questionnaires first. Then, integrate it all and test each functionality: make sure that nothing is affected by the new functionality added. After all the tests are performed, we will merge the project with the main project, thus integrating it with the final build.&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
The features required for the dashboard for students project have already been implemented. So, the main task to be performed by us is to merge the project files with the main project and make sure that nothing else is affected by the process.&lt;br /&gt;
&lt;br /&gt;
The current code is able to display the maximum scores, average scores, number of reviews and distribution charts.&lt;br /&gt;
&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Files to be merged : Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  questionnaire_type_node.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb, tree_display/actions/_courses_actions.html.erb, tree_display/_page_header.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, questionnaires_controller.rb, tree_display_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 db/schema.rb&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Functionality of each file====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality involved for implementation&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_type_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/actions/_courses_actions.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/_page_header.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaires_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; schema.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Database&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Files to be changed : Better display of assignment===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 course_node.rb,assignment_node.rb,questionnaire_node.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 tree_display\ _row_header.html.erb,tree_display\ _entry.html.erb,tree_display/actions/_courses_actions.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tree_display controller.rb,course_controller.rb,assignment_controller.rb,questionnaire_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  JavaScript&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tableactions.js&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Functionality of each file====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality involved for implementation&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all course none in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all assignment node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all questionnaire node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _row_header.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display of header in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _entry.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display entity in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/actions/_courses_actions.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display separate actions on each row &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various course related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various assignment related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 9 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various questionnaire related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 10 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| For direct access to every entity like questionnaires, review rubric etc..&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Screenshots =&lt;br /&gt;
&amp;lt;b&amp;gt;1) Better display for assignments:&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
A new icon for questionnaires added&amp;lt;br/&amp;gt;&lt;br /&gt;
[[File:new_icon_view.png|center|frame]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
On click of icon it will display questionnaires related to the selected course&amp;lt;br/&amp;gt;&lt;br /&gt;
[[File:questionnaires_view.png|center|frame]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;2) Dashboard for students:&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
It shows the different between previous implementation and new implementation views.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Before&lt;br /&gt;
! After&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:before_view.png|frame|left| ]]&lt;br /&gt;
| [[File:after_view.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
For the instructor, there needs to be a way to quickly find rubrics (and other questionnaires) that have been used in a single course. It should be possible to search or click somewhere to bring up a list of questionnaires used in the course, expanding only the applicable questionnaires in the list of questionnaires. A search functionality for questionnaire is expected. Currently, assignment and course searches is implemented, and there is a dropdown for questionnaire, but it's functionality is missing. &lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Instructot&lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition:''' There are few questionnaires in the system&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Instructor lands on &amp;quot;Manage content&amp;quot; page  &lt;br /&gt;
&lt;br /&gt;
3. Search for a questionnaire, by selecting questionnaire in the search dropdown and input some search string&lt;br /&gt;
&lt;br /&gt;
4. Search results displayed, expanding only the applicable questionnaires in the list of questionnaires&lt;br /&gt;
&lt;br /&gt;
[[File:Assignment_display_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following use case diagram shows the system of Assignment grades for a student on Expertiza as it is depicted right now. These include viewing their own project submission (with url and attachments), reviews and metareviews on their work, author feedbacks, teammate reviews and their final score on that assignment/project.&amp;lt;ref&amp;gt;Previous year's design document for ''E715: Dashboard for Students'' by Ambika Tripathi, Milan Tonse, Krutika Nagar, Shruti Buch&amp;lt;/ref&amp;gt; As part of this project we shall be adding more data on this page, so that student has better understanding of his/her marks. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing scores for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for average high and low scores. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class scores for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the average, high and low class score for that particular assignment&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing graphical output for scores for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for average high and low scores. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class scores for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the graphical output for average, high and low class score for that particular assignment&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing number of reviews done by him/her&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for number of reviews done by the student. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for my reviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the number of reviews the student has done for that particular assignment and also the &lt;br /&gt;
&lt;br /&gt;
number of reviews he still has to do to reach the threshold. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing number of metareviews done by him/her&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for number of metareviews done by the student. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for my metareviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the number of metareviews the student has done for that particular assignment and also &lt;br /&gt;
&lt;br /&gt;
the number of metareviews he still has to do to reach the threshold.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing average number of class reviews for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for class reviews for that assignment. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class reviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the average number of class reviews for that particular assignment&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing average number of class metareviews for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for class metareviews for that assignment. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class metareviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the average number of class metareviews for that particular assignment&lt;br /&gt;
 &lt;br /&gt;
[[File:Dashboard_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_new.jpg]]&lt;br /&gt;
=UML diagram=&lt;br /&gt;
Following is class diagram for Assignment display module. &amp;lt;ref&amp;gt;Previous year's design document for ''E707: Better display for assignments'' by Bharath Sampath(bsampat2),Prakash Vasudevan(pvasude),Raghavendran Nedunchezhian(rnedunc), Yuchuan Liu(yliu63)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:UML.jpg]]&lt;br /&gt;
&lt;br /&gt;
Following is class diagram for Dashboard for students module.&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard.jpg]]&lt;br /&gt;
&lt;br /&gt;
=Steps to check the new implementations=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== The new Student dashboard ==&lt;br /&gt;
Sample Test case.&lt;br /&gt;
&amp;lt;br&amp;gt;1. Log-in to Expertiza as an student (Username: user480, Password: password).&lt;br /&gt;
&amp;lt;br&amp;gt;2. Click on 'Program 1: BackChannel' assignment.&lt;br /&gt;
&amp;lt;br&amp;gt;3. Click on the option 'Your Scores'.&lt;br /&gt;
&amp;lt;br&amp;gt;4. The dashboard is then displayed with the class statistics along with the new graph added.&lt;br /&gt;
&lt;br /&gt;
== The Questionnaire search ==&lt;br /&gt;
&amp;lt;br&amp;gt;1. Log-in to Expertiza as an instructor (Username: user2, Password: password).&lt;br /&gt;
&amp;lt;br&amp;gt;2. Enter any string in the search box&lt;br /&gt;
&amp;lt;br&amp;gt;3. We would be able to see all the questionnaires that have the entered string as a substring in them. &lt;br /&gt;
&lt;br /&gt;
== The Course specific questionnaire list ==&lt;br /&gt;
Sample Test case.&lt;br /&gt;
&amp;lt;br&amp;gt;1. Log-in to Expertiza as an instructor (Username: user2, Password: password).&lt;br /&gt;
&amp;lt;br&amp;gt;2. Expand the Courses option.&lt;br /&gt;
&amp;lt;br&amp;gt;3. Hover over the Course actions menu for the course 'CSC 517, Spring 2014'.&lt;br /&gt;
&amp;lt;br&amp;gt;4. Click on the menu-item that says 'View Questionnaires'.&lt;br /&gt;
&amp;lt;br&amp;gt;5. List of questionnaires would be displayed here.&lt;br /&gt;
&amp;lt;br&amp;gt;6. Search within the above list of questionnaires is also possible by using the search given in the page.&lt;br /&gt;
&lt;br /&gt;
='''References'''=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=92503</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=92503"/>
		<updated>2014-12-04T05:08:16Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Steps to check the new implementations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Information Display and Student Interaction=&lt;br /&gt;
&lt;br /&gt;
[My main comment is that I would like a mockup of how your screens are going to look, so I can judge if the required info is there and if the UI is intuitive enough.]&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and its codebase is maintained in GitHub.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Our contribution in this project would be to improve the display of questionnaires for all the instructors and also integrating a previous project which provides a new dashboard for students to view and compare their performance of each assignment. &lt;br /&gt;
&lt;br /&gt;
==Current State==&lt;br /&gt;
*In the current state instructor should go through all the questionnaires to find the one they are looking for. &lt;br /&gt;
*The keyword search functionality is not yet implemented for questionnaires.&lt;br /&gt;
*The current student dashboard provides the average score and range of the student’s assignment, review and final score. &lt;br /&gt;
*The system has a limitation where in a student/instructor cannot view and compare the student scores based on the class performance.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
*As a part of our project we will implement the search functionality and also make it possible to click and bring up a list of questionnaires used in the course, expanding only the applicable questionnaires in the list of questionnaires.&lt;br /&gt;
*A project from last year has the implementation for the new student dashboard. We would like to take that project, make the required changes to it and integrate it into expertiza.&lt;br /&gt;
*This new dashboard gives the students a comparative statistics for that particular assignment for the entire class. &lt;br /&gt;
*Giving the min, mean and max gives the student a range to judge where they stand with respect to the class. &lt;br /&gt;
*Other features were part of the project were to show the number of reviews and metareviews he/she has done for this assignment and also based on a threshold what are the number of reviews/metareviews the student still needs to do. &lt;br /&gt;
*A histogram distribution of the scores of the class (all teams) for that assignment would also shown as a part of the dashboard.&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed a significant amount of time ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible and missing parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
We found that while the currently existing code covers most of the functionality, a major part of the functionality is missing. According to definition, the instructor should see the following on his home page:&lt;br /&gt;
*The instructor's courses&lt;br /&gt;
*Assignments for those courses&lt;br /&gt;
*Questionnaire by assignment name&lt;br /&gt;
&lt;br /&gt;
Each of these should be compressed to titles only, and it should be possible to expand them by single mouse click. Each course should have its own list of assignments which can, again, be expanded. Also, there is a search box on the page which allows to search assignments, courses and questionnaires.&lt;br /&gt;
&lt;br /&gt;
The search functionality for assignments and courses is working well, but the search for questionnaires is not implemented.&lt;br /&gt;
&lt;br /&gt;
So, for this specific project, we plan to focus on implementing the search for questionnaires first. Then, integrate it all and test each functionality: make sure that nothing is affected by the new functionality added. After all the tests are performed, we will merge the project with the main project, thus integrating it with the final build.&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
The features required for the dashboard for students project have already been implemented. So, the main task to be performed by us is to merge the project files with the main project and make sure that nothing else is affected by the process.&lt;br /&gt;
&lt;br /&gt;
The current code is able to display the maximum scores, average scores, number of reviews and distribution charts.&lt;br /&gt;
&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Files to be merged : Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  questionnaire_type_node.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb, tree_display/actions/_courses_actions.html.erb, tree_display/_page_header.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, questionnaires_controller.rb, tree_display_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 db/schema.rb&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Functionality of each file====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality involved for implementation&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_type_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/actions/_courses_actions.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/_page_header.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaires_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; schema.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Database&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Files to be changed : Better display of assignment===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 course_node.rb,assignment_node.rb,questionnaire_node.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 tree_display\ _row_header.html.erb,tree_display\ _entry.html.erb,tree_display/actions/_courses_actions.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tree_display controller.rb,course_controller.rb,assignment_controller.rb,questionnaire_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  JavaScript&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tableactions.js&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Functionality of each file====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality involved for implementation&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all course none in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all assignment node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all questionnaire node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _row_header.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display of header in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _entry.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display entity in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/actions/_courses_actions.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display separate actions on each row &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various course related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various assignment related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 9 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various questionnaire related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 10 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| For direct access to every entity like questionnaires, review rubric etc..&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Screenshots =&lt;br /&gt;
&amp;lt;b&amp;gt;1) Better display for assignments:&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
A new icon for questionnaires added&amp;lt;br/&amp;gt;&lt;br /&gt;
[[File:new_icon_view.png|center|frame]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
On click of icon it will display questionnaires related to the selected course&amp;lt;br/&amp;gt;&lt;br /&gt;
[[File:questionnaires_view.png|center|frame]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;2) Dashboard for students:&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
It shows the different between previous implementation and new implementation views.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Before&lt;br /&gt;
! After&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:before_view.png|frame|left| ]]&lt;br /&gt;
| [[File:after_view.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
For the instructor, there needs to be a way to quickly find rubrics (and other questionnaires) that have been used in a single course. It should be possible to search or click somewhere to bring up a list of questionnaires used in the course, expanding only the applicable questionnaires in the list of questionnaires. A search functionality for questionnaire is expected. Currently, assignment and course searches is implemented, and there is a dropdown for questionnaire, but it's functionality is missing. &lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Instructot&lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition:''' There are few questionnaires in the system&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Instructor lands on &amp;quot;Manage content&amp;quot; page  &lt;br /&gt;
&lt;br /&gt;
3. Search for a questionnaire, by selecting questionnaire in the search dropdown and input some search string&lt;br /&gt;
&lt;br /&gt;
4. Search results displayed, expanding only the applicable questionnaires in the list of questionnaires&lt;br /&gt;
&lt;br /&gt;
[[File:Assignment_display_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following use case diagram shows the system of Assignment grades for a student on Expertiza as it is depicted right now. These include viewing their own project submission (with url and attachments), reviews and metareviews on their work, author feedbacks, teammate reviews and their final score on that assignment/project.&amp;lt;ref&amp;gt;Previous year's design document for ''E715: Dashboard for Students'' by Ambika Tripathi, Milan Tonse, Krutika Nagar, Shruti Buch&amp;lt;/ref&amp;gt; As part of this project we shall be adding more data on this page, so that student has better understanding of his/her marks. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing scores for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for average high and low scores. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class scores for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the average, high and low class score for that particular assignment&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing graphical output for scores for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for average high and low scores. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class scores for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the graphical output for average, high and low class score for that particular assignment&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing number of reviews done by him/her&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for number of reviews done by the student. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for my reviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the number of reviews the student has done for that particular assignment and also the &lt;br /&gt;
&lt;br /&gt;
number of reviews he still has to do to reach the threshold. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing number of metareviews done by him/her&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for number of metareviews done by the student. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for my metareviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the number of metareviews the student has done for that particular assignment and also &lt;br /&gt;
&lt;br /&gt;
the number of metareviews he still has to do to reach the threshold.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing average number of class reviews for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for class reviews for that assignment. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class reviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the average number of class reviews for that particular assignment&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing average number of class metareviews for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for class metareviews for that assignment. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class metareviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the average number of class metareviews for that particular assignment&lt;br /&gt;
 &lt;br /&gt;
[[File:Dashboard_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_new.jpg]]&lt;br /&gt;
=UML diagram=&lt;br /&gt;
Following is class diagram for Assignment display module. &amp;lt;ref&amp;gt;Previous year's design document for ''E707: Better display for assignments'' by Bharath Sampath(bsampat2),Prakash Vasudevan(pvasude),Raghavendran Nedunchezhian(rnedunc), Yuchuan Liu(yliu63)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:UML.jpg]]&lt;br /&gt;
&lt;br /&gt;
Following is class diagram for Dashboard for students module.&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard.jpg]]&lt;br /&gt;
&lt;br /&gt;
=Steps to check the new implementations=&lt;br /&gt;
&lt;br /&gt;
== The new Student dashboard ==&lt;br /&gt;
1. Log-in to Expertiza as an student (Username: user480, Password: password).&lt;br /&gt;
&amp;lt;br&amp;gt;2. Click on 'Program 1: BackChannel' assignment.&lt;br /&gt;
&amp;lt;br&amp;gt;3. Click on the option 'Your Scores'.&lt;br /&gt;
&amp;lt;br&amp;gt;4. The dashboard is then displayed with the class statistics along with the new graph added.&lt;br /&gt;
&lt;br /&gt;
== The Questionnaire search ==&lt;br /&gt;
1. Log-in to Expertiza as an instructor (Username: user2, Password: password).&lt;br /&gt;
&amp;lt;br&amp;gt;2. Enter a string 'wiki' in the search box&lt;br /&gt;
&amp;lt;br&amp;gt;3. We would be able to see all the questionnaires that have the substring 'wiki' in them. &lt;br /&gt;
&lt;br /&gt;
== The Course specific questionnaire list ==&lt;br /&gt;
1. Log-in to Expertiza as an instructor (Username: user2, Password: password).&lt;br /&gt;
&amp;lt;br&amp;gt;2. Expand the Courses option.&lt;br /&gt;
&amp;lt;br&amp;gt;3. Hover over the Course actions menu for the course 'CSC 517, Spring 2014'.&lt;br /&gt;
&amp;lt;br&amp;gt;4. Click on the menu-item that says 'View Questionnaires'.&lt;br /&gt;
&amp;lt;br&amp;gt;5. List of questionnaires would be displayed here.&lt;br /&gt;
&lt;br /&gt;
='''References'''=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=92499</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=92499"/>
		<updated>2014-12-04T05:00:25Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Steps to check the new implementations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Information Display and Student Interaction=&lt;br /&gt;
&lt;br /&gt;
[My main comment is that I would like a mockup of how your screens are going to look, so I can judge if the required info is there and if the UI is intuitive enough.]&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and its codebase is maintained in GitHub.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Our contribution in this project would be to improve the display of questionnaires for all the instructors and also integrating a previous project which provides a new dashboard for students to view and compare their performance of each assignment. &lt;br /&gt;
&lt;br /&gt;
==Current State==&lt;br /&gt;
*In the current state instructor should go through all the questionnaires to find the one they are looking for. &lt;br /&gt;
*The keyword search functionality is not yet implemented for questionnaires.&lt;br /&gt;
*The current student dashboard provides the average score and range of the student’s assignment, review and final score. &lt;br /&gt;
*The system has a limitation where in a student/instructor cannot view and compare the student scores based on the class performance.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
*As a part of our project we will implement the search functionality and also make it possible to click and bring up a list of questionnaires used in the course, expanding only the applicable questionnaires in the list of questionnaires.&lt;br /&gt;
*A project from last year has the implementation for the new student dashboard. We would like to take that project, make the required changes to it and integrate it into expertiza.&lt;br /&gt;
*This new dashboard gives the students a comparative statistics for that particular assignment for the entire class. &lt;br /&gt;
*Giving the min, mean and max gives the student a range to judge where they stand with respect to the class. &lt;br /&gt;
*Other features were part of the project were to show the number of reviews and metareviews he/she has done for this assignment and also based on a threshold what are the number of reviews/metareviews the student still needs to do. &lt;br /&gt;
*A histogram distribution of the scores of the class (all teams) for that assignment would also shown as a part of the dashboard.&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed a significant amount of time ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible and missing parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
We found that while the currently existing code covers most of the functionality, a major part of the functionality is missing. According to definition, the instructor should see the following on his home page:&lt;br /&gt;
*The instructor's courses&lt;br /&gt;
*Assignments for those courses&lt;br /&gt;
*Questionnaire by assignment name&lt;br /&gt;
&lt;br /&gt;
Each of these should be compressed to titles only, and it should be possible to expand them by single mouse click. Each course should have its own list of assignments which can, again, be expanded. Also, there is a search box on the page which allows to search assignments, courses and questionnaires.&lt;br /&gt;
&lt;br /&gt;
The search functionality for assignments and courses is working well, but the search for questionnaires is not implemented.&lt;br /&gt;
&lt;br /&gt;
So, for this specific project, we plan to focus on implementing the search for questionnaires first. Then, integrate it all and test each functionality: make sure that nothing is affected by the new functionality added. After all the tests are performed, we will merge the project with the main project, thus integrating it with the final build.&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
The features required for the dashboard for students project have already been implemented. So, the main task to be performed by us is to merge the project files with the main project and make sure that nothing else is affected by the process.&lt;br /&gt;
&lt;br /&gt;
The current code is able to display the maximum scores, average scores, number of reviews and distribution charts.&lt;br /&gt;
&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Files to be merged : Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  questionnaire_type_node.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb, tree_display/actions/_courses_actions.html.erb, tree_display/_page_header.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, questionnaires_controller.rb, tree_display_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 db/schema.rb&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Functionality of each file====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality involved for implementation&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_type_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/actions/_courses_actions.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/_page_header.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaires_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; schema.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Database&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Files to be changed : Better display of assignment===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 course_node.rb,assignment_node.rb,questionnaire_node.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 tree_display\ _row_header.html.erb,tree_display\ _entry.html.erb,tree_display/actions/_courses_actions.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tree_display controller.rb,course_controller.rb,assignment_controller.rb,questionnaire_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  JavaScript&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tableactions.js&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Functionality of each file====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality involved for implementation&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all course none in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all assignment node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all questionnaire node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _row_header.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display of header in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _entry.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display entity in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/actions/_courses_actions.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display separate actions on each row &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various course related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various assignment related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 9 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various questionnaire related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 10 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| For direct access to every entity like questionnaires, review rubric etc..&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Screenshots =&lt;br /&gt;
&amp;lt;b&amp;gt;1) Better display for assignments:&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
A new icon for questionnaires added&amp;lt;br/&amp;gt;&lt;br /&gt;
[[File:new_icon_view.png|center|frame]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
On click of icon it will display questionnaires related to the selected course&amp;lt;br/&amp;gt;&lt;br /&gt;
[[File:questionnaires_view.png|center|frame]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;2) Dashboard for students:&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
It shows the different between previous implementation and new implementation views.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Before&lt;br /&gt;
! After&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:before_view.png|frame|left| ]]&lt;br /&gt;
| [[File:after_view.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
For the instructor, there needs to be a way to quickly find rubrics (and other questionnaires) that have been used in a single course. It should be possible to search or click somewhere to bring up a list of questionnaires used in the course, expanding only the applicable questionnaires in the list of questionnaires. A search functionality for questionnaire is expected. Currently, assignment and course searches is implemented, and there is a dropdown for questionnaire, but it's functionality is missing. &lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Instructot&lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition:''' There are few questionnaires in the system&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Instructor lands on &amp;quot;Manage content&amp;quot; page  &lt;br /&gt;
&lt;br /&gt;
3. Search for a questionnaire, by selecting questionnaire in the search dropdown and input some search string&lt;br /&gt;
&lt;br /&gt;
4. Search results displayed, expanding only the applicable questionnaires in the list of questionnaires&lt;br /&gt;
&lt;br /&gt;
[[File:Assignment_display_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following use case diagram shows the system of Assignment grades for a student on Expertiza as it is depicted right now. These include viewing their own project submission (with url and attachments), reviews and metareviews on their work, author feedbacks, teammate reviews and their final score on that assignment/project.&amp;lt;ref&amp;gt;Previous year's design document for ''E715: Dashboard for Students'' by Ambika Tripathi, Milan Tonse, Krutika Nagar, Shruti Buch&amp;lt;/ref&amp;gt; As part of this project we shall be adding more data on this page, so that student has better understanding of his/her marks. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing scores for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for average high and low scores. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class scores for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the average, high and low class score for that particular assignment&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing graphical output for scores for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for average high and low scores. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class scores for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the graphical output for average, high and low class score for that particular assignment&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing number of reviews done by him/her&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for number of reviews done by the student. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for my reviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the number of reviews the student has done for that particular assignment and also the &lt;br /&gt;
&lt;br /&gt;
number of reviews he still has to do to reach the threshold. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing number of metareviews done by him/her&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for number of metareviews done by the student. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for my metareviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the number of metareviews the student has done for that particular assignment and also &lt;br /&gt;
&lt;br /&gt;
the number of metareviews he still has to do to reach the threshold.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing average number of class reviews for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for class reviews for that assignment. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class reviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the average number of class reviews for that particular assignment&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing average number of class metareviews for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for class metareviews for that assignment. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class metareviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the average number of class metareviews for that particular assignment&lt;br /&gt;
 &lt;br /&gt;
[[File:Dashboard_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_new.jpg]]&lt;br /&gt;
=UML diagram=&lt;br /&gt;
Following is class diagram for Assignment display module. &amp;lt;ref&amp;gt;Previous year's design document for ''E707: Better display for assignments'' by Bharath Sampath(bsampat2),Prakash Vasudevan(pvasude),Raghavendran Nedunchezhian(rnedunc), Yuchuan Liu(yliu63)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:UML.jpg]]&lt;br /&gt;
&lt;br /&gt;
Following is class diagram for Dashboard for students module.&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard.jpg]]&lt;br /&gt;
&lt;br /&gt;
=Steps to check the new implementations=&lt;br /&gt;
&lt;br /&gt;
== The new Student dashboard ==&lt;br /&gt;
1. Log-in to Expertiza as an student (Username: user480, Password: password).&lt;br /&gt;
&amp;lt;br&amp;gt;2. Search for an assignment .&lt;br /&gt;
Click on the Edit Assignment option as shown below:&lt;br /&gt;
&lt;br /&gt;
== The Questionnaire search ==&lt;br /&gt;
1. Log-in to Expertiza as an instructor (Username: user2, Password: password).&lt;br /&gt;
2. Enter a string 'wiki' in the search box&lt;br /&gt;
3. We would be able to see all the questionnaires that have the substring 'wiki' in them. &lt;br /&gt;
&lt;br /&gt;
== The Course specific questionnaire list ==&lt;br /&gt;
1. Log-in to Expertiza as an instructor (Username: user2, Password: password).&lt;br /&gt;
2. Expand the Courses option.&lt;br /&gt;
3. Hover over the Course actions menu for the course 'CSC 517, Spring 2014'.&lt;br /&gt;
4. Click on the menu-item that says 'View Questionnaires'  &lt;br /&gt;
Click on the Edit Assignment option as shown below:&lt;br /&gt;
&lt;br /&gt;
='''References'''=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=92498</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=92498"/>
		<updated>2014-12-04T04:59:28Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Steps to check the new implementations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Information Display and Student Interaction=&lt;br /&gt;
&lt;br /&gt;
[My main comment is that I would like a mockup of how your screens are going to look, so I can judge if the required info is there and if the UI is intuitive enough.]&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and its codebase is maintained in GitHub.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Our contribution in this project would be to improve the display of questionnaires for all the instructors and also integrating a previous project which provides a new dashboard for students to view and compare their performance of each assignment. &lt;br /&gt;
&lt;br /&gt;
==Current State==&lt;br /&gt;
*In the current state instructor should go through all the questionnaires to find the one they are looking for. &lt;br /&gt;
*The keyword search functionality is not yet implemented for questionnaires.&lt;br /&gt;
*The current student dashboard provides the average score and range of the student’s assignment, review and final score. &lt;br /&gt;
*The system has a limitation where in a student/instructor cannot view and compare the student scores based on the class performance.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
*As a part of our project we will implement the search functionality and also make it possible to click and bring up a list of questionnaires used in the course, expanding only the applicable questionnaires in the list of questionnaires.&lt;br /&gt;
*A project from last year has the implementation for the new student dashboard. We would like to take that project, make the required changes to it and integrate it into expertiza.&lt;br /&gt;
*This new dashboard gives the students a comparative statistics for that particular assignment for the entire class. &lt;br /&gt;
*Giving the min, mean and max gives the student a range to judge where they stand with respect to the class. &lt;br /&gt;
*Other features were part of the project were to show the number of reviews and metareviews he/she has done for this assignment and also based on a threshold what are the number of reviews/metareviews the student still needs to do. &lt;br /&gt;
*A histogram distribution of the scores of the class (all teams) for that assignment would also shown as a part of the dashboard.&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed a significant amount of time ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible and missing parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
We found that while the currently existing code covers most of the functionality, a major part of the functionality is missing. According to definition, the instructor should see the following on his home page:&lt;br /&gt;
*The instructor's courses&lt;br /&gt;
*Assignments for those courses&lt;br /&gt;
*Questionnaire by assignment name&lt;br /&gt;
&lt;br /&gt;
Each of these should be compressed to titles only, and it should be possible to expand them by single mouse click. Each course should have its own list of assignments which can, again, be expanded. Also, there is a search box on the page which allows to search assignments, courses and questionnaires.&lt;br /&gt;
&lt;br /&gt;
The search functionality for assignments and courses is working well, but the search for questionnaires is not implemented.&lt;br /&gt;
&lt;br /&gt;
So, for this specific project, we plan to focus on implementing the search for questionnaires first. Then, integrate it all and test each functionality: make sure that nothing is affected by the new functionality added. After all the tests are performed, we will merge the project with the main project, thus integrating it with the final build.&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
The features required for the dashboard for students project have already been implemented. So, the main task to be performed by us is to merge the project files with the main project and make sure that nothing else is affected by the process.&lt;br /&gt;
&lt;br /&gt;
The current code is able to display the maximum scores, average scores, number of reviews and distribution charts.&lt;br /&gt;
&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Files to be merged : Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  questionnaire_type_node.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb, tree_display/actions/_courses_actions.html.erb, tree_display/_page_header.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, questionnaires_controller.rb, tree_display_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 db/schema.rb&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Functionality of each file====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality involved for implementation&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_type_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/actions/_courses_actions.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/_page_header.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaires_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; schema.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Database&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Files to be changed : Better display of assignment===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 course_node.rb,assignment_node.rb,questionnaire_node.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 tree_display\ _row_header.html.erb,tree_display\ _entry.html.erb,tree_display/actions/_courses_actions.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tree_display controller.rb,course_controller.rb,assignment_controller.rb,questionnaire_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  JavaScript&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tableactions.js&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Functionality of each file====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality involved for implementation&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all course none in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all assignment node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all questionnaire node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _row_header.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display of header in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _entry.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display entity in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/actions/_courses_actions.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display separate actions on each row &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various course related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various assignment related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 9 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various questionnaire related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 10 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| For direct access to every entity like questionnaires, review rubric etc..&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Screenshots =&lt;br /&gt;
&amp;lt;b&amp;gt;1) Better display for assignments:&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
A new icon for questionnaires added&amp;lt;br/&amp;gt;&lt;br /&gt;
[[File:new_icon_view.png|center|frame]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
On click of icon it will display questionnaires related to the selected course&amp;lt;br/&amp;gt;&lt;br /&gt;
[[File:questionnaires_view.png|center|frame]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;2) Dashboard for students:&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
It shows the different between previous implementation and new implementation views.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Before&lt;br /&gt;
! After&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:before_view.png|frame|left| ]]&lt;br /&gt;
| [[File:after_view.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
For the instructor, there needs to be a way to quickly find rubrics (and other questionnaires) that have been used in a single course. It should be possible to search or click somewhere to bring up a list of questionnaires used in the course, expanding only the applicable questionnaires in the list of questionnaires. A search functionality for questionnaire is expected. Currently, assignment and course searches is implemented, and there is a dropdown for questionnaire, but it's functionality is missing. &lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Instructot&lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition:''' There are few questionnaires in the system&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Instructor lands on &amp;quot;Manage content&amp;quot; page  &lt;br /&gt;
&lt;br /&gt;
3. Search for a questionnaire, by selecting questionnaire in the search dropdown and input some search string&lt;br /&gt;
&lt;br /&gt;
4. Search results displayed, expanding only the applicable questionnaires in the list of questionnaires&lt;br /&gt;
&lt;br /&gt;
[[File:Assignment_display_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following use case diagram shows the system of Assignment grades for a student on Expertiza as it is depicted right now. These include viewing their own project submission (with url and attachments), reviews and metareviews on their work, author feedbacks, teammate reviews and their final score on that assignment/project.&amp;lt;ref&amp;gt;Previous year's design document for ''E715: Dashboard for Students'' by Ambika Tripathi, Milan Tonse, Krutika Nagar, Shruti Buch&amp;lt;/ref&amp;gt; As part of this project we shall be adding more data on this page, so that student has better understanding of his/her marks. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing scores for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for average high and low scores. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class scores for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the average, high and low class score for that particular assignment&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing graphical output for scores for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for average high and low scores. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class scores for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the graphical output for average, high and low class score for that particular assignment&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing number of reviews done by him/her&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for number of reviews done by the student. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for my reviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the number of reviews the student has done for that particular assignment and also the &lt;br /&gt;
&lt;br /&gt;
number of reviews he still has to do to reach the threshold. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing number of metareviews done by him/her&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for number of metareviews done by the student. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for my metareviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the number of metareviews the student has done for that particular assignment and also &lt;br /&gt;
&lt;br /&gt;
the number of metareviews he still has to do to reach the threshold.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing average number of class reviews for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for class reviews for that assignment. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class reviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the average number of class reviews for that particular assignment&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing average number of class metareviews for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for class metareviews for that assignment. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class metareviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the average number of class metareviews for that particular assignment&lt;br /&gt;
 &lt;br /&gt;
[[File:Dashboard_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_new.jpg]]&lt;br /&gt;
=UML diagram=&lt;br /&gt;
Following is class diagram for Assignment display module. &amp;lt;ref&amp;gt;Previous year's design document for ''E707: Better display for assignments'' by Bharath Sampath(bsampat2),Prakash Vasudevan(pvasude),Raghavendran Nedunchezhian(rnedunc), Yuchuan Liu(yliu63)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:UML.jpg]]&lt;br /&gt;
&lt;br /&gt;
Following is class diagram for Dashboard for students module.&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard.jpg]]&lt;br /&gt;
&lt;br /&gt;
=Steps to check the new implementations=&lt;br /&gt;
&lt;br /&gt;
== The new Student dashboard ==&lt;br /&gt;
1. Log-in to Expertiza as an student (Username: user480, Password: password).&lt;br /&gt;
2. Search for an assignment .&lt;br /&gt;
Click on the Edit Assignment option as shown below:&lt;br /&gt;
&lt;br /&gt;
== The Questionnaire search ==&lt;br /&gt;
1. Log-in to Expertiza as an instructor (Username: user2, Password: password).&lt;br /&gt;
2. Enter a string 'wiki' in the search box&lt;br /&gt;
3. We would be able to see all the questionnaires that have the substring 'wiki' in them. &lt;br /&gt;
&lt;br /&gt;
== The Course specific questionnaire list ==&lt;br /&gt;
1. Log-in to Expertiza as an instructor (Username: user2, Password: password).&lt;br /&gt;
2. Expand the Courses option.&lt;br /&gt;
3. Hover over the Course actions menu for the course 'CSC 517, Spring 2014'.&lt;br /&gt;
4. Click on the menu-item that says 'View Questionnaires'  &lt;br /&gt;
Click on the Edit Assignment option as shown below:&lt;br /&gt;
&lt;br /&gt;
='''References'''=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=92479</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=92479"/>
		<updated>2014-12-04T04:20:19Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Information Display and Student Interaction=&lt;br /&gt;
&lt;br /&gt;
[My main comment is that I would like a mockup of how your screens are going to look, so I can judge if the required info is there and if the UI is intuitive enough.]&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and its codebase is maintained in GitHub.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Our contribution in this project would be to improve the display of questionnaires for all the instructors and also integrating a previous project which provides a new dashboard for students to view and compare their performance of each assignment. &lt;br /&gt;
&lt;br /&gt;
==Current State==&lt;br /&gt;
*In the current state instructor should go through all the questionnaires to find the one they are looking for. &lt;br /&gt;
*The keyword search functionality is not yet implemented for questionnaires.&lt;br /&gt;
*The current student dashboard provides the average score and range of the student’s assignment, review and final score. &lt;br /&gt;
*The system has a limitation where in a student/instructor cannot view and compare the student scores based on the class performance.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
*As a part of our project we will implement the search functionality and also make it possible to click and bring up a list of questionnaires used in the course, expanding only the applicable questionnaires in the list of questionnaires.&lt;br /&gt;
*A project from last year has the implementation for the new student dashboard. We would like to take that project, make the required changes to it and integrate it into expertiza.&lt;br /&gt;
*This new dashboard gives the students a comparative statistics for that particular assignment for the entire class. &lt;br /&gt;
*Giving the min, mean and max gives the student a range to judge where they stand with respect to the class. &lt;br /&gt;
*Other features were part of the project were to show the number of reviews and metareviews he/she has done for this assignment and also based on a threshold what are the number of reviews/metareviews the student still needs to do. &lt;br /&gt;
*A histogram distribution of the scores of the class (all teams) for that assignment would also shown as a part of the dashboard.&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed a significant amount of time ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible and missing parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
We found that while the currently existing code covers most of the functionality, a major part of the functionality is missing. According to definition, the instructor should see the following on his home page:&lt;br /&gt;
*The instructor's courses&lt;br /&gt;
*Assignments for those courses&lt;br /&gt;
*Questionnaire by assignment name&lt;br /&gt;
&lt;br /&gt;
Each of these should be compressed to titles only, and it should be possible to expand them by single mouse click. Each course should have its own list of assignments which can, again, be expanded. Also, there is a search box on the page which allows to search assignments, courses and questionnaires.&lt;br /&gt;
&lt;br /&gt;
The search functionality for assignments and courses is working well, but the search for questionnaires is not implemented.&lt;br /&gt;
&lt;br /&gt;
So, for this specific project, we plan to focus on implementing the search for questionnaires first. Then, integrate it all and test each functionality: make sure that nothing is affected by the new functionality added. After all the tests are performed, we will merge the project with the main project, thus integrating it with the final build.&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
The features required for the dashboard for students project have already been implemented. So, the main task to be performed by us is to merge the project files with the main project and make sure that nothing else is affected by the process.&lt;br /&gt;
&lt;br /&gt;
The current code is able to display the maximum scores, average scores, number of reviews and distribution charts.&lt;br /&gt;
&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Files to be merged : Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  questionnaire_type_node.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb, tree_display/actions/_courses_actions.html.erb, tree_display/_page_header.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, questionnaires_controller.rb, tree_display_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 db/schema.rb&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Functionality of each file====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality involved for implementation&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; ScoreCache.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; review_mapping_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Assignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| All information related to assignment&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Responses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review response information&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Score_caches &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review score information &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; response_maps &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Files to be changed : Better display of assignment===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 course_node.rb,assignment_node.rb,questionnaire_node.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 tree_display\ _row_header.html.erb,tree_display\ _entry.html.erb,tree_display/actions/_courses_actions.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tree_display controller.rb,course_controller.rb,assignment_controller.rb,questionnaire_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  JavaScript&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tableactions.js&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Functionality of each file====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality involved for implementation&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all course none in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all assignment node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all questionnaire node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _row_header.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display of header in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _entry.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display entity in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/actions/_courses_actions.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display separate actions on each row &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various course related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various assignment related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 9 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various questionnaire related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 10 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| For direct access to every entity like questionnaires, review rubric etc..&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Screenshots =&lt;br /&gt;
&amp;lt;b&amp;gt;1) Better display for assignments:&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
A new icon for questionnaires added&amp;lt;br/&amp;gt;&lt;br /&gt;
[[File:new_icon_view.png|center|frame]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
On click of icon it will display questionnaires related to the selected course&amp;lt;br/&amp;gt;&lt;br /&gt;
[[File:questionnaires_view.png|center|frame]]&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;2) Dashboard for students:&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
It shows the different between previous implementation and new implementation views.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Before&lt;br /&gt;
! After&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:before_view.png|frame|left| ]]&lt;br /&gt;
| [[File:after_view.png|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
For the instructor, there needs to be a way to quickly find rubrics (and other questionnaires) that have been used in a single course. It should be possible to search or click somewhere to bring up a list of questionnaires used in the course, expanding only the applicable questionnaires in the list of questionnaires. A search functionality for questionnaire is expected. Currently, assignment and course searches is implemented, and there is a dropdown for questionnaire, but it's functionality is missing. &lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Instructot&lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition:''' There are few questionnaires in the system&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Instructor lands on &amp;quot;Manage content&amp;quot; page  &lt;br /&gt;
&lt;br /&gt;
3. Search for a questionnaire, by selecting questionnaire in the search dropdown and input some search string&lt;br /&gt;
&lt;br /&gt;
4. Search results displayed, expanding only the applicable questionnaires in the list of questionnaires&lt;br /&gt;
&lt;br /&gt;
[[File:Assignment_display_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following use case diagram shows the system of Assignment grades for a student on Expertiza as it is depicted right now. These include viewing their own project submission (with url and attachments), reviews and metareviews on their work, author feedbacks, teammate reviews and their final score on that assignment/project.&amp;lt;ref&amp;gt;Previous year's design document for ''E715: Dashboard for Students'' by Ambika Tripathi, Milan Tonse, Krutika Nagar, Shruti Buch&amp;lt;/ref&amp;gt; As part of this project we shall be adding more data on this page, so that student has better understanding of his/her marks. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing scores for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for average high and low scores. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class scores for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the average, high and low class score for that particular assignment&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing graphical output for scores for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for average high and low scores. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class scores for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the graphical output for average, high and low class score for that particular assignment&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing number of reviews done by him/her&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for number of reviews done by the student. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for my reviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the number of reviews the student has done for that particular assignment and also the &lt;br /&gt;
&lt;br /&gt;
number of reviews he still has to do to reach the threshold. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing number of metareviews done by him/her&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for number of metareviews done by the student. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for my metareviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the number of metareviews the student has done for that particular assignment and also &lt;br /&gt;
&lt;br /&gt;
the number of metareviews he still has to do to reach the threshold.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing average number of class reviews for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for class reviews for that assignment. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class reviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the average number of class reviews for that particular assignment&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Students viewing average number of class metareviews for the assignment&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Student &lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None &lt;br /&gt;
&lt;br /&gt;
'''Precondition''': Statistics have been recorded for class metareviews for that assignment. &lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:''' &lt;br /&gt;
&lt;br /&gt;
1. Log in to Expertiza&lt;br /&gt;
&lt;br /&gt;
2. Select an assignment &lt;br /&gt;
&lt;br /&gt;
3. Select Your Scores&lt;br /&gt;
&lt;br /&gt;
4. Click on the link for view class metareviews for this assignment.&lt;br /&gt;
&lt;br /&gt;
5. View the average number of class metareviews for that particular assignment&lt;br /&gt;
 &lt;br /&gt;
[[File:Dashboard_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_new.jpg]]&lt;br /&gt;
=UML diagram=&lt;br /&gt;
Following is class diagram for Assignment display module. &amp;lt;ref&amp;gt;Previous year's design document for ''E707: Better display for assignments'' by Bharath Sampath(bsampat2),Prakash Vasudevan(pvasude),Raghavendran Nedunchezhian(rnedunc), Yuchuan Liu(yliu63)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:UML.jpg]]&lt;br /&gt;
&lt;br /&gt;
Following is class diagram for Dashboard for students module.&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard.jpg]]&lt;br /&gt;
&lt;br /&gt;
=Steps to check the new implementations=&lt;br /&gt;
&lt;br /&gt;
='''References'''=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91970</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91970"/>
		<updated>2014-11-12T02:37:53Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Information Display and Student Interaction=&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Our contribution in this project would be to improve the display of questionnaires for all the instructors and also integrating a previous project which provides a new dashboard for students to view and compare their performance of each assignment. &lt;br /&gt;
&lt;br /&gt;
==Current State==&lt;br /&gt;
*In the current state instructor should go through all the questionnaires to find the one they are looking for. &lt;br /&gt;
*The keyword search functionality is not yet implemented for questionnaires.&lt;br /&gt;
*The current student dashboard provides the average score and range of the student’s assignment, review and final score. &lt;br /&gt;
*The system has a limitation where in a student/instructor cannot view and compare the student scores based on the class performance.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
*As a part of our project we will implement the search functionality and also make it possible to click and bring up a list of questionnaires used in the course, expanding only the applicable questionnaires in the list of questionnaires.&lt;br /&gt;
*A project from last year has the implementation for the new student dashboard. We would like to take that project, make the required changes to it and integrate it into expertiza.&lt;br /&gt;
*This new dashboard gives the students a comparative statistics for that particular assignment for the entire class. &lt;br /&gt;
*Giving the min, mean and max gives the student a range to judge where they stand with respect to the class. &lt;br /&gt;
*Other features were part of the project were to show the number of reviews and metareviews he/she has done for this assignment and also based on a threshold what are the number of reviews/metareviews the student still needs to do. &lt;br /&gt;
*A histogram distribution of the scores of the class (all teams) for that assignment would also shown as a part of the dashboard.&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed 2 years ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible and missing parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
We found that while the currently existing code covers most of the functionality, a major part of the functionality is missing. According to definition, the instructor should see the following on his home page:&lt;br /&gt;
*The instructor's courses&lt;br /&gt;
*Assignments for those courses&lt;br /&gt;
*Questionnaire by assignment name&lt;br /&gt;
&lt;br /&gt;
Each of these should be compressed to titles only, and it should be possible to expand them by single mouse click. Each course should have its own list of assignments which can, again, be expanded. Also, there is a search box on the page which allows to search assignments, courses and questionnaires.&lt;br /&gt;
&lt;br /&gt;
The search functionality for assignments and courses is working well, but the search for questionnaires is not implemented.&lt;br /&gt;
&lt;br /&gt;
So, for this specific project, we plan to focus on implementing the search for questionnaires first. Then, integrate it all and test each functionality: make sure that nothing is affected by the new functionality added. After all the tests are performed, we will merge the project with the main project, thus integrating it with the final build.&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
The features required for the dashboard for students project have already been implemented. So, the main task to be performed by us is to merge the project files with the main project and make sure that nothing else is affected by the process.&lt;br /&gt;
&lt;br /&gt;
The current code is able to display the maximum scores, average scores, number of reviews and distribution charts.&lt;br /&gt;
&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Files to be merged : Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  ScoreCache.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, review_mapping_controller.rb,response_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database tables&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 Assignments,Participants, score_caches, response_maps,responses&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Functionality of each file===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; ScoreCache.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; review_mapping_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Assignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| All information related to assignment&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Responses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review response information&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Score_caches &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review score information &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; response_maps &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files to be changed : Better display of assignment===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 course_node.rb,assignment_node.rb,questionnaire_node.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 tree_display\ _row_header.html.erb,tree_display\ _entry.html.erb,tree_display/actions/_courses_actions.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tree_display controller.rb,course_controller.rb,assignment_controller.rb,questionnaire_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  JavaScript&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tableactions.js&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Functionality of each file===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all course none in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all assignment node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all questionnaire node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| For direct access to every entity like questionnaires, review rubric etc..&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _row_header.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display of header in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _entry.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display entity in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/actions/_courses_actions.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display separate actions on each row &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various course related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 9 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various assignment related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 10 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various questionnaire related functions&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
[[File:Assignment_display_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_new.jpg]]&lt;br /&gt;
=UML diagram=&lt;br /&gt;
[[File:UML.jpg]]&lt;br /&gt;
&lt;br /&gt;
='''References'''=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91958</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91958"/>
		<updated>2014-11-12T02:28:38Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Information Display and Student Interaction=&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Our contribution in this project would be to improve the display of questionnaires for all the instructors and also integrating a previous project which provides a new dashboard for students to view and compare their performance of each assignment. &lt;br /&gt;
&lt;br /&gt;
==Current State==&lt;br /&gt;
In the current state instructor should go through all the questionnaires to find the one they are looking for. The keyword search functionality is not yet implemented for questionnaires.&lt;br /&gt;
&lt;br /&gt;
The current student dashboard provides the average score and range of the student’s assignment, review and final score. The system has a limitation where in a student/instructor cannot view and compare the student scores based on the class performance.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
As a part of our project we will implement the search functionality and also make it possible to click and bring up a list of questionnaires used in the course, expanding only the applicable questionnaires in the list of questionnaires.&lt;br /&gt;
&lt;br /&gt;
A project from last year has the implementation for the new student dashboard. We would like to take that project, make the required changes to it and integrate it into expertiza.&lt;br /&gt;
This new dashboard gives the students a comparative statistics for that particular assignment for the entire class. Giving the min, mean and max gives the student a range to judge where they stand with respect to the class. Other features were part of the project were to show the number of reviews and metareviews he/she has done for this assignment and also based on a threshold what are the number of reviews/metareviews the student still needs to do. A histogram distribution of the scores of the class (all teams) for that assignment would also shown as a part of the dashboard.&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed 2 years ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible and missing parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
We found that while the currently existing code covers most of the functionality, a major part of the functionality is missing. According to definition, the instructor should see the following on his home page:&lt;br /&gt;
*The instructor's courses&lt;br /&gt;
*Assignments for those courses&lt;br /&gt;
*Questionnaire by assignment name&lt;br /&gt;
&lt;br /&gt;
Each of these should be compressed to titles only, and it should be possible to expand them by single mouse click. Each course should have its own list of assignments which can, again, be expanded. Also, there is a search box on the page which allows to search assignments, courses and questionnaires.&lt;br /&gt;
&lt;br /&gt;
The search functionality for assignments and courses is working well, but the search for questionnaires is not implemented.&lt;br /&gt;
&lt;br /&gt;
So, for this specific project, we plan to focus on implementing the search for questionnaires first. Then, integrate it all and test each functionality: make sure that nothing is affected by the new functionality added. After all the tests are performed, we will merge the project with the main project, thus integrating it with the final build.&lt;br /&gt;
&lt;br /&gt;
[[File:Better_Display_Approach.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
The features required for the dashboard for students project have already been implemented. So, the main task to be performed by us is to merge the project files with the main project and make sure that nothing else is affected by the process.&lt;br /&gt;
&lt;br /&gt;
The current code is able to display the maximum scores, average scores, number of reviews and distribution charts.&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_Approach.jpg]]&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Files to be merged : Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  ScoreCache.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, review_mapping_controller.rb,response_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database tables&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 Assignments,Participants, score_caches, response_maps,responses&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Functionality of each file===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; ScoreCache.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; review_mapping_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Assignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| All information related to assignment&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Responses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review response information&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Score_caches &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review score information &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; response_maps &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files to be changed : Better display of assignment===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 course_node.rb,assignment_node.rb,questionnaire_node.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 tree_display\ _row_header.html.erb,tree_display\ _entry.html.erb,tree_display/actions/_courses_actions.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tree_display controller.rb,course_controller.rb,assignment_controller.rb,questionnaire_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  JavaScript&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tableactions.js&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Functionality of each file===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all course none in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all assignment node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all questionnaire node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| For direct access to every entity like questionnaires, review rubric etc..&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _row_header.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display of header in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _entry.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display entity in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/actions/_courses_actions.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display separate actions on each row &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various course related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 9 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various assignment related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 10 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various questionnaire related functions&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
[[File:Assignment_display_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_new.jpg]]&lt;br /&gt;
=UML diagram=&lt;br /&gt;
[[File:UML.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91945</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91945"/>
		<updated>2014-11-12T02:14:40Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Information Display and Student Interaction=&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Our contribution in this project would be to improve the display of questionnaires for all the instructors and also integrating a previous project which is a new dashboard for students to view and compare their performance of the assignments. &lt;br /&gt;
&lt;br /&gt;
==Current State==&lt;br /&gt;
In the current state instructor should go through all the questionnaires to find the one they are looking for. The keyword search functionality is not yet implemented for it.&lt;br /&gt;
&lt;br /&gt;
The current student dashboard provides the average score and range of the student’s assignment, review and final score. The system has a limitation where in a student/instructor cannot view and compare the student scores based on the class performance. The system also does not show the mean , min and max score for a particular assignment which provides students and instructors deep insight into the comparative performance of students.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
As a part of our project we will implement the search functionality and also make it possible to click somewhere to bring up a list of questionnaires used in the course, expanding only the applicable questionnaires in the list of questionnaires.&lt;br /&gt;
&lt;br /&gt;
A project from last year has the implementation for the new student dashboard. We would like to take that project, make the required changes to it and integrate it into expertiza.&lt;br /&gt;
So this new dashboard gives the students a comparative statistics for that particular assignment for the entire class. Giving the min, mean and max gives the student a range to judge where they stand with respect to the class. Other features were part of the project were to show the number of reviews and metareviews he/she has done for this assignment and also based on a threshold what are the number of reviews/metareviews the student still needs to do. A histogram distribution of the scores of the class (all teams) for that assignment would also shown as a part of the dashboard.&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed 2 years ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible and missing parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
We found that while the currently existing code covers most of the functionality, a major part of the functionality is missing. According to definition, the instructor should see the following on his home page:&lt;br /&gt;
*The instructor's courses&lt;br /&gt;
*Assignments for those courses&lt;br /&gt;
*Questionnaire by assignment name&lt;br /&gt;
&lt;br /&gt;
Each of these should be compressed to titles only, and it should be possible to expand them by single mouse click. Each course should have its own list of assignments which can, again, be expanded. Also, there is a search box on the page which allows to search assignments, courses and questionnaires.&lt;br /&gt;
&lt;br /&gt;
The search functionality for assignments and courses is working well, but the search for questionnaires is not implemented.&lt;br /&gt;
&lt;br /&gt;
So, for this specific project, we plan to focus on implementing the search for questionnaires first. Then, integrate it all and test each functionality: make sure that nothing is affected by the new functionality added. After all the tests are performed, we will merge the project with the main project, thus integrating it with the final build.&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
The features required for the dashboard for students project have already been implemented. So, the main task to be performed by us is to merge the project files with the main project and make sure that nothing else is affected by the process.&lt;br /&gt;
&lt;br /&gt;
The current code is able to display the maximum scores, average scores, number of reviews and distribution charts.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Files to be merged : Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  ScoreCache.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, review_mapping_controller.rb,response_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database tables&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 Assignments,Participants, score_caches, response_maps,responses&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Functionality of each file===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; ScoreCache.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; review_mapping_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Assignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| All information related to assignment&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Responses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review response information&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Score_caches &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review score information &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; response_maps &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files to be changed : Better display of assignment===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 course_node.rb,assignment_node.rb,questionnaire_node.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 tree_display\ _row_header.html.erb,tree_display\ _entry.html.erb,tree_display/actions/_courses_actions.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tree_display controller.rb,course_controller.rb,assignment_controller.rb,questionnaire_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  JavaScript&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tableactions.js&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Functionality of each file===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all course none in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all assignment node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all questionnaire node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| For direct access to every entity like questionnaires, review rubric etc..&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _row_header.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display of header in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _entry.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display entity in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/actions/_courses_actions.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display separate actions on each row &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various course related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 9 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various assignment related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 10 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various questionnaire related functions&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
[[File:Assignment_display_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_new.jpg]]&lt;br /&gt;
=UML diagram=&lt;br /&gt;
[[File:UML.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91931</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91931"/>
		<updated>2014-11-12T02:02:05Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Goals */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Information Display and Student Interaction=&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Our contribution in this project would be to improve the display of assignments for all the instructors and also to edit and merge a previous project which a new dashboard for students to view and compare their performance of the assignments.  &lt;br /&gt;
In the current state the professor needs to look at all the questionnaires together and the &lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
The instructors for each course would find expertiza more useful if features like search questionnaires and to be able to see the ones that are specific to their particular course.&lt;br /&gt;
&amp;lt;br&amp;gt;Dashboard for students module of the expertiza project aims at improving the visualization of the student’s dashboard so that the student/instructors can view and compare the assignments scores with clarity and ease.&lt;br /&gt;
&lt;br /&gt;
==Current State==&lt;br /&gt;
In the current state instructor cannot search for questionnaires or cannot see the questionnaires&lt;br /&gt;
that have been used in a specific course. &lt;br /&gt;
&lt;br /&gt;
The current student dashboard provides the average score and range of the student’s assignment,review and final score. The system has a limitation where in a student/instructor cannot view and compare the student scores based on the class performance. The system also does not show the mean , min and max score for a particular assignment which provides students and instructors deep insight into the comparative performance of students.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
As a part of our project we  will implement the search functionality and also make it possible to click somewhere to bring up a list of questionnaires used in the course, expanding only the applicable questionnaires in the list of questionnaires.&lt;br /&gt;
&lt;br /&gt;
A project from last year has the implementation for the new student dashboard. We would like to take that project, make the required changes to it and integrate it into expertiza.&lt;br /&gt;
So this new dashboard gives the students a comparative statistics for that particular assignment for the entire class. Giving the min, mean and max gives the student a range to judge where they stand with respect to the class. Other features were part of the project were to show the number of reviews and metareviews he/she has done for this assignment and also based on a threshold what are the number of reviews/metareviews the student still needs to do. A histogram distribution of the scores of the class (all teams) for that assignment would also shown as a part of the dashboard.&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed 2 years ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible and missing parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
We found that while the currently existing code covers most of the functionality, a major part of the functionality is missing. According to definition, the instructor should see the following on his home page:&lt;br /&gt;
*The instructor's courses&lt;br /&gt;
*Assignments for those courses&lt;br /&gt;
*Questionnaire by assignment name&lt;br /&gt;
&lt;br /&gt;
Each of these should be compressed to titles only, and it should be possible to expand them by single mouse click. Each course should have its own list of assignments which can, again, be expanded. Also, there is a search box on the page which allows to search assignments, courses and questionnaires.&lt;br /&gt;
&lt;br /&gt;
The search functionality for assignments and courses is working well, but the search for questionnaires is not implemented.&lt;br /&gt;
&lt;br /&gt;
So, for this specific project, we plan to focus on implementing the search for questionnaires first. Then, integrate it all and test each functionality: make sure that nothing is affected by the new functionality added. After all the tests are performed, we will merge the project with the main project, thus integrating it with the final build.&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
The features required for the dashboard for students project have already been implemented. So, the main task to be performed by us is to merge the project files with the main project and make sure that nothing else is affected by the process.&lt;br /&gt;
&lt;br /&gt;
The current code is able to display the maximum scores, average scores, number of reviews and distribution charts.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Files to be merged : Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  ScoreCache.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, review_mapping_controller.rb,response_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database tables&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 Assignments,Participants, score_caches, response_maps,responses&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Functionality of each file===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; ScoreCache.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; review_mapping_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Assignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| All information related to assignment&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Responses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review response information&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Score_caches &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review score information &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; response_maps &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files to be changed : Better display of assignment===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 course_node.rb,assignment_node.rb,questionnaire_node.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 tree_display\ _row_header.html.erb,tree_display\ _entry.html.erb,tree_display/actions/_courses_actions.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tree_display controller.rb,course_controller.rb,assignment_controller.rb,questionnaire_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  JavaScript&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tableactions.js&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Functionality of each file===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all course none in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all assignment node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all questionnaire node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| For direct access to every entity like questionnaires, review rubric etc..&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _row_header.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display of header in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _entry.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display entity in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/actions/_courses_actions.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display separate actions on each row &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various course related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 9 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various assignment related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 10 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various questionnaire related functions&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
[[File:Assignment_display_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_new.jpg]]&lt;br /&gt;
=UML diagram=&lt;br /&gt;
[[File:UML.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91930</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91930"/>
		<updated>2014-11-12T02:00:40Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Purpose */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Information Display and Student Interaction=&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Our contribution in this project would be to improve the display of assignments for all the instructors and also to edit and merge a previous project which a new dashboard for students to view and compare their performance of the assignments.  &lt;br /&gt;
In the current state the professor needs to look at all the questionnaires together and the &lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
The instructors for each course would find expertiza more useful if features like search questionnaires and to be able to see the ones that are specific to their particular course.&lt;br /&gt;
&amp;lt;br&amp;gt;Dashboard for students module of the expertiza project aims at improving the visualization of the student’s dashboard so that the student/instructors can view and compare the assignments scores with clarity and ease.&lt;br /&gt;
&lt;br /&gt;
==Current State==&lt;br /&gt;
In the current state instructor cannot search for questionnaires or cannot see the questionnaires&lt;br /&gt;
that have been used in a specific course. &lt;br /&gt;
&lt;br /&gt;
The current student dashboard provides the average score and range of the student’s assignment,review and final score. The system has a limitation where in a student/instructor cannot view and compare the student scores based on the class performance. The system also does not show the mean , min and max score for a particular assignment which provides students and instructors deep insight into the comparative performance of students.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
As a part of our project we  will implement the search functionality and also make it possible to click somewhere to bring up a list of questionnaires used in the course, expanding only the applicable questionnaires in the list of questionnaires.&lt;br /&gt;
&lt;br /&gt;
A project from last year has the implementation for the new student dashboard. We would like to take that project, make adequate changes to it and then integrate it into expertiza.&lt;br /&gt;
So this new dashboard gives the students a comparative statistics for that particular assignment for the entire class. Giving the min, mean and max gives the student a range to judge where they stand with respect to the class. Other features were part of the project were to show the number of reviews and metareviews he/she has done for this assignment and also based on a threshold &lt;br /&gt;
what are the number of reviews/metareviews the student still needs to do. A histogram distribution of the scores of the class (all teams) for that assignment would also shown as a part of the dashboard.&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed 2 years ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible and missing parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
We found that while the currently existing code covers most of the functionality, a major part of the functionality is missing. According to definition, the instructor should see the following on his home page:&lt;br /&gt;
*The instructor's courses&lt;br /&gt;
*Assignments for those courses&lt;br /&gt;
*Questionnaire by assignment name&lt;br /&gt;
&lt;br /&gt;
Each of these should be compressed to titles only, and it should be possible to expand them by single mouse click. Each course should have its own list of assignments which can, again, be expanded. Also, there is a search box on the page which allows to search assignments, courses and questionnaires.&lt;br /&gt;
&lt;br /&gt;
The search functionality for assignments and courses is working well, but the search for questionnaires is not implemented.&lt;br /&gt;
&lt;br /&gt;
So, for this specific project, we plan to focus on implementing the search for questionnaires first. Then, integrate it all and test each functionality: make sure that nothing is affected by the new functionality added. After all the tests are performed, we will merge the project with the main project, thus integrating it with the final build.&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
The features required for the dashboard for students project have already been implemented. So, the main task to be performed by us is to merge the project files with the main project and make sure that nothing else is affected by the process.&lt;br /&gt;
&lt;br /&gt;
The current code is able to display the maximum scores, average scores, number of reviews and distribution charts.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Files to be merged : Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  ScoreCache.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, review_mapping_controller.rb,response_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database tables&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 Assignments,Participants, score_caches, response_maps,responses&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Functionality of each file===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; ScoreCache.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; review_mapping_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Assignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| All information related to assignment&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Responses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review response information&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Score_caches &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review score information &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; response_maps &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files to be changed : Better display of assignment===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 course_node.rb,assignment_node.rb,questionnaire_node.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 tree_display\ _row_header.html.erb,tree_display\ _entry.html.erb,tree_display/actions/_courses_actions.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tree_display controller.rb,course_controller.rb,assignment_controller.rb,questionnaire_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  JavaScript&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tableactions.js&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Functionality of each file===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all course none in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all assignment node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all questionnaire node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| For direct access to every entity like questionnaires, review rubric etc..&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _row_header.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display of header in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _entry.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display entity in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/actions/_courses_actions.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display separate actions on each row &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various course related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 9 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various assignment related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 10 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various questionnaire related functions&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
[[File:Assignment_display_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_new.jpg]]&lt;br /&gt;
=UML diagram=&lt;br /&gt;
[[File:UML.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91929</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91929"/>
		<updated>2014-11-12T02:00:27Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Purpose */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Information Display and Student Interaction=&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Our contribution in this project would be to improve the display of assignments for all the instructors and also to edit and merge a previous project which a new dashboard for students to view and compare their performance of the assignments.  &lt;br /&gt;
In the current state the professor needs to look at all the questionnaires together and the &lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
The instructors for each course would find expertiza more useful if features like search questionnaires and to be able to see the ones that are specific to their particular course.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;Dashboard for students module of the expertiza project aims at improving the visualization of the student’s dashboard so that the student/instructors can view and compare the assignments scores with clarity and ease.&lt;br /&gt;
&lt;br /&gt;
==Current State==&lt;br /&gt;
In the current state instructor cannot search for questionnaires or cannot see the questionnaires&lt;br /&gt;
that have been used in a specific course. &lt;br /&gt;
&lt;br /&gt;
The current student dashboard provides the average score and range of the student’s assignment,review and final score. The system has a limitation where in a student/instructor cannot view and compare the student scores based on the class performance. The system also does not show the mean , min and max score for a particular assignment which provides students and instructors deep insight into the comparative performance of students.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
As a part of our project we  will implement the search functionality and also make it possible to click somewhere to bring up a list of questionnaires used in the course, expanding only the applicable questionnaires in the list of questionnaires.&lt;br /&gt;
&lt;br /&gt;
A project from last year has the implementation for the new student dashboard. We would like to take that project, make adequate changes to it and then integrate it into expertiza.&lt;br /&gt;
So this new dashboard gives the students a comparative statistics for that particular assignment for the entire class. Giving the min, mean and max gives the student a range to judge where they stand with respect to the class. Other features were part of the project were to show the number of reviews and metareviews he/she has done for this assignment and also based on a threshold &lt;br /&gt;
what are the number of reviews/metareviews the student still needs to do. A histogram distribution of the scores of the class (all teams) for that assignment would also shown as a part of the dashboard.&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed 2 years ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible and missing parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
We found that while the currently existing code covers most of the functionality, a major part of the functionality is missing. According to definition, the instructor should see the following on his home page:&lt;br /&gt;
*The instructor's courses&lt;br /&gt;
*Assignments for those courses&lt;br /&gt;
*Questionnaire by assignment name&lt;br /&gt;
&lt;br /&gt;
Each of these should be compressed to titles only, and it should be possible to expand them by single mouse click. Each course should have its own list of assignments which can, again, be expanded. Also, there is a search box on the page which allows to search assignments, courses and questionnaires.&lt;br /&gt;
&lt;br /&gt;
The search functionality for assignments and courses is working well, but the search for questionnaires is not implemented.&lt;br /&gt;
&lt;br /&gt;
So, for this specific project, we plan to focus on implementing the search for questionnaires first. Then, integrate it all and test each functionality: make sure that nothing is affected by the new functionality added. After all the tests are performed, we will merge the project with the main project, thus integrating it with the final build.&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
The features required for the dashboard for students project have already been implemented. So, the main task to be performed by us is to merge the project files with the main project and make sure that nothing else is affected by the process.&lt;br /&gt;
&lt;br /&gt;
The current code is able to display the maximum scores, average scores, number of reviews and distribution charts.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Files to be merged : Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  ScoreCache.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, review_mapping_controller.rb,response_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database tables&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 Assignments,Participants, score_caches, response_maps,responses&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Functionality of each file===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; ScoreCache.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; review_mapping_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Assignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| All information related to assignment&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Responses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review response information&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Score_caches &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review score information &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; response_maps &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files to be changed : Better display of assignment===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 course_node.rb,assignment_node.rb,questionnaire_node.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 tree_display\ _row_header.html.erb,tree_display\ _entry.html.erb,tree_display/actions/_courses_actions.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tree_display controller.rb,course_controller.rb,assignment_controller.rb,questionnaire_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  JavaScript&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tableactions.js&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Functionality of each file===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all course none in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all assignment node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all questionnaire node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| For direct access to every entity like questionnaires, review rubric etc..&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _row_header.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display of header in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _entry.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display entity in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/actions/_courses_actions.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display separate actions on each row &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various course related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 9 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various assignment related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 10 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various questionnaire related functions&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
[[File:Assignment_display_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_new.jpg]]&lt;br /&gt;
=UML diagram=&lt;br /&gt;
[[File:UML.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91925</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91925"/>
		<updated>2014-11-12T01:56:57Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Information Display and Student Interaction=&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Our contribution in this project would be to improve the display of assignments for all the instructors and also to edit and merge a previous project which a new dashboard for students to view and compare their performance of the assignments.  &lt;br /&gt;
In the current state the professor needs to look at all the questionnaires together and the &lt;br /&gt;
&lt;br /&gt;
==Purpose==&lt;br /&gt;
The instructors for each course would find expertiza more useful if features like search expertiza  &lt;br /&gt;
&lt;br /&gt;
“Dashboard for students” module of the expertiza project aims at improving the visualization of the &lt;br /&gt;
student’s dashboard so that the student/instructors can view and compare the assignments scores with &lt;br /&gt;
clarity and ease. The project shows the student grades for a particular assignment with the average &lt;br /&gt;
score and range of the submitted work, review, author feedback and final score along with the &lt;br /&gt;
maximum score, minimum score and mean functionality.&lt;br /&gt;
&lt;br /&gt;
==Current State==&lt;br /&gt;
In the current state instructor cannot search for questionnaires or cannot see the questionnaires&lt;br /&gt;
that have been used in a specific course. &lt;br /&gt;
&lt;br /&gt;
The current student dashboard provides the average score and range of the student’s assignment,review and final score. The system has a limitation where in a student/instructor cannot view and compare the student scores based on the class performance. The system also does not show the mean , min and max score for a particular assignment which provides students and instructors deep insight into the comparative performance of students.&lt;br /&gt;
&lt;br /&gt;
==Goals==&lt;br /&gt;
As a part of our project we  will implement the search functionality and also make it possible to click somewhere to bring up a list of questionnaires used in the course, expanding only the applicable questionnaires in the list of questionnaires.&lt;br /&gt;
&lt;br /&gt;
A project from last year has the implementation for the new student dashboard. We would like to take that project, make adequate changes to it and then integrate it into expertiza.&lt;br /&gt;
So this new dashboard gives the students a comparative statistics for that particular assignment for the entire class. Giving the min, mean and max gives the student a range to judge where they stand with respect to the class. Other features were part of the project were to show the number of reviews and metareviews he/she has done for this assignment and also based on a threshold &lt;br /&gt;
what are the number of reviews/metareviews the student still needs to do. A histogram distribution of the scores of the class (all teams) for that assignment would also shown as a part of the dashboard.&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed 2 years ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible and missing parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
We found that while the currently existing code covers most of the functionality, a major part of the functionality is missing. According to definition, the instructor should see the following on his home page:&lt;br /&gt;
*The instructor's courses&lt;br /&gt;
*Assignments for those courses&lt;br /&gt;
*Questionnaire by assignment name&lt;br /&gt;
&lt;br /&gt;
Each of these should be compressed to titles only, and it should be possible to expand them by single mouse click. Each course should have its own list of assignments which can, again, be expanded. Also, there is a search box on the page which allows to search assignments, courses and questionnaires.&lt;br /&gt;
&lt;br /&gt;
The search functionality for assignments and courses is working well, but the search for questionnaires is not implemented.&lt;br /&gt;
&lt;br /&gt;
So, for this specific project, we plan to focus on implementing the search for questionnaires first. Then, integrate it all and test each functionality: make sure that nothing is affected by the new functionality added. After all the tests are performed, we will merge the project with the main project, thus integrating it with the final build.&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
The features required for the dashboard for students project have already been implemented. So, the main task to be performed by us is to merge the project files with the main project and make sure that nothing else is affected by the process.&lt;br /&gt;
&lt;br /&gt;
The current code is able to display the maximum scores, average scores, number of reviews and distribution charts.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Files to be merged : Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  ScoreCache.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, review_mapping_controller.rb,response_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database tables&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 Assignments,Participants, score_caches, response_maps,responses&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Functionality of each file===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; ScoreCache.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; review_mapping_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Assignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| All information related to assignment&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Responses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review response information&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Score_caches &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review score information &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; response_maps &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files to be changed : Better display of assignment===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 course_node.rb,assignment_node.rb,questionnaire_node.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 tree_display\ _row_header.html.erb,tree_display\ _entry.html.erb,tree_display/actions/_courses_actions.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tree_display controller.rb,course_controller.rb,assignment_controller.rb,questionnaire_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  JavaScript&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  tableactions.js&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Functionality of each file===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all course none in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all assignment node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_node.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| To fetch information about all questionnaire node in the system&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| For direct access to every entity like questionnaires, review rubric etc..&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _row_header.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display of header in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display\ _entry.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display entity in a row&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; tree_display/actions/_courses_actions.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Display separate actions on each row &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; course_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various course related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 9 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; assignment_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various assignment related functions&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 10 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; questionnaire_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| Provides various questionnaire related functions&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
[[File:Assignment_display_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_existing.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:Dashboard_new.jpg]]&lt;br /&gt;
=UML diagram=&lt;br /&gt;
[[File:UML.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91732</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91732"/>
		<updated>2014-11-11T21:20:06Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Information Display and Student Interaction=&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Our contribution in this project is by improving the display of assignments for all the instructors and also to merge a previous project which made a improve the dashboard for student to view and compare their performance of the assignments.  &lt;br /&gt;
==Background==&lt;br /&gt;
==Scope==&lt;br /&gt;
==Purpose==&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed 2 years ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible and missing parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
We found that while the currently existing code covers most of the functionality, a major part of the functionality is missing. According to definition, the instructor should see the following on his home page:&lt;br /&gt;
*His courses&lt;br /&gt;
*Assignments for his courses&lt;br /&gt;
*Questionnaires&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  ScoreCache.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, review_mapping_controller.rb,response_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database tables&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 Assignments,Participants, score_caches, response_maps,responses&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Functionality of each file==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; ScoreCache.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; review_mapping_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Assignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| All information related to assignment&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Responses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review response information&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Score_caches &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review score information &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; response_maps &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
=UML diagram=&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91727</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91727"/>
		<updated>2014-11-11T21:12:01Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Expertiza - Information Display and Student Interaction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Information Display and Student Interaction=&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
==Background==&lt;br /&gt;
==Scope==&lt;br /&gt;
==Purpose==&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed 2 years ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible and missing parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  ScoreCache.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, review_mapping_controller.rb,response_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database tables&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 Assignments,Participants, score_caches, response_maps,responses&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Functionality of each file==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; ScoreCache.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; review_mapping_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Assignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| All information related to assignment&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Responses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review response information&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Score_caches &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review score information &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; response_maps &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
=UML diagram=&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91700</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91700"/>
		<updated>2014-11-11T17:22:24Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Information Display and Student Interaction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Information Display and Student Interaction=&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. Our contribution in this project is by improving the display of assignments for all the instructors and also to improve the dashboard for student to view and compare their performance of the assignments.  &lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
==Background==&lt;br /&gt;
==Scope==&lt;br /&gt;
==Purpose==&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed 2 years ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  ScoreCache.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, review_mapping_controller.rb,response_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database tables&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 Assignments,Participants, score_caches, response_maps,responses&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Functionality of each file==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; ScoreCache.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; review_mapping_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Assignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| All information related to assignment&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Responses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review response information&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Score_caches &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review score information &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; response_maps &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
=UML diagram=&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91699</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91699"/>
		<updated>2014-11-11T17:14:17Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Information Display and Student Interaction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Information Display and Student Interaction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the &amp;lt;b&amp;gt;StudentQuiz controller&amp;lt;/b&amp;gt;. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
==Background==&lt;br /&gt;
==Scope==&lt;br /&gt;
==Purpose==&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed 2 years ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  ScoreCache.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, review_mapping_controller.rb,response_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database tables&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 Assignments,Participants, score_caches, response_maps,responses&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Functionality of each file==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; ScoreCache.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; review_mapping_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Assignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| All information related to assignment&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Responses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review response information&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Score_caches &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review score information &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; response_maps &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
=UML diagram=&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91698</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91698"/>
		<updated>2014-11-11T17:14:03Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Information Display and Student Interaction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Information Display and Student Interaction==&lt;br /&gt;
---&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the &amp;lt;b&amp;gt;StudentQuiz controller&amp;lt;/b&amp;gt;. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
==Background==&lt;br /&gt;
==Scope==&lt;br /&gt;
==Purpose==&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed 2 years ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  ScoreCache.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, review_mapping_controller.rb,response_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database tables&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 Assignments,Participants, score_caches, response_maps,responses&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Functionality of each file==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; ScoreCache.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; review_mapping_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Assignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| All information related to assignment&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Responses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review response information&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Score_caches &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review score information &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; response_maps &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
=UML diagram=&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91697</id>
		<title>CSC/ECE 517 Fall 2014/final E1471 asuv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1471_asuv&amp;diff=91697"/>
		<updated>2014-11-11T17:13:41Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Information Display and Student Interaction==&lt;br /&gt;
---&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the &amp;lt;b&amp;gt;StudentQuiz controller&amp;lt;/b&amp;gt;. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
=Introduction=&lt;br /&gt;
==Background==&lt;br /&gt;
==Scope==&lt;br /&gt;
==Purpose==&lt;br /&gt;
&lt;br /&gt;
=Approach=&lt;br /&gt;
&lt;br /&gt;
As the project was originally assigned to students two years ago, the functionality is mostly complete. The main concern is that, as the project was completed 2 years ago (in December 2012), it was made for an older version of rails.&lt;br /&gt;
&lt;br /&gt;
==General Approach==&lt;br /&gt;
Our general approach to the project would be as follows:&lt;br /&gt;
*Run the current project with rails 4&lt;br /&gt;
*Check the functionality to find out the incompatible parts&lt;br /&gt;
*Refactor the parts of code that do not function as expected and port them to rails 4 specification&lt;br /&gt;
*After making sure everything runs, refactor the entire code to make sure it follows the global code rules.&lt;br /&gt;
&lt;br /&gt;
==Specific Approach==&lt;br /&gt;
The specific approach to each of the two functionality is as  follows:&lt;br /&gt;
===Better display for assignments===&lt;br /&gt;
&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
=Files involved=&lt;br /&gt;
===Dashboard for students===&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Model&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  ScoreCache.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  View&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
  grades\view_my_scored.html.erb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Controller&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 grades_controller.rb, review_mapping_controller.rb,response_controller.rb&lt;br /&gt;
 &amp;lt;li&amp;gt;&lt;br /&gt;
  Database tables&lt;br /&gt;
 &amp;lt;/li&amp;gt;&lt;br /&gt;
 Assignments,Participants, score_caches, response_maps,responses&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Functionality of each file==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:8%;&amp;quot;|File Name&lt;br /&gt;
!style=&amp;quot;width:13%;&amp;quot;| Type&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Functionality for this project&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; ScoreCache.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Model&lt;br /&gt;
| Makes an entry into score_cache table whenever a response is given/edited&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades\view_my_scores.html.erb &amp;lt;/code&amp;gt;&lt;br /&gt;
| View&lt;br /&gt;
| Modified in order to display all new features&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; grades_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get information all information about an assignment and its score which is average score of all reviews and plotting the graph for grade distinction&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; review_mapping_controller.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
| Controller&lt;br /&gt;
| To get additional information about assignment like total reviews submitted&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Assignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| All information related to assignment&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Responses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review response information&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 7 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; Score_caches &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Stores individual assignment review score information &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 8 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; response_maps &amp;lt;/code&amp;gt;&lt;br /&gt;
| Table&lt;br /&gt;
| Mapping between response, reviewer and reviewee&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Use case=&lt;br /&gt;
=UML diagram=&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=91459</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=91459"/>
		<updated>2014-11-06T00:25:19Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Code Cleanup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the &amp;lt;b&amp;gt;StudentQuiz controller&amp;lt;/b&amp;gt;. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The &amp;lt;b&amp;gt;StudentQuiz controller&amp;lt;/b&amp;gt; consists of methods involved in creating, scoring &amp;amp; recording responses of the quizzes taken by reviewers or students of the other teams with the same topic. &lt;br /&gt;
&amp;lt;br&amp;gt;The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;[https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit# GoogleDoc for our project requirements]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class. (StudentQuizzesController)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style. (e.g. :- Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method &amp;lt;b&amp;gt;graded?&amp;lt;/b&amp;gt; for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Perform Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Split a method performing multiple tasks, into seperate methods.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fix logical errors in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
----&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;[http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails Using the Singular or Plural controller and helper names in Rails]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the &amp;lt;b&amp;gt;StudentQuiz&amp;lt;/b&amp;gt; controller class to &amp;lt;b&amp;gt;StudentQuizzes&amp;lt;/b&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
----&lt;br /&gt;
The purpose of the &amp;lt;b&amp;gt;list&amp;lt;/b&amp;gt; method in the &amp;lt;b&amp;gt;StudentQuizzes controller&amp;lt;/b&amp;gt; is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as &amp;lt;b&amp;gt;index&amp;lt;/b&amp;gt;. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : index&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them &amp;lt;ref&amp;gt;[http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability Decreasing Controller-View Coupling in Rails]&amp;lt;/ref&amp;gt;. Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages Disadvantages of Tight Coupling - Wikipedia]&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;b&amp;gt;take_quiz method&amp;lt;/b&amp;gt;, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Follow principle of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;[https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf About Boolean Zen]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Method : graded?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : graded?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view. This is illustrated well in the example mentioned above for the restful implementation style.&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
----&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition. Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
----&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code. Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Replace controller method with a model method ===&lt;br /&gt;
----&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the &amp;lt;b&amp;gt;quiz_response_map&amp;lt;/b&amp;gt; model, since it queries that particular table in the database.&lt;br /&gt;
The code was extracted into the &amp;lt;b&amp;gt;get_mappings_for_reviewer&amp;lt;/b&amp;gt; method and placed in the file &amp;lt;b&amp;gt;quiz_response_map.rb&amp;lt;/b&amp;gt;. This method was then called from the &amp;lt;b&amp;gt;StudentQuizzes&amp;lt;/b&amp;gt; controller.&lt;br /&gt;
&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models Fat Models and Skinny Controllers.]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : index&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : index&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; quiz_response_map.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.get_mappings_for_reviewer(participant_id)&lt;br /&gt;
  return QuizResponseMap.where(reviewer_id: participant_id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
----&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;b&amp;gt;score&amp;lt;/b&amp;gt; variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The &amp;lt;b&amp;gt;new_scores&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;scores&amp;lt;/b&amp;gt; array stored almost the similar values. The &amp;lt;b&amp;gt;scores&amp;lt;/b&amp;gt; array contained a copy of the value that the &amp;lt;b&amp;gt;new_scores&amp;lt;/b&amp;gt; array contained. Therefore we eliminated the &amp;lt;b&amp;gt;new_scores&amp;lt;/b&amp;gt; array and are performing all the operations only on the &amp;lt;b&amp;gt;scores&amp;lt;/b&amp;gt; array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The &amp;lt;b&amp;gt;record_response&amp;lt;/b&amp;gt; function was performing two distinct operations : One operation was saving the response to the database and the other was to calculate the score for the questions. We created a new function &amp;lt;b&amp;gt;calculate_score&amp;lt;/b&amp;gt; that would calculate the score for the questions and &amp;lt;b&amp;gt;record_response&amp;lt;/b&amp;gt; now only performs the task of saving responses to the database. By doing this, we followed the &amp;lt;b&amp;gt;Single Responsibility O-O Design Principle for methods&amp;lt;/b&amp;gt; mentioned by &amp;lt;b&amp;gt; Mr. Robert C. Martin &amp;lt;/b&amp;gt; which states that &amp;quot;Every software module should have only one reason to change&amp;quot;&amp;lt;ref&amp;gt;[http://www.codeproject.com/Articles/567768/Object-Oriented-Design-Principles O-O Design Principles]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    scores = Array.new&lt;br /&gt;
    valid = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
      if ques_type.eql? 'MCC'&lt;br /&gt;
        if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
          valid = false&lt;br /&gt;
        else&lt;br /&gt;
          params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
            correct_answers.each do |correct|&lt;br /&gt;
              if choice.eql? correct.txt&lt;br /&gt;
                score += 1&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            end&lt;br /&gt;
            new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
            unless new_score.valid?&lt;br /&gt;
              valid = false&lt;br /&gt;
            end&lt;br /&gt;
            scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
            score = 1&lt;br /&gt;
          else&lt;br /&gt;
            score = 0&lt;br /&gt;
          end&lt;br /&gt;
          scores.each do |score_update|&lt;br /&gt;
            score_update.score = score&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = correct_answers.first&lt;br /&gt;
        if ques_type.eql? 'Essay'&lt;br /&gt;
          score = -1&lt;br /&gt;
        elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; response.id, :score =&amp;gt; score&lt;br /&gt;
        if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
          valid = false&lt;br /&gt;
        end&lt;br /&gt;
        scores.push(new_score)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if valid&lt;br /&gt;
      scores.each do |score|&lt;br /&gt;
        score.save&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; map.id&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
      redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=91458</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=91458"/>
		<updated>2014-11-06T00:24:22Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Code Cleanup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the &amp;lt;b&amp;gt;StudentQuiz controller&amp;lt;/b&amp;gt;. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The &amp;lt;b&amp;gt;StudentQuiz controller&amp;lt;/b&amp;gt; consists of methods involved in creating, scoring &amp;amp; recording responses of the quizzes taken by reviewers or students of the other teams with the same topic. &lt;br /&gt;
&amp;lt;br&amp;gt;The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;[https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit# GoogleDoc for our project requirements]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class. (StudentQuizzesController)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style. (e.g. :- Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method &amp;lt;b&amp;gt;graded?&amp;lt;/b&amp;gt; for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Perform Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Split a method performing multiple tasks, into seperate methods.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fix logical errors in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
----&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;[http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails Using the Singular or Plural controller and helper names in Rails]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the &amp;lt;b&amp;gt;StudentQuiz&amp;lt;/b&amp;gt; controller class to &amp;lt;b&amp;gt;StudentQuizzes&amp;lt;/b&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
----&lt;br /&gt;
The purpose of the &amp;lt;b&amp;gt;list&amp;lt;/b&amp;gt; method in the &amp;lt;b&amp;gt;StudentQuizzes controller&amp;lt;/b&amp;gt; is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as &amp;lt;b&amp;gt;index&amp;lt;/b&amp;gt;. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : index&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them &amp;lt;ref&amp;gt;[http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability Decreasing Controller-View Coupling in Rails]&amp;lt;/ref&amp;gt;. Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages Disadvantages of Tight Coupling - Wikipedia]&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;b&amp;gt;take_quiz method&amp;lt;/b&amp;gt;, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Follow principle of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;[https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf About Boolean Zen]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Method : graded?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : graded?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view. While we were refactoring the name list to index we were able to remove a great amount of code that was not needed. This is illustrated well in the example mentioned above for the restful implementation style.&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
----&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition. Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
----&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code. Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Replace controller method with a model method ===&lt;br /&gt;
----&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the &amp;lt;b&amp;gt;quiz_response_map&amp;lt;/b&amp;gt; model, since it queries that particular table in the database.&lt;br /&gt;
The code was extracted into the &amp;lt;b&amp;gt;get_mappings_for_reviewer&amp;lt;/b&amp;gt; method and placed in the file &amp;lt;b&amp;gt;quiz_response_map.rb&amp;lt;/b&amp;gt;. This method was then called from the &amp;lt;b&amp;gt;StudentQuizzes&amp;lt;/b&amp;gt; controller.&lt;br /&gt;
&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models Fat Models and Skinny Controllers.]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : index&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : index&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; quiz_response_map.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.get_mappings_for_reviewer(participant_id)&lt;br /&gt;
  return QuizResponseMap.where(reviewer_id: participant_id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
----&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;b&amp;gt;score&amp;lt;/b&amp;gt; variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The &amp;lt;b&amp;gt;new_scores&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;scores&amp;lt;/b&amp;gt; array stored almost the similar values. The &amp;lt;b&amp;gt;scores&amp;lt;/b&amp;gt; array contained a copy of the value that the &amp;lt;b&amp;gt;new_scores&amp;lt;/b&amp;gt; array contained. Therefore we eliminated the &amp;lt;b&amp;gt;new_scores&amp;lt;/b&amp;gt; array and are performing all the operations only on the &amp;lt;b&amp;gt;scores&amp;lt;/b&amp;gt; array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The &amp;lt;b&amp;gt;record_response&amp;lt;/b&amp;gt; function was performing two distinct operations : One operation was saving the response to the database and the other was to calculate the score for the questions. We created a new function &amp;lt;b&amp;gt;calculate_score&amp;lt;/b&amp;gt; that would calculate the score for the questions and &amp;lt;b&amp;gt;record_response&amp;lt;/b&amp;gt; now only performs the task of saving responses to the database. By doing this, we followed the &amp;lt;b&amp;gt;Single Responsibility O-O Design Principle for methods&amp;lt;/b&amp;gt; mentioned by &amp;lt;b&amp;gt; Mr. Robert C. Martin &amp;lt;/b&amp;gt; which states that &amp;quot;Every software module should have only one reason to change&amp;quot;&amp;lt;ref&amp;gt;[http://www.codeproject.com/Articles/567768/Object-Oriented-Design-Principles O-O Design Principles]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    scores = Array.new&lt;br /&gt;
    valid = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
      if ques_type.eql? 'MCC'&lt;br /&gt;
        if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
          valid = false&lt;br /&gt;
        else&lt;br /&gt;
          params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
            correct_answers.each do |correct|&lt;br /&gt;
              if choice.eql? correct.txt&lt;br /&gt;
                score += 1&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            end&lt;br /&gt;
            new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
            unless new_score.valid?&lt;br /&gt;
              valid = false&lt;br /&gt;
            end&lt;br /&gt;
            scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
            score = 1&lt;br /&gt;
          else&lt;br /&gt;
            score = 0&lt;br /&gt;
          end&lt;br /&gt;
          scores.each do |score_update|&lt;br /&gt;
            score_update.score = score&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = correct_answers.first&lt;br /&gt;
        if ques_type.eql? 'Essay'&lt;br /&gt;
          score = -1&lt;br /&gt;
        elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; response.id, :score =&amp;gt; score&lt;br /&gt;
        if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
          valid = false&lt;br /&gt;
        end&lt;br /&gt;
        scores.push(new_score)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if valid&lt;br /&gt;
      scores.each do |score|&lt;br /&gt;
        score.save&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; map.id&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
      redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=91457</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=91457"/>
		<updated>2014-11-06T00:23:59Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Code Cleanup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the &amp;lt;b&amp;gt;StudentQuiz controller&amp;lt;/b&amp;gt;. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The &amp;lt;b&amp;gt;StudentQuiz controller&amp;lt;/b&amp;gt; consists of methods involved in creating, scoring &amp;amp; recording responses of the quizzes taken by reviewers or students of the other teams with the same topic. &lt;br /&gt;
&amp;lt;br&amp;gt;The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;[https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit# GoogleDoc for our project requirements]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class. (StudentQuizzesController)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style. (e.g. :- Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method &amp;lt;b&amp;gt;graded?&amp;lt;/b&amp;gt; for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Perform Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Split a method performing multiple tasks, into seperate methods.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fix logical errors in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
----&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;[http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails Using the Singular or Plural controller and helper names in Rails]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the &amp;lt;b&amp;gt;StudentQuiz&amp;lt;/b&amp;gt; controller class to &amp;lt;b&amp;gt;StudentQuizzes&amp;lt;/b&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
----&lt;br /&gt;
The purpose of the &amp;lt;b&amp;gt;list&amp;lt;/b&amp;gt; method in the &amp;lt;b&amp;gt;StudentQuizzes controller&amp;lt;/b&amp;gt; is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as &amp;lt;b&amp;gt;index&amp;lt;/b&amp;gt;. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : index&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them &amp;lt;ref&amp;gt;[http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability Decreasing Controller-View Coupling in Rails]&amp;lt;/ref&amp;gt;. Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages Disadvantages of Tight Coupling - Wikipedia]&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;b&amp;gt;take_quiz method&amp;lt;/b&amp;gt;, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Follow principle of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;[https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf About Boolean Zen]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Method : graded?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : graded?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
While we were refactoring the name list to index we were able to remove a great amount of code that was not needed. This is illustrated well in the example mentioned above for the restful implementation style.&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
----&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition. Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
----&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code. Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Replace controller method with a model method ===&lt;br /&gt;
----&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the &amp;lt;b&amp;gt;quiz_response_map&amp;lt;/b&amp;gt; model, since it queries that particular table in the database.&lt;br /&gt;
The code was extracted into the &amp;lt;b&amp;gt;get_mappings_for_reviewer&amp;lt;/b&amp;gt; method and placed in the file &amp;lt;b&amp;gt;quiz_response_map.rb&amp;lt;/b&amp;gt;. This method was then called from the &amp;lt;b&amp;gt;StudentQuizzes&amp;lt;/b&amp;gt; controller.&lt;br /&gt;
&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models Fat Models and Skinny Controllers.]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : index&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : index&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; quiz_response_map.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.get_mappings_for_reviewer(participant_id)&lt;br /&gt;
  return QuizResponseMap.where(reviewer_id: participant_id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
----&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;b&amp;gt;score&amp;lt;/b&amp;gt; variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The &amp;lt;b&amp;gt;new_scores&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;scores&amp;lt;/b&amp;gt; array stored almost the similar values. The &amp;lt;b&amp;gt;scores&amp;lt;/b&amp;gt; array contained a copy of the value that the &amp;lt;b&amp;gt;new_scores&amp;lt;/b&amp;gt; array contained. Therefore we eliminated the &amp;lt;b&amp;gt;new_scores&amp;lt;/b&amp;gt; array and are performing all the operations only on the &amp;lt;b&amp;gt;scores&amp;lt;/b&amp;gt; array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The &amp;lt;b&amp;gt;record_response&amp;lt;/b&amp;gt; function was performing two distinct operations : One operation was saving the response to the database and the other was to calculate the score for the questions. We created a new function &amp;lt;b&amp;gt;calculate_score&amp;lt;/b&amp;gt; that would calculate the score for the questions and &amp;lt;b&amp;gt;record_response&amp;lt;/b&amp;gt; now only performs the task of saving responses to the database. By doing this, we followed the &amp;lt;b&amp;gt;Single Responsibility O-O Design Principle for methods&amp;lt;/b&amp;gt; mentioned by &amp;lt;b&amp;gt; Mr. Robert C. Martin &amp;lt;/b&amp;gt; which states that &amp;quot;Every software module should have only one reason to change&amp;quot;&amp;lt;ref&amp;gt;[http://www.codeproject.com/Articles/567768/Object-Oriented-Design-Principles O-O Design Principles]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    scores = Array.new&lt;br /&gt;
    valid = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
      if ques_type.eql? 'MCC'&lt;br /&gt;
        if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
          valid = false&lt;br /&gt;
        else&lt;br /&gt;
          params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
            correct_answers.each do |correct|&lt;br /&gt;
              if choice.eql? correct.txt&lt;br /&gt;
                score += 1&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            end&lt;br /&gt;
            new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
            unless new_score.valid?&lt;br /&gt;
              valid = false&lt;br /&gt;
            end&lt;br /&gt;
            scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
            score = 1&lt;br /&gt;
          else&lt;br /&gt;
            score = 0&lt;br /&gt;
          end&lt;br /&gt;
          scores.each do |score_update|&lt;br /&gt;
            score_update.score = score&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = correct_answers.first&lt;br /&gt;
        if ques_type.eql? 'Essay'&lt;br /&gt;
          score = -1&lt;br /&gt;
        elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; response.id, :score =&amp;gt; score&lt;br /&gt;
        if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
          valid = false&lt;br /&gt;
        end&lt;br /&gt;
        scores.push(new_score)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if valid&lt;br /&gt;
      scores.each do |score|&lt;br /&gt;
        score.save&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; map.id&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
      redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=91456</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=91456"/>
		<updated>2014-11-06T00:23:45Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Code Cleanup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the &amp;lt;b&amp;gt;StudentQuiz controller&amp;lt;/b&amp;gt;. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The &amp;lt;b&amp;gt;StudentQuiz controller&amp;lt;/b&amp;gt; consists of methods involved in creating, scoring &amp;amp; recording responses of the quizzes taken by reviewers or students of the other teams with the same topic. &lt;br /&gt;
&amp;lt;br&amp;gt;The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;[https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit# GoogleDoc for our project requirements]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class. (StudentQuizzesController)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style. (e.g. :- Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method &amp;lt;b&amp;gt;graded?&amp;lt;/b&amp;gt; for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Perform Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Split a method performing multiple tasks, into seperate methods.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fix logical errors in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
----&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;[http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails Using the Singular or Plural controller and helper names in Rails]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the &amp;lt;b&amp;gt;StudentQuiz&amp;lt;/b&amp;gt; controller class to &amp;lt;b&amp;gt;StudentQuizzes&amp;lt;/b&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
----&lt;br /&gt;
The purpose of the &amp;lt;b&amp;gt;list&amp;lt;/b&amp;gt; method in the &amp;lt;b&amp;gt;StudentQuizzes controller&amp;lt;/b&amp;gt; is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as &amp;lt;b&amp;gt;index&amp;lt;/b&amp;gt;. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : index&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them &amp;lt;ref&amp;gt;[http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability Decreasing Controller-View Coupling in Rails]&amp;lt;/ref&amp;gt;. Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages Disadvantages of Tight Coupling - Wikipedia]&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;b&amp;gt;take_quiz method&amp;lt;/b&amp;gt;, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Follow principle of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;[https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf About Boolean Zen]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Method : graded?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : graded?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
While we were refactoring the name list to index we were able to remove a great amount of code that was not needed. This is illustrated well in the example mentioned above for the restful implementation style.&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
----&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition. Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
----&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code. Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Replace controller method with a model method ===&lt;br /&gt;
----&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the &amp;lt;b&amp;gt;quiz_response_map&amp;lt;/b&amp;gt; model, since it queries that particular table in the database.&lt;br /&gt;
The code was extracted into the &amp;lt;b&amp;gt;get_mappings_for_reviewer&amp;lt;/b&amp;gt; method and placed in the file &amp;lt;b&amp;gt;quiz_response_map.rb&amp;lt;/b&amp;gt;. This method was then called from the &amp;lt;b&amp;gt;StudentQuizzes&amp;lt;/b&amp;gt; controller.&lt;br /&gt;
&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models Fat Models and Skinny Controllers.]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : index&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : index&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; quiz_response_map.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.get_mappings_for_reviewer(participant_id)&lt;br /&gt;
  return QuizResponseMap.where(reviewer_id: participant_id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
----&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;b&amp;gt;score&amp;lt;/b&amp;gt; variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The &amp;lt;b&amp;gt;new_scores&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;scores&amp;lt;/b&amp;gt; array stored almost the similar values. The &amp;lt;b&amp;gt;scores&amp;lt;/b&amp;gt; array contained a copy of the value that the &amp;lt;b&amp;gt;new_scores&amp;lt;/b&amp;gt; array contained. Therefore we eliminated the &amp;lt;b&amp;gt;new_scores&amp;lt;/b&amp;gt; array and are performing all the operations only on the &amp;lt;b&amp;gt;scores&amp;lt;/b&amp;gt; array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The &amp;lt;b&amp;gt;record_response&amp;lt;/b&amp;gt; function was performing two distinct operations : One operation was saving the response to the database and the other was to calculate the score for the questions. We created a new function &amp;lt;b&amp;gt;calculate_score&amp;lt;/b&amp;gt; that would calculate the score for the questions and &amp;lt;b&amp;gt;record_response&amp;lt;/b&amp;gt; now only performs the task of saving responses to the database. By doing this, we followed the &amp;lt;b&amp;gt;Single Responsibility O-O Design Principle for methods&amp;lt;/b&amp;gt; mentioned by &amp;lt;b&amp;gt; Mr. Robert C. Martin &amp;lt;/b&amp;gt; which states that &amp;quot;Every software module should have only one reason to change&amp;quot;&amp;lt;ref&amp;gt;[http://www.codeproject.com/Articles/567768/Object-Oriented-Design-Principles O-O Design Principles]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    scores = Array.new&lt;br /&gt;
    valid = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
      if ques_type.eql? 'MCC'&lt;br /&gt;
        if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
          valid = false&lt;br /&gt;
        else&lt;br /&gt;
          params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
            correct_answers.each do |correct|&lt;br /&gt;
              if choice.eql? correct.txt&lt;br /&gt;
                score += 1&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            end&lt;br /&gt;
            new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
            unless new_score.valid?&lt;br /&gt;
              valid = false&lt;br /&gt;
            end&lt;br /&gt;
            scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
            score = 1&lt;br /&gt;
          else&lt;br /&gt;
            score = 0&lt;br /&gt;
          end&lt;br /&gt;
          scores.each do |score_update|&lt;br /&gt;
            score_update.score = score&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = correct_answers.first&lt;br /&gt;
        if ques_type.eql? 'Essay'&lt;br /&gt;
          score = -1&lt;br /&gt;
        elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; response.id, :score =&amp;gt; score&lt;br /&gt;
        if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
          valid = false&lt;br /&gt;
        end&lt;br /&gt;
        scores.push(new_score)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if valid&lt;br /&gt;
      scores.each do |score|&lt;br /&gt;
        score.save&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; map.id&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
      redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90505</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90505"/>
		<updated>2014-10-29T14:49:15Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the &amp;lt;b&amp;gt;StudentQuiz controller&amp;lt;/b&amp;gt;. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The &amp;lt;b&amp;gt;StudentQuiz controller&amp;lt;/b&amp;gt; consists of methods involved in creating, scoring &amp;amp; recording responses of the quizzes taken by reviewers or students of the other teams with the same topic. &lt;br /&gt;
&amp;lt;br&amp;gt;The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;[https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit# GoogleDoc for our project requirements]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class. (StudentQuizzesController)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style. (e.g. :- Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method &amp;lt;b&amp;gt;graded?&amp;lt;/b&amp;gt; for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Perform Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Split a method performing multiple tasks, into seperate methods.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fix logical errors in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
----&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;[http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails Using the Singular or Plural controller and helper names in Rails]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the &amp;lt;b&amp;gt;StudentQuiz&amp;lt;/b&amp;gt; controller class to &amp;lt;b&amp;gt;StudentQuizzes&amp;lt;/b&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
----&lt;br /&gt;
The purpose of the &amp;lt;b&amp;gt;list&amp;lt;/b&amp;gt; method in the &amp;lt;b&amp;gt;StudentQuizzes controller&amp;lt;/b&amp;gt; is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as &amp;lt;b&amp;gt;index&amp;lt;/b&amp;gt;. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : list&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : index&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them &amp;lt;ref&amp;gt;[http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability Decreasing Controller-View Coupling in Rails]&amp;lt;/ref&amp;gt;. Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages Disadvantages of Tight Coupling - Wikipedia]&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;b&amp;gt;take_quiz method&amp;lt;/b&amp;gt;, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;[https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf About Boolean Zen]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Method : graded?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : graded?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Method : list&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : index&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
----&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition. Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
----&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code. Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Replace controller method with a model method ===&lt;br /&gt;
----&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the &amp;lt;b&amp;gt;quiz_response_map&amp;lt;/b&amp;gt; model, since it queries that particular table in the database.&lt;br /&gt;
The code was extracted into the &amp;lt;b&amp;gt;get_mappings_for_reviewer&amp;lt;/b&amp;gt; method and placed in the file &amp;lt;b&amp;gt;quiz_response_map.rb&amp;lt;/b&amp;gt;. This method was then called from the &amp;lt;b&amp;gt;StudentQuizzes&amp;lt;/b&amp;gt; controller.&lt;br /&gt;
&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models Fat Models and Skinny Controllers.]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : index&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : index&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; quiz_response_map.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.get_mappings_for_reviewer(participant_id)&lt;br /&gt;
  return QuizResponseMap.where(reviewer_id: participant_id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
----&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;b&amp;gt;score&amp;lt;/b&amp;gt; variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The &amp;lt;b&amp;gt;new_scores&amp;lt;/b&amp;gt; and &amp;lt;b&amp;gt;scores&amp;lt;/b&amp;gt; array stored almost the similar values. The &amp;lt;b&amp;gt;scores&amp;lt;/b&amp;gt; array contained a copy of the value that the &amp;lt;b&amp;gt;new_scores&amp;lt;/b&amp;gt; array contained. Therefore we eliminated the &amp;lt;b&amp;gt;new_scores&amp;lt;/b&amp;gt; array and are performing all the operations only on the &amp;lt;b&amp;gt;scores&amp;lt;/b&amp;gt; array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The &amp;lt;b&amp;gt;record_response&amp;lt;/b&amp;gt; function was performing two distinct operations : One operation was saving the response to the database and the other was to calculate the score for the questions. We created a new function &amp;lt;b&amp;gt;calculate_score&amp;lt;/b&amp;gt; that would calculate the score for the questions and &amp;lt;b&amp;gt;record_response&amp;lt;/b&amp;gt; now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    scores = Array.new&lt;br /&gt;
    valid = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
      if ques_type.eql? 'MCC'&lt;br /&gt;
        if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
          valid = false&lt;br /&gt;
        else&lt;br /&gt;
          params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
            correct_answers.each do |correct|&lt;br /&gt;
              if choice.eql? correct.txt&lt;br /&gt;
                score += 1&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
            end&lt;br /&gt;
            new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
            unless new_score.valid?&lt;br /&gt;
              valid = false&lt;br /&gt;
            end&lt;br /&gt;
            scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
            score = 1&lt;br /&gt;
          else&lt;br /&gt;
            score = 0&lt;br /&gt;
          end&lt;br /&gt;
          scores.each do |score_update|&lt;br /&gt;
            score_update.score = score&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = correct_answers.first&lt;br /&gt;
        if ques_type.eql? 'Essay'&lt;br /&gt;
          score = -1&lt;br /&gt;
        elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; response.id, :score =&amp;gt; score&lt;br /&gt;
        if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
          valid = false&lt;br /&gt;
        end&lt;br /&gt;
        scores.push(new_score)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if valid&lt;br /&gt;
      scores.each do |score|&lt;br /&gt;
        score.save&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; map.id&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
      redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90139</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90139"/>
		<updated>2014-10-28T21:04:40Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Changes made in method logic */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;[https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit# GoogleDoc for our project requirements]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;[http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails Using the Singular or Plural controller and helper names in Rails]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them &amp;lt;ref&amp;gt;[http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability Decreasing Controller-View Coupling in Rails]&amp;lt;/ref&amp;gt;. Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
----&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
----&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
----&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
----&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
----&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
----&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90137</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90137"/>
		<updated>2014-10-28T21:03:10Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Changes made in method logic */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;[https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit# GoogleDoc for our project requirements]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;[http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails Using the Singular or Plural controller and helper names in Rails]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
----&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
----&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
----&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
----&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
----&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
----&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90136</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90136"/>
		<updated>2014-10-28T21:02:57Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Replace controller method with a model method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;[https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit# GoogleDoc for our project requirements]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;[http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails Using the Singular or Plural controller and helper names in Rails]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
----&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
----&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
----&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
----&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
----&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90134</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90134"/>
		<updated>2014-10-28T21:02:45Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Use of Routing Helpers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;[https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit# GoogleDoc for our project requirements]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
----&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
----&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
----&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
----&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90133</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90133"/>
		<updated>2014-10-28T21:02:28Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Use good conditional statements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;[https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit# GoogleDoc for our project requirements]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
----&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
----&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
----&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90132</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90132"/>
		<updated>2014-10-28T21:02:11Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Used a Boolean variable when that is sufficient */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;[https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit# GoogleDoc for our project requirements]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
----&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
----&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90131</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90131"/>
		<updated>2014-10-28T21:01:59Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Used .nil? instead of &amp;quot;== nil&amp;quot; */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;[https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit# GoogleDoc for our project requirements]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
----&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90130</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90130"/>
		<updated>2014-10-28T21:01:41Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Replace find_by_...  with a where command */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;[https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit# GoogleDoc for our project requirements]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
----&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90128</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90128"/>
		<updated>2014-10-28T21:01:18Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Replace find_by_...  with a where command */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;[https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit# GoogleDoc for our assignment requirements]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
---&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90126</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90126"/>
		<updated>2014-10-28T21:01:01Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Replace find_by_...  with a where command */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
----&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90125</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90125"/>
		<updated>2014-10-28T21:00:43Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Use key: ‘value’, not :key =&amp;gt; ‘value’ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90124</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90124"/>
		<updated>2014-10-28T21:00:27Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90123</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90123"/>
		<updated>2014-10-28T21:00:14Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Eliminated the &amp;quot;== true/false&amp;quot; check */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90122</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90122"/>
		<updated>2014-10-28T20:59:31Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Used .eql? instead of &amp;quot;==&amp;quot; */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza Wiki Page]&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90120</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90120"/>
		<updated>2014-10-28T20:59:03Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Following Ruby Style Guidelines (Global Rules) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
----&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90118</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90118"/>
		<updated>2014-10-28T20:58:46Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Following Ruby Style Guidelines (Global Rules) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;ref&amp;gt;http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
--&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90117</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90117"/>
		<updated>2014-10-28T20:58:09Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Code Cleanup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;ref&amp;gt;http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
----&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90116</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90116"/>
		<updated>2014-10-28T20:57:52Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Elimination of Boolean Zen */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;ref&amp;gt;http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
----&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90115</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90115"/>
		<updated>2014-10-28T20:57:28Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Instance Variable Reductions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)[https://github.com/expertiza/expertiza Expertiza on GitHub]&amp;lt;ref&amp;gt;http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
----&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90113</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90113"/>
		<updated>2014-10-28T20:52:50Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Instance Variable Reductions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Splitting a method performing multiple tasks, into seperate methods&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Fixing logical errors in the code&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems intuitive.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quizzes_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling as much as possible and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unnecessary instance variables and to convert all the instance variables to local variables that are not used in the views.&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
  @quizzes = Array.new&lt;br /&gt;
  reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
  @assignment = Assignment.find(assignment_id)&lt;br /&gt;
  teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
  Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
    unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
      Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
        if !@assignment.team_assignment?&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            @quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
               @quizzes.push(questionnaire)&lt;br /&gt;
             end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return @quizzes&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
    quizzes = Array.new&lt;br /&gt;
    reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
    Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
      unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
        Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
            quizzes.push(questionnaire)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return quizzes&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90097</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90097"/>
		<updated>2014-10-28T20:13:13Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems more natural and helps in understanding&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quiz_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling to the maximum possible extent and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unused and unnecessary instance variables.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
-    @quizzes = Array.new&lt;br /&gt;
+    quizzes = Array.new&lt;br /&gt;
     reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
-    @assignment = Assignment.find(assignment_id)&lt;br /&gt;
-    teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
     Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
       unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
         Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
-          if !@assignment.team_assignment?&lt;br /&gt;
-            unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
-              @quizzes.push(questionnaire)&lt;br /&gt;
-            end&lt;br /&gt;
-          else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
-            @quizzes.push(questionnaire)&lt;br /&gt;
+          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
+            quizzes.push(questionnaire)&lt;br /&gt;
           end&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
+    return quizzes&lt;br /&gt;
   end&lt;br /&gt;
-  return @quizzes&lt;br /&gt;
-end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Removed unused methods like self.participants_in and commented out code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Method names should use underscores, not camelcase. ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good array checking====&lt;br /&gt;
&lt;br /&gt;
[].empty? # not [].length == 0 or [].length.zero?&lt;br /&gt;
[:foo].any? # not [:foo].length &amp;gt; 0&lt;br /&gt;
[:foo].one? # not [:foo].length == 1&lt;br /&gt;
[:foo].first # not [:foo][0]&lt;br /&gt;
[:foo].last # not [:foo][-1]&lt;br /&gt;
&lt;br /&gt;
====Use find_each for efficient loops over models====&lt;br /&gt;
&lt;br /&gt;
SignedUpUser.all.each do |user| # BAD&lt;br /&gt;
SignedUpUser.find_each do |user| # GOOD&lt;br /&gt;
	&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quiz_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90096</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90096"/>
		<updated>2014-10-28T20:12:52Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems more natural and helps in understanding&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quiz_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling to the maximum possible extent and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unused and unnecessary instance variables.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
-    @quizzes = Array.new&lt;br /&gt;
+    quizzes = Array.new&lt;br /&gt;
     reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
-    @assignment = Assignment.find(assignment_id)&lt;br /&gt;
-    teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
     Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
       unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
         Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
-          if !@assignment.team_assignment?&lt;br /&gt;
-            unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
-              @quizzes.push(questionnaire)&lt;br /&gt;
-            end&lt;br /&gt;
-          else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
-            @quizzes.push(questionnaire)&lt;br /&gt;
+          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
+            quizzes.push(questionnaire)&lt;br /&gt;
           end&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
+    return quizzes&lt;br /&gt;
   end&lt;br /&gt;
-  return @quizzes&lt;br /&gt;
-end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Removed unused methods like self.participants_in and commented out code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Method names should use underscores, not camelcase. ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good array checking====&lt;br /&gt;
&lt;br /&gt;
[].empty? # not [].length == 0 or [].length.zero?&lt;br /&gt;
[:foo].any? # not [:foo].length &amp;gt; 0&lt;br /&gt;
[:foo].one? # not [:foo].length == 1&lt;br /&gt;
[:foo].first # not [:foo][0]&lt;br /&gt;
[:foo].last # not [:foo][-1]&lt;br /&gt;
&lt;br /&gt;
====Use find_each for efficient loops over models====&lt;br /&gt;
&lt;br /&gt;
SignedUpUser.all.each do |user| # BAD&lt;br /&gt;
SignedUpUser.find_each do |user| # GOOD&lt;br /&gt;
	&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quiz_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90093</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90093"/>
		<updated>2014-10-28T20:07:55Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Expertiza - Refactoring StudentQuizController */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;Expertiza - Refactoring StudentQuizController&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems more natural and helps in understanding&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quiz_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling to the maximum possible extent and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unused and unnecessary instance variables.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
-    @quizzes = Array.new&lt;br /&gt;
+    quizzes = Array.new&lt;br /&gt;
     reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
-    @assignment = Assignment.find(assignment_id)&lt;br /&gt;
-    teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
     Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
       unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
         Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
-          if !@assignment.team_assignment?&lt;br /&gt;
-            unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
-              @quizzes.push(questionnaire)&lt;br /&gt;
-            end&lt;br /&gt;
-          else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
-            @quizzes.push(questionnaire)&lt;br /&gt;
+          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
+            quizzes.push(questionnaire)&lt;br /&gt;
           end&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
+    return quizzes&lt;br /&gt;
   end&lt;br /&gt;
-  return @quizzes&lt;br /&gt;
-end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Removed unused methods like self.participants_in and commented out code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Method names should use underscores, not camelcase. ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good array checking====&lt;br /&gt;
&lt;br /&gt;
[].empty? # not [].length == 0 or [].length.zero?&lt;br /&gt;
[:foo].any? # not [:foo].length &amp;gt; 0&lt;br /&gt;
[:foo].one? # not [:foo].length == 1&lt;br /&gt;
[:foo].first # not [:foo][0]&lt;br /&gt;
[:foo].last # not [:foo][-1]&lt;br /&gt;
&lt;br /&gt;
====Use find_each for efficient loops over models====&lt;br /&gt;
&lt;br /&gt;
SignedUpUser.all.each do |user| # BAD&lt;br /&gt;
SignedUpUser.find_each do |user| # GOOD&lt;br /&gt;
	&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quiz_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90092</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=90092"/>
		<updated>2014-10-28T20:05:50Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Expertiza - Refactoring StudentQuizController */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza - Refactoring StudentQuizController==&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application developed using Ruby on Rails that serves as a peer-review system. The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. It is an open source project and it's codebase is maintained in GitHub. We are contributing to Expertiza as a part of our Object-Oriented Design and Development's Open-Source Software (OSS) Project. Our goal in this project is to refactor the Student Quiz Controller. In this Wiki Page, we would be explaining the changes that we have made for the same.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
Our Goal in this project is to refactor the StudentQuiz controller. This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student. The changes that are needed to be done are described as follows:&amp;lt;ref&amp;gt;https://docs.google.com/a/ncsu.edu/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Pluralize the class (StudentQuizzesController).&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename methods to conform to RESTful style (Rename the list method to index.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Reduce the number of instance variables per controller action.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Review Method graded? for boolean zen.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Performing Code cleanup by removing unused code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Using good Ruby style guidelines in the code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per the Rails convention the controller class names are suggested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems more natural and helps in understanding&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMine to rename the StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed change-set for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here].&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
The purpose of the list method in the StudentQuizzes controller is to list all the quizzes that are available to a particular user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quiz_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring :&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
In Rails, the data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling to the maximum possible extent and in this case it can be achieved by reducing as many instance variables as possible in the controller. Therefore, we have refactored our code in order to eliminate unused and unnecessary instance variables.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed: &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Changed the &amp;lt;b&amp;gt;quizzes&amp;lt;/b&amp;gt; instance variable to a local variable.&lt;br /&gt;
* Eliminated the instance variable &amp;lt;b&amp;gt;assignment&amp;lt;/b&amp;gt; which was not being used anywhere.&lt;br /&gt;
* Eliminated the local variable &amp;lt;b&amp;gt;teams&amp;lt;/b&amp;gt; which was not being used any where&lt;br /&gt;
The unified diff of the changes made is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
-    @quizzes = Array.new&lt;br /&gt;
+    quizzes = Array.new&lt;br /&gt;
     reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
-    @assignment = Assignment.find(assignment_id)&lt;br /&gt;
-    teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
     Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
       unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
         Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
-          if !@assignment.team_assignment?&lt;br /&gt;
-            unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
-              @quizzes.push(questionnaire)&lt;br /&gt;
-            end&lt;br /&gt;
-          else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
-            @quizzes.push(questionnaire)&lt;br /&gt;
+          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
+            quizzes.push(questionnaire)&lt;br /&gt;
           end&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
+    return quizzes&lt;br /&gt;
   end&lt;br /&gt;
-  return @quizzes&lt;br /&gt;
-end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Removed unused methods like self.participants_in and commented out code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method : finished_quiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Method names should use underscores, not camelcase. ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good array checking====&lt;br /&gt;
&lt;br /&gt;
[].empty? # not [].length == 0 or [].length.zero?&lt;br /&gt;
[:foo].any? # not [:foo].length &amp;gt; 0&lt;br /&gt;
[:foo].one? # not [:foo].length == 1&lt;br /&gt;
[:foo].first # not [:foo][0]&lt;br /&gt;
[:foo].last # not [:foo][-1]&lt;br /&gt;
&lt;br /&gt;
====Use find_each for efficient loops over models====&lt;br /&gt;
&lt;br /&gt;
SignedUpUser.all.each do |user| # BAD&lt;br /&gt;
SignedUpUser.find_each do |user| # GOOD&lt;br /&gt;
	&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: record_response&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quizzes_controller.rb&lt;br /&gt;
&amp;lt;br&amp;gt; Method: calculate_score&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
   valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use of Routing Helpers====&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;:&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb does not contain a student_quizzes resource&lt;br /&gt;
&amp;lt;br&amp;gt; review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'index', :id =&amp;gt; params[:participant_id]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; config.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
resources :student_quizzes, :only =&amp;gt; [:index]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
review_mapping_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
redirect_to student_quizzes_path(:id =&amp;gt; params[:participant_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Replace controller method with a model method ====&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models StackOverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; student_quiz_controller.rb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Changes made in method logic===&lt;br /&gt;
We have made certain changes in the logic of the methods calculate_score and record_response (previously the code of both these methods was only in record_response) primarily to improve the existing logic and eliminate redundant code. These changes are described as follows:&lt;br /&gt;
&lt;br /&gt;
* The score variable was already being set to 0 on the loop entry, therefore it was redundant to reset score to zero again. Thus, we eliminated this line of code inside the if statement.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|		&lt;br /&gt;
  score = 0		&lt;br /&gt;
  if (QuestionType.find_by_question_id question.id).q_type == 'MCC'		&lt;br /&gt;
    score = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if ques_type.eql? 'MCC'&lt;br /&gt;
    # Eliminated score = 0 over here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The variable &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; stored multiple values as the where condition to which it was assigned was returning multiple values. Therefore it seemed more intuitive to rename &amp;lt;b&amp;gt;correct_answer&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;correct_answers&amp;lt;/b&amp;gt; so that it is apparent that it contains multiple values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The below piece of code found out the question type twice in the same loop. Therefore we extracted it and assigned it to a local variable so that the query is executed only once.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First Query&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
# Repetition of the query in the same loop&lt;br /&gt;
if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Querying only once and assigning it to a local variable ques_type&lt;br /&gt;
ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
# Usage 1 of ques_type&lt;br /&gt;
if ques_type.eql? 'MCC'&lt;br /&gt;
# Usage 2 of ques_type&lt;br /&gt;
if ques_type.eql? 'Essay'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The new_scores and scores array stored almost the similar values. The scores contained a copy of the value that the new_scores array contained. Therefore we eliminated the new_scores array and are performing all the operations only on the scores array.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
 valid = 1&lt;br /&gt;
end&lt;br /&gt;
new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
# Part 2		  &lt;br /&gt;
new_scores.each do |score_update|&lt;br /&gt;
 score_update.score = score&lt;br /&gt;
 scores.push(score_update)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1&lt;br /&gt;
new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&lt;br /&gt;
&lt;br /&gt;
unless new_score.valid?&lt;br /&gt;
  valid = false&lt;br /&gt;
end&lt;br /&gt;
scores.push(new_score)&lt;br /&gt;
	&lt;br /&gt;
# Part 2		&lt;br /&gt;
scores.each do |score_update|&lt;br /&gt;
  score_update.score = score&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The logic to compute the final score for a multiple-choice, multiple-correct type of question seemed to be incorrect and therefore we fixed it.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
  score = 0&lt;br /&gt;
  if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
   valid = 1&lt;br /&gt;
  else&lt;br /&gt;
    correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
    params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
    correct_answer.each do |correct|&lt;br /&gt;
    if choice == correct.txt&lt;br /&gt;
      score += 1&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic which seems to award full points even if you marked some extra options apart from marking all correct answers&lt;br /&gt;
  unless score == correct_answer.count&lt;br /&gt;
   score = 0&lt;br /&gt;
  else&lt;br /&gt;
   score = 1&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Part 1 of the Scoring Logic&lt;br /&gt;
questions.each do |question|&lt;br /&gt;
 score = 0&lt;br /&gt;
 correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
 ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
  if ques_type.eql? 'MCC'&lt;br /&gt;
     if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
       valid = false&lt;br /&gt;
     else&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
          if choice.eql? correct.txt&lt;br /&gt;
             score += 1&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
# Part 2 of the scoring logic - We have also compared the number of options the user selected to the total number of correct answers&lt;br /&gt;
if score.eql? correct_answers.count &amp;amp;&amp;amp; score == params[&amp;quot;#{question.id}&amp;quot;].count&lt;br /&gt;
  score = 1&lt;br /&gt;
else&lt;br /&gt;
  score = 0&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The record_response function was performing two distinct operations : One operation was saving the response to the Database and the other was to calculate the score for the questions. We created a new function calculate_score that would calculate the score for the questions and record_response now only performs the task of saving responses to the database.&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def record_response&lt;br /&gt;
  @map = ResponseMap.find(params[:map_id])&lt;br /&gt;
  @response = Response.new()&lt;br /&gt;
  @response.map_id = params[:map_id]&lt;br /&gt;
  @response.created_at = DateTime.current&lt;br /&gt;
  @response.updated_at = DateTime.current&lt;br /&gt;
  @response.save&lt;br /&gt;
&lt;br /&gt;
  @questionnaire = Questionnaire.find(@map.reviewed_object_id)&lt;br /&gt;
  scores = Array.new&lt;br /&gt;
  new_scores = Array.new&lt;br /&gt;
  valid = 0&lt;br /&gt;
  questions = Question.where(questionnaire_id: @questionnaire.id)&lt;br /&gt;
  questions.each do |question|&lt;br /&gt;
    score = 0&lt;br /&gt;
    if (QuestionType.find_by_question_id question.id).q_type == 'MCC'&lt;br /&gt;
      score = 0&lt;br /&gt;
      if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
        valid = 1&lt;br /&gt;
      else&lt;br /&gt;
        correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect: 1)&lt;br /&gt;
        params[&amp;quot;#{question.id}&amp;quot;].each do |choice|&lt;br /&gt;
&lt;br /&gt;
          correct_answer.each do |correct|&lt;br /&gt;
            if choice == correct.txt&lt;br /&gt;
              score += 1&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
          end&lt;br /&gt;
          new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&lt;br /&gt;
&lt;br /&gt;
          unless new_score.valid?&lt;br /&gt;
            valid = 1&lt;br /&gt;
          end&lt;br /&gt;
          new_scores.push(new_score)&lt;br /&gt;
&lt;br /&gt;
        end&lt;br /&gt;
        unless score == correct_answer.count&lt;br /&gt;
          score = 0&lt;br /&gt;
        else&lt;br /&gt;
          score = 1&lt;br /&gt;
        end&lt;br /&gt;
        new_scores.each do |score_update|&lt;br /&gt;
          score_update.score = score&lt;br /&gt;
          scores.push(score_update)&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      score = 0&lt;br /&gt;
      correct_answer = QuizQuestionChoice.where(question_id: question.id, iscorrect:  1).first&lt;br /&gt;
      if (QuestionType.find_by_question_id question.id).q_type == 'Essay'&lt;br /&gt;
        score = -1&lt;br /&gt;
      elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt&lt;br /&gt;
        score = 1&lt;br /&gt;
      end&lt;br /&gt;
      new_score = Score.new :comments =&amp;gt; params[&amp;quot;#{question.id}&amp;quot;], :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id, :score =&amp;gt; score&lt;br /&gt;
      unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
        valid = 1&lt;br /&gt;
      end&lt;br /&gt;
      scores.push(new_score)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  if valid == 0&lt;br /&gt;
    scores.each do |score|&lt;br /&gt;
      score.save&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'student_quizzes', :action =&amp;gt; 'finished_quiz', :map_id =&amp;gt; @map.id&lt;br /&gt;
  else&lt;br /&gt;
    flash[:error] = &amp;quot;Please answer every question.&amp;quot;&lt;br /&gt;
    redirect_to :action =&amp;gt; :take_quiz, :assignment_id =&amp;gt; params[:assignment_id], :questionnaire_id =&amp;gt; @questionnaire.id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# New record_response method&lt;br /&gt;
  def record_response&lt;br /&gt;
    map = ResponseMap.find(params[:map_id])&lt;br /&gt;
    response = Response.new&lt;br /&gt;
    response.map_id = params[:map_id]&lt;br /&gt;
    response.created_at = DateTime.current&lt;br /&gt;
    response.updated_at = DateTime.current&lt;br /&gt;
    response.save&lt;br /&gt;
&lt;br /&gt;
    calculate_score map,response&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
# New calculate_score&lt;br /&gt;
def calculate_score map, response&lt;br /&gt;
    # The entire logic below the response.save line from the earlier record_response method goes here.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=89944</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=89944"/>
		<updated>2014-10-27T18:11:29Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Use good conditional statements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring StudentQuizController=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is a web application available to both students and professors. The Expertiza project is a system to create reusable learning objects through peer review. Expertiza supports team projects, and the submission of almost any document type, including URLs and wiki pages. Students can keep a track of their assignments, teammates and can conduct peer reviews on diverse topics and projects. It is an open source project developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code can be forked and cloned for making modifications. &lt;br /&gt;
ertiza with main focus of Refactoring the Users Controller. &lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; student_quiz_controller.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
*change list to index (and others in the RESTful style)&lt;br /&gt;
* Pluralize the class (StudentQuizzesController)&lt;br /&gt;
* graded? - review boolean zen&lt;br /&gt;
* Reduce the number of instance variables per controller action.&lt;br /&gt;
* Change the instance variables to local variables if they are not being used in the view. &lt;br /&gt;
* Modify methods to conform to RESTful style &lt;br /&gt;
* Code cleanup by using string interpolation instead of concatenation, replacing '==' with eql? and :key =&amp;gt;'value' with key: 'value', modifying declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Replace find_by with where to follow Rails 4.0 conventions&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per Rails convention the controller class names are sugested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems more natural and helps in understanding&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMineto rename StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed changeset for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here]. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
* Modifications to student_quiz_controller.rb :&lt;br /&gt;
The purpose of the list method in the Student Quizzes controller is to list all the quizzes that are available to this user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quiz_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
After Refactoring :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
In Rails, data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling to the maximum possible extent and in this case it can be achieved by reducing as many instance variables as possible. Therefore, we have refactored our code in order to eliminate unused and unneccessary instance variables.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed&lt;br /&gt;
Changed the quizzes instance variable to a local variable.&lt;br /&gt;
Eliminated instance variable assignment which was not used anywhere.&lt;br /&gt;
Eliminated local variable teams which was not used any where&lt;br /&gt;
The unified diff of the changes made is shown below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
-    @quizzes = Array.new&lt;br /&gt;
+    quizzes = Array.new&lt;br /&gt;
     reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
-    @assignment = Assignment.find(assignment_id)&lt;br /&gt;
-    teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
     Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
       unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
         Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
-          if !@assignment.team_assignment?&lt;br /&gt;
-            unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
-              @quizzes.push(questionnaire)&lt;br /&gt;
-            end&lt;br /&gt;
-          else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
-            @quizzes.push(questionnaire)&lt;br /&gt;
+          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
+            quizzes.push(questionnaire)&lt;br /&gt;
           end&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
+    return quizzes&lt;br /&gt;
   end&lt;br /&gt;
-  return @quizzes&lt;br /&gt;
-end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Replaced :key =&amp;gt;'value' with key: 'value'&lt;br /&gt;
&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Removed unused methods like self.participants_in and commented out code.&lt;br /&gt;
&lt;br /&gt;
===Use of Routing Helpers===&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
After Refactoring&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Replace find_by_.. with where in querying===&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
Before Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Method names should use underscores, not camelcase. ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good array checking====&lt;br /&gt;
&lt;br /&gt;
[].empty? # not [].length == 0 or [].length.zero?&lt;br /&gt;
[:foo].any? # not [:foo].length &amp;gt; 0&lt;br /&gt;
[:foo].one? # not [:foo].length == 1&lt;br /&gt;
[:foo].first # not [:foo][0]&lt;br /&gt;
[:foo].last # not [:foo][-1]&lt;br /&gt;
&lt;br /&gt;
====Use find_each for efficient loops over models====&lt;br /&gt;
&lt;br /&gt;
SignedUpUser.all.each do |user| # BAD&lt;br /&gt;
SignedUpUser.find_each do |user| # GOOD&lt;br /&gt;
	&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
Using unless is a good practice. But it is not a good practice to use unless and ! within the condition.&lt;br /&gt;
&amp;lt;br&amp;gt; Instead we could use an if condition itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
      valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
          valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Replace controller method with a model method ===&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models stackoverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=89942</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=89942"/>
		<updated>2014-10-27T18:03:52Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Used .nil? instead of &amp;quot;== nil&amp;quot; */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring StudentQuizController=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is a web application available to both students and professors. The Expertiza project is a system to create reusable learning objects through peer review. Expertiza supports team projects, and the submission of almost any document type, including URLs and wiki pages. Students can keep a track of their assignments, teammates and can conduct peer reviews on diverse topics and projects. It is an open source project developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code can be forked and cloned for making modifications. &lt;br /&gt;
ertiza with main focus of Refactoring the Users Controller. &lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; student_quiz_controller.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
*change list to index (and others in the RESTful style)&lt;br /&gt;
* Pluralize the class (StudentQuizzesController)&lt;br /&gt;
* graded? - review boolean zen&lt;br /&gt;
* Reduce the number of instance variables per controller action.&lt;br /&gt;
* Change the instance variables to local variables if they are not being used in the view. &lt;br /&gt;
* Modify methods to conform to RESTful style &lt;br /&gt;
* Code cleanup by using string interpolation instead of concatenation, replacing '==' with eql? and :key =&amp;gt;'value' with key: 'value', modifying declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Replace find_by with where to follow Rails 4.0 conventions&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per Rails convention the controller class names are sugested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems more natural and helps in understanding&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMineto rename StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed changeset for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here]. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
* Modifications to student_quiz_controller.rb :&lt;br /&gt;
The purpose of the list method in the Student Quizzes controller is to list all the quizzes that are available to this user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quiz_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
After Refactoring :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
In Rails, data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling to the maximum possible extent and in this case it can be achieved by reducing as many instance variables as possible. Therefore, we have refactored our code in order to eliminate unused and unneccessary instance variables.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed&lt;br /&gt;
Changed the quizzes instance variable to a local variable.&lt;br /&gt;
Eliminated instance variable assignment which was not used anywhere.&lt;br /&gt;
Eliminated local variable teams which was not used any where&lt;br /&gt;
The unified diff of the changes made is shown below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
-    @quizzes = Array.new&lt;br /&gt;
+    quizzes = Array.new&lt;br /&gt;
     reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
-    @assignment = Assignment.find(assignment_id)&lt;br /&gt;
-    teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
     Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
       unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
         Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
-          if !@assignment.team_assignment?&lt;br /&gt;
-            unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
-              @quizzes.push(questionnaire)&lt;br /&gt;
-            end&lt;br /&gt;
-          else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
-            @quizzes.push(questionnaire)&lt;br /&gt;
+          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
+            quizzes.push(questionnaire)&lt;br /&gt;
           end&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
+    return quizzes&lt;br /&gt;
   end&lt;br /&gt;
-  return @quizzes&lt;br /&gt;
-end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Replaced :key =&amp;gt;'value' with key: 'value'&lt;br /&gt;
&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Removed unused methods like self.participants_in and commented out code.&lt;br /&gt;
&lt;br /&gt;
===Use of Routing Helpers===&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
After Refactoring&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Replace find_by_.. with where in querying===&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
Before Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Method names should use underscores, not camelcase. ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good array checking====&lt;br /&gt;
&lt;br /&gt;
[].empty? # not [].length == 0 or [].length.zero?&lt;br /&gt;
[:foo].any? # not [:foo].length &amp;gt; 0&lt;br /&gt;
[:foo].one? # not [:foo].length == 1&lt;br /&gt;
[:foo].first # not [:foo][0]&lt;br /&gt;
[:foo].last # not [:foo][-1]&lt;br /&gt;
&lt;br /&gt;
====Use find_each for efficient loops over models====&lt;br /&gt;
&lt;br /&gt;
SignedUpUser.all.each do |user| # BAD&lt;br /&gt;
SignedUpUser.find_each do |user| # GOOD&lt;br /&gt;
	&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&amp;lt;br&amp;gt; we have used this to replace an == nil check that was there in the code. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
The boolean itself would suffice as an if condition.&lt;br /&gt;
&amp;lt;br&amp;gt;It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
      valid = 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
          valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Replace controller method with a model method ===&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models stackoverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=89940</id>
		<title>CSC/ECE 517 Fall 2014/oss E1460 aua</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1460_aua&amp;diff=89940"/>
		<updated>2014-10-27T18:02:57Z</updated>

		<summary type="html">&lt;p&gt;Vsonthy: /* Use a Boolean variable when that is sufficient */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring StudentQuizController=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt; is a web application available to both students and professors. The Expertiza project is a system to create reusable learning objects through peer review. Expertiza supports team projects, and the submission of almost any document type, including URLs and wiki pages. Students can keep a track of their assignments, teammates and can conduct peer reviews on diverse topics and projects. It is an open source project developed on Ruby on Rails platform. More information on Expertiza can be found [https://github.com/expertiza/expertiza here]. The source code can be forked and cloned for making modifications. &lt;br /&gt;
ertiza with main focus of Refactoring the Users Controller. &lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Classes :&amp;lt;/b&amp;gt; student_quiz_controller.rb&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What it does : &amp;lt;/b&amp;gt;This class records the quizzes that the student has attempted and its progress and also submits grades for the essays in the quizzes attempted by the student.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;What has to be changed : &amp;lt;/b&amp;gt;&lt;br /&gt;
*change list to index (and others in the RESTful style)&lt;br /&gt;
* Pluralize the class (StudentQuizzesController)&lt;br /&gt;
* graded? - review boolean zen&lt;br /&gt;
* Reduce the number of instance variables per controller action.&lt;br /&gt;
* Change the instance variables to local variables if they are not being used in the view. &lt;br /&gt;
* Modify methods to conform to RESTful style &lt;br /&gt;
* Code cleanup by using string interpolation instead of concatenation, replacing '==' with eql? and :key =&amp;gt;'value' with key: 'value', modifying declarations of Arrays and Hashes,removing commented out code&lt;br /&gt;
* Replace find_by with where to follow Rails 4.0 conventions&lt;br /&gt;
&lt;br /&gt;
==Modification to Existing Code==&lt;br /&gt;
&lt;br /&gt;
===Pluralized the class name StudentQuizController===&lt;br /&gt;
As per Rails convention the controller class names are sugested to be plural.&lt;br /&gt;
This helps in generating RESTful routing URI helpers. Also, naming the classes as plural seems more natural and helps in understanding&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/646951/singular-or-plural-controller-and-helper-names-in-rails&amp;lt;/ref&amp;gt;. &lt;br /&gt;
We used the refactor functionality in RubyMineto rename StudentQuiz controller class to StudentQuizzes.&lt;br /&gt;
&lt;br /&gt;
The following files were modified and/or renamed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
app/controllers/review_mapping_controller.rb&lt;br /&gt;
app/controllers/{student_quiz_controller.rb → student_quizzes_controller.rb}&lt;br /&gt;
app/helpers/student_quiz_helper.rb&lt;br /&gt;
app/helpers/student_quizzes_helper.rb&lt;br /&gt;
app/views/questionnaires/view.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_quiz_form.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_responses.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_dynamic_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/_set_self_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/finished_quiz.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/grade_essays.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/list.html.erb&lt;br /&gt;
app/views/{student_quiz → student_quizzes}/take_quiz.html.erb&lt;br /&gt;
app/views/student_task/view.html.erb&lt;br /&gt;
app/views/tree_display/actions/_assignments_actions.html.erb&lt;br /&gt;
test/functional/{student_quiz_controller_test.rb → student_quizzes_controller_test.rb}&lt;br /&gt;
test/test_helper.rb&lt;br /&gt;
test/unit/helpers/student_quiz_helper_test.rb&lt;br /&gt;
test/unit/helpers/student_quizzes_helper_test.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The detailed changeset for this refactor can be seen [https://github.com/ankit3005/expertiza/commit/20981333a14a3f468f76cd6d414b3088975b71bd here]. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===RESTful style implementation===&lt;br /&gt;
* Modifications to student_quiz_controller.rb :&lt;br /&gt;
The purpose of the list method in the Student Quizzes controller is to list all the quizzes that are available to this user for a particular assignment. RESTful guidelines state that a method that returns a list of all available objects, in this case the quizzes, should be named as index. Therefore, we renamed the list method to the index method in the controller and in all the files that had references to the list method of the student_quiz_controller (For e.g. :- The view finished_quiz.html.erb of the Student Quiz controller, the review_mapping controller.rb etc.).&lt;br /&gt;
&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
After Refactoring :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Instance Variable Reductions===&lt;br /&gt;
In Rails, data is shared between the controllers and views through the instance variables. The instance variabIes that are set during the execution a particular controller method are accessible to the view. Excessive usage of this standard method of data sharing between the controller and the view results in increased coupling between them. &amp;lt;ref&amp;gt;http://blog.remarkablelabs.com/2013/01/how-to-decrease-coupling-in-your-controllers-views-with-decent_exposure-for-better-maintainability&amp;lt;/ref&amp;gt; Increased coupling results in several problems, including less maintainability of code, difficulty in code reuse etc. &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Disadvantages&amp;lt;/ref&amp;gt; Thus, we need to reduce coupling to the maximum possible extent and in this case it can be achieved by reducing as many instance variables as possible. Therefore, we have refactored our code in order to eliminate unused and unneccessary instance variables.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
student_quizzes_controller.rb&lt;br /&gt;
&lt;br /&gt;
In the take_quiz method, the following instance variables were removed&lt;br /&gt;
Changed the quizzes instance variable to a local variable.&lt;br /&gt;
Eliminated instance variable assignment which was not used anywhere.&lt;br /&gt;
Eliminated local variable teams which was not used any where&lt;br /&gt;
The unified diff of the changes made is shown below&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.take_quiz assignment_id , reviewer_id&lt;br /&gt;
-    @quizzes = Array.new&lt;br /&gt;
+    quizzes = Array.new&lt;br /&gt;
     reviewer = Participant.where(user_id: reviewer_id, parent_id: assignment_id).first&lt;br /&gt;
-    @assignment = Assignment.find(assignment_id)&lt;br /&gt;
-    teams = TeamsUser.where(user_id: reviewer_id)&lt;br /&gt;
     Team.where(parent_id: assignment_id).each do |quiz_creator|&lt;br /&gt;
       unless TeamsUser.find_by_team_id(quiz_creator.id).user_id == reviewer_id&lt;br /&gt;
         Questionnaire.where(instructor_id: quiz_creator.id).each do |questionnaire|&lt;br /&gt;
-          if !@assignment.team_assignment?&lt;br /&gt;
-            unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
-              @quizzes.push(questionnaire)&lt;br /&gt;
-            end&lt;br /&gt;
-          else unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer_id).first&lt;br /&gt;
-            @quizzes.push(questionnaire)&lt;br /&gt;
+          unless QuizResponseMap.where(reviewed_object_id: questionnaire.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
+            quizzes.push(questionnaire)&lt;br /&gt;
           end&lt;br /&gt;
         end&lt;br /&gt;
       end&lt;br /&gt;
     end&lt;br /&gt;
+    return quizzes&lt;br /&gt;
   end&lt;br /&gt;
-  return @quizzes&lt;br /&gt;
-end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Elimination of Boolean Zen===&lt;br /&gt;
In cases where a method only returns a boolean value by evaluating an expression (using the if..else construct), the if..else statement is redundant and can be eliminated. We have a method &amp;lt;b&amp;gt; graded? &amp;lt;/b&amp;gt; that does this thing. Thus, we eliminated the if..else construct in the graded? method as it was redundant.&amp;lt;ref&amp;gt;https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic16_boolean_logic.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  if Score.where(question_id: question.id, response_id:  response.id).first&lt;br /&gt;
    return true&lt;br /&gt;
  else&lt;br /&gt;
    return false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def graded?(response, question)&lt;br /&gt;
  return (Score.where(question_id: question.id, response_id:  response.id).first)&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code Cleanup===&lt;br /&gt;
At some places, we found certain statements and variable assignments that were not being used later on in the method or code. We have eliminated such unused statements, so that methods contain only code that is being used later on. This would improve the readability and the maintainability of the code. For example in the code below we eliminated the &amp;lt;b&amp;gt;@quiz_phase&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;@num_quizzes_total&amp;lt;/b&amp;gt; variables because they were not being used anywhere in the code. Also, since the &amp;lt;b&amp;gt;local&amp;lt;/b&amp;gt; variables &amp;lt;b&amp;gt;quiz_due_date, deadline_type_id, participant&amp;lt;/b&amp;gt; were not being used anywhere, we could eliminate the entire &amp;lt;b&amp;gt;if&amp;lt;/b&amp;gt; block from the code below. We then converted the instance variable &amp;lt;b&amp;gt;participant&amp;lt;/b&amp;gt; to a local variable because it was not being used in the corresponding view.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
    @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(@participant.user_id)&lt;br /&gt;
&lt;br /&gt;
    @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&lt;br /&gt;
    # Find the current phase that the assignment is in.&lt;br /&gt;
    @quiz_phase = @assignment.get_current_stage(AssignmentParticipant.find(params[:id]).topic_id)&lt;br /&gt;
&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.where(reviewer_id: @participant.id)&lt;br /&gt;
&lt;br /&gt;
    # Calculate the number of quizzes that the user has completed so far.&lt;br /&gt;
    @num_quizzes_total = @quiz_mappings.size&lt;br /&gt;
&lt;br /&gt;
    @num_quizzes_completed = 0&lt;br /&gt;
    @quiz_mappings.each do |map|&lt;br /&gt;
      @num_quizzes_completed += 1 if map.response&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if @assignment.staggered_deadline?&lt;br /&gt;
      @quiz_mappings.each { |quiz_mapping|&lt;br /&gt;
        if @assignment.team_assignment?&lt;br /&gt;
          participant = AssignmentTeam.get_first_member(quiz_mapping.reviewee_id)&lt;br /&gt;
        else&lt;br /&gt;
          participant = quiz_mapping.reviewee&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if !participant.nil? and !participant.topic_id.nil?&lt;br /&gt;
          quiz_due_date = TopicDeadline.where(topic_id: participant.topic_id, deadline_type_id: 1).first&lt;br /&gt;
        end&lt;br /&gt;
      }&lt;br /&gt;
      deadline_type_id = DeadlineType.find_by_name('quiz').id&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;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def index&lt;br /&gt;
    participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
    return unless current_user_id?(participant.user_id)&lt;br /&gt;
    @assignment = Assignment.find(participant.parent_id)&lt;br /&gt;
    @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Replaced :key =&amp;gt;'value' with key: 'value'&lt;br /&gt;
&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Modified declarations of Arrays and Hashes&lt;br /&gt;
Before Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Removed unused methods like self.participants_in and commented out code.&lt;br /&gt;
&lt;br /&gt;
===Use of Routing Helpers===&lt;br /&gt;
Routing helpers are a simpler alternative to the otherwise complex hard coded URLs which reduce the readability of the code.Routing helpers allow us to declare possible common routes for a given controller. Routing helpers have been implemented since they maintain consistency even if changes are made to the routing paths. &lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
After Refactoring&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Replace find_by_.. with where in querying===&lt;br /&gt;
Rails 4 conventions dictate the use of 'where()' over the use of 'find_by_...' methods while querying ActiveRecords. The code has been refactored to replace the usages of find_by.. with where().&lt;br /&gt;
&lt;br /&gt;
Before Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Following Ruby Style Guidelines (Global Rules)===&lt;br /&gt;
At many places in the code we found that the Ruby Style Guidelines were not followed. We have refactored the code so that it uses the good code style guidelines. The following are some of the refactorings the we have done:-&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Used .eql? instead of &amp;quot;==&amp;quot; ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score == -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if score.score.eql? -1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Eliminated the &amp;quot;== true/false&amp;quot; check ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded == true &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if essay_not_graded &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Use `&amp;amp;&amp;amp;` and `||` rather than `and` and `or` to keep boolean precedence ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer and params[&amp;quot;#{question.id}&amp;quot;] == correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; elsif  correct_answer &amp;amp;&amp;amp; params[&amp;quot;#{question.id}&amp;quot;]== correct_answer.txt &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Method names should use underscores, not camelcase. ====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Use key: ‘value’, not :key =&amp;gt; ‘value’ ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new :comments =&amp;gt; choice, :question_id =&amp;gt; question.id, :response_id =&amp;gt; @response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;new_score = Score.new comments: choice, question_id: question.id, response_id: response.id&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Replace find_by_...  with a where command ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Before Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; if (QuestionType.find_by_question_id question.id).q_type == 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; After Refactoring &amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ques_type = (QuestionType.where( question_id: question.id)).q_type&lt;br /&gt;
if ques_type.eql? 'MCC' &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good array checking====&lt;br /&gt;
&lt;br /&gt;
[].empty? # not [].length == 0 or [].length.zero?&lt;br /&gt;
[:foo].any? # not [:foo].length &amp;gt; 0&lt;br /&gt;
[:foo].one? # not [:foo].length == 1&lt;br /&gt;
[:foo].first # not [:foo][0]&lt;br /&gt;
[:foo].last # not [:foo][-1]&lt;br /&gt;
&lt;br /&gt;
====Use find_each for efficient loops over models====&lt;br /&gt;
&lt;br /&gt;
SignedUpUser.all.each do |user| # BAD&lt;br /&gt;
SignedUpUser.find_each do |user| # GOOD&lt;br /&gt;
	&lt;br /&gt;
====Used .nil? instead of &amp;quot;== nil&amp;quot; ====&lt;br /&gt;
The inbuilt method .nil? returns a boolean. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;] == nil&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if params[&amp;quot;#{question.id}&amp;quot;].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Used a Boolean variable when that is sufficient====&lt;br /&gt;
It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = 1&lt;br /&gt;
 if valid == 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
valid = false&lt;br /&gt;
 if valid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use good conditional statements====&lt;br /&gt;
The boolean itself would suffice as an if condition.&lt;br /&gt;
&amp;lt;br&amp;gt;It is a good practice to use a boolean variable if we only need a boolean for our purpose.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unless new_score.comments != &amp;quot;&amp;quot; &amp;amp;&amp;amp; new_score.comments&lt;br /&gt;
      valid = 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if new_score.comments.empty? || new_score.comments.nil?&lt;br /&gt;
          valid = false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Replace controller method with a model method ===&lt;br /&gt;
Rails 4 conventions dictate the use of a fat model and skinny controller.&lt;br /&gt;
It is better to put place the search function in the model rather than placing it in the controller.&lt;br /&gt;
The search code belonged to the quiz_response_map model, since it queries that particular table in the DB.&lt;br /&gt;
The code was extracted into the subsequent method displayed below and called from the invitation controller.&amp;lt;ref name = &amp;quot;stackoverflow&amp;quot;&amp;gt;[http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models stackoverflow]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Before Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.where(reviewer_id: participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;After Refactoring&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @quiz_mappings = QuizResponseMap.get_mappings_for_reviewer(participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vsonthy</name></author>
	</entry>
</feed>