<?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=Pvemuri</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=Pvemuri"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Pvemuri"/>
	<updated>2026-07-02T03:43:47Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145311</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=145311"/>
		<updated>2022-04-26T00:04:53Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* Proposed Design Change */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb and export_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
* Find and fix the existing bugs in the import and export process flows.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially, High Priority modules are users, topics, and grades, and then move on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
The questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: Ic usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: EC usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller/export_file_controller should be used for importing/exporting the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Actual Changes Made ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Export Functionality code flow ''' - We started by analyzing the code flow of export_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, Grades and Topics'''. On analyzing the code we found that all these three models are using the export_file_controller.rb to generate the respective CSVs. However, there were a few bugs that we found in the existing ''' Export Grades ''' functionality. We debugged this flow completely and fixed those bugs. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section. Apart from that, there was no ''' Export Topics ''' functionality present in the system. We created a completely new flow for exporting the topics leveraging the existing export_file_controller logic to keep the modules consistent. More information about the new features added can be found in the ''' New Features Added ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* ''' Analyzing Import Functionality code flow ''' - We analyzed the code flow of import_file_controller.rb and whether it is being used by different models to export data or not. '''The models we focussed on are Users, and Topics'''. On analyzing the code we found that these two models are using the export_file_controller.rb to import the respective CSVs with required data. However, we found a few bugs in the Import Topics functionality and we fixed those. The bugs and their corresponding fixes are mentioned below in the ''' Bug Fixes ''' section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Analysis of these two workflows (Export and Import) took a considerable amount of our time since there were a lot of moving pieces present in these controllers. We had to manually test these flows for different models because of the different data and customizations present. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for export_file_controller''' - After we finished the analysis and development of the required features for the export functionality, we proceeded with writing the test cases for the export_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users, Grades and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Test Cases for import_file_controller''' - After we finished the analysis and development of the required features for the import functionality, we proceeded with writing the test cases for the import_file_controller.rb file. There were no test cases present for this file and we wrote all the test cases from scratch. Our test cases revolve around these '''models (Users and Topics)''' since the methods inside these controllers are pretty big and contain a lot of if-else for different models.&lt;br /&gt;
&lt;br /&gt;
== New Features Added ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Export Topics''' - The Export Topics Feature was not present in the application. You can navigate to Export Topics by going to '''Assignments &amp;gt; Click on Edit (pencil icon) &amp;gt; Click on Topics menu'''. Once you click the Export Topics button, you will be taken to a customizations page where you can select what columns you want in your CSV file. You can select/deselect the options by clicking on the checkboxes provided. Once you select the desired cloumns, click on the export button to generate the CSV file. The Export Topics and Customizations pages are attached below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Export Topics.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Customization.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Export Topics'''''&lt;br /&gt;
&lt;br /&gt;
[[File:C1.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C2.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C3.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C4.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C5.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
[[File:C6.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Bug Fixes ==&lt;br /&gt;
&lt;br /&gt;
On analyzing the code flow for import and export functionality we found that the '''Export Grades''' functionality was broken. There were a few things that were creating problems in this flow. Mentioned below are the fixes that we made in this flow:&lt;br /&gt;
&lt;br /&gt;
*'''Fix 1: Export grades into a file successfully''' - When exporting grades, self.export method of Assignment.rb is called. This internally calls review_grades method in Scoring.rb. But review_grades method was not being invoked because it was being called from a class method but was imported as an instance method. Then self.export method internally invokes self.export_data method. Some lines related to the business logic were missing here. &lt;br /&gt;
&lt;br /&gt;
[[File:Bug1.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 1: Export grades into a file successfully'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix1 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 2: Incorrect headers in the exported file''' - During the export, the generated CSV had some issues with the headers. A few headers were not separated into multiple columns which was not the desired result. We fixed those as well.&lt;br /&gt;
[[File:Incorrect grouped column.jpeg|800x520px]]&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 2: Incorrect headers in the exported file'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix2 code.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 3: Only export selected columns from the UI''' - Removed author feedback score from being exported. What happens in the file? &lt;br /&gt;
** Problem 1: The meta-review feedback column is removed but the author feedback header still shows up.&lt;br /&gt;
** Problem 2: Also only the headers have changed but all values of all columns are still being exported.&lt;br /&gt;
&lt;br /&gt;
[[File:E3.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
[[File:E3 1.png|800x520px]]  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 3: Only export selected columns from the UI'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix3 code.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button''' - We tried importing the topics.csv and it imported all the data except the Category, Description, and Link columns. These columns were optional columns and when we selected the checkboxes for these, the data was not persisted in the database. We debugged this workflow and fixed this bug.&lt;br /&gt;
&lt;br /&gt;
*'''''Code Changes for Fix 4: Category, Description, and Link were not being updated in the database while importing the CSV using the Import Topics button'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Fix 4.png|800x520px]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails'' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Execution of Test Plan ==&lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''export_file_controller''' use the command - '''''rspec spec/controllers/export_file_controller_spec.rb'''''&lt;br /&gt;
&lt;br /&gt;
To run the test cases for '''import_file_controller''' use the command - '''''rspec spec/controllers/import_file_controller_spec.rb'' ''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We wrote the test cases for the above-mentioned methods focussing on the ''' models (Users, Topics and Grades) ''' since these were the high priority models assigned to us. Our Test Coverage so far is as follows:&lt;br /&gt;
&lt;br /&gt;
*'''''export_file_controller test coverage - 54.84%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Export test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''''import_file_controller test coverage - 52.43%'''''&lt;br /&gt;
&lt;br /&gt;
[[File:Import test coverage.png|800x520px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We also implemented '''''fixtures''''' for testing the generated CSVs. This is a new concept that was not implemented earlier in this project and can be leveraged in future to test the CSVs. This provides the developers ability to test the Export and Import functionalities for CSV files.&lt;br /&gt;
&lt;br /&gt;
We did not attach the code difference screenshots for the test cases because it was quite big. Kindly refer to the PR to view the code changes for the test cases corresponding to '''export_file_controller''' and '''import_file_controller'''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''''Link to Pull Request:''''' https://github.com/expertiza/expertiza/pull/2396 ==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:EC_usecase.png&amp;diff=145309</id>
		<title>File:EC usecase.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:EC_usecase.png&amp;diff=145309"/>
		<updated>2022-04-26T00:03:23Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Ic_usecase.png&amp;diff=145306</id>
		<title>File:Ic usecase.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Ic_usecase.png&amp;diff=145306"/>
		<updated>2022-04-26T00:02:41Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=144862</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=144862"/>
		<updated>2022-04-12T02:07:56Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* Proposed Design Change */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially High Priority modules are users, topics, and grades and then moving on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
Questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like: UML Diagram'''&lt;br /&gt;
&lt;br /&gt;
[[Image: import_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
[[Image: export_usecase.png|600px]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller should be used for importing the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails''' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Export_usecase.png&amp;diff=144860</id>
		<title>File:Export usecase.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Export_usecase.png&amp;diff=144860"/>
		<updated>2022-04-12T02:05:15Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Import_usecase.png&amp;diff=144858</id>
		<title>File:Import usecase.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Import_usecase.png&amp;diff=144858"/>
		<updated>2022-04-12T02:01:01Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=144813</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=144813"/>
		<updated>2022-04-12T01:18:31Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially High Priority modules are users, topics, and grades and then moving on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
Questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like:'''&lt;br /&gt;
&lt;br /&gt;
[[Image: goodUML.png]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller should be used for importing the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in the export_file_controller class that needed to be tested were:&lt;br /&gt;
*'''action_allowed''' - This is a method that calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the export operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''exportdetails''' - This method fetches the delimiter and the file name required to perform the export operation. It also stores additional metadata from the Assignments class in a CSV file. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export''' - This is the main method that does the actual exporting task. It gathers all the necessary data such as - assignment, course, participant id, team, questions, answers, reviews, etc, and saves the data unless the model is not supported. We will test this method by verifying whether the export process works with supported model types.&lt;br /&gt;
*'''export_advices''' - This method is similar to export but only exports &amp;quot;Question&amp;quot; type models along with &amp;quot;QuestionAdvice&amp;quot;. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
*'''export_tags''' - This method exports the user's answers with their respective tags and comments. We will test this method by checking if the correct data is being exported.&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - Similar to the one in export_file_controller, this is a method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=144795</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=144795"/>
		<updated>2022-04-12T01:00:53Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially High Priority modules are users, topics, and grades and then moving on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
Questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like:'''&lt;br /&gt;
&lt;br /&gt;
[[Image: goodUML.png]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller should be used for importing the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in export_file_controller class that needed to be tested were:&lt;br /&gt;
*action_allowed&lt;br /&gt;
*exportdetails&lt;br /&gt;
*export&lt;br /&gt;
*export_advices&lt;br /&gt;
*export_tags&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*'''action_allowed''' - This is a precursor method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*'''show''' - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*'''import''' - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=144794</id>
		<title>CSC/ECE 517 Spring 2022 - E2238. Implementing and testing Import &amp; Export controllers</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2238._Implementing_and_testing_Import_%26_Export_controllers&amp;diff=144794"/>
		<updated>2022-04-12T01:00:23Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Team==&lt;br /&gt;
=== Mentor ===&lt;br /&gt;
&lt;br /&gt;
* Vinay Deshmukh&lt;br /&gt;
&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
&lt;br /&gt;
*Bollineni, Rachana Sri	rbollin@ncsu.edu&lt;br /&gt;
*Nangia, Chirrag - cnangia@ncsu.edu&lt;br /&gt;
*Priyadarshan, Saswat - spriyad2@ncsu.edu&lt;br /&gt;
*Vemuri, Pradyumna	pvemuri@ncsu.edu&lt;br /&gt;
&lt;br /&gt;
== Project Purpose &amp;amp; Description ==&lt;br /&gt;
&lt;br /&gt;
The export/import feature is the most helpful feature for instructors to set up assignments. The instructors usually have a list of students, teams, etc from their learning management system. Being able to export/import these into expertiza saves a lot of time when setting up an assignment.&lt;br /&gt;
&lt;br /&gt;
Expertiza provides multiple export and import features for eg. export students, teams etc. Essentially what it does is it fetches some data from the database and saves it as a file in the desired format. However, the same functionality is implemented multiple times for exporting and importing different things. The aim of this project is to design a generic export/import feature that can be used across the application. This will help in maintaining the codebase and keep things consistent throughout.&lt;br /&gt;
&lt;br /&gt;
== Current Project Scope ==&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller has already been experimented with in Project E1923: https://github.com/expertiza/expertiza/pull/1438&lt;br /&gt;
But as discussed with the professor and the mentors, the PR hasn’t been merged, and it’s not known whether the code was correct or it had issues. And given the existing code has lots of if-else, it would be better to rewrite it from scratch.&lt;br /&gt;
&lt;br /&gt;
'''Below listed are our primary goals for this project:'''&lt;br /&gt;
* Redo the code for import_file_controller.rb, by referring to the code in the pull request. Our plan of action is to rewrite the code than try to refactor it, as it’s not known whether the code in the PR is correct. &lt;br /&gt;
* Write test cases for the new import_file_controller and the existing export_file_controller.&lt;br /&gt;
&lt;br /&gt;
== Extended Project Scope ==&lt;br /&gt;
&lt;br /&gt;
'''Below listed is the stretch goal for this project. We'll try to pick it only if the time permits.'''&lt;br /&gt;
&lt;br /&gt;
* After the functionality is fixed, the next step is to leverage the import and export controllers for importing/exporting users, topics, teams, questionnaires, and grades. Initially High Priority modules are users, topics, and grades and then moving on to the other modules.&lt;br /&gt;
&lt;br /&gt;
== Existing Import/Export Controller design ==&lt;br /&gt;
&lt;br /&gt;
The existing import and export functionality primarily uses the '''import_file_controller''' and '''export_file_controller'''. &lt;br /&gt;
&lt;br /&gt;
SignUpTopic and User, rely on helper classes that extract attributes from a hash and create an ActiveRecord object.&lt;br /&gt;
&lt;br /&gt;
Questionnaire relies on a helper method that can import Question objects (objects that make up a Questionnaire) from a CSV and adjust the size of the associated QuestionAdvice (the words that pop up after you pick a certain number of stars). However, these functions might be deprecated, as it appears that Question importing is now routed through the ImportFileController unsuccessfully. More detail about specific functions is provided below.&lt;br /&gt;
&lt;br /&gt;
=== Controllers ===&lt;br /&gt;
&lt;br /&gt;
*'''import_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** File processing methods:&lt;br /&gt;
*** #get_delimiter - Sets proper delimiter for filetype&lt;br /&gt;
*** #parse_line - Processes line (row) of the file&lt;br /&gt;
*** #parse_to_grid - Turns file into 2D array&lt;br /&gt;
*** #parse_to_hash - Turns file into hash where 'header' stores header row and 'body' stores all contents.&lt;br /&gt;
*** #hash_rows_with_headers - Creates hash for each row of file. Keys are headers, values are row values.&lt;br /&gt;
** Import methods:&lt;br /&gt;
*** #import_from_hash - Primary import functionality. Creates objects for hashed rows (from #hash_rows_with_headers).&lt;br /&gt;
*** #import - Larger controller of import, sets error messages and displays.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaires_controller''', the list of methods in the controller are the following: &lt;br /&gt;
** ::import - Allows import from CSV using QuestionnaireHelper (Appears to be deprecated/unused)&lt;br /&gt;
&lt;br /&gt;
*'''export_file_controller''', the list of methods in the controller are the following:&lt;br /&gt;
** ::find_delim_filename - Sets and returns attributes for User object from hash.&lt;br /&gt;
** ::exportdetails - Generates the metadata for the data that needs to be exported.&lt;br /&gt;
** ::export - Converts the data into CSV format files.&lt;br /&gt;
** ::export_advices - Export question advice data to CSV file.&lt;br /&gt;
** ::export_tags - Export the tags.&lt;br /&gt;
&lt;br /&gt;
=== Helpers ===&lt;br /&gt;
*'''import_file_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::create_new_user - Makes a user object in the database.&lt;br /&gt;
&lt;br /&gt;
*'''import_topics_helper''', the list of methods in the file are the following: &lt;br /&gt;
** ::define_attributes - Find the filename and delimiter.&lt;br /&gt;
&lt;br /&gt;
*'''questionnaire_helper''' (Appears to be deprecated/unused), the list of methods in the file are the following: &lt;br /&gt;
** ::get_questions_from_csv - Allows Question and QuestionAdvice import/creation with CSV file.&lt;br /&gt;
&lt;br /&gt;
== Proposed Design Change ==&lt;br /&gt;
* Search for occurrences of “import” and “export” to find all the valid models that can be imported or exported.&lt;br /&gt;
* Identify the flow of import/export functionality involving those models and figure out whether they are using import_file_controller/export_file_controller or using their own logic to perform these actions.&lt;br /&gt;
* Once all the involved pieces are identified, we will change the code to ensure that all the involved modules make use of the new import_file_controller/export_file_controller.&lt;br /&gt;
* Once everything is in working condition, we will proceed with testing.&lt;br /&gt;
&lt;br /&gt;
Everything should work as expected based on our analysis so far. However, there are a few models which use the import/export functionality and have very different structures. We need to create helper methods for them to make the imports and exports specific to those models leveraging the common controllers created. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''In a more generic way, this is how the import functionality is working as of now (taking one example for simplicity):'''&lt;br /&gt;
&lt;br /&gt;
[[Image: badUML.png]]&lt;br /&gt;
&lt;br /&gt;
Import_file_controller is used for importing the data of team and course_participant models in a CSV. Questionnaires_controller is being used to import data of the question model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''What we want it to look like:'''&lt;br /&gt;
&lt;br /&gt;
[[Image: goodUML.png]]&lt;br /&gt;
&lt;br /&gt;
A generic import_file_controller should be used for importing the data of all modules i.e., team, course_participant and questions model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refer to the above PR (https://github.com/expertiza/expertiza/pull/1438) for reference.&lt;br /&gt;
The major part of our effort will be targeted at rewriting this import_file_controller controller and removing the pieces which are breaking. Once we achieve that, we will create helper methods specific to each method and leverage the controllers to do the import and export in a consistent fashion across the application.&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Writing test cases for '''import_file_controller''' and '''export_file_controller'''. We would be focussing on writing test cases for the controllers and the helpers that we will create specific to the models.&lt;br /&gt;
&lt;br /&gt;
Now we have only 5 methods in the export_file_controller class that we need to test. Five methods in export_file_controller class that needed to be tested were:&lt;br /&gt;
*action_allowed&lt;br /&gt;
*exportdetails&lt;br /&gt;
*export&lt;br /&gt;
*export_advices&lt;br /&gt;
*export_tags&lt;br /&gt;
&lt;br /&gt;
For the import_file_controller class, we identified the following methods to be tested:&lt;br /&gt;
*action_allowed - This is a precursor method that in turn calls &amp;quot;current_user_has_ta_privileges?&amp;quot; to ensure that the current user has the proper privileges to perform the import operation. We write a test for this method expecting that a user calling the method has required permissions.&lt;br /&gt;
*show - This method stores necessary metadata required to perform import operations such as - user id, delimiters, header, and also additional information such as the assignment id and team number. We write a test to check whether the necessary variables in the method are populated.&lt;br /&gt;
*import - The import method is used to verify the hash header or body, and generate error messages if needed. We will be writing a test to verify if this method can throw an error if something goes wrong with the import process.&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143774</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143774"/>
		<updated>2022-03-28T02:14:27Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* Pull Request */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as the DRY principle. There are a few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments need to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. app/controllers/'''student_quizzes_controller.rb''' &amp;lt;br&amp;gt;2. app/views/student_quizzes/f'''inished_quiz.html''' &amp;lt;br&amp;gt;3. app/helpers/'''student_quizzes_helper.rb'''&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
def self.take_quiz(assignment_id, reviewer_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
def record_response&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
def review_questions&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
# Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
def calculate_score(map, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions since the original method is too big and is split to use the other methods to handle score calculation for Single choice / True or False questions and Multiple answer questions separately. Then all three methods have been moved to student_quizzes_helper.rb file since they are being reused. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&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;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
Follow these instructions to manually test the functionality of student_quizzes_controller.&amp;lt;br&amp;gt;&lt;br /&gt;
'''1'''. Login as instructor using the credentials, username: instructor6, password: password.&amp;lt;br&amp;gt;&lt;br /&gt;
'''2'''. Select the '''Assignments''' subheading. Here, create a new assignment by entering the necessary details. Enable the '''Has Teams?''' checkbox and create. Also enable the '''Has quiz?''' checkbox.&amp;lt;br&amp;gt;&lt;br /&gt;
'''3'''. Navigate to the Due Dates tab and set appropriate due dates for submission and review. For Round 1: Review, enable Has Quiz using the dropdown Menu. Once you save, A '''Number of Quiz questions''' field will be visible on the Assignments page. Set this to 2 and save.&amp;lt;br&amp;gt;&lt;br /&gt;
'''4'''. At the top of the page, there will be a notice asking you to add participants. Using the link provided, add a few students to the assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
'''5'''. Logout as the Instructor and Login as the students. Make submissions for the assignment before the submission deadline. &amp;lt;br&amp;gt;&lt;br /&gt;
Note: You must create a team and set team name to be able to make a submission.&amp;lt;br&amp;gt;&lt;br /&gt;
'''6'''. At the bottom of the submission page, you will see a '''Create a Quiz''' link. Select that link.&amp;lt;br&amp;gt;&lt;br /&gt;
'''7'''. This takes you to the quiz creation page. Here you can set Radio Button MCQs, Checkbox MCQs and True/False Questions and set the correct answers.&amp;lt;br&amp;gt;&lt;br /&gt;
Then select '''Create Quiz'''. This creates the quiz.&amp;lt;br&amp;gt;&lt;br /&gt;
'''8'''. Logout and login as another student registered in the assignment. Make a submission as this student. Once the submission deadline has passed, review the first student's work and return to the main menu. &amp;lt;br&amp;gt;&lt;br /&gt;
'''9'''. You will see the option to '''Take quizzes'''. Here, select the quiz you have created and select '''Request'''. Here, you can take the quiz created by the other student.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing Walkthorugh===&lt;br /&gt;
The video below shows the steps for manually testing the controller functionality.&lt;br /&gt;
&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[https://drive.google.com/file/d/1b78JR5vAPQfzn569rciZ603gRJ8eIQnS/view?usp=sharing Manual testing video]&lt;br /&gt;
&lt;br /&gt;
===Testing Video===&lt;br /&gt;
Originally the student_quizzes_controller did not have any test cases, so according to the documentation, we wrote some to check if the changes we introduced have broken the functionality. Our test cases have run successfully. Here is the video for the same. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[https://drive.google.com/file/d/1Kl8f71sylFVBIKymvjWN9A_69jbwoDdP/view?usp=sharing Test Video link]&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
The link for our pull request - [https://github.com/expertiza/expertiza/pull/2340 https://github.com/expertiza/expertiza/pull/2340]&lt;br /&gt;
&lt;br /&gt;
==Team members==&lt;br /&gt;
Jyothi Sumer Goud Maduru (jmaduru@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Pradyumna Vemuri (pvemuri@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Karthik Narayanan Gopala Sundaresan (kgopala3@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Team Mentor==&lt;br /&gt;
Divyang Doshi (ddoshi2@ncsu.edu)&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143773</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143773"/>
		<updated>2022-03-28T02:14:15Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as the DRY principle. There are a few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments need to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. app/controllers/'''student_quizzes_controller.rb''' &amp;lt;br&amp;gt;2. app/views/student_quizzes/f'''inished_quiz.html''' &amp;lt;br&amp;gt;3. app/helpers/'''student_quizzes_helper.rb'''&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
def self.take_quiz(assignment_id, reviewer_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
def record_response&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
def review_questions&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
# Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
def calculate_score(map, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions since the original method is too big and is split to use the other methods to handle score calculation for Single choice / True or False questions and Multiple answer questions separately. Then all three methods have been moved to student_quizzes_helper.rb file since they are being reused. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&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;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
Follow these instructions to manually test the functionality of student_quizzes_controller.&amp;lt;br&amp;gt;&lt;br /&gt;
'''1'''. Login as instructor using the credentials, username: instructor6, password: password.&amp;lt;br&amp;gt;&lt;br /&gt;
'''2'''. Select the '''Assignments''' subheading. Here, create a new assignment by entering the necessary details. Enable the '''Has Teams?''' checkbox and create. Also enable the '''Has quiz?''' checkbox.&amp;lt;br&amp;gt;&lt;br /&gt;
'''3'''. Navigate to the Due Dates tab and set appropriate due dates for submission and review. For Round 1: Review, enable Has Quiz using the dropdown Menu. Once you save, A '''Number of Quiz questions''' field will be visible on the Assignments page. Set this to 2 and save.&amp;lt;br&amp;gt;&lt;br /&gt;
'''4'''. At the top of the page, there will be a notice asking you to add participants. Using the link provided, add a few students to the assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
'''5'''. Logout as the Instructor and Login as the students. Make submissions for the assignment before the submission deadline. &amp;lt;br&amp;gt;&lt;br /&gt;
Note: You must create a team and set team name to be able to make a submission.&amp;lt;br&amp;gt;&lt;br /&gt;
'''6'''. At the bottom of the submission page, you will see a '''Create a Quiz''' link. Select that link.&amp;lt;br&amp;gt;&lt;br /&gt;
'''7'''. This takes you to the quiz creation page. Here you can set Radio Button MCQs, Checkbox MCQs and True/False Questions and set the correct answers.&amp;lt;br&amp;gt;&lt;br /&gt;
Then select '''Create Quiz'''. This creates the quiz.&amp;lt;br&amp;gt;&lt;br /&gt;
'''8'''. Logout and login as another student registered in the assignment. Make a submission as this student. Once the submission deadline has passed, review the first student's work and return to the main menu. &amp;lt;br&amp;gt;&lt;br /&gt;
'''9'''. You will see the option to '''Take quizzes'''. Here, select the quiz you have created and select '''Request'''. Here, you can take the quiz created by the other student.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing Walkthorugh===&lt;br /&gt;
The video below shows the steps for manually testing the controller functionality.&lt;br /&gt;
&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[https://drive.google.com/file/d/1b78JR5vAPQfzn569rciZ603gRJ8eIQnS/view?usp=sharing Manual testing video]&lt;br /&gt;
&lt;br /&gt;
===Testing Video===&lt;br /&gt;
Originally the student_quizzes_controller did not have any test cases, so according to the documentation, we wrote some to check if the changes we introduced have broken the functionality. Our test cases have run successfully. Here is the video for the same. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[https://drive.google.com/file/d/1Kl8f71sylFVBIKymvjWN9A_69jbwoDdP/view?usp=sharing Test Video link]&lt;br /&gt;
&lt;br /&gt;
==Pull Request==&lt;br /&gt;
The link for our pull request - [https://github.com/expertiza/expertiza/pull/2340]&lt;br /&gt;
&lt;br /&gt;
==Team members==&lt;br /&gt;
Jyothi Sumer Goud Maduru (jmaduru@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Pradyumna Vemuri (pvemuri@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Karthik Narayanan Gopala Sundaresan (kgopala3@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Team Mentor==&lt;br /&gt;
Divyang Doshi (ddoshi2@ncsu.edu)&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143772</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143772"/>
		<updated>2022-03-28T02:13:37Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* Manual Testing Walkthorugh */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as the DRY principle. There are a few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments need to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. app/controllers/'''student_quizzes_controller.rb''' &amp;lt;br&amp;gt;2. app/views/student_quizzes/f'''inished_quiz.html''' &amp;lt;br&amp;gt;3. app/helpers/'''student_quizzes_helper.rb'''&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
def self.take_quiz(assignment_id, reviewer_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
def record_response&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
def review_questions&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
# Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
def calculate_score(map, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions since the original method is too big and is split to use the other methods to handle score calculation for Single choice / True or False questions and Multiple answer questions separately. Then all three methods have been moved to student_quizzes_helper.rb file since they are being reused. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&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;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
Follow these instructions to manually test the functionality of student_quizzes_controller.&amp;lt;br&amp;gt;&lt;br /&gt;
'''1'''. Login as instructor using the credentials, username: instructor6, password: password.&amp;lt;br&amp;gt;&lt;br /&gt;
'''2'''. Select the '''Assignments''' subheading. Here, create a new assignment by entering the necessary details. Enable the '''Has Teams?''' checkbox and create. Also enable the '''Has quiz?''' checkbox.&amp;lt;br&amp;gt;&lt;br /&gt;
'''3'''. Navigate to the Due Dates tab and set appropriate due dates for submission and review. For Round 1: Review, enable Has Quiz using the dropdown Menu. Once you save, A '''Number of Quiz questions''' field will be visible on the Assignments page. Set this to 2 and save.&amp;lt;br&amp;gt;&lt;br /&gt;
'''4'''. At the top of the page, there will be a notice asking you to add participants. Using the link provided, add a few students to the assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
'''5'''. Logout as the Instructor and Login as the students. Make submissions for the assignment before the submission deadline. &amp;lt;br&amp;gt;&lt;br /&gt;
Note: You must create a team and set team name to be able to make a submission.&amp;lt;br&amp;gt;&lt;br /&gt;
'''6'''. At the bottom of the submission page, you will see a '''Create a Quiz''' link. Select that link.&amp;lt;br&amp;gt;&lt;br /&gt;
'''7'''. This takes you to the quiz creation page. Here you can set Radio Button MCQs, Checkbox MCQs and True/False Questions and set the correct answers.&amp;lt;br&amp;gt;&lt;br /&gt;
Then select '''Create Quiz'''. This creates the quiz.&amp;lt;br&amp;gt;&lt;br /&gt;
'''8'''. Logout and login as another student registered in the assignment. Make a submission as this student. Once the submission deadline has passed, review the first student's work and return to the main menu. &amp;lt;br&amp;gt;&lt;br /&gt;
'''9'''. You will see the option to '''Take quizzes'''. Here, select the quiz you have created and select '''Request'''. Here, you can take the quiz created by the other student.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing Walkthorugh===&lt;br /&gt;
The video below shows the steps for manually testing the controller functionality.&lt;br /&gt;
&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[https://drive.google.com/file/d/1b78JR5vAPQfzn569rciZ603gRJ8eIQnS/view?usp=sharing Manual testing video]&lt;br /&gt;
&lt;br /&gt;
===Testing Video===&lt;br /&gt;
Originally the student_quizzes_controller did not have any test cases, so according to the documentation, we wrote some to check if the changes we introduced have broken the functionality. Our test cases have run successfully. Here is the video for the same. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[https://drive.google.com/file/d/1Kl8f71sylFVBIKymvjWN9A_69jbwoDdP/view?usp=sharing Test Video link]&lt;br /&gt;
&lt;br /&gt;
==Team members==&lt;br /&gt;
Jyothi Sumer Goud Maduru (jmaduru@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Pradyumna Vemuri (pvemuri@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Karthik Narayanan Gopala Sundaresan (kgopala3@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Team Mentor==&lt;br /&gt;
Divyang Doshi (ddoshi2@ncsu.edu)&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143770</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143770"/>
		<updated>2022-03-28T02:09:45Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* Manual Testing Walkthorugh */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as the DRY principle. There are a few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments need to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. app/controllers/'''student_quizzes_controller.rb''' &amp;lt;br&amp;gt;2. app/views/student_quizzes/f'''inished_quiz.html''' &amp;lt;br&amp;gt;3. app/helpers/'''student_quizzes_helper.rb'''&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
def self.take_quiz(assignment_id, reviewer_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
def record_response&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
def review_questions&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
# Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
def calculate_score(map, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions since the original method is too big and is split to use the other methods to handle score calculation for Single choice / True or False questions and Multiple answer questions separately. Then all three methods have been moved to student_quizzes_helper.rb file since they are being reused. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&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;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
Follow these instructions to manually test the functionality of student_quizzes_controller.&amp;lt;br&amp;gt;&lt;br /&gt;
'''1'''. Login as instructor using the credentials, username: instructor6, password: password.&amp;lt;br&amp;gt;&lt;br /&gt;
'''2'''. Select the '''Assignments''' subheading. Here, create a new assignment by entering the necessary details. Enable the '''Has Teams?''' checkbox and create. Also enable the '''Has quiz?''' checkbox.&amp;lt;br&amp;gt;&lt;br /&gt;
'''3'''. Navigate to the Due Dates tab and set appropriate due dates for submission and review. For Round 1: Review, enable Has Quiz using the dropdown Menu. Once you save, A '''Number of Quiz questions''' field will be visible on the Assignments page. Set this to 2 and save.&amp;lt;br&amp;gt;&lt;br /&gt;
'''4'''. At the top of the page, there will be a notice asking you to add participants. Using the link provided, add a few students to the assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
'''5'''. Logout as the Instructor and Login as the students. Make submissions for the assignment before the submission deadline. &amp;lt;br&amp;gt;&lt;br /&gt;
Note: You must create a team and set team name to be able to make a submission.&amp;lt;br&amp;gt;&lt;br /&gt;
'''6'''. At the bottom of the submission page, you will see a '''Create a Quiz''' link. Select that link.&amp;lt;br&amp;gt;&lt;br /&gt;
'''7'''. This takes you to the quiz creation page. Here you can set Radio Button MCQs, Checkbox MCQs and True/False Questions and set the correct answers.&amp;lt;br&amp;gt;&lt;br /&gt;
Then select '''Create Quiz'''. This creates the quiz.&amp;lt;br&amp;gt;&lt;br /&gt;
'''8'''. Logout and login as another student registered in the assignment. Make a submission as this student. Once the submission deadline has passed, review the first student's work and return to the main menu. &amp;lt;br&amp;gt;&lt;br /&gt;
'''9'''. You will see the option to '''Take quizzes'''. Here, select the quiz you have created and select '''Request'''. Here, you can take the quiz created by the other student.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing Walkthorugh===&lt;br /&gt;
The video below shows the steps above for manually testing the controller functionality.&lt;br /&gt;
&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[https://drive.google.com/file/d/1b78JR5vAPQfzn569rciZ603gRJ8eIQnS/view?usp=sharing Manual testing video]&lt;br /&gt;
&lt;br /&gt;
===Testing Video===&lt;br /&gt;
Originally the student_quizzes_controller did not have any test cases, so according to the documentation, we wrote some to check if the changes we introduced have broken the functionality. Our test cases have run successfully. Here is the video for the same. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[https://drive.google.com/file/d/1Kl8f71sylFVBIKymvjWN9A_69jbwoDdP/view?usp=sharing Test Video link]&lt;br /&gt;
&lt;br /&gt;
==Team members==&lt;br /&gt;
Jyothi Sumer Goud Maduru (jmaduru@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Pradyumna Vemuri (pvemuri@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Karthik Narayanan Gopala Sundaresan (kgopala3@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Team Mentor==&lt;br /&gt;
Divyang Doshi (ddoshi2@ncsu.edu)&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143766</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143766"/>
		<updated>2022-03-28T02:04:18Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* Testing Video */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as the DRY principle. There are a few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments need to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. app/controllers/'''student_quizzes_controller.rb''' &amp;lt;br&amp;gt;2. app/views/student_quizzes/f'''inished_quiz.html''' &amp;lt;br&amp;gt;3. app/helpers/'''student_quizzes_helper.rb'''&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
def self.take_quiz(assignment_id, reviewer_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
def record_response&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
def review_questions&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
# Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
def calculate_score(map, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions since the original method is too big and is split to use the other methods to handle score calculation for Single choice / True or False questions and Multiple answer questions separately. Then all three methods have been moved to student_quizzes_helper.rb file since they are being reused. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&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;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
Follow these instructions to manually test the functionality of student_quizzes_controller.&amp;lt;br&amp;gt;&lt;br /&gt;
'''1'''. Login as instructor using the credentials, username: instructor6, password: password.&amp;lt;br&amp;gt;&lt;br /&gt;
'''2'''. Select the '''Assignments''' subheading. Here, create a new assignment by entering the necessary details. Enable the '''Has Teams?''' checkbox and create. Also enable the '''Has quiz?''' checkbox.&amp;lt;br&amp;gt;&lt;br /&gt;
'''3'''. Navigate to the Due Dates tab and set appropriate due dates for submission and review. For Round 1: Review, enable Has Quiz using the dropdown Menu. Once you save, A '''Number of Quiz questions''' field will be visible on the Assignments page. Set this to 2 and save.&amp;lt;br&amp;gt;&lt;br /&gt;
'''4'''. At the top of the page, there will be a notice asking you to add participants. Using the link provided, add a few students to the assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
'''5'''. Logout as the Instructor and Login as the students. Make submissions for the assignment before the submission deadline. &amp;lt;br&amp;gt;&lt;br /&gt;
Note: You must create a team and set team name to be able to make a submission.&amp;lt;br&amp;gt;&lt;br /&gt;
'''6'''. At the bottom of the submission page, you will see a '''Create a Quiz''' link. Select that link.&amp;lt;br&amp;gt;&lt;br /&gt;
'''7'''. This takes you to the quiz creation page. Here you can set Radio Button MCQs, Checkbox MCQs and True/False Questions and set the correct answers.&amp;lt;br&amp;gt;&lt;br /&gt;
Then select '''Create Quiz'''. This creates the quiz.&amp;lt;br&amp;gt;&lt;br /&gt;
'''8'''. Logout and login as another student registered in the assignment. Make a submission as this student. Once the submission deadline has passed, review the first student's work and return to the main menu. &amp;lt;br&amp;gt;&lt;br /&gt;
'''9'''. You will see the option to '''Take quizzes'''. Here, select the quiz you have created and select '''Request'''. Here, you can take the quiz created by the other student.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing Walkthorugh===&lt;br /&gt;
&lt;br /&gt;
===Testing Video===&lt;br /&gt;
Originally the student_quizzes_controller did not have any test cases, so according to the documentation, we wrote some to check if the changes we introduced have broken the functionality. Our test cases have run successfully. Here is the video for the same. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[https://drive.google.com/file/d/1Kl8f71sylFVBIKymvjWN9A_69jbwoDdP/view?usp=sharing Test Video link]&lt;br /&gt;
&lt;br /&gt;
==Team members==&lt;br /&gt;
Jyothi Sumer Goud Maduru (jmaduru@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Pradyumna Vemuri (pvemuri@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Karthik Narayanan Gopala Sundaresan (kgopala3@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Team Mentor==&lt;br /&gt;
Divyang Doshi (ddoshi2@ncsu.edu)&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143765</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143765"/>
		<updated>2022-03-28T02:03:48Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* Testing Video */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as the DRY principle. There are a few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments need to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. app/controllers/'''student_quizzes_controller.rb''' &amp;lt;br&amp;gt;2. app/views/student_quizzes/f'''inished_quiz.html''' &amp;lt;br&amp;gt;3. app/helpers/'''student_quizzes_helper.rb'''&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
def self.take_quiz(assignment_id, reviewer_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
def record_response&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
def review_questions&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
# Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
def calculate_score(map, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions since the original method is too big and is split to use the other methods to handle score calculation for Single choice / True or False questions and Multiple answer questions separately. Then all three methods have been moved to student_quizzes_helper.rb file since they are being reused. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&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;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
Follow these instructions to manually test the functionality of student_quizzes_controller.&amp;lt;br&amp;gt;&lt;br /&gt;
'''1'''. Login as instructor using the credentials, username: instructor6, password: password.&amp;lt;br&amp;gt;&lt;br /&gt;
'''2'''. Select the '''Assignments''' subheading. Here, create a new assignment by entering the necessary details. Enable the '''Has Teams?''' checkbox and create. Also enable the '''Has quiz?''' checkbox.&amp;lt;br&amp;gt;&lt;br /&gt;
'''3'''. Navigate to the Due Dates tab and set appropriate due dates for submission and review. For Round 1: Review, enable Has Quiz using the dropdown Menu. Once you save, A '''Number of Quiz questions''' field will be visible on the Assignments page. Set this to 2 and save.&amp;lt;br&amp;gt;&lt;br /&gt;
'''4'''. At the top of the page, there will be a notice asking you to add participants. Using the link provided, add a few students to the assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
'''5'''. Logout as the Instructor and Login as the students. Make submissions for the assignment before the submission deadline. &amp;lt;br&amp;gt;&lt;br /&gt;
Note: You must create a team and set team name to be able to make a submission.&amp;lt;br&amp;gt;&lt;br /&gt;
'''6'''. At the bottom of the submission page, you will see a '''Create a Quiz''' link. Select that link.&amp;lt;br&amp;gt;&lt;br /&gt;
'''7'''. This takes you to the quiz creation page. Here you can set Radio Button MCQs, Checkbox MCQs and True/False Questions and set the correct answers.&amp;lt;br&amp;gt;&lt;br /&gt;
Then select '''Create Quiz'''. This creates the quiz.&amp;lt;br&amp;gt;&lt;br /&gt;
'''8'''. Logout and login as another student registered in the assignment. Make a submission as this student. Once the submission deadline has passed, review the first student's work and return to the main menu. &amp;lt;br&amp;gt;&lt;br /&gt;
'''9'''. You will see the option to '''Take quizzes'''. Here, select the quiz you have created and select '''Request'''. Here, you can take the quiz created by the other student.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing Walkthorugh===&lt;br /&gt;
&lt;br /&gt;
===Testing Video===&lt;br /&gt;
Originally the student_quizzes_controller does not have any test cases, so according to the documentation, we wrote some to check if the changes we introduced have broken the functionality. Our test cases have run successfully. Here is the video for the same. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[https://drive.google.com/file/d/1Kl8f71sylFVBIKymvjWN9A_69jbwoDdP/view?usp=sharing Test Video link]&lt;br /&gt;
&lt;br /&gt;
==Team members==&lt;br /&gt;
Jyothi Sumer Goud Maduru (jmaduru@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Pradyumna Vemuri (pvemuri@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Karthik Narayanan Gopala Sundaresan (kgopala3@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Team Mentor==&lt;br /&gt;
Divyang Doshi (ddoshi2@ncsu.edu)&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143764</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143764"/>
		<updated>2022-03-28T02:03:33Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* Testing Video */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as the DRY principle. There are a few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments need to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. app/controllers/'''student_quizzes_controller.rb''' &amp;lt;br&amp;gt;2. app/views/student_quizzes/f'''inished_quiz.html''' &amp;lt;br&amp;gt;3. app/helpers/'''student_quizzes_helper.rb'''&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
def self.take_quiz(assignment_id, reviewer_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
def record_response&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
def review_questions&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
# Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
def calculate_score(map, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions since the original method is too big and is split to use the other methods to handle score calculation for Single choice / True or False questions and Multiple answer questions separately. Then all three methods have been moved to student_quizzes_helper.rb file since they are being reused. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&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;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
Follow these instructions to manually test the functionality of student_quizzes_controller.&amp;lt;br&amp;gt;&lt;br /&gt;
'''1'''. Login as instructor using the credentials, username: instructor6, password: password.&amp;lt;br&amp;gt;&lt;br /&gt;
'''2'''. Select the '''Assignments''' subheading. Here, create a new assignment by entering the necessary details. Enable the '''Has Teams?''' checkbox and create. Also enable the '''Has quiz?''' checkbox.&amp;lt;br&amp;gt;&lt;br /&gt;
'''3'''. Navigate to the Due Dates tab and set appropriate due dates for submission and review. For Round 1: Review, enable Has Quiz using the dropdown Menu. Once you save, A '''Number of Quiz questions''' field will be visible on the Assignments page. Set this to 2 and save.&amp;lt;br&amp;gt;&lt;br /&gt;
'''4'''. At the top of the page, there will be a notice asking you to add participants. Using the link provided, add a few students to the assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
'''5'''. Logout as the Instructor and Login as the students. Make submissions for the assignment before the submission deadline. &amp;lt;br&amp;gt;&lt;br /&gt;
Note: You must create a team and set team name to be able to make a submission.&amp;lt;br&amp;gt;&lt;br /&gt;
'''6'''. At the bottom of the submission page, you will see a '''Create a Quiz''' link. Select that link.&amp;lt;br&amp;gt;&lt;br /&gt;
'''7'''. This takes you to the quiz creation page. Here you can set Radio Button MCQs, Checkbox MCQs and True/False Questions and set the correct answers.&amp;lt;br&amp;gt;&lt;br /&gt;
Then select '''Create Quiz'''. This creates the quiz.&amp;lt;br&amp;gt;&lt;br /&gt;
'''8'''. Logout and login as another student registered in the assignment. Make a submission as this student. Once the submission deadline has passed, review the first student's work and return to the main menu. &amp;lt;br&amp;gt;&lt;br /&gt;
'''9'''. You will see the option to '''Take quizzes'''. Here, select the quiz you have created and select '''Request'''. Here, you can take the quiz created by the other student.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing Walkthorugh===&lt;br /&gt;
&lt;br /&gt;
===Testing Video===&lt;br /&gt;
Originally the student_quizzes_controller does not have any test cases, so according to the documentation, we wrote some to check if the changes we introduced have broken the functionality. Our test cases have run successfully. Here is the video for the same. &amp;lt;br&amp;gt; &lt;br /&gt;
[https://drive.google.com/file/d/1Kl8f71sylFVBIKymvjWN9A_69jbwoDdP/view?usp=sharing Test Video link]&lt;br /&gt;
&lt;br /&gt;
==Team members==&lt;br /&gt;
Jyothi Sumer Goud Maduru (jmaduru@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Pradyumna Vemuri (pvemuri@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Karthik Narayanan Gopala Sundaresan (kgopala3@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Team Mentor==&lt;br /&gt;
Divyang Doshi (ddoshi2@ncsu.edu)&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143763</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143763"/>
		<updated>2022-03-28T02:02:59Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* Testing Video */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as the DRY principle. There are a few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments need to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. app/controllers/'''student_quizzes_controller.rb''' &amp;lt;br&amp;gt;2. app/views/student_quizzes/f'''inished_quiz.html''' &amp;lt;br&amp;gt;3. app/helpers/'''student_quizzes_helper.rb'''&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
def self.take_quiz(assignment_id, reviewer_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
def record_response&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
def review_questions&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
# Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
def calculate_score(map, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions since the original method is too big and is split to use the other methods to handle score calculation for Single choice / True or False questions and Multiple answer questions separately. Then all three methods have been moved to student_quizzes_helper.rb file since they are being reused. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&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;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
Follow these instructions to manually test the functionality of student_quizzes_controller.&amp;lt;br&amp;gt;&lt;br /&gt;
'''1'''. Login as instructor using the credentials, username: instructor6, password: password.&amp;lt;br&amp;gt;&lt;br /&gt;
'''2'''. Select the '''Assignments''' subheading. Here, create a new assignment by entering the necessary details. Enable the '''Has Teams?''' checkbox and create. Also enable the '''Has quiz?''' checkbox.&amp;lt;br&amp;gt;&lt;br /&gt;
'''3'''. Navigate to the Due Dates tab and set appropriate due dates for submission and review. For Round 1: Review, enable Has Quiz using the dropdown Menu. Once you save, A '''Number of Quiz questions''' field will be visible on the Assignments page. Set this to 2 and save.&amp;lt;br&amp;gt;&lt;br /&gt;
'''4'''. At the top of the page, there will be a notice asking you to add participants. Using the link provided, add a few students to the assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
'''5'''. Logout as the Instructor and Login as the students. Make submissions for the assignment before the submission deadline. &amp;lt;br&amp;gt;&lt;br /&gt;
Note: You must create a team and set team name to be able to make a submission.&amp;lt;br&amp;gt;&lt;br /&gt;
'''6'''. At the bottom of the submission page, you will see a '''Create a Quiz''' link. Select that link.&amp;lt;br&amp;gt;&lt;br /&gt;
'''7'''. This takes you to the quiz creation page. Here you can set Radio Button MCQs, Checkbox MCQs and True/False Questions and set the correct answers.&amp;lt;br&amp;gt;&lt;br /&gt;
Then select '''Create Quiz'''. This creates the quiz.&amp;lt;br&amp;gt;&lt;br /&gt;
'''8'''. Logout and login as another student registered in the assignment. Make a submission as this student. Once the submission deadline has passed, review the first student's work and return to the main menu. &amp;lt;br&amp;gt;&lt;br /&gt;
'''9'''. You will see the option to '''Take quizzes'''. Here, select the quiz you have created and select '''Request'''. Here, you can take the quiz created by the other student.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing Walkthorugh===&lt;br /&gt;
&lt;br /&gt;
===Testing Video===&lt;br /&gt;
Originally the student_quizzes_controller does not have any test cases, so according to the documentation, we wrote some to check if the changes we introduced have broken the functionality. Our test cases have run successfully. Here is the video for the same. &amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;iframe src=&amp;quot;https://drive.google.com/file/d/1Kl8f71sylFVBIKymvjWN9A_69jbwoDdP/preview&amp;quot; width=&amp;quot;640&amp;quot; height=&amp;quot;480&amp;quot; allow=&amp;quot;autoplay&amp;quot;&amp;gt;&amp;lt;/iframe&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team members==&lt;br /&gt;
Jyothi Sumer Goud Maduru (jmaduru@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Pradyumna Vemuri (pvemuri@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Karthik Narayanan Gopala Sundaresan (kgopala3@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Team Mentor==&lt;br /&gt;
Divyang Doshi (ddoshi2@ncsu.edu)&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143760</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143760"/>
		<updated>2022-03-28T01:59:07Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* Testing Video */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as the DRY principle. There are a few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments need to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. app/controllers/'''student_quizzes_controller.rb''' &amp;lt;br&amp;gt;2. app/views/student_quizzes/f'''inished_quiz.html''' &amp;lt;br&amp;gt;3. app/helpers/'''student_quizzes_helper.rb'''&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
def self.take_quiz(assignment_id, reviewer_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
def record_response&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
def review_questions&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
# Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
def calculate_score(map, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions since the original method is too big and is split to use the other methods to handle score calculation for Single choice / True or False questions and Multiple answer questions separately. Then all three methods have been moved to student_quizzes_helper.rb file since they are being reused. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&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;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
Follow these instructions to manually test the functionality of student_quizzes_controller.&amp;lt;br&amp;gt;&lt;br /&gt;
'''1'''. Login as instructor using the credentials, username: instructor6, password: password.&amp;lt;br&amp;gt;&lt;br /&gt;
'''2'''. Select the '''Assignments''' subheading. Here, create a new assignment by entering the necessary details. Enable the '''Has Teams?''' checkbox and create. Also enable the '''Has quiz?''' checkbox.&amp;lt;br&amp;gt;&lt;br /&gt;
'''3'''. Navigate to the Due Dates tab and set appropriate due dates for submission and review. For Round 1: Review, enable Has Quiz using the dropdown Menu. Once you save, A '''Number of Quiz questions''' field will be visible on the Assignments page. Set this to 2 and save.&amp;lt;br&amp;gt;&lt;br /&gt;
'''4'''. At the top of the page, there will be a notice asking you to add participants. Using the link provided, add a few students to the assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
'''5'''. Logout as the Instructor and Login as the students. Make submissions for the assignment before the submission deadline. &amp;lt;br&amp;gt;&lt;br /&gt;
Note: You must create a team and set team name to be able to make a submission.&amp;lt;br&amp;gt;&lt;br /&gt;
'''6'''. At the bottom of the submission page, you will see a '''Create a Quiz''' link. Select that link.&amp;lt;br&amp;gt;&lt;br /&gt;
'''7'''. This takes you to the quiz creation page. Here you can set Radio Button MCQs, Checkbox MCQs and True/False Questions and set the correct answers.&amp;lt;br&amp;gt;&lt;br /&gt;
Then select '''Create Quiz'''. This creates the quiz.&amp;lt;br&amp;gt;&lt;br /&gt;
'''8'''. Logout and login as another student registered in the assignment. Make a submission as this student. Once the submission deadline has passed, review the first student's work and return to the main menu. &amp;lt;br&amp;gt;&lt;br /&gt;
'''9'''. You will see the option to '''Take quizzes'''. Here, select the quiz you have created and select '''Request'''. Here, you can take the quiz created by the other student.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing Walkthorugh===&lt;br /&gt;
&lt;br /&gt;
===Testing Video===&lt;br /&gt;
Originally the student_quizzes_controller does not have any test cases, so according to the documentation, we wrote some to check if the changes we introduced have broken the functionality. Our test cases have run successfully. Here is the video for the same. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[https://drive.google.com/file/d/1Kl8f71sylFVBIKymvjWN9A_69jbwoDdP/view?usp=sharing Test Video]&lt;br /&gt;
&lt;br /&gt;
==Team members==&lt;br /&gt;
Jyothi Sumer Goud Maduru (jmaduru@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Pradyumna Vemuri (pvemuri@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Karthik Narayanan Gopala Sundaresan (kgopala3@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Team Mentor==&lt;br /&gt;
Divyang Doshi (ddoshi2@ncsu.edu)&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143616</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143616"/>
		<updated>2022-03-27T22:12:38Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as the DRY principle. There are a few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments need to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. app/controllers/'''student_quizzes_controller.rb''' &amp;lt;br&amp;gt;2. app/views/student_quizzes/f'''inished_quiz.html''' &amp;lt;br&amp;gt;3. app/helpers/'''student_quizzes_helper.rb'''&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
def self.take_quiz(assignment_id, reviewer_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
def record_response&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
def review_questions&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
# Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
def calculate_score(map, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions since the original method is too big and is split to use the other methods to handle score calculation for Single choice / True or False questions and Multiple answer questions separately. Then all three methods have been moved to student_quizzes_helper.rb file since they are being reused. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&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;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
Follow these instructions to manually test the functionality of student_quizzes_controller.&amp;lt;br&amp;gt;&lt;br /&gt;
'''1'''. Login as instructor using the credentials, username: instructor6, password: password.&amp;lt;br&amp;gt;&lt;br /&gt;
'''2'''. Select the '''Assignments''' subheading. Here, create a new assignment by entering the necessary details. Enable the '''Has Teams?''' checkbox and create. Also enable the '''Has quiz?''' checkbox.&amp;lt;br&amp;gt;&lt;br /&gt;
'''3'''. Navigate to the Due Dates tab and set appropriate due dates for submission and review. For Round 1: Review, enable Has Quiz using the dropdown Menu. Once you save, A '''Number of Quiz questions''' field will be visible on the Assignments page. Set this to 2 and save.&amp;lt;br&amp;gt;&lt;br /&gt;
'''4'''. At the top of the page, there will be a notice asking you to add participants. Using the link provided, add a few students to the assignment.&amp;lt;br&amp;gt;&lt;br /&gt;
'''5'''. Logout as the Instructor and Login as the students. Make submissions for the assignment before the submission deadline. &amp;lt;br&amp;gt;&lt;br /&gt;
Note: You must create a team and set team name to be able to make a submission.&amp;lt;br&amp;gt;&lt;br /&gt;
'''6'''. At the bottom of the submission page, you will see a '''Create a Quiz''' link. Select that link.&amp;lt;br&amp;gt;&lt;br /&gt;
'''7'''. This takes you to the quiz creation page. Here you can set Radio Button MCQs, Checkbox MCQs and True/False Questions and set the correct answers.&amp;lt;br&amp;gt;&lt;br /&gt;
Then select '''Create Quiz'''. This creates the quiz.&amp;lt;br&amp;gt;&lt;br /&gt;
'''8'''. Logout and login as another student registered in the assignment. Make a submission as this student. Once the submission deadline has passed, review the first student's work and return to the main menu. &amp;lt;br&amp;gt;&lt;br /&gt;
'''9'''. You will see the option to '''Take quizzes'''. Here, select the quiz you have created and select '''Request'''. Here, you can take the quiz created by the other student.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing Walkthorugh===&lt;br /&gt;
&lt;br /&gt;
===Testing Video===&lt;br /&gt;
&lt;br /&gt;
==Team members==&lt;br /&gt;
Jyothi Sumer Goud Maduru (jmaduru@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Pradyumna Vemuri (pvemuri@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Karthik Narayanan Gopala Sundaresan (kgopala3@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Team Mentor==&lt;br /&gt;
Divyang Doshi (ddoshi2@ncsu.edu)&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143469</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143469"/>
		<updated>2022-03-22T01:24:56Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* Team members */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as the DRY principle. There are a few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments need to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. app/controllers/'''student_quizzes_controller.rb''' &amp;lt;br&amp;gt;2. app/views/student_quizzes/f'''inished_quiz.html''' &amp;lt;br&amp;gt;3. app/helpers/'''student_quizzes_helper.rb'''&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
def self.take_quiz(assignment_id, reviewer_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
def record_response&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
def review_questions&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
# Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
def calculate_score(map, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions since the original method is too big and is split to use the other methods to handle score calculation for Single choice / True or False questions and Multiple answer questions separately. Then all three methods have been moved to student_quizzes_helper.rb file since they are being reused. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&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;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team members==&lt;br /&gt;
Jyothi Sumer Goud Maduru (jmaduru@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Pradyumna Vemuri (pvemuri@ncsu.edu)&amp;lt;br&amp;gt;&lt;br /&gt;
Karthik Narayanan Gopala Sundaresan (kgopala3@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Team Mentor==&lt;br /&gt;
Divyang Doshi (ddoshi2@ncsu.edu)&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143468</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143468"/>
		<updated>2022-03-22T01:24:40Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as the DRY principle. There are a few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments need to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. app/controllers/'''student_quizzes_controller.rb''' &amp;lt;br&amp;gt;2. app/views/student_quizzes/f'''inished_quiz.html''' &amp;lt;br&amp;gt;3. app/helpers/'''student_quizzes_helper.rb'''&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
def self.take_quiz(assignment_id, reviewer_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
def record_response&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
def review_questions&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
# Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
def calculate_score(map, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions since the original method is too big and is split to use the other methods to handle score calculation for Single choice / True or False questions and Multiple answer questions separately. Then all three methods have been moved to student_quizzes_helper.rb file since they are being reused. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&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;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Team members==&lt;br /&gt;
Jyothi Sumer Goud Maduru (jmaduru@ncsu.edu)&lt;br /&gt;
Pradyumna Vemuri (pvemuri@ncsu.edu)&lt;br /&gt;
Karthik Narayanan Gopala Sundaresan (kgopala3@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Team Mentor==&lt;br /&gt;
Divyang Doshi (ddoshi2@ncsu.edu)&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143441</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143441"/>
		<updated>2022-03-22T00:49:05Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as the DRY principle. There are a few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments need to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. app/controllers/'''student_quizzes_controller.rb''' &amp;lt;br&amp;gt;2. app/views/student_quizzes/f'''inished_quiz.html''' &amp;lt;br&amp;gt;3. app/helpers/'''student_quizzes_helper.rb'''&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
def self.take_quiz(assignment_id, reviewer_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
def record_response&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
def review_questions&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
# Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
def calculate_score(map, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions since the original method is too big and is split to use the other methods to handle score calculation for Single choice / True or False questions and Multiple answer questions separately. Then all three methods have been moved to student_quizzes_helper.rb file since they are being reused. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&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;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tests on the Controller Methods==&lt;br /&gt;
&lt;br /&gt;
==Video on changes made==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143437</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143437"/>
		<updated>2022-03-22T00:41:17Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as the DRY principle. There are a few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments need to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. app/controllers/'''student_quizzes_controller.rb''' &amp;lt;br&amp;gt;2. app/views/student_quizzes/f'''inished_quiz.html''' &amp;lt;br&amp;gt;3. app/helpers/'''student_quizzes_helper.rb'''&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
def self.take_quiz(assignment_id, reviewer_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
def record_response&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
def review_questions&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
# Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
def calculate_score(map, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions since the original method is too big and is split to use the other methods to handle score calculation for Single choice / True or False questions and Multiple answer questions separately. Then all three methods have been moved to student_quizzes_helper.rb file since they are being reused. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&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;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tests on the Controller Methods==&lt;br /&gt;
&lt;br /&gt;
==Video on changes made==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143424</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143424"/>
		<updated>2022-03-22T00:28:43Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as the DRY principle. There are a few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments need to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. app/controllers/'''student_quizzes_controller.rb''' &amp;lt;br&amp;gt;2. app/views/student_quizzes/f'''inished_quiz.html''' &amp;lt;br&amp;gt;3. app/helpers/'''student_quizzes_helper.rb'''&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
def self.take_quiz(assignment_id, reviewer_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
def record_response&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
def review_questions&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
# Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
def calculate_score(map, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions and has been moved to student_quizzes_helper.rb. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tests on the Controller Methods==&lt;br /&gt;
&lt;br /&gt;
==Video on changes made==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143419</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143419"/>
		<updated>2022-03-22T00:25:46Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as DRY principle. There are few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments needs to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. student_quizzes_controller.rb &amp;lt;br&amp;gt;2. finished_quiz.html &amp;lt;br&amp;gt;3. student_quizzes_helper.rb&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
def self.take_quiz(assignment_id, reviewer_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
def record_response&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
def review_questions&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
# Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
def calculate_score(map, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions and has been moved to student_quizzes_helper.rb. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tests on the Controller Methods==&lt;br /&gt;
&lt;br /&gt;
==Video on changes made==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143416</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143416"/>
		<updated>2022-03-22T00:24:36Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as DRY principle. There are few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments needs to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. student_quizzes_controller.rb &amp;lt;br&amp;gt;2. finished_quiz.html &amp;lt;br&amp;gt;3. student_quizzes_helper.rb&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
def self.take_quiz(assignment_id, reviewer_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
def record_response&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
def review_questions&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
# Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
def calculate_score(map, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Evaluates scores for questions that contains multiple answers&lt;br /&gt;
def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions and has been moved to student_quizzes_helper.rb. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tests on the Controller Methods==&lt;br /&gt;
&lt;br /&gt;
==Video on changes made==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143401</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143401"/>
		<updated>2022-03-22T00:11:58Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as DRY principle. There are few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments needs to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. student_quizzes_controller.rb &amp;lt;br&amp;gt;2. finished_quiz.html &amp;lt;br&amp;gt;3. student_quizzes_helper.rb&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Initializes instance variables needed to fetch the necessary details of the quizzes.&lt;br /&gt;
def index&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For the response provided, this methods displays the questions, right/wrong answers and the final score.&lt;br /&gt;
def finished_quiz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions and has been moved to student_quizzes_helper.rb. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tests on the Controller Methods==&lt;br /&gt;
&lt;br /&gt;
==Video on changes made==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143399</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143399"/>
		<updated>2022-03-22T00:10:42Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as DRY principle. There are few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments needs to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Modified==&lt;br /&gt;
1. student_quizzes_controller.rb &amp;lt;br&amp;gt;2. finished_quiz.html &amp;lt;br&amp;gt;3. student_quizzes_helper.rb&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Added comments for custom methods in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Based on the logged in user, verifies user's authourizations and privileges&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''2. Modification - ''' Line 29  - .first has been changed to .last to count the score of the most recent attempt of the quiz. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@response = Response.where(map_id: params[:map_id]).last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''3. Modification - ''' Line 33  - @map has been renamed to @quiz_response_map to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@quiz_response_map = ResponseMap.find(params[:map_id])&lt;br /&gt;
@quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''4. Modification - ''' Line 34  - @participant has been changed to @quiz_taker to more accurately describe its function. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@participant = AssignmentTeam.find(@map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
quiz_taker = AssignmentTeam.find(@quiz_response_map.reviewee_id).participants.first&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
finished_quiz.html.erb:&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@participant.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @participant, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%  @assignment = Assignment.find(@quiz_taker.parent_id)%&amp;gt;&lt;br /&gt;
&amp;lt;%= render :partial =&amp;gt; 'submitted_content/main', :locals =&amp;gt; {:participant =&amp;gt; @quiz_taker, :stage =&amp;gt; &amp;quot;&amp;quot;} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''5. Modification - ''' Line 39  - The method comment of self.take_quiz has been updated to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Gives details of the list of quizzes created by other teams for current project that a reviewer can take&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Lists all the available quizzes created by the other teams in the current project which can be attempted.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''6. Modification - ''' Controller Method calculate_score has been split into three separate functions and has been moved to student_quizzes_helper.rb. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_helper.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module StudentQuizzesHelper&lt;br /&gt;
&lt;br /&gt;
  # This method as whole fetches the answers provided and calculates the final scores for the quiz.&lt;br /&gt;
  # Also calls seperate methods for handling single answer/ true or false evaluations and mulitple answer evaluations for calculating score.&lt;br /&gt;
  def calculate_score(map, response)&lt;br /&gt;
    questionnaire = Questionnaire.find(map.reviewed_object_id)&lt;br /&gt;
    answers = []&lt;br /&gt;
    has_response = true&lt;br /&gt;
    questions = Question.where(questionnaire_id: questionnaire.id)&lt;br /&gt;
    questions.each do |question|&lt;br /&gt;
      correct_answers = QuizQuestionChoice.where(question_id: question.id, iscorrect: true)&lt;br /&gt;
      ques_type = question.type&lt;br /&gt;
      if ques_type.eql? 'MultipleChoiceCheckbox'&lt;br /&gt;
        has_response = multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      # TrueFalse and MultipleChoiceRadio&lt;br /&gt;
      else&lt;br /&gt;
        has_response = single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if has_response&lt;br /&gt;
      answers.each(&amp;amp;:save)&lt;br /&gt;
      redirect_to controller: 'student_quizzes', action: 'finished_quiz', map_id: map.id&lt;br /&gt;
    else&lt;br /&gt;
      response.destroy&lt;br /&gt;
      flash[:error] = 'Please answer every question.'&lt;br /&gt;
      redirect_to action: :take_quiz, assignment_id: params[:assignment_id], questionnaire_id: questionnaire.id, map_id: map.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains multiple answers&lt;br /&gt;
  def multiple_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    score = 0&lt;br /&gt;
    if params[question.id.to_s].nil?&lt;br /&gt;
        has_response = false&lt;br /&gt;
      else&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          # loop the quiz taker's choices and see if 1)all the correct choice are checked and 2) # of quiz taker's choice matches the # of the correct choices&lt;br /&gt;
          correct_answers.each do |correct|&lt;br /&gt;
            score += 1 if choice.eql? correct.txt&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        score = score == correct_answers.count &amp;amp;&amp;amp; score == params[question.id.to_s].count ? 1 : 0&lt;br /&gt;
        # for MultipleChoiceCheckbox, score =1 means the quiz taker have done this question correctly, not just make select this choice correctly.&lt;br /&gt;
        params[question.id.to_s].each do |choice|&lt;br /&gt;
          new_answer = Answer.new comments: choice, question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
&lt;br /&gt;
          has_response = false unless new_answer.valid?&lt;br /&gt;
          answers.push(new_answer)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Evaluates scores for questions that contains only single/ true or false answers&lt;br /&gt;
  def single_answer_evaluation(answers, params, question, correct_answers, has_response, response)&lt;br /&gt;
    correct_answer = correct_answers.first&lt;br /&gt;
    score = correct_answer.txt == params[question.id.to_s] ? 1 : 0&lt;br /&gt;
    new_score = Answer.new comments: params[question.id.to_s], question_id: question.id, response_id: response.id, answer: score&lt;br /&gt;
    has_response = false if new_score.nil? || new_score.comments.nil? || new_score.comments.empty?&lt;br /&gt;
    answers.push(new_score)&lt;br /&gt;
    return has_response&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''7. Modification - ''' Line 60  - A method comment has been added for record_response to describe its function &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Stores the answers entered by the quiz taker and calculates the score based on the answers entered.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''8. Modification - ''' -graded? has been removed as it is no longer necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
'''9. Modification - ''' Line 72  - The Flash message has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz, below are the records for your response.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[:error] = 'You have already taken this quiz. Below are the responses of your previous attempt.'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''10. Modification - ''' Line 77  - The method comment for review_questions has been updated. &amp;lt;br&amp;gt;&lt;br /&gt;
student_quizzes_controller.rb:&amp;lt;br&amp;gt;&lt;br /&gt;
Old:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
New:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This method is only for quiz questionnaires, it is called when instructors click &amp;quot;view quiz questions&amp;quot; on the pop-up panel.&lt;br /&gt;
# Using the current assignment id parameter, fetches all the questions for each quiz and finally lists all the answers and scores for each submission.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tests on the Controller Methods==&lt;br /&gt;
&lt;br /&gt;
==Video on changes made==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143011</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143011"/>
		<updated>2022-03-19T20:01:55Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as DRY principle. There are few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments needs to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Involved==&lt;br /&gt;
student_quizzes_controller.rb and &amp;lt;br&amp;gt;finished_quiz.html&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Add comments for custom method in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
'''2. Modification - ''' Line 24  - Shouldn’t .first really be .last?  If someone took the quiz multiple times, we wouldn’t want to count the first score. &amp;lt;br&amp;gt;&lt;br /&gt;
'''3. Modification - ''' Change the variables like @map on line 28 and use names which are intuitive for the purpose it serves &amp;lt;br&amp;gt;&lt;br /&gt;
'''4. Modification - ''' Line 28  - Shouldn’t @participant be @quiz_taker?  Also, this line of code seems to assume that only one person is on the team.  I think that’s the team that took the quiz, but is it perhaps the team whose quiz was taken?  This is not clear. &amp;lt;br&amp;gt;&lt;br /&gt;
'''5. Modification - ''' Line 34  -  For self.take_quiz, if the method comment is correct, the name of the method should be changed to something relating to what it does. Something like create_quiz.  However, what it does is not particularly clear. &amp;lt;br&amp;gt;&lt;br /&gt;
'''6. Modification - ''' calculate_score should be a model method, not a controller method. It has so much in common with calculating the score of other rubrics that the code should not be duplicated and separate methods for duplicated code should be generated. &amp;lt;br&amp;gt;&lt;br /&gt;
'''7. Modification - ''' Line 98 - record_response needs a method comment. &amp;lt;br&amp;gt;&lt;br /&gt;
'''8. Modification - ''' Line 108 calls the calculate_score method, which is going to change to something else in a current refactoring. &amp;lt;br&amp;gt;&lt;br /&gt;
'''9. Modification - ''' Line 110 - Fix the English in the message (no run-on sentence, what does “records” mean, etc.) &amp;lt;br&amp;gt;&lt;br /&gt;
'''10. Modification - ''' Line 119 - If the method is only for quiz_questionnaires, then why isn’t it in quiz_questionnaire.rb?? Method comment on review_questions does not say what the method does. Write a comment explaining how the method achieves the task instead of what task it achieves. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tests on the Controller Methods==&lt;br /&gt;
&lt;br /&gt;
==Video on changes made==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143010</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143010"/>
		<updated>2022-03-19T20:01:17Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* Modifications made to the existing code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as DRY principle. There are few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments needs to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Involved==&lt;br /&gt;
student_quizzes_controller.rb and &amp;lt;br&amp;gt;finished_quiz.html&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
'''1. Modification - ''' Add comments for custom method in this controller explaining the purpose. &amp;lt;br&amp;gt;&lt;br /&gt;
'''2. Modification - ''' Line 24  - Shouldn’t .first really be .last?  If someone took the quiz multiple times, we wouldn’t want to count the first score. &amp;lt;br&amp;gt;&lt;br /&gt;
'''3. Modification - ''' Change the variables like @map on line 28 and use names which are intuitive for the purpose it serves &amp;lt;br&amp;gt;&lt;br /&gt;
'''4. Modification - ''' Line 28  - Shouldn’t @participant be @quiz_taker?  Also, this line of code seems to assume that only one person is on the team.  I think that’s the team that took the quiz, but is it perhaps the team whose quiz was taken?  This is not clear. &amp;lt;br&amp;gt;&lt;br /&gt;
'''5. Modification - ''' Line 34  -  For self.take_quiz, if the method comment is correct, the name of the method should be changed to something relating to what it does. Something like create_quiz.  However, what it does is not particularly clear. &amp;lt;br&amp;gt;&lt;br /&gt;
'''6. Modification - ''' calculate_score should be a model method, not a controller method. It has so much in common with calculating the score of other rubrics that the code should not be duplicated and separate methods for duplicated code should be generated. &amp;lt;br&amp;gt;&lt;br /&gt;
'''7. Modification - ''' Line 98 - record_response needs a method comment. &amp;lt;br&amp;gt;&lt;br /&gt;
'''8. Modification - ''' Line 108 calls the calculate_score method, which is going to change to something else in a current refactoring. &amp;lt;br&amp;gt;&lt;br /&gt;
'''9. Modification - ''' Line 110 - Fix the English in the message (no run-on sentence, what does “records” mean, etc.) &amp;lt;br&amp;gt;&lt;br /&gt;
'''10. Modification - ''' Line 119 - If the method is only for quiz_questionnaires, then why isn’t it in quiz_questionnaire.rb?? Method comment on review_questions does not say what the method does. Write a comment explaining how the method achieves the task instead of what task it achieves. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tests on the Controller Methods==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143009</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143009"/>
		<updated>2022-03-19T19:53:36Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as DRY principle. There are few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments needs to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Files Involved==&lt;br /&gt;
student_quizzes_controller.rb and &amp;lt;br&amp;gt;finished_quiz.html&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
&lt;br /&gt;
==Tests on the Controller Methods==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143008</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143008"/>
		<updated>2022-03-19T19:53:14Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* Files Involved */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as DRY principle. There are few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments needs to be rewritten.&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
student_quizzes_controller.rb and &amp;lt;br&amp;gt;finished_quiz.html&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
&lt;br /&gt;
==Tests on the Controller Methods==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143007</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143007"/>
		<updated>2022-03-19T19:52:58Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as DRY principle. There are few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments needs to be rewritten.&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
student_quizzes_controller.rb and &amp;lt;br&amp;gt;finished_quiz.html&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
&lt;br /&gt;
==Tests on the Controller Methods==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143006</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143006"/>
		<updated>2022-03-19T16:52:13Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as DRY principle. There are few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments needs to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;br /&gt;
&lt;br /&gt;
==Tests on the Controller Methods==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143005</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143005"/>
		<updated>2022-03-19T16:51:38Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* Controller Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
The student_quizzes_controller 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 assignment. This controller has some issues that violate essential Rails design principles such as DRY principle. There are few methods in this controller that should have been in model classes.  Some methods share code, which creates code repetition. Some method comments needs to be rewritten.&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143004</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143004"/>
		<updated>2022-03-19T16:50:26Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* E2215. Refactoring student_quizzes_controller.rb in Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143003</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143003"/>
		<updated>2022-03-19T16:50:00Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* E2215. Refactoring student_quizzes_controller.rb in Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
'''Mentor''': Divyang Doshi (ddoshi2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143002</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143002"/>
		<updated>2022-03-19T16:49:49Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* E2215. Refactoring student_quizzes_controller.rb in Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
'''Mentor''': Divyang Doshi (ddoshi2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143001</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143001"/>
		<updated>2022-03-19T16:48:37Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* E2215. Refactoring student_quizzes_controller.rb in Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
This page is a description of Expertiza OSS project E2215, which is refactoring the student_quizzes_controller.rb file.&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143000</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=143000"/>
		<updated>2022-03-19T16:42:35Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in Expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [https://github.com/expertiza/expertiza Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=142999</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=142999"/>
		<updated>2022-03-19T16:42:05Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [[https://github.com/expertiza/expertiza] Expertiza].&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=142998</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=142998"/>
		<updated>2022-03-19T16:40:47Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is a multi-purpose web application built using Ruby on Rails for Students and Instructors. Instructors enrolled in expertiza can create and customize classes, teams, assignments, quizzes, and many more. On the other hand, Students are also allowed to form teams, attempt quizzes, and complete assignments. Apart from that, Expertiza also allows students to provide peer reviews enabling them to work together to improve others' learning experiences. It is an open-source application and its Github repository is [[https://github.com/expertiza/expertiza]]&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=142997</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=142997"/>
		<updated>2022-03-19T16:22:59Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;br /&gt;
&lt;br /&gt;
==Controller Description==&lt;br /&gt;
&lt;br /&gt;
==Modifications made to the existing code==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=142996</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=142996"/>
		<updated>2022-03-19T16:21:10Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
==E2215. Refactoring student_quizzes_controller.rb in Expertiza==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=142995</id>
		<title>CSC/ECE 517 Spring 2022 - E2215: Refactor student quizzes controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2215:_Refactor_student_quizzes_controller&amp;diff=142995"/>
		<updated>2022-03-19T16:20:28Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: Created page with &amp;quot;==About Expertiza==&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022&amp;diff=142994</id>
		<title>CSC/ECE 517 Spring 2022</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022&amp;diff=142994"/>
		<updated>2022-03-19T16:19:10Z</updated>

		<summary type="html">&lt;p&gt;Pvemuri: /* OSS Projects */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== OSS Projects ==&lt;br /&gt;
&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2203: Adding tests for courses_controller, eula_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2204: Adding tests for markup_styles_controller, lock_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2217: Refactor questionnaires_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2216: Refactor late_policies_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2215: Refactor student_quizzes_controller]]&lt;br /&gt;
&lt;br /&gt;
== Final Projects ==&lt;/div&gt;</summary>
		<author><name>Pvemuri</name></author>
	</entry>
</feed>