<?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=Tsattle</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=Tsattle"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Tsattle"/>
	<updated>2026-05-17T15:36:20Z</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_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133856</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133856"/>
		<updated>2020-04-24T17:41:52Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Database Schema */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1662/commits E1989] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages and the reason it was not integrated into expertiza was due to the amount of white space in commits and unsatisfactory commit messages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] is used, however small edits were made to provide clean code and a trackable commit history. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved, the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the spreadsheet below. We use '''map_id''' to join '''response_maps''' table for storing the primary information. '''Round''' contains an int variable associated with the specific round review, '''link''' contains a character string storing the external link the reviewer clicked on, '''start_at''' contains the starting time the external link was pressed, while '''end_at''' contains the time when the link was closed. &lt;br /&gt;
&lt;br /&gt;
[[File:Db_FINAL.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The highlight demonstrate which field correspond to response_maps key.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema_FINAL.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1989. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes were made:&lt;br /&gt;
&lt;br /&gt;
=== '''Files Created''' ===&lt;br /&gt;
&amp;lt;hr/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''controllers/submission_viewing_events_controller.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Creates a controller for handling events of submission viewing reviews. Created using rails 'generate controller' function.  Includes three methods&lt;br /&gt;
&lt;br /&gt;
# record_start_time :  function starts the time for links that have been visited by the user.&lt;br /&gt;
# record_end_time : records the end time for links that have been visited by the user.&lt;br /&gt;
# mark_end_time :  records the end time for links that have no end times.&lt;br /&gt;
&lt;br /&gt;
==== '''db/migrate/20200420201807_create_submission_viewing_events.rb''' ==== &lt;br /&gt;
&lt;br /&gt;
Migration file to create data table for handling log start and end time for each link/file in the review.  Created using rails 'generate model' function.  More info regarding schema is included in the Database section.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/index.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created a simple index page for viewing of submission events.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/edit.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created file to allow for editing capabilities of submission viewing events. &lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/_form.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created partial form that was used to fill in edit.html.haml file, as well as a few others.&lt;br /&gt;
&lt;br /&gt;
==== '''spec/controllers/submission_viewing_events_controller_spec.rb''' ==== &lt;br /&gt;
&lt;br /&gt;
Implemented test cases for created SubmissionViewingEventsController using Rspec as per expertiza standard.&lt;br /&gt;
&lt;br /&gt;
=== '''Files Edited''' ===&lt;br /&gt;
&amp;lt;hr/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''db/schema.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Updated to include the SubmissionViewingEvents model migration, as executed via a 'rake db:migrate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====  '''app/views/reports/_review_submissions_time_spent.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
&lt;br /&gt;
====  '''app/views/reports/_review_report.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/new.html.haml'''==== &lt;br /&gt;
&lt;br /&gt;
Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/show.html.haml'''==== &lt;br /&gt;
&lt;br /&gt;
Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
&lt;br /&gt;
==== '''app/helpers/submitted_content_helper.rb'''==== &lt;br /&gt;
&lt;br /&gt;
Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
&lt;br /&gt;
===='''app/views/popup/view_review_scores_popup.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Break up query in line 55 into two queries.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/reports/_review_submissions_time_spent.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Created a view for reports controller.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/reports/_review_report.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/_submitted_files.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Added JavaScript to this file which allows tracking of start and end times of accessing a hyperlink. Most functionality is on-click for tracking these times.&lt;br /&gt;
&lt;br /&gt;
==== '''config/routes.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Added collection for start and end times when hyperlink is accessed. Includes post and get calls for recording start and end times as necessary (see lines 420-428)&lt;br /&gt;
&lt;br /&gt;
==== '''app/controllers/response_controller.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Added field @current_round to file for tracking the current round of reviews for a student. See lines 83 and 267 for variable instantiation.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/view.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Edited to set submission check variable to false.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/response.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Edited to contain two functions to track start and end time or review. Added hidden field tags to form to track timeouts, as well as a submission check to ensure reviewer is still working on review.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submitted_content/_main.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Added checks for local assignment submissions, where if true a partial specifically for hyperlinks and submitted files are loaded. See lines 10-20 for specific changes.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submitted_content/_hyperlink.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Adds functionality to ensure that user must click on a hyperlink instead of copying and pasting the link. From line 41-end there is more JavaScript that marks start and end times for accessing these hyperlinks.&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/tree/E1989_Merge_Fixes E1989 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/expertiza/expertiza/pull/1728/commits Pull commits]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattler &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133855</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133855"/>
		<updated>2020-04-24T17:41:23Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Our Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1662/commits E1989] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages and the reason it was not integrated into expertiza was due to the amount of white space in commits and unsatisfactory commit messages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] is used, however small edits were made to provide clean code and a trackable commit history. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved, the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the spreadsheet below. We use map_id to join '''response_maps''' table for storing the primary information. '''Round''' contains an int variable associated with the specific round review, '''link''' contains a character string storing the external link the reviewer clicked on, '''start_at''' contains the starting time the external link was pressed, while '''end_at''' contains the time when the link was closed. &lt;br /&gt;
&lt;br /&gt;
[[File:Db_FINAL.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The highlight demonstrate which field correspond to response_maps key.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema_FINAL.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1989. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes were made:&lt;br /&gt;
&lt;br /&gt;
=== '''Files Created''' ===&lt;br /&gt;
&amp;lt;hr/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''controllers/submission_viewing_events_controller.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Creates a controller for handling events of submission viewing reviews. Created using rails 'generate controller' function.  Includes three methods&lt;br /&gt;
&lt;br /&gt;
# record_start_time :  function starts the time for links that have been visited by the user.&lt;br /&gt;
# record_end_time : records the end time for links that have been visited by the user.&lt;br /&gt;
# mark_end_time :  records the end time for links that have no end times.&lt;br /&gt;
&lt;br /&gt;
==== '''db/migrate/20200420201807_create_submission_viewing_events.rb''' ==== &lt;br /&gt;
&lt;br /&gt;
Migration file to create data table for handling log start and end time for each link/file in the review.  Created using rails 'generate model' function.  More info regarding schema is included in the Database section.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/index.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created a simple index page for viewing of submission events.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/edit.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created file to allow for editing capabilities of submission viewing events. &lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/_form.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created partial form that was used to fill in edit.html.haml file, as well as a few others.&lt;br /&gt;
&lt;br /&gt;
==== '''spec/controllers/submission_viewing_events_controller_spec.rb''' ==== &lt;br /&gt;
&lt;br /&gt;
Implemented test cases for created SubmissionViewingEventsController using Rspec as per expertiza standard.&lt;br /&gt;
&lt;br /&gt;
=== '''Files Edited''' ===&lt;br /&gt;
&amp;lt;hr/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''db/schema.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Updated to include the SubmissionViewingEvents model migration, as executed via a 'rake db:migrate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====  '''app/views/reports/_review_submissions_time_spent.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
&lt;br /&gt;
====  '''app/views/reports/_review_report.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/new.html.haml'''==== &lt;br /&gt;
&lt;br /&gt;
Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/show.html.haml'''==== &lt;br /&gt;
&lt;br /&gt;
Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
&lt;br /&gt;
==== '''app/helpers/submitted_content_helper.rb'''==== &lt;br /&gt;
&lt;br /&gt;
Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
&lt;br /&gt;
===='''app/views/popup/view_review_scores_popup.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Break up query in line 55 into two queries.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/reports/_review_submissions_time_spent.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Created a view for reports controller.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/reports/_review_report.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/_submitted_files.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Added JavaScript to this file which allows tracking of start and end times of accessing a hyperlink. Most functionality is on-click for tracking these times.&lt;br /&gt;
&lt;br /&gt;
==== '''config/routes.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Added collection for start and end times when hyperlink is accessed. Includes post and get calls for recording start and end times as necessary (see lines 420-428)&lt;br /&gt;
&lt;br /&gt;
==== '''app/controllers/response_controller.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Added field @current_round to file for tracking the current round of reviews for a student. See lines 83 and 267 for variable instantiation.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/view.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Edited to set submission check variable to false.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/response.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Edited to contain two functions to track start and end time or review. Added hidden field tags to form to track timeouts, as well as a submission check to ensure reviewer is still working on review.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submitted_content/_main.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Added checks for local assignment submissions, where if true a partial specifically for hyperlinks and submitted files are loaded. See lines 10-20 for specific changes.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submitted_content/_hyperlink.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Adds functionality to ensure that user must click on a hyperlink instead of copying and pasting the link. From line 41-end there is more JavaScript that marks start and end times for accessing these hyperlinks.&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/tree/E1989_Merge_Fixes E1989 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/expertiza/expertiza/pull/1728/commits Pull commits]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattler &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133854</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133854"/>
		<updated>2020-04-24T17:40:29Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Useful Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1662/commits E1989] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages and the reason it was not integrated into expertiza was due to the amount of white space in commits and unsatisfactory commit messages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] is used, however small edits were made to provide clean code and a trackable commit history. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved, the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the spreadsheet below. We use map_id to join '''response_maps''' table for storing the primary information. '''Round''' contains an int variable associated with the specific round review, '''link''' contains a character string storing the external link the reviewer clicked on, '''start_at''' contains the starting time the external link was pressed, while '''end_at''' contains the time when the link was closed. &lt;br /&gt;
&lt;br /&gt;
[[File:Db_FINAL.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The highlight demonstrate which field correspond to response_maps key.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema_FINAL.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1989. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes were made:&lt;br /&gt;
&lt;br /&gt;
=== '''Files Created''' ===&lt;br /&gt;
&amp;lt;hr/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''controllers/submission_viewing_events_controller.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Creates a controller for handling events of submission viewing reviews. Created using rails 'generate controller' function.  Includes three methods&lt;br /&gt;
&lt;br /&gt;
# record_start_time :  function starts the time for links that have been visited by the user.&lt;br /&gt;
# record_end_time : records the end time for links that have been visited by the user.&lt;br /&gt;
# mark_end_time :  records the end time for links that have no end times.&lt;br /&gt;
&lt;br /&gt;
==== '''db/migrate/20200420201807_create_submission_viewing_events.rb''' ==== &lt;br /&gt;
&lt;br /&gt;
Migration file to create data table for handling log start and end time for each link/file in the review.  Created using rails 'generate model' function.  More info regarding schema is included in the Database section.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/index.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created a simple index page for viewing of submission events.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/edit.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created file to allow for editing capabilities of submission viewing events. &lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/_form.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created partial form that was used to fill in edit.html.haml file, as well as a few others.&lt;br /&gt;
&lt;br /&gt;
==== '''spec/controllers/submission_viewing_events_controller_spec.rb''' ==== &lt;br /&gt;
&lt;br /&gt;
Implemented test cases for created SubmissionViewingEventsController using Rspec as per expertiza standard.&lt;br /&gt;
&lt;br /&gt;
=== '''Files Edited''' ===&lt;br /&gt;
&amp;lt;hr/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''db/schema.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Updated to include the SubmissionViewingEvents model migration, as executed via a 'rake db:migrate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====  '''app/views/reports/_review_submissions_time_spent.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
&lt;br /&gt;
====  '''app/views/reports/_review_report.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/new.html.haml'''==== &lt;br /&gt;
&lt;br /&gt;
Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/show.html.haml'''==== &lt;br /&gt;
&lt;br /&gt;
Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
&lt;br /&gt;
==== '''app/helpers/submitted_content_helper.rb'''==== &lt;br /&gt;
&lt;br /&gt;
Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
&lt;br /&gt;
===='''app/views/popup/view_review_scores_popup.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Break up query in line 55 into two queries.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/reports/_review_submissions_time_spent.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Created a view for reports controller.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/reports/_review_report.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/_submitted_files.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Added JavaScript to this file which allows tracking of start and end times of accessing a hyperlink. Most functionality is on-click for tracking these times.&lt;br /&gt;
&lt;br /&gt;
==== '''config/routes.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Added collection for start and end times when hyperlink is accessed. Includes post and get calls for recording start and end times as necessary (see lines 420-428)&lt;br /&gt;
&lt;br /&gt;
==== '''app/controllers/response_controller.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Added field @current_round to file for tracking the current round of reviews for a student. See lines 83 and 267 for variable instantiation.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/view.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Edited to set submission check variable to false.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/response.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Edited to contain two functions to track start and end time or review. Added hidden field tags to form to track timeouts, as well as a submission check to ensure reviewer is still working on review.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submitted_content/_main.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Added checks for local assignment submissions, where if true a partial specifically for hyperlinks and submitted files are loaded. See lines 10-20 for specific changes.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submitted_content/_hyperlink.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Adds functionality to ensure that user must click on a hyperlink instead of copying and pasting the link. From line 41-end there is more JavaScript that marks start and end times for accessing these hyperlinks.&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/tree/E1989_Merge_Fixes E1989 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattler &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133853</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133853"/>
		<updated>2020-04-24T17:37:48Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Instructor */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1662/commits E1989] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages and the reason it was not integrated into expertiza was due to the amount of white space in commits and unsatisfactory commit messages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] is used, however small edits were made to provide clean code and a trackable commit history. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved, the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the spreadsheet below. We use map_id to join '''response_maps''' table for storing the primary information. '''Round''' contains an int variable associated with the specific round review, '''link''' contains a character string storing the external link the reviewer clicked on, '''start_at''' contains the starting time the external link was pressed, while '''end_at''' contains the time when the link was closed. &lt;br /&gt;
&lt;br /&gt;
[[File:Db_FINAL.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The highlight demonstrate which field correspond to response_maps key.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema_FINAL.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1989. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes were made:&lt;br /&gt;
&lt;br /&gt;
=== '''Files Created''' ===&lt;br /&gt;
&amp;lt;hr/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''controllers/submission_viewing_events_controller.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Creates a controller for handling events of submission viewing reviews. Created using rails 'generate controller' function.  Includes three methods&lt;br /&gt;
&lt;br /&gt;
# record_start_time :  function starts the time for links that have been visited by the user.&lt;br /&gt;
# record_end_time : records the end time for links that have been visited by the user.&lt;br /&gt;
# mark_end_time :  records the end time for links that have no end times.&lt;br /&gt;
&lt;br /&gt;
==== '''db/migrate/20200420201807_create_submission_viewing_events.rb''' ==== &lt;br /&gt;
&lt;br /&gt;
Migration file to create data table for handling log start and end time for each link/file in the review.  Created using rails 'generate model' function.  More info regarding schema is included in the Database section.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/index.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created a simple index page for viewing of submission events.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/edit.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created file to allow for editing capabilities of submission viewing events. &lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/_form.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created partial form that was used to fill in edit.html.haml file, as well as a few others.&lt;br /&gt;
&lt;br /&gt;
==== '''spec/controllers/submission_viewing_events_controller_spec.rb''' ==== &lt;br /&gt;
&lt;br /&gt;
Implemented test cases for created SubmissionViewingEventsController using Rspec as per expertiza standard.&lt;br /&gt;
&lt;br /&gt;
=== '''Files Edited''' ===&lt;br /&gt;
&amp;lt;hr/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''db/schema.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Updated to include the SubmissionViewingEvents model migration, as executed via a 'rake db:migrate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====  '''app/views/reports/_review_submissions_time_spent.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
&lt;br /&gt;
====  '''app/views/reports/_review_report.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/new.html.haml'''==== &lt;br /&gt;
&lt;br /&gt;
Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/show.html.haml'''==== &lt;br /&gt;
&lt;br /&gt;
Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
&lt;br /&gt;
==== '''app/helpers/submitted_content_helper.rb'''==== &lt;br /&gt;
&lt;br /&gt;
Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
&lt;br /&gt;
===='''app/views/popup/view_review_scores_popup.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Break up query in line 55 into two queries.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/reports/_review_submissions_time_spent.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Created a view for reports controller.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/reports/_review_report.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/_submitted_files.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Added JavaScript to this file which allows tracking of start and end times of accessing a hyperlink. Most functionality is on-click for tracking these times.&lt;br /&gt;
&lt;br /&gt;
==== '''config/routes.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Added collection for start and end times when hyperlink is accessed. Includes post and get calls for recording start and end times as necessary (see lines 420-428)&lt;br /&gt;
&lt;br /&gt;
==== '''app/controllers/response_controller.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Added field @current_round to file for tracking the current round of reviews for a student. See lines 83 and 267 for variable instantiation.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/view.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Edited to set submission check variable to false.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/response.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Edited to contain two functions to track start and end time or review. Added hidden field tags to form to track timeouts, as well as a submission check to ensure reviewer is still working on review.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submitted_content/_main.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Added checks for local assignment submissions, where if true a partial specifically for hyperlinks and submitted files are loaded. See lines 10-20 for specific changes.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submitted_content/_hyperlink.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Adds functionality to ensure that user must click on a hyperlink instead of copying and pasting the link. From line 41-end there is more JavaScript that marks start and end times for accessing these hyperlinks.&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattler &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133852</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133852"/>
		<updated>2020-04-24T17:37:31Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Student */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1662/commits E1989] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages and the reason it was not integrated into expertiza was due to the amount of white space in commits and unsatisfactory commit messages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] is used, however small edits were made to provide clean code and a trackable commit history. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved, the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the spreadsheet below. We use map_id to join '''response_maps''' table for storing the primary information. '''Round''' contains an int variable associated with the specific round review, '''link''' contains a character string storing the external link the reviewer clicked on, '''start_at''' contains the starting time the external link was pressed, while '''end_at''' contains the time when the link was closed. &lt;br /&gt;
&lt;br /&gt;
[[File:Db_FINAL.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The highlight demonstrate which field correspond to response_maps key.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema_FINAL.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1989. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes were made:&lt;br /&gt;
&lt;br /&gt;
=== '''Files Created''' ===&lt;br /&gt;
&amp;lt;hr/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''controllers/submission_viewing_events_controller.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Creates a controller for handling events of submission viewing reviews. Created using rails 'generate controller' function.  Includes three methods&lt;br /&gt;
&lt;br /&gt;
# record_start_time :  function starts the time for links that have been visited by the user.&lt;br /&gt;
# record_end_time : records the end time for links that have been visited by the user.&lt;br /&gt;
# mark_end_time :  records the end time for links that have no end times.&lt;br /&gt;
&lt;br /&gt;
==== '''db/migrate/20200420201807_create_submission_viewing_events.rb''' ==== &lt;br /&gt;
&lt;br /&gt;
Migration file to create data table for handling log start and end time for each link/file in the review.  Created using rails 'generate model' function.  More info regarding schema is included in the Database section.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/index.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created a simple index page for viewing of submission events.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/edit.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created file to allow for editing capabilities of submission viewing events. &lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/_form.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created partial form that was used to fill in edit.html.haml file, as well as a few others.&lt;br /&gt;
&lt;br /&gt;
==== '''spec/controllers/submission_viewing_events_controller_spec.rb''' ==== &lt;br /&gt;
&lt;br /&gt;
Implemented test cases for created SubmissionViewingEventsController using Rspec as per expertiza standard.&lt;br /&gt;
&lt;br /&gt;
=== '''Files Edited''' ===&lt;br /&gt;
&amp;lt;hr/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''db/schema.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Updated to include the SubmissionViewingEvents model migration, as executed via a 'rake db:migrate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====  '''app/views/reports/_review_submissions_time_spent.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
&lt;br /&gt;
====  '''app/views/reports/_review_report.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/new.html.haml'''==== &lt;br /&gt;
&lt;br /&gt;
Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/show.html.haml'''==== &lt;br /&gt;
&lt;br /&gt;
Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
&lt;br /&gt;
==== '''app/helpers/submitted_content_helper.rb'''==== &lt;br /&gt;
&lt;br /&gt;
Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
&lt;br /&gt;
===='''app/views/popup/view_review_scores_popup.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Break up query in line 55 into two queries.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/reports/_review_submissions_time_spent.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Created a view for reports controller.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/reports/_review_report.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/_submitted_files.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Added JavaScript to this file which allows tracking of start and end times of accessing a hyperlink. Most functionality is on-click for tracking these times.&lt;br /&gt;
&lt;br /&gt;
==== '''config/routes.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Added collection for start and end times when hyperlink is accessed. Includes post and get calls for recording start and end times as necessary (see lines 420-428)&lt;br /&gt;
&lt;br /&gt;
==== '''app/controllers/response_controller.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Added field @current_round to file for tracking the current round of reviews for a student. See lines 83 and 267 for variable instantiation.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/view.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Edited to set submission check variable to false.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/response.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Edited to contain two functions to track start and end time or review. Added hidden field tags to form to track timeouts, as well as a submission check to ensure reviewer is still working on review.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submitted_content/_main.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Added checks for local assignment submissions, where if true a partial specifically for hyperlinks and submitted files are loaded. See lines 10-20 for specific changes.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submitted_content/_hyperlink.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Adds functionality to ensure that user must click on a hyperlink instead of copying and pasting the link. From line 41-end there is more JavaScript that marks start and end times for accessing these hyperlinks.&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattler &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133851</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133851"/>
		<updated>2020-04-24T17:35:53Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Student */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1662/commits E1989] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages and the reason it was not integrated into expertiza was due to the amount of white space in commits and unsatisfactory commit messages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://github.com/expertiza/expertiza/pull/1662/commits E1989] is used, however small edits were made to provide clean code and a trackable commit history. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved, the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the spreadsheet below. We use map_id to join '''response_maps''' table for storing the primary information. '''Round''' contains an int variable associated with the specific round review, '''link''' contains a character string storing the external link the reviewer clicked on, '''start_at''' contains the starting time the external link was pressed, while '''end_at''' contains the time when the link was closed. &lt;br /&gt;
&lt;br /&gt;
[[File:Db_FINAL.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The highlight demonstrate which field correspond to response_maps key.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema_FINAL.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1989. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes were made:&lt;br /&gt;
&lt;br /&gt;
=== '''Files Created''' ===&lt;br /&gt;
&amp;lt;hr/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''controllers/submission_viewing_events_controller.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Creates a controller for handling events of submission viewing reviews. Created using rails 'generate controller' function.  Includes three methods&lt;br /&gt;
&lt;br /&gt;
# record_start_time :  function starts the time for links that have been visited by the user.&lt;br /&gt;
# record_end_time : records the end time for links that have been visited by the user.&lt;br /&gt;
# mark_end_time :  records the end time for links that have no end times.&lt;br /&gt;
&lt;br /&gt;
==== '''db/migrate/20200420201807_create_submission_viewing_events.rb''' ==== &lt;br /&gt;
&lt;br /&gt;
Migration file to create data table for handling log start and end time for each link/file in the review.  Created using rails 'generate model' function.  More info regarding schema is included in the Database section.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/index.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created a simple index page for viewing of submission events.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/edit.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created file to allow for editing capabilities of submission viewing events. &lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/_form.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created partial form that was used to fill in edit.html.haml file, as well as a few others.&lt;br /&gt;
&lt;br /&gt;
==== '''spec/controllers/submission_viewing_events_controller_spec.rb''' ==== &lt;br /&gt;
&lt;br /&gt;
Implemented test cases for created SubmissionViewingEventsController using Rspec as per expertiza standard.&lt;br /&gt;
&lt;br /&gt;
=== '''Files Edited''' ===&lt;br /&gt;
&amp;lt;hr/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''db/schema.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Updated to include the SubmissionViewingEvents model migration, as executed via a 'rake db:migrate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====  '''app/views/reports/_review_submissions_time_spent.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
&lt;br /&gt;
====  '''app/views/reports/_review_report.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/new.html.haml'''==== &lt;br /&gt;
&lt;br /&gt;
Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/show.html.haml'''==== &lt;br /&gt;
&lt;br /&gt;
Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
&lt;br /&gt;
==== '''app/helpers/submitted_content_helper.rb'''==== &lt;br /&gt;
&lt;br /&gt;
Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
&lt;br /&gt;
===='''app/views/popup/view_review_scores_popup.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Break up query in line 55 into two queries.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/reports/_review_submissions_time_spent.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Created a view for reports controller.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/reports/_review_report.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/_submitted_files.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Added JavaScript to this file which allows tracking of start and end times of accessing a hyperlink. Most functionality is on-click for tracking these times.&lt;br /&gt;
&lt;br /&gt;
==== '''config/routes.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Added collection for start and end times when hyperlink is accessed. Includes post and get calls for recording start and end times as necessary (see lines 420-428)&lt;br /&gt;
&lt;br /&gt;
==== '''app/controllers/response_controller.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Added field @current_round to file for tracking the current round of reviews for a student. See lines 83 and 267 for variable instantiation.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/view.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Edited to set submission check variable to false.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/response.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Edited to contain two functions to track start and end time or review. Added hidden field tags to form to track timeouts, as well as a submission check to ensure reviewer is still working on review.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submitted_content/_main.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Added checks for local assignment submissions, where if true a partial specifically for hyperlinks and submitted files are loaded. See lines 10-20 for specific changes.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submitted_content/_hyperlink.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Adds functionality to ensure that user must click on a hyperlink instead of copying and pasting the link. From line 41-end there is more JavaScript that marks start and end times for accessing these hyperlinks.&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattler &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133850</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133850"/>
		<updated>2020-04-24T17:35:30Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Student */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1662/commits E1989] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages and the reason it was not integrated into expertiza was due to the amount of white space in commits and unsatisfactory commit messages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://github.com/expertiza/expertiza/pull/1662/commits E1989] is used, however small edits were made to provide clean code and a valuable commit history. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved, the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the spreadsheet below. We use map_id to join '''response_maps''' table for storing the primary information. '''Round''' contains an int variable associated with the specific round review, '''link''' contains a character string storing the external link the reviewer clicked on, '''start_at''' contains the starting time the external link was pressed, while '''end_at''' contains the time when the link was closed. &lt;br /&gt;
&lt;br /&gt;
[[File:Db_FINAL.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The highlight demonstrate which field correspond to response_maps key.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema_FINAL.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1989. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes were made:&lt;br /&gt;
&lt;br /&gt;
=== '''Files Created''' ===&lt;br /&gt;
&amp;lt;hr/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''controllers/submission_viewing_events_controller.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Creates a controller for handling events of submission viewing reviews. Created using rails 'generate controller' function.  Includes three methods&lt;br /&gt;
&lt;br /&gt;
# record_start_time :  function starts the time for links that have been visited by the user.&lt;br /&gt;
# record_end_time : records the end time for links that have been visited by the user.&lt;br /&gt;
# mark_end_time :  records the end time for links that have no end times.&lt;br /&gt;
&lt;br /&gt;
==== '''db/migrate/20200420201807_create_submission_viewing_events.rb''' ==== &lt;br /&gt;
&lt;br /&gt;
Migration file to create data table for handling log start and end time for each link/file in the review.  Created using rails 'generate model' function.  More info regarding schema is included in the Database section.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/index.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created a simple index page for viewing of submission events.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/edit.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created file to allow for editing capabilities of submission viewing events. &lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/_form.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created partial form that was used to fill in edit.html.haml file, as well as a few others.&lt;br /&gt;
&lt;br /&gt;
==== '''spec/controllers/submission_viewing_events_controller_spec.rb''' ==== &lt;br /&gt;
&lt;br /&gt;
Implemented test cases for created SubmissionViewingEventsController using Rspec as per expertiza standard.&lt;br /&gt;
&lt;br /&gt;
=== '''Files Edited''' ===&lt;br /&gt;
&amp;lt;hr/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''db/schema.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Updated to include the SubmissionViewingEvents model migration, as executed via a 'rake db:migrate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====  '''app/views/reports/_review_submissions_time_spent.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
&lt;br /&gt;
====  '''app/views/reports/_review_report.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/new.html.haml'''==== &lt;br /&gt;
&lt;br /&gt;
Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/show.html.haml'''==== &lt;br /&gt;
&lt;br /&gt;
Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
&lt;br /&gt;
==== '''app/helpers/submitted_content_helper.rb'''==== &lt;br /&gt;
&lt;br /&gt;
Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
&lt;br /&gt;
===='''app/views/popup/view_review_scores_popup.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Break up query in line 55 into two queries.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/reports/_review_submissions_time_spent.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Created a view for reports controller.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/reports/_review_report.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/_submitted_files.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Added JavaScript to this file which allows tracking of start and end times of accessing a hyperlink. Most functionality is on-click for tracking these times.&lt;br /&gt;
&lt;br /&gt;
==== '''config/routes.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Added collection for start and end times when hyperlink is accessed. Includes post and get calls for recording start and end times as necessary (see lines 420-428)&lt;br /&gt;
&lt;br /&gt;
==== '''app/controllers/response_controller.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Added field @current_round to file for tracking the current round of reviews for a student. See lines 83 and 267 for variable instantiation.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/view.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Edited to set submission check variable to false.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/response.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Edited to contain two functions to track start and end time or review. Added hidden field tags to form to track timeouts, as well as a submission check to ensure reviewer is still working on review.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submitted_content/_main.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Added checks for local assignment submissions, where if true a partial specifically for hyperlinks and submitted files are loaded. See lines 10-20 for specific changes.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submitted_content/_hyperlink.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Adds functionality to ensure that user must click on a hyperlink instead of copying and pasting the link. From line 41-end there is more JavaScript that marks start and end times for accessing these hyperlinks.&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattler &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133848</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133848"/>
		<updated>2020-04-24T17:28:07Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Proposed Solution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1662/commits E1989] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages and the reason it was not integrated into expertiza was due to the amount of white space in commits and unsatisfactory commit messages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] is used, however small edits were made to better suite our proposed implementation. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the spreadsheet below. We use map_id to join '''response_maps''' table for storing the primary information. '''Round''' contains an int variable associated with the specific round review, '''link''' contains a character string storing the external link the reviewer clicked on, '''start_at''' contains the starting time the external link was pressed, while '''end_at''' contains the time when the link was closed. &lt;br /&gt;
&lt;br /&gt;
[[File:Db_FINAL.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The highlight demonstrate which field correspond to response_maps key.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema_FINAL.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1989. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes were made:&lt;br /&gt;
&lt;br /&gt;
=== '''Files Created''' ===&lt;br /&gt;
&amp;lt;hr/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''controllers/submission_viewing_events_controller.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Creates a controller for handling events of submission viewing reviews. Created using rails 'generate controller' function.  Includes three methods&lt;br /&gt;
&lt;br /&gt;
# record_start_time :  function starts the time for links that have been visited by the user.&lt;br /&gt;
# record_end_time : records the end time for links that have been visited by the user.&lt;br /&gt;
# mark_end_time :  records the end time for links that have no end times.&lt;br /&gt;
&lt;br /&gt;
==== '''20200420201807_create_submission_viewing_events.rb''' ==== &lt;br /&gt;
&lt;br /&gt;
Migration file to create data table for handling log start and end time for each link/file in the review.  Created using rails 'generate model' function.  More info regarding schema is included in the Database section.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/index.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created a simple index page for viewing of submission events.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/edit.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created file to allow for editing capabilities of submission viewing events. &lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/_form.html.haml''' ==== &lt;br /&gt;
&lt;br /&gt;
Created partial form that was used to fill in edit.html.haml file, as well as a few others.&lt;br /&gt;
&lt;br /&gt;
=== '''Files Edited''' ===&lt;br /&gt;
&amp;lt;hr/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''db/schema.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Updated to include the SubmissionViewingEvents model migration, as executed via a 'rake db:migrate&amp;quot;&lt;br /&gt;
&lt;br /&gt;
====  '''app/views/reports/_review_submissions_time_spent.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
&lt;br /&gt;
====  '''app/views/reports/_review_report.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/new.html.haml'''==== &lt;br /&gt;
&lt;br /&gt;
Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submission_viewing_events/show.html.haml'''==== &lt;br /&gt;
&lt;br /&gt;
Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
&lt;br /&gt;
==== '''app/helpers/submitted_content_helper.rb'''==== &lt;br /&gt;
&lt;br /&gt;
Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
&lt;br /&gt;
===='''app/views/popup/view_review_scores_popup.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Break up query in line 55 into two queries.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/reports/_review_submissions_time_spent.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Created a view for reports controller.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/reports/_review_report.html.erb'''==== &lt;br /&gt;
&lt;br /&gt;
Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/_submitted_files.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Added JavaScript to this file which allows tracking of start and end times of accessing a hyperlink. Most functionality is on-click for tracking these times.&lt;br /&gt;
&lt;br /&gt;
==== '''config/routes.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Added collection for start and end times when hyperlink is accessed. Includes post and get calls for recording start and end times as necessary (see lines 420-428)&lt;br /&gt;
&lt;br /&gt;
==== '''app/controllers/response_controller.rb''' ====&lt;br /&gt;
&lt;br /&gt;
Added field @current_round to file for tracking the current round of reviews for a student. See lines 83 and 267 for variable instantiation.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/view.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Edited to set submission check variable to false.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/response/response.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Edited to contain two functions to track start and end time or review. Added hidden field tags to form to track timeouts, as well as a submission check to ensure reviewer is still working on review.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submitted_content/_main.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Added checks for local assignment submissions, where if true a partial specifically for hyperlinks and submitted files are loaded. See lines 10-20 for specific changes.&lt;br /&gt;
&lt;br /&gt;
==== '''app/views/submitted_content/_hyperlink.html.erb''' ====&lt;br /&gt;
&lt;br /&gt;
Adds functionality to ensure that user must click on a hyperlink instead of copying and pasting the link. From line 41-end there is more JavaScript that marks start and end times for accessing these hyperlinks.&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattler &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133689</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133689"/>
		<updated>2020-04-23T19:05:14Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Database Schema */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1791. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes were made:&lt;br /&gt;
&lt;br /&gt;
'''Files editted:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
# controllers/submission_viewing_events_controller.rb handles the start and end time of reviews. So, edits will need to be made to methods markEndTime() and endTime() to remove overlap issues.&lt;br /&gt;
# submission_viewing_events datatable to handle log start and end time for each link/file. Edits to algorithm for logging may present need to adjust structure of existing datatable.&lt;br /&gt;
#  app/views/reports/_review_submissions_time_spent.html.erb will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
#  app/views/reports/_review_report.html.erb will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
# app/views/submission_viewing_events/new.html.haml Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/views/submission_viewing_events/show.html.haml Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/helpers/submitted_content_helper.rb Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
# app/views/popup/view_review_scores_popup.html.erb Break up query in line 55 into two queries.&lt;br /&gt;
# app/views/reports/_review_submissions_time_spent.html.erb Created a view for reports controller.&lt;br /&gt;
# app/views/reports/_review_report.html.erb Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] is used, however small edits were made to better suite our proposed implementation. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the spreadsheet below. We use map_id to join '''response_maps''' table for storing the primary information. '''Round''' contains an int variable associated with the specific round review, '''link''' contains a character string storing the external link the reviewer clicked on, '''start_at''' contains the starting time the external link was pressed, while '''end_at''' contains the time when the link was closed. &lt;br /&gt;
&lt;br /&gt;
[[File:Db_FINAL.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The highlight demonstrate which field correspond to response_maps key.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema_FINAL.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattler &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133688</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133688"/>
		<updated>2020-04-23T19:03:09Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Database Schema */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1791. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes were made:&lt;br /&gt;
&lt;br /&gt;
'''Files editted:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
# controllers/submission_viewing_events_controller.rb handles the start and end time of reviews. So, edits will need to be made to methods markEndTime() and endTime() to remove overlap issues.&lt;br /&gt;
# submission_viewing_events datatable to handle log start and end time for each link/file. Edits to algorithm for logging may present need to adjust structure of existing datatable.&lt;br /&gt;
#  app/views/reports/_review_submissions_time_spent.html.erb will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
#  app/views/reports/_review_report.html.erb will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
# app/views/submission_viewing_events/new.html.haml Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/views/submission_viewing_events/show.html.haml Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/helpers/submitted_content_helper.rb Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
# app/views/popup/view_review_scores_popup.html.erb Break up query in line 55 into two queries.&lt;br /&gt;
# app/views/reports/_review_submissions_time_spent.html.erb Created a view for reports controller.&lt;br /&gt;
# app/views/reports/_review_report.html.erb Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] is used, however small edits were made to better suite our proposed implementation. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the spreadsheet below. We use map_id to join '''response_maps table''' for storing the primary information. '''Round''' contains an int variable associated with the specific round review, '''link''' contains a character string storing the external link the reviewer clicked on, '''start_at''' contains the starting time the external link was pressed, while '''end_at''' contains the time when the link was closed. &lt;br /&gt;
&lt;br /&gt;
[[File:Db_FINAL.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The highlight demonstrate which field correspond to response_maps key.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema_FINAL.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattler &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133687</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133687"/>
		<updated>2020-04-23T18:59:34Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Database Schema */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1791. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes were made:&lt;br /&gt;
&lt;br /&gt;
'''Files editted:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
# controllers/submission_viewing_events_controller.rb handles the start and end time of reviews. So, edits will need to be made to methods markEndTime() and endTime() to remove overlap issues.&lt;br /&gt;
# submission_viewing_events datatable to handle log start and end time for each link/file. Edits to algorithm for logging may present need to adjust structure of existing datatable.&lt;br /&gt;
#  app/views/reports/_review_submissions_time_spent.html.erb will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
#  app/views/reports/_review_report.html.erb will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
# app/views/submission_viewing_events/new.html.haml Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/views/submission_viewing_events/show.html.haml Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/helpers/submitted_content_helper.rb Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
# app/views/popup/view_review_scores_popup.html.erb Break up query in line 55 into two queries.&lt;br /&gt;
# app/views/reports/_review_submissions_time_spent.html.erb Created a view for reports controller.&lt;br /&gt;
# app/views/reports/_review_report.html.erb Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] is used, however small edits were made to better suite our proposed implementation. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the spreadsheet below. We use map_id to join response_maps table for storing the primary information.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_FINAL.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The highlight demonstrate which field correspond to response_maps key.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema_FINAL.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattler &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133686</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133686"/>
		<updated>2020-04-23T18:57:00Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Database Schema */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1791. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes were made:&lt;br /&gt;
&lt;br /&gt;
'''Files editted:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
# controllers/submission_viewing_events_controller.rb handles the start and end time of reviews. So, edits will need to be made to methods markEndTime() and endTime() to remove overlap issues.&lt;br /&gt;
# submission_viewing_events datatable to handle log start and end time for each link/file. Edits to algorithm for logging may present need to adjust structure of existing datatable.&lt;br /&gt;
#  app/views/reports/_review_submissions_time_spent.html.erb will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
#  app/views/reports/_review_report.html.erb will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
# app/views/submission_viewing_events/new.html.haml Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/views/submission_viewing_events/show.html.haml Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/helpers/submitted_content_helper.rb Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
# app/views/popup/view_review_scores_popup.html.erb Break up query in line 55 into two queries.&lt;br /&gt;
# app/views/reports/_review_submissions_time_spent.html.erb Created a view for reports controller.&lt;br /&gt;
# app/views/reports/_review_report.html.erb Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] is used, however small edits were made to better suite our proposed implementation. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the below spreadsheet. For the table, we would use map_id in table response, which uses response_map_id as the primary information. Then we need to record reviewer_id and reviewee_id, source_link for submitted links or file names, as well as time start_at and end_at, then store them in the table.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_FINAL.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The highlight demonstrate which field correspond to response_maps key.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema_FINAL.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattler &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Db_FINAL.PNG&amp;diff=133685</id>
		<title>File:Db FINAL.PNG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Db_FINAL.PNG&amp;diff=133685"/>
		<updated>2020-04-23T18:56:43Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133684</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133684"/>
		<updated>2020-04-23T18:52:44Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Database Schema */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1791. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes were made:&lt;br /&gt;
&lt;br /&gt;
'''Files editted:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
# controllers/submission_viewing_events_controller.rb handles the start and end time of reviews. So, edits will need to be made to methods markEndTime() and endTime() to remove overlap issues.&lt;br /&gt;
# submission_viewing_events datatable to handle log start and end time for each link/file. Edits to algorithm for logging may present need to adjust structure of existing datatable.&lt;br /&gt;
#  app/views/reports/_review_submissions_time_spent.html.erb will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
#  app/views/reports/_review_report.html.erb will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
# app/views/submission_viewing_events/new.html.haml Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/views/submission_viewing_events/show.html.haml Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/helpers/submitted_content_helper.rb Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
# app/views/popup/view_review_scores_popup.html.erb Break up query in line 55 into two queries.&lt;br /&gt;
# app/views/reports/_review_submissions_time_spent.html.erb Created a view for reports controller.&lt;br /&gt;
# app/views/reports/_review_report.html.erb Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] is used, however small edits were made to better suite our proposed implementation. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the below spreadsheet. For the table, we would use map_id in table response, which uses response_map_id as the primary information. Then we need to record reviewer_id and reviewee_id, source_link for submitted links or file names, as well as time start_at and end_at, then store them in the table.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The highlight demonstrate which field correspond to response_maps key.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema_FINAL.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattler &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133683</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133683"/>
		<updated>2020-04-23T18:51:34Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Database Schema */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1791. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes were made:&lt;br /&gt;
&lt;br /&gt;
'''Files editted:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
# controllers/submission_viewing_events_controller.rb handles the start and end time of reviews. So, edits will need to be made to methods markEndTime() and endTime() to remove overlap issues.&lt;br /&gt;
# submission_viewing_events datatable to handle log start and end time for each link/file. Edits to algorithm for logging may present need to adjust structure of existing datatable.&lt;br /&gt;
#  app/views/reports/_review_submissions_time_spent.html.erb will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
#  app/views/reports/_review_report.html.erb will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
# app/views/submission_viewing_events/new.html.haml Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/views/submission_viewing_events/show.html.haml Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/helpers/submitted_content_helper.rb Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
# app/views/popup/view_review_scores_popup.html.erb Break up query in line 55 into two queries.&lt;br /&gt;
# app/views/reports/_review_submissions_time_spent.html.erb Created a view for reports controller.&lt;br /&gt;
# app/views/reports/_review_report.html.erb Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] is used, however small edits were made to better suite our proposed implementation. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the below spreadsheet. For the table, we would use map_id in table response, which uses response_map_id as the primary information. Then we need to record reviewer_id and reviewee_id, source_link for submitted links or file names, as well as time start_at and end_at, then store them in the table.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The boxes demonstrate which fields correspond to each other.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema_FINAL.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattler &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Db_schema_FINAL.png&amp;diff=133682</id>
		<title>File:Db schema FINAL.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Db_schema_FINAL.png&amp;diff=133682"/>
		<updated>2020-04-23T18:50:36Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133681</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133681"/>
		<updated>2020-04-23T17:28:51Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Team Information */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1791. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes were made:&lt;br /&gt;
&lt;br /&gt;
'''Files editted:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
# controllers/submission_viewing_events_controller.rb handles the start and end time of reviews. So, edits will need to be made to methods markEndTime() and endTime() to remove overlap issues.&lt;br /&gt;
# submission_viewing_events datatable to handle log start and end time for each link/file. Edits to algorithm for logging may present need to adjust structure of existing datatable.&lt;br /&gt;
#  app/views/reports/_review_submissions_time_spent.html.erb will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
#  app/views/reports/_review_report.html.erb will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
# app/views/submission_viewing_events/new.html.haml Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/views/submission_viewing_events/show.html.haml Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/helpers/submitted_content_helper.rb Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
# app/views/popup/view_review_scores_popup.html.erb Break up query in line 55 into two queries.&lt;br /&gt;
# app/views/reports/_review_submissions_time_spent.html.erb Created a view for reports controller.&lt;br /&gt;
# app/views/reports/_review_report.html.erb Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] is used, however small edits were made to better suite our proposed implementation. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the below spreadsheet. For the table, we would use map_id in table response, which uses response_map_id as the primary information. Then we need to record reviewer_id and reviewee_id, source_link for submitted links or file names, as well as time start_at and end_at, then store them in the table.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The boxes demonstrate which fields correspond to each other.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema1.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattler &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133680</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133680"/>
		<updated>2020-04-23T17:28:14Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Team Information */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1791. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes were made:&lt;br /&gt;
&lt;br /&gt;
'''Files editted:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
# controllers/submission_viewing_events_controller.rb handles the start and end time of reviews. So, edits will need to be made to methods markEndTime() and endTime() to remove overlap issues.&lt;br /&gt;
# submission_viewing_events datatable to handle log start and end time for each link/file. Edits to algorithm for logging may present need to adjust structure of existing datatable.&lt;br /&gt;
#  app/views/reports/_review_submissions_time_spent.html.erb will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
#  app/views/reports/_review_report.html.erb will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
# app/views/submission_viewing_events/new.html.haml Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/views/submission_viewing_events/show.html.haml Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/helpers/submitted_content_helper.rb Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
# app/views/popup/view_review_scores_popup.html.erb Break up query in line 55 into two queries.&lt;br /&gt;
# app/views/reports/_review_submissions_time_spent.html.erb Created a view for reports controller.&lt;br /&gt;
# app/views/reports/_review_report.html.erb Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] is used, however small edits were made to better suite our proposed implementation. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the below spreadsheet. For the table, we would use map_id in table response, which uses response_map_id as the primary information. Then we need to record reviewer_id and reviewee_id, source_link for submitted links or file names, as well as time start_at and end_at, then store them in the table.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The boxes demonstrate which fields correspond to each other.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema1.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Lero &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonal &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morri &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattler &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133679</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133679"/>
		<updated>2020-04-23T17:27:08Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Code Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1791. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes were made:&lt;br /&gt;
&lt;br /&gt;
'''Files editted:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
# controllers/submission_viewing_events_controller.rb handles the start and end time of reviews. So, edits will need to be made to methods markEndTime() and endTime() to remove overlap issues.&lt;br /&gt;
# submission_viewing_events datatable to handle log start and end time for each link/file. Edits to algorithm for logging may present need to adjust structure of existing datatable.&lt;br /&gt;
#  app/views/reports/_review_submissions_time_spent.html.erb will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
#  app/views/reports/_review_report.html.erb will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
# app/views/submission_viewing_events/new.html.haml Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/views/submission_viewing_events/show.html.haml Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/helpers/submitted_content_helper.rb Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
# app/views/popup/view_review_scores_popup.html.erb Break up query in line 55 into two queries.&lt;br /&gt;
# app/views/reports/_review_submissions_time_spent.html.erb Created a view for reports controller.&lt;br /&gt;
# app/views/reports/_review_report.html.erb Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] is used, however small edits were made to better suite our proposed implementation. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the below spreadsheet. For the table, we would use map_id in table response, which uses response_map_id as the primary information. Then we need to record reviewer_id and reviewee_id, source_link for submitted links or file names, as well as time start_at and end_at, then store them in the table.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The boxes demonstrate which fields correspond to each other.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema1.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattle &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133678</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133678"/>
		<updated>2020-04-23T17:26:25Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Code Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1791. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes are expected to be made:&lt;br /&gt;
&lt;br /&gt;
'''Files editted:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
# controllers/submission_viewing_events_controller.rb handles the start and end time of reviews. So, edits will need to be made to methods markEndTime() and endTime() to remove overlap issues.&lt;br /&gt;
# submission_viewing_events datatable to handle log start and end time for each link/file. Edits to algorithm for logging may present need to adjust structure of existing datatable.&lt;br /&gt;
#  app/views/reports/_review_submissions_time_spent.html.erb will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
#  app/views/reports/_review_report.html.erb will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
# app/views/submission_viewing_events/new.html.haml Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/views/submission_viewing_events/show.html.haml Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/helpers/submitted_content_helper.rb Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
# app/views/popup/view_review_scores_popup.html.erb Break up query in line 55 into two queries.&lt;br /&gt;
# app/views/reports/_review_submissions_time_spent.html.erb Created a view for reports controller.&lt;br /&gt;
# app/views/reports/_review_report.html.erb Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] is used, however small edits were made to better suite our proposed implementation. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the below spreadsheet. For the table, we would use map_id in table response, which uses response_map_id as the primary information. Then we need to record reviewer_id and reviewee_id, source_link for submitted links or file names, as well as time start_at and end_at, then store them in the table.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The boxes demonstrate which fields correspond to each other.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema1.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattle &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133677</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133677"/>
		<updated>2020-04-23T17:26:07Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Code Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the completed aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1662/commits E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
== '''Code Changes''' ==&lt;br /&gt;
Our implementation builds off of the work done in E1791. This previous project has a substantial amount of the functionality already completed for tracking and viewing external pages and certain types of files. The primary error in this implementation is that when multiple files are open, the times at which they record reviews are overlapped creating inaccurate review reports. The displayed review report will also need to be edited to present review reports in a visually appealing manner. The following changes are expected to be made:&lt;br /&gt;
&lt;br /&gt;
'''Files to be editted:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
# controllers/submission_viewing_events_controller.rb handles the start and end time of reviews. So, edits will need to be made to methods markEndTime() and endTime() to remove overlap issues.&lt;br /&gt;
# submission_viewing_events datatable to handle log start and end time for each link/file. Edits to algorithm for logging may present need to adjust structure of existing datatable.&lt;br /&gt;
#  app/views/reports/_review_submissions_time_spent.html.erb will be edited to accurately log viewing times for multiple links open at the same time.  This will include creating methods such as calculateTime to help with parsing review times of different links, and a function drawChart to display review times in a visually appealing manner.&lt;br /&gt;
#  app/views/reports/_review_report.html.erb will be edited to reflect chart made in _review_submissions_time_spent.html.erb&lt;br /&gt;
# app/views/submission_viewing_events/new.html.haml Created new.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/views/submission_viewing_events/show.html.haml Created show.html.haml for submission_viewing_events for assisting in setting up the views.&lt;br /&gt;
# app/helpers/submitted_content_helper.rb Updated line 32 to incorporate file link for the return variable, ret.&lt;br /&gt;
# app/views/popup/view_review_scores_popup.html.erb Break up query in line 55 into two queries.&lt;br /&gt;
# app/views/reports/_review_submissions_time_spent.html.erb Created a view for reports controller.&lt;br /&gt;
# app/views/reports/_review_report.html.erb Made changes to _review_report to reflect changes in reports_controller&lt;br /&gt;
&lt;br /&gt;
== '''User Stories''' ==&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] is used, however small edits were made to better suite our proposed implementation. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
== '''Database Schema''' ==&lt;br /&gt;
Our datatable is named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the below spreadsheet. For the table, we would use map_id in table response, which uses response_map_id as the primary information. Then we need to record reviewer_id and reviewee_id, source_link for submitted links or file names, as well as time start_at and end_at, then store them in the table.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The boxes demonstrate which fields correspond to each other.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema1.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. The primary controller for testing will be controllers/submission_viewing_events_controller.rb, as edits will be made to mark_end_time and record_end_time methods to ensure that recorded review times for resources are not overlapping.&lt;br /&gt;
&lt;br /&gt;
Proposed Rspec Tests:&lt;br /&gt;
* When a new review is started probe the Expertiza timer and ensure it returns the start value (0)&lt;br /&gt;
* When a saved review is started again probe the Expertiza timer and ensure it returns the time value stored in the database&lt;br /&gt;
* When an external link is clicked on a new review probe the timer link for that link and ensure it returns the start value (0)&lt;br /&gt;
* When an external link is clicked on a previously saved review probe the timer link for that link and ensure it returns and ensure it returns the time value stored in the database&lt;br /&gt;
* When a review is saved/submitted ensure that the time sent to the database matches time stored in database after execution&lt;br /&gt;
* When a review is clicked on by the instructor the data returned from date base should match test data.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Assign a review to a student&lt;br /&gt;
# Log in as student&lt;br /&gt;
# Complete the dummy review in 5 minutes&lt;br /&gt;
# Log in as instructor&lt;br /&gt;
# Navigate to review report tab&lt;br /&gt;
# Verify that the review was completed ~5 minutes.&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&lt;br /&gt;
=== Useful Links ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/expertiza/expertiza Expertiza Repo] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza E1791 Repo]&lt;br /&gt;
&lt;br /&gt;
=== Our Implementation ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/jamcdon3/expertiza/tree/E2015 Github Repo:] &amp;lt;br /&amp;gt;&lt;br /&gt;
[https://github.com/rohanpillai20/expertiza/pull/51 Pull Request:]&lt;br /&gt;
&lt;br /&gt;
=== Team Information ===&lt;br /&gt;
'''Mentor:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Abhirav Kariya &lt;br /&gt;
&lt;br /&gt;
'''Students:''' &amp;lt;br /&amp;gt;&lt;br /&gt;
Hartley Leroy &amp;lt;br /&amp;gt;&lt;br /&gt;
John McDonald &amp;lt;br /&amp;gt;&lt;br /&gt;
Christian Morris &amp;lt;br /&amp;gt;&lt;br /&gt;
Tyler Sattle &amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133395</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133395"/>
		<updated>2020-04-14T00:23:18Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Design pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
== '''Abstract''' ==&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project.&lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
== '''Problem Statement''' ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review is most important. One can track the amount of time spent on the review by tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a resource is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and resources should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== '''Previous Implementations''' ==&lt;br /&gt;
Thus far, Expertiza does not have the aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== '''Proposed Solution''' ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
*There are a few solutions one could implement to fix such an issue, such as marking both the start time and end time for when an external link or application was accessed by a user. Another solution which we will attempt in our first iteration of development is to track the time that an external link was clicked, and use the submission time of the review as our estimated end time for the external link. We thought of this design choice because once the report is submitted, the access time to external links should be stopped since the review is complete.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints about the use of a tabular method that was implemented in [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791], stating that the review report table becomes too cluttered, we intend to create a pop-up window that will display the results in a table or graph of some sort. The proposed pop up will display all necessary information in a neat and simple self contained form. The exact display is undetermined, however proposed solutions include another tabular design, bar graphs, pie charts, etc.&lt;br /&gt;
&lt;br /&gt;
=== Design pattern ===&lt;br /&gt;
'''What is the Strategy Pattern?''' Software design pattern that enables an algorithm's behavior to be selected at runtime. The strategy pattern:&lt;br /&gt;
* defines a family of algorithms&lt;br /&gt;
* encapsulates each algorithm, and&lt;br /&gt;
* makes the algorithm interchangeable within that family&lt;br /&gt;
'''Strategy:''' This project, for each review page, deals with different type of links. Javascript is used to track the access time for online links, such as github repo, youtube links, and more.&lt;br /&gt;
&lt;br /&gt;
=== User Stories ===&lt;br /&gt;
The following section outlines the predicted user interactions with our software. Two potential users have been identified; users and instructors.&lt;br /&gt;
====Student====&lt;br /&gt;
Students will be interacting with the implementation when filling out a review. A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] is used, however small edits were made to better suite our proposed implementation. Initially, the user will click on the review they want to complete. Once the link is clicked the time will start to be logged. Upon the clicking of an external link another another timer will begin tracking it. This process repeats until the submission is saved/submitted or the page is exited out of. In the case where a review was previously saved the timer will pick up from the last tracked time. The diagram below displays the flow of interactions visually.&lt;br /&gt;
[[File:User_Story.png| center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
====Instructor====&lt;br /&gt;
Instructors will be interacting with the implementation when the are observing student reviews. Once again, a similar story from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for the instructor  with minor changes. Firstly, the instructor will navigate to a page that displays all current and previously reviews. They will then be able to select a review from the given list and look at statistics about resources accessed and time spent on each resource. Saved reviews and already submitted reviews will be tagged differently. The diagram below displays the flow of interactions visually.&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 50 pixels]]&lt;br /&gt;
&lt;br /&gt;
=== Files to be Added and Edited ===&lt;br /&gt;
&lt;br /&gt;
# Create a controller to handle the start/end times of the files viewed by the user in =&amp;gt; controllers/submission_viewing_events_controller.rb&lt;br /&gt;
# Create a datatable to handle log start and end time for each link/file.  Schema for this table is provided in the below section.&lt;br /&gt;
# Edit and add views to display results in a user-friendly manner.  Edits to views should be defined in both the wiki and through modular commits on the repository in order to clearly distinguish code changes, an issue that prevented [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] from pushing to base.&lt;br /&gt;
&lt;br /&gt;
=== Database Schema ===&lt;br /&gt;
&lt;br /&gt;
Our datatable will be named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the below spreadsheet.  There is some uncertainty in how the time will be tracked separately for viewing downloadable files vs viewing the Expertiza assignment review page.  Final form of the data table with this tracking feature will be elaborate on in future submissions.  &lt;br /&gt;
&lt;br /&gt;
[[File:Db_.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The boxes demonstrate which fields correspond to each other.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema1.png | center]]&lt;br /&gt;
&lt;br /&gt;
== '''Testing Plan''' ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. We will test the changes made to controllers/submission_viewing_events_controller.rb to ensure proper test converge.  Test cases are to be written in a meaningful and elegant manner, adhering to the following rules:&lt;br /&gt;
&lt;br /&gt;
* Test incoming query messages by making assertions for what they send back&lt;br /&gt;
* Test incoming command messages by making assertions about direct public side effects&lt;br /&gt;
* Do not test private methods&lt;br /&gt;
* Do not test outgoing query messages&lt;br /&gt;
* Expect to send outgoing command messages&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
1. Log in as instructor&lt;br /&gt;
&lt;br /&gt;
2. Assign a review to a student&lt;br /&gt;
&lt;br /&gt;
3. Log in as student&lt;br /&gt;
&lt;br /&gt;
4. Complete the dummy review in 5 minutes&lt;br /&gt;
&lt;br /&gt;
5. Log in as instructor&lt;br /&gt;
&lt;br /&gt;
6. Navigate to review report tab&lt;br /&gt;
&lt;br /&gt;
7. Verify that the review was completed ~5 minutes.&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133254</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133254"/>
		<updated>2020-04-13T19:21:29Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Database Schema */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review itself is most important. One can track the amount of time spent on the review itself quite easily by simply tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a link is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and documents should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
Thus far, Expertiza does not have the aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== Proposed Solution ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints on a tabular method, citing the review report table becoming too cluttered, we intend to create a pop-up window that will display the results in a table. Unlike the approach taken in project [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 from the fall of 2019], this project will work to display all information using the aforementioned tabular design in a pop-up window. With this approach, the table provides the information and estimates regarding all of the external links accessed throughout this review in a simple and uncluttered fashion.&lt;br /&gt;
&lt;br /&gt;
=== Design pattern ===&lt;br /&gt;
'''Strategy:''' This project, for each review page, deals with different type of links. Javascript is used to track the access time for online links, such as github repo, youtube links, and more. For submitted files, such as txt, jpg, we will time it with  views/response/_submitted_files.html.erb.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;User&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] is used, however small edits were made to the diagram to better suite our proposed implementation. &lt;br /&gt;
[[File:User_Story.png | center |Image: 100 pixels]]&lt;br /&gt;
&amp;lt;b&amp;gt;Instructor&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once again, a similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for an instructor to access the tabularized information regarding access times:&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 100 pixels]]&lt;br /&gt;
&lt;br /&gt;
=== Files to be Added and Editted ===&lt;br /&gt;
&lt;br /&gt;
# Create a controller to handle the start/end times of the files viewed by the user in =&amp;gt; controllers/submission_viewing_events_controller.rb&lt;br /&gt;
# Create a datatable to handle log start and end time for each link/file.  Schema for this table is provided in the below section.&lt;br /&gt;
# Edit and add views to display results in a user-friendly manner.  Edits to views should be defined in both the wiki and through modular commits on the repository in order to clearly distinguish code changes, an issue that prevented [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] from pushing to base.&lt;br /&gt;
&lt;br /&gt;
=== Database Schema ===&lt;br /&gt;
&lt;br /&gt;
Our datatable will be named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the below spreadsheet.  There is some uncertainty in how the time will be tracked separately for viewing downloadable files vs viewing the Expertiza assignment review page.  Final form of the data table with this tracking feature will be elaborate on in future submissions.  &lt;br /&gt;
&lt;br /&gt;
[[File:Db_.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The boxes demonstrate which fields correspond to each other.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema1.png | center]]&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. We will test the changes made to controllers/submission_viewing_events_controller.rb to ensure proper test converge.  Test cases are to be written in a meaningful and elegant manner, adhering to the following rules:&lt;br /&gt;
&lt;br /&gt;
* Test incoming query messages by making assertions for what they send back&lt;br /&gt;
* Test incoming command messages by making assertions about direct public side effects&lt;br /&gt;
* Do not test private methods&lt;br /&gt;
* Do not test outgoing query messages&lt;br /&gt;
* Expect to send outgoing command messages&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
1. Log in as instructor&lt;br /&gt;
&lt;br /&gt;
2. Assign a review to a student&lt;br /&gt;
&lt;br /&gt;
3. Log in as student&lt;br /&gt;
&lt;br /&gt;
4. Complete the dummy review in 5 minutes&lt;br /&gt;
&lt;br /&gt;
5. Log in as instructor&lt;br /&gt;
&lt;br /&gt;
6. Navigate to review report tab&lt;br /&gt;
&lt;br /&gt;
7. Verify that the review was completed ~5 minutes.&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133253</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133253"/>
		<updated>2020-04-13T19:20:59Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Database Schema */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review itself is most important. One can track the amount of time spent on the review itself quite easily by simply tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a link is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and documents should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
Thus far, Expertiza does not have the aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== Proposed Solution ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints on a tabular method, citing the review report table becoming too cluttered, we intend to create a pop-up window that will display the results in a table. Unlike the approach taken in project [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 from the fall of 2019], this project will work to display all information using the aforementioned tabular design in a pop-up window. With this approach, the table provides the information and estimates regarding all of the external links accessed throughout this review in a simple and uncluttered fashion.&lt;br /&gt;
&lt;br /&gt;
=== Design pattern ===&lt;br /&gt;
'''Strategy:''' This project, for each review page, deals with different type of links. Javascript is used to track the access time for online links, such as github repo, youtube links, and more. For submitted files, such as txt, jpg, we will time it with  views/response/_submitted_files.html.erb.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;User&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] is used, however small edits were made to the diagram to better suite our proposed implementation. &lt;br /&gt;
[[File:User_Story.png | center |Image: 100 pixels]]&lt;br /&gt;
&amp;lt;b&amp;gt;Instructor&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once again, a similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for an instructor to access the tabularized information regarding access times:&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 100 pixels]]&lt;br /&gt;
&lt;br /&gt;
=== Files to be Added and Editted ===&lt;br /&gt;
&lt;br /&gt;
# Create a controller to handle the start/end times of the files viewed by the user in =&amp;gt; controllers/submission_viewing_events_controller.rb&lt;br /&gt;
# Create a datatable to handle log start and end time for each link/file.  Schema for this table is provided in the below section.&lt;br /&gt;
# Edit and add views to display results in a user-friendly manner.  Edits to views should be defined in both the wiki and through modular commits on the repository in order to clearly distinguish code changes, an issue that prevented [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] from pushing to base.&lt;br /&gt;
&lt;br /&gt;
=== Database Schema ===&lt;br /&gt;
&lt;br /&gt;
Our datatable will be named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the below spreadsheet.  There is some uncertainty in how the time will be tracked separately for viewing downloadable files vs viewing the Expertiza assignment review page.  Final form of the data table with this tracking feature will be elaborate on in future submissions.  &lt;br /&gt;
&lt;br /&gt;
[[File:Db_.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below shows the database relationship with other tables. '''submission_viewing_events''' will be touching '''response_maps'''. The boxes demonstrate which fields correspond to each other.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_schema1.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. We will test the changes made to controllers/submission_viewing_events_controller.rb to ensure proper test converge.  Test cases are to be written in a meaningful and elegant manner, adhering to the following rules:&lt;br /&gt;
&lt;br /&gt;
* Test incoming query messages by making assertions for what they send back&lt;br /&gt;
* Test incoming command messages by making assertions about direct public side effects&lt;br /&gt;
* Do not test private methods&lt;br /&gt;
* Do not test outgoing query messages&lt;br /&gt;
* Expect to send outgoing command messages&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
1. Log in as instructor&lt;br /&gt;
&lt;br /&gt;
2. Assign a review to a student&lt;br /&gt;
&lt;br /&gt;
3. Log in as student&lt;br /&gt;
&lt;br /&gt;
4. Complete the dummy review in 5 minutes&lt;br /&gt;
&lt;br /&gt;
5. Log in as instructor&lt;br /&gt;
&lt;br /&gt;
6. Navigate to review report tab&lt;br /&gt;
&lt;br /&gt;
7. Verify that the review was completed ~5 minutes.&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Db_schema1.png&amp;diff=133252</id>
		<title>File:Db schema1.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Db_schema1.png&amp;diff=133252"/>
		<updated>2020-04-13T19:18:34Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133251</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133251"/>
		<updated>2020-04-13T19:18:10Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Database Schema */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review.  It is important that functionality be added so Expertiza can track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
The overall amount of time directly spent on the review itself is most important. One can track the amount of time spent on the review itself quite easily by simply tracking the amount of time from when the page is opened untill when the review is saved/submitted. Therefore, being able to track the time from once a link is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
The following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and documents should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
Thus far, Expertiza does not have the aforementioned feature.  Previous attempts to implement this functionality have been made but the work was not merged into Expertiza code base for various reason. These previous projects are summarized below:&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== Proposed Solution ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both.  Tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints on a tabular method, citing the review report table becoming too cluttered, we intend to create a pop-up window that will display the results in a table. Unlike the approach taken in project [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 from the fall of 2019], this project will work to display all information using the aforementioned tabular design in a pop-up window. With this approach, the table provides the information and estimates regarding all of the external links accessed throughout this review in a simple and uncluttered fashion.&lt;br /&gt;
&lt;br /&gt;
=== Design pattern ===&lt;br /&gt;
'''Strategy:''' This project, for each review page, deals with different type of links. Javascript is used to track the access time for online links, such as github repo, youtube links, and more. For submitted files, such as txt, jpg, we will time it with  views/response/_submitted_files.html.erb.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;User&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] is used, however small edits were made to the diagram to better suite our proposed implementation. &lt;br /&gt;
[[File:User_Story.png | center |Image: 100 pixels]]&lt;br /&gt;
&amp;lt;b&amp;gt;Instructor&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Once again, a similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for an instructor to access the tabularized information regarding access times:&lt;br /&gt;
[[File:Instructor_Story.png | center |Image: 100 pixels]]&lt;br /&gt;
&lt;br /&gt;
=== Files to be Added and Editted ===&lt;br /&gt;
&lt;br /&gt;
# Create a controller to handle the start/end times of the files viewed by the user in =&amp;gt; controllers/submission_viewing_events_controller.rb&lt;br /&gt;
# Create a datatable to handle log start and end time for each link/file.  Schema for this table is provided in the below section.&lt;br /&gt;
# Edit and add views to display results in a user-friendly manner.  Edits to views should be defined in both the wiki and through modular commits on the repository in order to clearly distinguish code changes, an issue that prevented [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] from pushing to base.&lt;br /&gt;
&lt;br /&gt;
=== Database Schema ===&lt;br /&gt;
&lt;br /&gt;
Our datatable will be named '''submission_viewing_events'''.  The attributes and their descriptions are provided in the below spreadsheet.  There is some uncertainty in how the time will be tracked separately for viewing downloadable files vs viewing the Expertiza assignment review page.  Final form of the data table with this tracking feature will be elaborate on in future submissions.  &lt;br /&gt;
&lt;br /&gt;
[[File:Db_.PNG | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using Rspec. We will test the changes made to controllers/submission_viewing_events_controller.rb to ensure proper test converge.  Test cases are to be written in a meaningful and elegant manner, adhering to the following rules:&lt;br /&gt;
&lt;br /&gt;
* Test incoming query messages by making assertions for what they send back&lt;br /&gt;
* Test incoming command messages by making assertions about direct public side effects&lt;br /&gt;
* Do not test private methods&lt;br /&gt;
* Do not test outgoing query messages&lt;br /&gt;
* Expect to send outgoing command messages&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
1. Log in as instructor&lt;br /&gt;
&lt;br /&gt;
2. Assign a review to a student&lt;br /&gt;
&lt;br /&gt;
3. Log in as student&lt;br /&gt;
&lt;br /&gt;
4. Complete the dummy review in 5 minutes&lt;br /&gt;
&lt;br /&gt;
5. Log in as instructor&lt;br /&gt;
&lt;br /&gt;
6. Navigate to review report tab&lt;br /&gt;
&lt;br /&gt;
7. Verify that the review was completed ~5 minutes.&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Db_.PNG&amp;diff=133250</id>
		<title>File:Db .PNG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Db_.PNG&amp;diff=133250"/>
		<updated>2020-04-13T19:17:30Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement&amp;diff=133249</id>
		<title>CSC/ECE 517 Fall 2017/E1791. Track the time that students look at the other submissions - logging improvement</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement&amp;diff=133249"/>
		<updated>2020-04-13T19:15:59Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Database shcema design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The expertiza project takes advantage of peer-review among students to allow them to learn from each other. To track the review time that each student spend on each submitted resources is meaningful to instructors to study and improve the teach experience. However, the time tracking of specific content on these resources is not perfect in the expertiza system. The previous team working on E1705 project has solved part of such problems by tracking the active time of windows opened from the submitted links. But for the submitted files which could be downloaded for local review, there is only a rough approximation solution yet. In this project, our team is going to solve this problem as well as improving previous time tracking methods using mature third-party APIs to record link review time more accurately. To accomplish this goal, here are the general solutions we designed and implemented in this project:&lt;br /&gt;
&lt;br /&gt;
*Designed a database schema for logging the time a reviewer spend on a submission;&lt;br /&gt;
*Designed and implemented dynamic partial components using Javascript and Ruby to open students’ submissions in new windows to view online;&lt;br /&gt;
*Used DOM to control the windows holding review submission files or links, and record the open and close time;&lt;br /&gt;
*Modify Review report (views/review_mapping/_review_report.html.erb) to show the total and detailed time spent on each review submissions with visualization.&lt;br /&gt;
&lt;br /&gt;
== Problem Description and Solution ==&lt;br /&gt;
Our team is going to solve the submission review time tracking by attempting to open the downloaded files inside popup windows of the web browser in order to record the time on the client side. &lt;br /&gt;
&lt;br /&gt;
=== Type of submitted files ===&lt;br /&gt;
For most of our tasks, there are two types of submitted files. &lt;br /&gt;
&lt;br /&gt;
1. One kind is online links, such as github repo or pull request link, youtube video link, expertiza wiki page link, etc&lt;br /&gt;
&lt;br /&gt;
2. The other one includes files such as pdf, txt, doc, images, etc and other download contents. (instructor can include more document types in /views/submitted_content/_submitted_files.html.erb)&lt;br /&gt;
&lt;br /&gt;
=== Design pattern ===&lt;br /&gt;
'''Strategy''' In this project, for each review page, we need to deal with different type of links. For online links, such as github repo, youtube link, etc, we use javascript to open a new window detect time when the window is closed. For submitted files, such as txt, jpg, we will open it with  views/response/_submitted_files.html.erb. For other files that need to be download and open locally, we can only make approximation for review time.&lt;br /&gt;
&lt;br /&gt;
=== Database schema design ===&lt;br /&gt;
For this project, we need to design a database table to store all the time that we need to record for each review submission event. We would like to name the table as '''submission_viewing_events'''. For the table, we would use '''map_id''' in table response, which uses '''response_map_id''' as the primary information. Then we need to record '''reviewer_id''' and '''reviewee_id''', '''source_link''' for submitted links or file names, as well as time '''start_at''' and '''end_at''', then store them in the table.&lt;br /&gt;
&lt;br /&gt;
[[File:E1791db.jpg | center]]&lt;br /&gt;
&lt;br /&gt;
=== Time tracking mechanism ===&lt;br /&gt;
&lt;br /&gt;
For each review, when the reviewer click on one link of the submitted files, we create an entry to the table review_time, we will write a function to record current time to the database. &lt;br /&gt;
&lt;br /&gt;
For how to determine time when the reviewer complete with the opened link, there are different cases. If the reviewer click on save or submit button, close the page, or logout, we need to write to all open entry (without end_at) respect to this review and save current time to end_at. But for how to decide when the review close the opened link is a little complicated. For github and youtube links and txt, pdf, doc, image files, we will open submitted files in views/response/_submitted_files.html.erb so that when the user click on the link, it opens a popup window that shows the submission, record time when it opens and closes. This is done by controlling DOM using jQuery javascript library, and then send back the time records through Ajax. For the other files that need to be downloaded, we can only make an approximation by record the time when the reviewer click on the link until the time he/she enter the reviews.&lt;br /&gt;
&lt;br /&gt;
For each task, reviewer might open each link several times, might also save the review process and restart it some times later, so we will have multiple records for each link. Every time the student click on the link, a new record is created and then the time in all records will be summed up to total time for every link and displayed on instructor page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:E1791_flowchart.png | center]]&lt;br /&gt;
&lt;br /&gt;
=== View modification ===&lt;br /&gt;
After we record start_at and end_at time for each piece of review, we need to display time that each reviewer spent on each link. Because the reviewer may save the review and start again in the future, so for each link there might be several entries, we need to sum them together. We modifed code in review_mapping/_review_report.html.erb first to modify the view. This framework follows well the &amp;quot;open to extension and close to modification&amp;quot; principle, which makes further changes more feasible by adding additional view components without affecting current functions.&lt;br /&gt;
[[File:review_piechart.png | center]]&lt;br /&gt;
&lt;br /&gt;
=== Edge cases ===&lt;br /&gt;
1. When user click on save or submit the review without closing opened windows, the system will search all records of response time for the reviewer and reviewee where end time is NULL, and update it with current time.&lt;br /&gt;
&lt;br /&gt;
2. If the reviewer opens the reference links or download files, but leave them open and turn to focus other unrelated stuff, the review page will send a popup alert dialog to confirm if the review is still in review mode. If not, it will close these windows and save the time as approximation of end time. Otherwise, it will continue the review process.&lt;br /&gt;
[[File:E1791popup alert.jpg | center]]&lt;br /&gt;
&lt;br /&gt;
3. In some cases, reviewer might shut down the computer, close the browser, log out without saving, etc., we set up periodically saving reviewing events automatically such that we will lose as less information as possible. Currently the period is 30 seconds and this can be changed. For the cases described, shut down computer etc., there will be records written in data base with end time NULL, next time when the reviewer restart the review, the system will just drop all the records with NULL end time and start a new query. Also if reviewer does not interact with the review page for a long time, it will pause the timer and commit all existing related time record in database. The time limit is now 2 minutes. Both the period and non-interaction time can be adjusted by instructors in code file /views/response/response.html.erb&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
=== UI and Manual test ===&lt;br /&gt;
We will test the following cases during our development&lt;br /&gt;
&lt;br /&gt;
1. When we work the review, if we click on GitHub link, GitHub pull request link, check whether the system record review time correctly.&lt;br /&gt;
&lt;br /&gt;
2. When we work the review, if we click on doc, pdf, image link, check whether system open submitted files in views/response/_submitted_files.html.erb and recore the review time correctly.&lt;br /&gt;
&lt;br /&gt;
3. Check if the reviewer save the process and start again with click on same clink, check whether the system will record all the entry, and on the view page take all entries for one link into account.&lt;br /&gt;
&lt;br /&gt;
=== Rspec Test ===&lt;br /&gt;
Test of new model and function will be written and tested during project development:&lt;br /&gt;
* Test the success of a review time record given valid start and end time;&lt;br /&gt;
&lt;br /&gt;
describe ResponseTimesController do&lt;br /&gt;
  describe '#action_allowed?' do&lt;br /&gt;
    it &amp;quot;should return true&amp;quot; do&lt;br /&gt;
      expect(true).to be_truthy&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
* Test whether the start time is updated to the end time last saved in the database when the user resumes a review;&lt;br /&gt;
&lt;br /&gt;
  describe '#response_start_time' do&lt;br /&gt;
    context 'when the link is opened and timed' do&lt;br /&gt;
      it 'should update time record with start time as end time' do&lt;br /&gt;
        response_time_records=double('ResponseTime')&lt;br /&gt;
        allow(ResponseTime).to receive(:where).with([:map_id,:round,:link]).and_return(response_time_records)&lt;br /&gt;
        dummy = double('BasicObject')&lt;br /&gt;
        allow(ResponseTime).to receive(:end_at).and_return(dummy)&lt;br /&gt;
        allow(dummy).to receive(:nil?).and_return(true)&lt;br /&gt;
        allow(ResponseTime).to receive(:update_attributes).with(:end_at,:start_at).and_return(response_time_records)&lt;br /&gt;
        expect(response.body).to be_blank&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
* Test whether the end time is updated as the current time when the review is saved to the database.&lt;br /&gt;
&lt;br /&gt;
 describe '#response_end_time' do&lt;br /&gt;
    context 'when response does not have a end time' do&lt;br /&gt;
      it 'should update time record with end time as current time' do&lt;br /&gt;
        response_time_records=double('ResponseTime')&lt;br /&gt;
        allow(ResponseTime).to receive(:where).with([:map_id,:round,:link]).and_return(response_time_records)&lt;br /&gt;
        dummy = double('BasicObject')&lt;br /&gt;
        allow(ResponseTime).to receive(:end_at).and_return(dummy)&lt;br /&gt;
        allow(dummy).to receive(:nil?).and_return(true)&lt;br /&gt;
        allow(ResponseTime).to receive(:update_attributes).with(:end_at,Time.now.to_date).and_return(response_time_records)&lt;br /&gt;
        expect(response.body).to be_blank&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Related Files ==&lt;br /&gt;
submission_viewing_events.rb &amp;lt;br&amp;gt;&lt;br /&gt;
submission_viewing_events_controller.rb &amp;lt;br&amp;gt;&lt;br /&gt;
responses_controller.rb &amp;lt;br&amp;gt;&lt;br /&gt;
helper/review_mapping_helper.rb &amp;lt;br&amp;gt;&lt;br /&gt;
helpers/submitted_content_helper.rb &amp;lt;br&amp;gt;&lt;br /&gt;
response/response.html.erb  &amp;lt;br&amp;gt;&lt;br /&gt;
review_mapping/_review_report.html.erb &amp;lt;br&amp;gt;&lt;br /&gt;
review_mapping/_review_submissions_time_spent.html.erb &amp;lt;br&amp;gt;&lt;br /&gt;
view/popup/reviewer_details_popup.html.erb &amp;lt;br&amp;gt;&lt;br /&gt;
view/submitted_content/_hyperlink.html.erb &amp;lt;br&amp;gt;&lt;br /&gt;
view/submitted_content/_submitted_files.html.erb &amp;lt;br&amp;gt;&lt;br /&gt;
db/migrate/20171117190721_create_response_times.rb &amp;lt;br&amp;gt;&lt;br /&gt;
config/routes.rb&lt;br /&gt;
&lt;br /&gt;
== Future Work ==&lt;br /&gt;
&lt;br /&gt;
In this project, we accomplished the requirement defined in the project instructions. However, due to the complexity of the Expertiza system and limited time period, there are still several points to improve in the future:&lt;br /&gt;
&lt;br /&gt;
1. Improve the accuracy of review time record. To record the exact time that the user spends on each link or file, it is more accurate to track the active time of each new window or tab of these links or online files. We attempted this design using 'window.focus()', but it does not work once the user moved away from the review page and turned to other applications. So either tweaking the web setting or using browser APIs may solve this problem.&lt;br /&gt;
&lt;br /&gt;
2. Notify the user when no response on the review page. Occasionally the user may open the review page to do the review, but is interrupted to focus on other applications. In this case, we stopped the time recording but try to alert the user that if he wants to continue the review. However, this notice cannot show in time if the user is not focusing on that review page. So a global alert is necessary to save the time and provide notice on time.&lt;br /&gt;
&lt;br /&gt;
== Project Links ==&lt;br /&gt;
1. [https://github.com/expertiza/expertiza/pull/1124 Project Github repo]&lt;br /&gt;
&lt;br /&gt;
2. [https://youtu.be/IMTBqiKth-k Project Video Demo]&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
[mailto:sli41@ncsu.edu Shijie Li]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:wsun12@ncsu.edu Wei Sun]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:asundar2@ncsu.edu Aishwarya Sundararajan]&amp;lt;br&amp;gt;&lt;br /&gt;
[mailto:dbhanda@ncsu.edu Darshan Balakrishna Bhandari]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133107</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133107"/>
		<updated>2020-04-09T01:03:39Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Manual Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review. Given that fact it is important that Expertiza is able to track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
However, overall the amount of time directly spent on the review itself is most important. One can track the amount of time spent on the review itself quite easily by simply tracking the amount of time from when the page is opened till when the review is saved/submitted. Therefore, being able to track the time from once a link is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
Therefore, the following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and documents should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
Thus far, Expertiza does not have the aforementioned feature, however previous work was undertaken by other teams. The prior work of other teams was not merged into the Expertiza code base do to the following issues.&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== Proposed Solution ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both, however tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints on a tabular method, citing the review report table becoming too cluttered, we intend to create a pop-up window that will display the results in a table. Unlike the approach taken in project [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 from the fall of 2019], this project will work to display all information using the aforementioned tabular design in a pop-up window. With this approach, the table provides the information and estimates regarding all of the external links accessed throughout this review in a simple and uncluttered fashion.&lt;br /&gt;
&lt;br /&gt;
=== Design pattern ===&lt;br /&gt;
'''Strategy:''' This project, for each review page, deals with different type of links. Javascript is used to track the access time for online links, such as github repo, youtube links, and more. For submitted files, such as txt, jpg, we will time it with  views/response/_submitted_files.html.erb.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Instructor&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for an instructor to access the tabularized information regarding access times:&lt;br /&gt;
[[File:E1989_Instructor_flowchart.png | center]]&lt;br /&gt;
&lt;br /&gt;
=== Database Schema ===&lt;br /&gt;
[[File:Db_schema.PNG]]&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using rspec. We will test the changes made to controllers/submission_viewing_events_controller.rb and ensure the new implementation will pass.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
1. Log in as instructor&lt;br /&gt;
&lt;br /&gt;
2. Assign a review to a student&lt;br /&gt;
&lt;br /&gt;
3. Log in as student&lt;br /&gt;
&lt;br /&gt;
4. Complete the dummy review in 5 minutes&lt;br /&gt;
&lt;br /&gt;
5. Log in as instructor&lt;br /&gt;
&lt;br /&gt;
6. Navigate to review report tab&lt;br /&gt;
&lt;br /&gt;
7. Verify that the review was completed ~5 minutes.&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133106</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133106"/>
		<updated>2020-04-09T01:03:08Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review. Given that fact it is important that Expertiza is able to track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
However, overall the amount of time directly spent on the review itself is most important. One can track the amount of time spent on the review itself quite easily by simply tracking the amount of time from when the page is opened till when the review is saved/submitted. Therefore, being able to track the time from once a link is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
Therefore, the following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and documents should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
Thus far, Expertiza does not have the aforementioned feature, however previous work was undertaken by other teams. The prior work of other teams was not merged into the Expertiza code base do to the following issues.&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== Proposed Solution ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both, however tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints on a tabular method, citing the review report table becoming too cluttered, we intend to create a pop-up window that will display the results in a table. Unlike the approach taken in project [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 from the fall of 2019], this project will work to display all information using the aforementioned tabular design in a pop-up window. With this approach, the table provides the information and estimates regarding all of the external links accessed throughout this review in a simple and uncluttered fashion.&lt;br /&gt;
&lt;br /&gt;
=== Design pattern ===&lt;br /&gt;
'''Strategy:''' This project, for each review page, deals with different type of links. Javascript is used to track the access time for online links, such as github repo, youtube links, and more. For submitted files, such as txt, jpg, we will time it with  views/response/_submitted_files.html.erb.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Instructor&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for an instructor to access the tabularized information regarding access times:&lt;br /&gt;
[[File:E1989_Instructor_flowchart.png | center]]&lt;br /&gt;
&lt;br /&gt;
=== Database Schema ===&lt;br /&gt;
[[File:Db_schema.PNG]]&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using rspec. We will test the changes made to controllers/submission_viewing_events_controller.rb and ensure the new implementation will pass.&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
1. Log in as instructor&lt;br /&gt;
2. Assign a review to a student&lt;br /&gt;
3. Log in as student&lt;br /&gt;
4. Complete the dummy review in 5 minutes&lt;br /&gt;
5. Log in as instructor&lt;br /&gt;
6. Navigate to review report tab&lt;br /&gt;
7. Verify that the review was completed ~5 minutes.&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133104</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133104"/>
		<updated>2020-04-09T00:58:51Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review. Given that fact it is important that Expertiza is able to track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
However, overall the amount of time directly spent on the review itself is most important. One can track the amount of time spent on the review itself quite easily by simply tracking the amount of time from when the page is opened till when the review is saved/submitted. Therefore, being able to track the time from once a link is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
Therefore, the following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and documents should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
Thus far, Expertiza does not have the aforementioned feature, however previous work was undertaken by other teams. The prior work of other teams was not merged into the Expertiza code base do to the following issues.&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== Proposed Solution ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both, however tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints on a tabular method, citing the review report table becoming too cluttered, we intend to create a pop-up window that will display the results in a table. Unlike the approach taken in project [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 from the fall of 2019], this project will work to display all information using the aforementioned tabular design in a pop-up window. With this approach, the table provides the information and estimates regarding all of the external links accessed throughout this review in a simple and uncluttered fashion.&lt;br /&gt;
&lt;br /&gt;
=== Design pattern ===&lt;br /&gt;
'''Strategy:''' This project, for each review page, deals with different type of links. Javascript is used to track the access time for online links, such as github repo, youtube links, and more. For submitted files, such as txt, jpg, we will time it with  views/response/_submitted_files.html.erb.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Instructor&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for an instructor to access the tabularized information regarding access times:&lt;br /&gt;
[[File:E1989_Instructor_flowchart.png | center]]&lt;br /&gt;
&lt;br /&gt;
=== Database Schema ===&lt;br /&gt;
[[File:Db_schema.PNG]]&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
===Rspec=== &lt;br /&gt;
Automatic testing will be achieved using rspec. We will test the changes made to controllers/submission_viewing_events_controller.rb and ensure the new implementation will pass.&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133102</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133102"/>
		<updated>2020-04-09T00:58:18Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review. Given that fact it is important that Expertiza is able to track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
However, overall the amount of time directly spent on the review itself is most important. One can track the amount of time spent on the review itself quite easily by simply tracking the amount of time from when the page is opened till when the review is saved/submitted. Therefore, being able to track the time from once a link is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
Therefore, the following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and documents should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
Thus far, Expertiza does not have the aforementioned feature, however previous work was undertaken by other teams. The prior work of other teams was not merged into the Expertiza code base do to the following issues.&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== Proposed Solution ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both, however tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints on a tabular method, citing the review report table becoming too cluttered, we intend to create a pop-up window that will display the results in a table. Unlike the approach taken in project [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 from the fall of 2019], this project will work to display all information using the aforementioned tabular design in a pop-up window. With this approach, the table provides the information and estimates regarding all of the external links accessed throughout this review in a simple and uncluttered fashion.&lt;br /&gt;
&lt;br /&gt;
=== Design pattern ===&lt;br /&gt;
'''Strategy:''' This project, for each review page, deals with different type of links. Javascript is used to track the access time for online links, such as github repo, youtube links, and more. For submitted files, such as txt, jpg, we will time it with  views/response/_submitted_files.html.erb.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Instructor&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for an instructor to access the tabularized information regarding access times:&lt;br /&gt;
[[File:E1989_Instructor_flowchart.png | center]]&lt;br /&gt;
&lt;br /&gt;
=== Database Schema ===&lt;br /&gt;
[[File:Db_schema.PNG]]&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
'''Rspec:''' Automatic testing will be achieved using rspec. We will test the changes made to controllers/submission_viewing_events_controller.rb and ensure the new implementation will pass.&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133100</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133100"/>
		<updated>2020-04-09T00:57:36Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review. Given that fact it is important that Expertiza is able to track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
However, overall the amount of time directly spent on the review itself is most important. One can track the amount of time spent on the review itself quite easily by simply tracking the amount of time from when the page is opened till when the review is saved/submitted. Therefore, being able to track the time from once a link is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
Therefore, the following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and documents should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
Thus far, Expertiza does not have the aforementioned feature, however previous work was undertaken by other teams. The prior work of other teams was not merged into the Expertiza code base do to the following issues.&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== Proposed Solution ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both, however tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints on a tabular method, citing the review report table becoming too cluttered, we intend to create a pop-up window that will display the results in a table. Unlike the approach taken in project [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 from the fall of 2019], this project will work to display all information using the aforementioned tabular design in a pop-up window. With this approach, the table provides the information and estimates regarding all of the external links accessed throughout this review in a simple and uncluttered fashion.&lt;br /&gt;
&lt;br /&gt;
=== Design pattern ===&lt;br /&gt;
'''Strategy:''' This project, for each review page, deals with different type of links. Javascript is used to track the access time for online links, such as github repo, youtube links, and more. For submitted files, such as txt, jpg, we will time it with  views/response/_submitted_files.html.erb.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Instructor&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for an instructor to access the tabularized information regarding access times:&lt;br /&gt;
[[File:E1989_Instructor_flowchart.png | center]]&lt;br /&gt;
&lt;br /&gt;
=== Database Schema ===&lt;br /&gt;
[[File:Db_schema.PNG]]&lt;br /&gt;
&lt;br /&gt;
=== Testing Plan ===&lt;br /&gt;
'''Rspec:'''Automatic testing will be achieved using rspec. We will test the changes made to controllers/submission_viewing_events_controller.rb and ensure the new implementation will pass.&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133098</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133098"/>
		<updated>2020-04-09T00:55:01Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Proposed Solution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review. Given that fact it is important that Expertiza is able to track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
However, overall the amount of time directly spent on the review itself is most important. One can track the amount of time spent on the review itself quite easily by simply tracking the amount of time from when the page is opened till when the review is saved/submitted. Therefore, being able to track the time from once a link is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
Therefore, the following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and documents should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
Thus far, Expertiza does not have the aforementioned feature, however previous work was undertaken by other teams. The prior work of other teams was not merged into the Expertiza code base do to the following issues.&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== Proposed Solution ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both, however tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints on a tabular method, citing the review report table becoming too cluttered, we intend to create a pop-up window that will display the results in a table. Unlike the approach taken in project [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 from the fall of 2019], this project will work to display all information using the aforementioned tabular design in a pop-up window. With this approach, the table provides the information and estimates regarding all of the external links accessed throughout this review in a simple and uncluttered fashion.&lt;br /&gt;
&lt;br /&gt;
=== Design pattern ===&lt;br /&gt;
'''Strategy:''' This project, for each review page, deals with different type of links. Javascript is used to track the access time for online links, such as github repo, youtube links, and more. For submitted files, such as txt, jpg, we will time it with  views/response/_submitted_files.html.erb.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Instructor&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for an instructor to access the tabularized information regarding access times:&lt;br /&gt;
[[File:E1989_Instructor_flowchart.png | center]]&lt;br /&gt;
&lt;br /&gt;
=== Database Schema ===&lt;br /&gt;
[[File:Db_schema.PNG]]&lt;br /&gt;
&lt;br /&gt;
=== Testing Plan ===&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133096</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133096"/>
		<updated>2020-04-09T00:53:34Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Database Table */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review. Given that fact it is important that Expertiza is able to track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
However, overall the amount of time directly spent on the review itself is most important. One can track the amount of time spent on the review itself quite easily by simply tracking the amount of time from when the page is opened till when the review is saved/submitted. Therefore, being able to track the time from once a link is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
Therefore, the following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and documents should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
Thus far, Expertiza does not have the aforementioned feature, however previous work was undertaken by other teams. The prior work of other teams was not merged into the Expertiza code base do to the following issues.&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== Proposed Solution ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both, however tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints on a tabular method, citing the review report table becoming too cluttered, we intend to create a pop-up window that will display the results in a table. Unlike the approach taken in project [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 from the fall of 2019], this project will work to display all information using the aforementioned tabular design in a pop-up window. With this approach, the table provides the information and estimates regarding all of the external links accessed throughout this review in a simple and uncluttered fashion.&lt;br /&gt;
&lt;br /&gt;
=== Design pattern ===&lt;br /&gt;
'''Strategy:''' This project, for each review page, deals with different type of links. Javascript is used to track the access time for online links, such as github repo, youtube links, and more. For submitted files, such as txt, jpg, we will time it with  views/response/_submitted_files.html.erb.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Instructor&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for an instructor to access the tabularized information regarding access times:&lt;br /&gt;
[[File:E1989_Instructor_flowchart.png | center]]&lt;br /&gt;
&lt;br /&gt;
=== Database Schema ===&lt;br /&gt;
[[File:Db_schema.PNG]]&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Db_schema.PNG&amp;diff=133094</id>
		<title>File:Db schema.PNG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Db_schema.PNG&amp;diff=133094"/>
		<updated>2020-04-09T00:52:37Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133079</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133079"/>
		<updated>2020-04-09T00:25:25Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review. Given that fact it is important that Expertiza is able to track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
However, overall the amount of time directly spent on the review itself is most important. One can track the amount of time spent on the review itself quite easily by simply tracking the amount of time from when the page is opened till when the review is saved/submitted. Therefore, being able to track the time from once a link is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
Therefore, the following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and documents should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
Thus far, Expertiza does not have the aforementioned feature, however previous work was undertaken by other teams. The prior work of other teams was not merged into the Expertiza code base do to the following issues.&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== Proposed Solution ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both, however tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints on a tabular method, citing the review report table becoming too cluttered, we intend to create a pop-up window that will display the results in a table. Unlike the approach taken in project [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 from the fall of 2019], this project will work to display all information using the aforementioned tabular design in a pop-up window. With this approach, the table provides the information and estimates regarding all of the external links accessed throughout this review in a simple and uncluttered fashion.&lt;br /&gt;
&lt;br /&gt;
=== Design pattern ===&lt;br /&gt;
'''Strategy:''' This project, for each review page, deals with different type of links. Javascript is used to track the access time for online links, such as github repo, youtube links, and more. For submitted files, such as txt, jpg, we will time it with  views/response/_submitted_files.html.erb.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Instructor&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for an instructor to access the tabularized information regarding access times:&lt;br /&gt;
[[File:E1989_Instructor_flowchart.png | center]]&lt;br /&gt;
&lt;br /&gt;
=== Database Table ===&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133078</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133078"/>
		<updated>2020-04-09T00:23:55Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Design pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review. Given that fact it is important that Expertiza is able to track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
However, overall the amount of time directly spent on the review itself is most important. One can track the amount of time spent on the review itself quite easily by simply tracking the amount of time from when the page is opened till when the review is saved/submitted. Therefore, being able to track the time from once a link is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
Therefore, the following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and documents should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
Thus far, Expertiza does not have the aforementioned feature, however previous work was undertaken by other teams. The prior work of other teams was not merged into the Expertiza code base do to the following issues.&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== Proposed Solution ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both, however tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints on a tabular method, citing the review report table becoming too cluttered, we intend to create a pop-up window that will display the results in a table. Unlike the approach taken in project [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 from the fall of 2019], this project will work to display all information using the aforementioned tabular design in a pop-up window. With this approach, the table provides the information and estimates regarding all of the external links accessed throughout this review in a simple and uncluttered fashion.&lt;br /&gt;
&lt;br /&gt;
=== Design pattern ===&lt;br /&gt;
'''Strategy:''' This project, for each review page, deals with different type of links. Javascript is used to track the access time for online links, such as github repo, youtube links, and more. For submitted files, such as txt, jpg, we will time it with  views/response/_submitted_files.html.erb.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Instructor&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for an instructor to access the tabularized information regarding access times:&lt;br /&gt;
[[File:E1989_Instructor_flowchart.png | center]]&lt;br /&gt;
&lt;br /&gt;
=== Database ===&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133077</id>
		<title>CSC/ECE 517 Spring 2020 / E2023 Track the Time Students Look at Other Submissions</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2023_Track_the_Time_Students_Look_at_Other_Submissions&amp;diff=133077"/>
		<updated>2020-04-09T00:23:31Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Proposed Solution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
== Problem Statement ==&lt;br /&gt;
Understanding how much time a student spends reviewing another's work is beneficial in order to better estimate the quality of said review. Given that fact it is important that Expertiza is able to track and display the given amount of time a student spends on a review.&lt;br /&gt;
&lt;br /&gt;
The time spent on each review is a summation of multiple sources:&lt;br /&gt;
* Time spent of the Expertiza review itself&lt;br /&gt;
* Time spent looking at external links&lt;br /&gt;
* Time spent looking at downloadable files&lt;br /&gt;
&lt;br /&gt;
However, overall the amount of time directly spent on the review itself is most important. One can track the amount of time spent on the review itself quite easily by simply tracking the amount of time from when the page is opened till when the review is saved/submitted. Therefore, being able to track the time from once a link is opened till when the review is saved/submitted will provide a reasonable estimate of the amount of time spent on each resource. This has the benefit of only needing to track information interacted with on the Expertiza review page, as opposed to other external files and links.&lt;br /&gt;
&lt;br /&gt;
Therefore, the following tasks need to be accomplished:&lt;br /&gt;
# Time spent on an Expertiza review must be tracked&lt;br /&gt;
# Time spent on external links and documents should be tracked/estimated&lt;br /&gt;
# Overall time spent on the review should be displayed in a &amp;quot;user friendly manner&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Current Implementation ===&lt;br /&gt;
Thus far, Expertiza does not have the aforementioned feature, however previous work was undertaken by other teams. The prior work of other teams was not merged into the Expertiza code base do to the following issues.&lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/875 E1705] identified how to track the active time of windows opened from the submitted links. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1124 E1791] provided detailed insights on how they planned to track time taken by a student in viewing a submission and possible edge cases. Further, they also implemented popups and figured out a way to open downloadable files. However, the details are rendered in a not-so-friendly manner and hence it was not merged. &lt;br /&gt;
#[https://github.com/expertiza/expertiza/pull/1309 E1872] tried to solve this by incorporating the statistics in the review reports page, but their UI made the page cluttered and not friendly. Further, it was hard to identify which statistic belonged to which review, and there were almost no tests. ([http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1872_Track_Time_Students_Look_At_Other_Submissions Wiki])&lt;br /&gt;
#[https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1989._Track_the_time_students_look_at_other_submissions E1989] tried to solve this by building off of [https://github.com/expertiza/expertiza/pull/1124 E1791]. The team took the base code and attempted to implement the ability to track time spent on the review page, as well as other external links, however the code was not merged due to a large amount of white-space, as well as difficulty in distinguishing actual code changes.&lt;br /&gt;
&lt;br /&gt;
== Proposed Solution ==&lt;br /&gt;
In review of previous iterations of this project, it was found that project [https://github.com/expertiza/expertiza/pull/1124 E1791] would prove to be a good starting point for completion of this project's requirements. This build has already implemented systems that help track time spent viewing external pages. To achieve our goals outlined in the [[#Problem Statement|Problem Statement]], the following changes need to be made:&lt;br /&gt;
&lt;br /&gt;
; The time spent on the Expertiza assignment review page needs to be tracked. &lt;br /&gt;
*Due to Expertiza generating report text boxes with HTML iFrames, we will track whether or not the document hasFocus() to determine when a student is on the page or not.&lt;br /&gt;
*After 5 minutes of mouse/keyboard inactivity, a popup is displayed asking if the user is still working. At that point, the time contributed towards the total by the Expertiza page is paused until the user interacts with the popup to indicate they are still working. This is already implemented in project [https://github.com/expertiza/expertiza/pull/1124 E1791].&lt;br /&gt;
&lt;br /&gt;
; The time spent viewing the external links/downloadable files needs to be tracked or estimated&lt;br /&gt;
*Currently, if a student has an external link open as well as the Expertiza page, time is being tracked for both, however tracking of external links may be unnecessary for the project, and instead an estimation approach may be taken. Either way it is likely that this measurement will be altered throughout development of this project.&lt;br /&gt;
&lt;br /&gt;
; The overall time spent on the review needs to be displayed in a &amp;quot;user friendly manner&amp;quot; on the &amp;quot;Review Report&amp;quot; page.&lt;br /&gt;
*Due to complaints on a tabular method, citing the review report table becoming too cluttered, we intend to create a pop-up window that will display the results in a table. Unlike the approach taken in project [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 from the fall of 2019], this project will work to display all information using the aforementioned tabular design in a pop-up window. With this approach, the table provides the information and estimates regarding all of the external links accessed throughout this review in a simple and uncluttered fashion.&lt;br /&gt;
&lt;br /&gt;
=== Design pattern ===&lt;br /&gt;
'''Strategy:''' This project, for each review page, deals with different type of links. Javascript is used to track the access time for online links, such as github repo, youtube links, and more. For submitted files, such as txt, jpg, we will time it with  views/response/_submitted_files.html.erb.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Instructor&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A similar workflow from [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2017/E1791._Track_the_time_that_students_look_at_the_other_submissions_-_logging_improvement E1791 Fall '19] will be used for an instructor to access the tabularized information regarding access times:&lt;br /&gt;
[[File:E1989_Instructor_flowchart.png | center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Database&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=132237</id>
		<title>CSC/ECE 517 Spring 2020 / E2001 Refactor Questionnaires Controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=132237"/>
		<updated>2020-03-30T18:00:47Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Manual Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E2001 Refactor questionnaires_controller.rb ==&lt;br /&gt;
This page provides a description of the Expertiza based OSS project&lt;br /&gt;
__TOC__&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project. &lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
=== About Questionnaires Controller ===&lt;br /&gt;
Questionnaire controller is the controller for the Questionnaire object. A Questionnaire can be of several types including the following:&lt;br /&gt;
* Review&lt;br /&gt;
* Metareview&lt;br /&gt;
* Author feedback&lt;br /&gt;
* Teammate Review&lt;br /&gt;
* Survey&lt;br /&gt;
* Assignment&lt;br /&gt;
* Global Survey&lt;br /&gt;
* Course Survey&lt;br /&gt;
* Quiz&lt;br /&gt;
&lt;br /&gt;
Of these several different types of questionnaire's the questions, that can be added, have a different formats including:&lt;br /&gt;
* Criterion &lt;br /&gt;
* Drop down (multiple choice)&lt;br /&gt;
* Text box (short question)&lt;br /&gt;
* Text area (long question)&lt;br /&gt;
&lt;br /&gt;
Within the controller itself the object can be copied (clone the given questionnaire), created, viewed, edited, updated, deleted, questions can be added, saved, or removed, and creating a questionnaire node for assignming questionnaire attributes.&lt;br /&gt;
&lt;br /&gt;
The next section explores the database relationships with questionnaires_controller.rb.&lt;br /&gt;
&lt;br /&gt;
===Database Relationships===&lt;br /&gt;
The following diagram visualizes connections in our database.  The relationships between relevant tables that are touching questionnaire.rb are shown.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_relationship.png]]&lt;br /&gt;
&lt;br /&gt;
=== Problem Statement ===&lt;br /&gt;
'''Background:''' In Expertiza, Questionnaire is a super-class utilized by all questionnaires, including rubrics, quizzes, and surveys. Rubrics are used to assess things such as project submissions and project teammates. All of the above-mentioned questionnaires are sub-classes of the Questionnaire super-class. Since this super-class is used in a multitude of locations ensuring that there are no issues in the code is very important since an error can cause malfunctions throughout Expertiza.&lt;br /&gt;
&lt;br /&gt;
'''Problem:''' Questionnaires controller has been refactored repeatedly over the past few years, yet some improvements can still be made through refactoring to increase the quality and dryness of the code. &lt;br /&gt;
&lt;br /&gt;
These problems are as follows:&lt;br /&gt;
* Unsafe reflection method const_get called with parameter value &lt;br /&gt;
* Hardwired variables in add_new_questions and save_new_questions&lt;br /&gt;
* Unnecessary checks for QuizQuestionnaire, checks can be removed&lt;br /&gt;
* Use guard clause to enclose methods instead of conditional&lt;br /&gt;
* Removed unnecessary method 'create_questionnaire'&lt;br /&gt;
* Break up create method into new 'create_questionnaire'&lt;br /&gt;
* Use each_key instead of keys.each &lt;br /&gt;
* Split lines of code to fit within recommended 160 character length&lt;br /&gt;
* Removed useless assignment of variable in save method&lt;br /&gt;
* Resolved issues involving use of unsafe reflection&lt;br /&gt;
&lt;br /&gt;
=== Files Modified in Project ===&lt;br /&gt;
#app/controllers/questionnaires_controller.rb&lt;br /&gt;
#spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Issues and Improvements ===&lt;br /&gt;
====Use guard clause====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions, delete, and save_questions used conditional to wrap code instead of guard clause. Using guard clause can reduce complexity and number of lines in code.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def save_new_questions(questionnaire_id)&lt;br /&gt;
    if params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def save_new_questions(questionnaire_id)&lt;br /&gt;
    return unless params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====QuizQuestionnaire checks====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) create and save_new_questions have unnecessary checks for if question type is QuizQuestionnaire.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
We removed the check in both methods. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
 q.weight = 1 # setting the weight to 1 for quiz questionnaire since the model validates this field&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
q.weight = 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Hardwired Variables====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions and add_new_questions used hardwired variables. When applicable all values used should be stored as variables so the user knows the purpose of the variable, if that value is used in multiple areas it can be changed with a single change, and it's just messy. For instance both add_new_questions and save_new_questions used the same scalar value 1 for a similar task. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = 1&lt;br /&gt;
 question.max_label = 'Strongly agree'&lt;br /&gt;
 question.min_label = 'Strongly disagree'&lt;br /&gt;
end&lt;br /&gt;
question.size = '50, 3' if question.is_a? Criterion&lt;br /&gt;
question.alternatives = '0|1|2|3|4|5' if question.is_a? Dropdown&lt;br /&gt;
question.size = '60, 5' if question.is_a? TextArea&lt;br /&gt;
question.size = '30' if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To our code which incorporates constants.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = WEIGHT&lt;br /&gt;
 question.max_label = LABEL_AGREE&lt;br /&gt;
 question.min_label = LABEL_DISAGREE&lt;br /&gt;
end&lt;br /&gt;
question.size = SIZE_CRITERION if question.is_a? Criterion&lt;br /&gt;
question.alternatives = SIZE_ALT_DROPDOWN if question.is_a? Dropdown&lt;br /&gt;
question.size = SIZE_TXT_AREA if question.is_a? TextArea&lt;br /&gt;
question.size = SIZE_TXT_FIELD if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With our constants at the top of the code for easy accessibility:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Constants&lt;br /&gt;
# add_new_questions&lt;br /&gt;
LABEL_AGREE = 'Strongly agree' # label for scored question if agree&lt;br /&gt;
LABEL_DISAGREE = 'Strongly disagree' # label for scored question if disagree&lt;br /&gt;
WEIGHT = 1  # question weight&lt;br /&gt;
SIZE_CRITERION = '50, 3' # size of the question box if it's a criterion&lt;br /&gt;
SIZE_ALT_DROPDOWN = '0|1|2|3|4|5' # alternative to size if question is a dropdown&lt;br /&gt;
SIZE_TXT_AREA = '60, 5' # size of question box if text area&lt;br /&gt;
SIZE_TXT_FIELD = '30' # size of question box if text field&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Unsafe Reflection====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Unsafe reflection method const_get called with parameter value&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
Remove the unsafe reflection through using a variable that checks for null values. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question_type = params[:question][:type] unless params[:question][:type].nil?&lt;br /&gt;
question = Object.const_get(question_type).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: question_type, break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed unnecessary method 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method create_questionnaire, had no apparent calls to it. Aside from assigning a creator ID, it is similar in functionality to create, so we assume that the method was at some point created as a duplicate.  We remove the method to make the code dry. &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we remove:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_questionnaire&lt;br /&gt;
    @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
    # Create Quiz content has been moved to Quiz Questionnaire Controller&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
      @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) &lt;br /&gt;
                                       if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      save&lt;br /&gt;
&lt;br /&gt;
      redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Break up create method into new 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The create method itself was 49 lines long.  This is too long to be viewable at a glance.  Breaking it up into a second private method 'create_questionnaire' to handle attribute assigning and node creation.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire.private = questionnaire_private&lt;br /&gt;
        @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
        @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
        @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
        @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
        @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
        # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
        # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
        # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
        if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
          display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
        @questionnaire.display_type = display_type&lt;br /&gt;
        @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
        @questionnaire.save&lt;br /&gt;
        # Create node&lt;br /&gt;
        tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
        parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
        QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        create_questionnaire questionnaire_private, display_type&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create_questions questionnaire_private, display_type&lt;br /&gt;
    @questionnaire.private = questionnaire_private&lt;br /&gt;
    @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
    @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
    @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
    @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
    @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
    # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
    # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
    # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
    if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
      display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    @questionnaire.display_type = display_type&lt;br /&gt;
    @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
    @questionnaire.save&lt;br /&gt;
    tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
    parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
    # Create node&lt;br /&gt;
    QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use each_key instead of keys.each====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code uses keys.each to iterate through the hash.  Keys.each is useful for modifying a hash, but in this implementation this is not necessary.  So, each_key is used to improve performance timing.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].keys.each do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].each_key do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split lines of code to fit within recommended 160 character length====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Some of the lines of code exceed the recommended 160 characters per line.  To remediate, we simply split code across multiple lines and indent accordingly to maintain readability.   &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id, seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,&lt;br /&gt;
                                                                   seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed useless assignment of variable in save method====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code included assignments of variables that were not used throughout the file.  We assume that these variables were created to implement functionality that has since been removed through previous refactor attempts.  In any case, we remove the variable keep the code dry.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    # We do not create node for quiz questionnaires&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
      p_folder = TreeFolder.find_by(name: @questionnaire.display_type)&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: p_folder.id)&lt;br /&gt;
      # create_new_node_if_necessary(parent)&lt;br /&gt;
    end&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We remove the unnecessary variables and comments, resulting in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Created new method 'save_question_hash'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The same do loop for hash iteration to update questions for a questionnaire existed in both the public methods 'update' and 'save_all_questions' methods.  In order to remove repetition and make the code dry, this do loop was refactored into its own method 'save_question_hash'.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_all_questions&lt;br /&gt;
    questionnaire_id = params[:id]&lt;br /&gt;
    begin&lt;br /&gt;
      if params[:save]&lt;br /&gt;
        params[:question].each_pair do |k, v|&lt;br /&gt;
          @question = Question.find(k)&lt;br /&gt;
          # example of 'v' value&lt;br /&gt;
          # {&amp;quot;seq&amp;quot;=&amp;gt;&amp;quot;1.0&amp;quot;, &amp;quot;txt&amp;quot;=&amp;gt;&amp;quot;WOW&amp;quot;, &amp;quot;weight&amp;quot;=&amp;gt;&amp;quot;1&amp;quot;, &amp;quot;size&amp;quot;=&amp;gt;&amp;quot;50,3&amp;quot;, &amp;quot;max_label&amp;quot;=&amp;gt;&amp;quot;Strong agree&amp;quot;, &amp;quot;min_label&amp;quot;=&amp;gt;&amp;quot;Not agree&amp;quot;}&lt;br /&gt;
          v.each_pair do |key, value|&lt;br /&gt;
            @question.send(key + '=', value) if @question.send(key) != value&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          @question.save&lt;br /&gt;
          flash[:success] = 'All questions have been successfully saved!'&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = $ERROR_INFO&lt;br /&gt;
    end&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We refactor the do loop into its own method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_question_hash(params)&lt;br /&gt;
    params[:question].each_pair do |k, v|&lt;br /&gt;
      @question = Question.find(k)&lt;br /&gt;
      v.each_pair do |key, value|&lt;br /&gt;
        @question.send(key + '=', value) if @question.send(key) != value&lt;br /&gt;
      end&lt;br /&gt;
      @question.save&lt;br /&gt;
      flash[:success] = 'All questions have been successfully saved!'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Testing Plan ===&lt;br /&gt;
In order to evaluate the changes to Expertiza throughout the OSS project two different methods were used. The first being automatic testing using RSpec and the second being manual testing through accessing the Expertiza project on one's local machine. More in depth discussion of these tests can be found below.&lt;br /&gt;
====RSpec Testing====&lt;br /&gt;
In many cases the issues were resolved by editing a few lines of code within various methods without the need for additional methods. Thus, adding more test was not needed in these cases. However, in order to ensure the code edits didn't cause any previously crafted test to fail an RSpec test was ran before each commit. If and only if all test passed could the commit be pushed. &lt;br /&gt;
&lt;br /&gt;
The command utilized to test the questionnaires controller is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
However, if a VCL was utilized for development this following command was used instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec /home/[UNITYID]/expertiza/spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In one case the create_questionnaire method was removed, thus in order to keep the set of tests clean the following test block was removed from the testing file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#create_questionnaire and #save' do&lt;br /&gt;
    context 'when quiz is valid' do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        # create_quiz_questionnaire&lt;br /&gt;
        allow_any_instance_of(QuestionnairesController).to receive(:valid_quiz).and_return('valid')&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when questionnaire type is not QuizQuestionnaire' do&lt;br /&gt;
        it 'redirects to submitted_content#edit page' do&lt;br /&gt;
          params = {aid: 1,&lt;br /&gt;
                    pid: 1,&lt;br /&gt;
                    questionnaire: {name: 'Test questionnaire',&lt;br /&gt;
                                    type: 'ReviewQuestionnaire'}}&lt;br /&gt;
          # create_questionnaire&lt;br /&gt;
          allow(ReviewQuestionnaire).to receive(:new).with(any_args).and_return(review_questionnaire)&lt;br /&gt;
          session = {user: build(:teaching_assistant, id: 1)}&lt;br /&gt;
          allow(Ta).to receive(:get_my_instructor).with(1).and_return(6)&lt;br /&gt;
          # save&lt;br /&gt;
          allow(TreeFolder).to receive(:find_by).with(name: 'Review').and_return(double('TreeFolder', id: 1))&lt;br /&gt;
          allow(FolderNode).to receive(:find_by).with(node_object_id: 1).and_return(double('FolderNode'))&lt;br /&gt;
          allow_any_instance_of(QuestionnairesController).to receive(:undo_link).with(any_args).and_return('')&lt;br /&gt;
          post :create_questionnaire, params, session&lt;br /&gt;
          expect(flash[:note]).to be nil&lt;br /&gt;
          expect(response).to redirect_to('/tree_display/list')&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).private).to eq false&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).name).to eq 'Test questionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).min_question_score).to eq 0&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).max_question_score).to eq 5&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).type).to eq 'ReviewQuestionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).instructor_id).to eq 6&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Manual Testing====&lt;br /&gt;
'''Test Log in'''&lt;br /&gt;
&lt;br /&gt;
Website url: http://152.46.18.99:8080/&lt;br /&gt;
&lt;br /&gt;
Log in: instructor6&lt;br /&gt;
&lt;br /&gt;
Password: password&lt;br /&gt;
&lt;br /&gt;
'''Test Create questionnaire'''&lt;br /&gt;
&lt;br /&gt;
1. After logging in click the Questionnaires tab.&lt;br /&gt;
&lt;br /&gt;
2. Select the plus sign for Review&lt;br /&gt;
&lt;br /&gt;
3. Enter &amp;quot;test1&amp;quot; for name (or something similiar), 0 for min, 10 for max, and no for review private.&lt;br /&gt;
&lt;br /&gt;
4. Select Create&lt;br /&gt;
&lt;br /&gt;
'''Test edit/add questions:'''&lt;br /&gt;
&lt;br /&gt;
5. Change dropbox of question type to TextArea, select Add &amp;quot;1&amp;quot; more. Press the add button.&lt;br /&gt;
&lt;br /&gt;
6. Change dropbox of question type to Criterion, select Add &amp;quot;2&amp;quot; more. Press the add button.&lt;br /&gt;
&lt;br /&gt;
7. Edit question content: &amp;quot;Test question Textarea&amp;quot;, &amp;quot;Test question Criterion1&amp;quot;, and &amp;quot;Test question Criterion2&amp;quot; in that order.&lt;br /&gt;
&lt;br /&gt;
8. Press Save review questionnaire. &lt;br /&gt;
&lt;br /&gt;
9. Refresh page. All entries should still be available.&lt;br /&gt;
&lt;br /&gt;
10. Select edit or view advice.&lt;br /&gt;
&lt;br /&gt;
11. From descending order fill the boxes with the associated number. i.e. the first box has a 5 above it. Insert 5 in the box. Do this for both criterion.&lt;br /&gt;
&lt;br /&gt;
12. Select save and redisplay advice, then press Back to Questionnaire&lt;br /&gt;
&lt;br /&gt;
13. Going back to Edit/view advice shows the same numbers inputted earlier.&lt;br /&gt;
&lt;br /&gt;
'''Test View Questionnaire'''&lt;br /&gt;
&lt;br /&gt;
14. Select back&lt;br /&gt;
&lt;br /&gt;
15. Click on the name Review: This should show a drop down showing different reviews made.&lt;br /&gt;
&lt;br /&gt;
16. Find the review that was created.&lt;br /&gt;
&lt;br /&gt;
17. Select the view icon to the right. The information should match what was created earlier.&lt;br /&gt;
&lt;br /&gt;
'''Test Delete Questionnaire'''&lt;br /&gt;
&lt;br /&gt;
18. Select Back.&lt;br /&gt;
&lt;br /&gt;
19. Repeat steps 15-16&lt;br /&gt;
&lt;br /&gt;
20. Select the big red X for delete. When prompted, select YES&lt;br /&gt;
&lt;br /&gt;
21. Click on the name Review. The Questionnaire created previously will not be present anymore&lt;br /&gt;
&lt;br /&gt;
These manual tests demonstrate some of the functionality of the questionnaire controller. Feel free to try your own test cases.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
*Code Refactoring Best Practices[https://www.altexsoft.com/blog/engineering/code-refactoring-best-practices-when-and-when-not-to-do-it/]&lt;br /&gt;
*Expertiza on Github[https://github.com/expertiza/expertiza]&lt;br /&gt;
*Expertiza Project Fork[https://github.com/Sattlert2/expertiza/tree/master]&lt;br /&gt;
*Expertiza Website[https://expertiza.ncsu.edu/]&lt;br /&gt;
*RSpec Documentation[https://relishapp.com/rspec]&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=132236</id>
		<title>CSC/ECE 517 Spring 2020 / E2001 Refactor Questionnaires Controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=132236"/>
		<updated>2020-03-30T17:52:02Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Manual Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E2001 Refactor questionnaires_controller.rb ==&lt;br /&gt;
This page provides a description of the Expertiza based OSS project&lt;br /&gt;
__TOC__&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project. &lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
=== About Questionnaires Controller ===&lt;br /&gt;
Questionnaire controller is the controller for the Questionnaire object. A Questionnaire can be of several types including the following:&lt;br /&gt;
* Review&lt;br /&gt;
* Metareview&lt;br /&gt;
* Author feedback&lt;br /&gt;
* Teammate Review&lt;br /&gt;
* Survey&lt;br /&gt;
* Assignment&lt;br /&gt;
* Global Survey&lt;br /&gt;
* Course Survey&lt;br /&gt;
* Quiz&lt;br /&gt;
&lt;br /&gt;
Of these several different types of questionnaire's the questions, that can be added, have a different formats including:&lt;br /&gt;
* Criterion &lt;br /&gt;
* Drop down (multiple choice)&lt;br /&gt;
* Text box (short question)&lt;br /&gt;
* Text area (long question)&lt;br /&gt;
&lt;br /&gt;
Within the controller itself the object can be copied (clone the given questionnaire), created, viewed, edited, updated, deleted, questions can be added, saved, or removed, and creating a questionnaire node for assignming questionnaire attributes.&lt;br /&gt;
&lt;br /&gt;
The next section explores the database relationships with questionnaires_controller.rb.&lt;br /&gt;
&lt;br /&gt;
===Database Relationships===&lt;br /&gt;
The following diagram visualizes connections in our database.  The relationships between relevant tables that are touching questionnaire.rb are shown.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_relationship.png]]&lt;br /&gt;
&lt;br /&gt;
=== Problem Statement ===&lt;br /&gt;
'''Background:''' In Expertiza, Questionnaire is a super-class utilized by all questionnaires, including rubrics, quizzes, and surveys. Rubrics are used to assess things such as project submissions and project teammates. All of the above-mentioned questionnaires are sub-classes of the Questionnaire super-class. Since this super-class is used in a multitude of locations ensuring that there are no issues in the code is very important since an error can cause malfunctions throughout Expertiza.&lt;br /&gt;
&lt;br /&gt;
'''Problem:''' Questionnaires controller has been refactored repeatedly over the past few years, yet some improvements can still be made through refactoring to increase the quality and dryness of the code. &lt;br /&gt;
&lt;br /&gt;
These problems are as follows:&lt;br /&gt;
* Unsafe reflection method const_get called with parameter value &lt;br /&gt;
* Hardwired variables in add_new_questions and save_new_questions&lt;br /&gt;
* Unnecessary checks for QuizQuestionnaire, checks can be removed&lt;br /&gt;
* Use guard clause to enclose methods instead of conditional&lt;br /&gt;
* Removed unnecessary method 'create_questionnaire'&lt;br /&gt;
* Break up create method into new 'create_questionnaire'&lt;br /&gt;
* Use each_key instead of keys.each &lt;br /&gt;
* Split lines of code to fit within recommended 160 character length&lt;br /&gt;
* Removed useless assignment of variable in save method&lt;br /&gt;
* Resolved issues involving use of unsafe reflection&lt;br /&gt;
&lt;br /&gt;
=== Files Modified in Project ===&lt;br /&gt;
#app/controllers/questionnaires_controller.rb&lt;br /&gt;
#spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Issues and Improvements ===&lt;br /&gt;
====Use guard clause====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions, delete, and save_questions used conditional to wrap code instead of guard clause. Using guard clause can reduce complexity and number of lines in code.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def save_new_questions(questionnaire_id)&lt;br /&gt;
    if params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def save_new_questions(questionnaire_id)&lt;br /&gt;
    return unless params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====QuizQuestionnaire checks====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) create and save_new_questions have unnecessary checks for if question type is QuizQuestionnaire.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
We removed the check in both methods. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
 q.weight = 1 # setting the weight to 1 for quiz questionnaire since the model validates this field&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
q.weight = 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Hardwired Variables====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions and add_new_questions used hardwired variables. When applicable all values used should be stored as variables so the user knows the purpose of the variable, if that value is used in multiple areas it can be changed with a single change, and it's just messy. For instance both add_new_questions and save_new_questions used the same scalar value 1 for a similar task. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = 1&lt;br /&gt;
 question.max_label = 'Strongly agree'&lt;br /&gt;
 question.min_label = 'Strongly disagree'&lt;br /&gt;
end&lt;br /&gt;
question.size = '50, 3' if question.is_a? Criterion&lt;br /&gt;
question.alternatives = '0|1|2|3|4|5' if question.is_a? Dropdown&lt;br /&gt;
question.size = '60, 5' if question.is_a? TextArea&lt;br /&gt;
question.size = '30' if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To our code which incorporates constants.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = WEIGHT&lt;br /&gt;
 question.max_label = LABEL_AGREE&lt;br /&gt;
 question.min_label = LABEL_DISAGREE&lt;br /&gt;
end&lt;br /&gt;
question.size = SIZE_CRITERION if question.is_a? Criterion&lt;br /&gt;
question.alternatives = SIZE_ALT_DROPDOWN if question.is_a? Dropdown&lt;br /&gt;
question.size = SIZE_TXT_AREA if question.is_a? TextArea&lt;br /&gt;
question.size = SIZE_TXT_FIELD if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With our constants at the top of the code for easy accessibility:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Constants&lt;br /&gt;
# add_new_questions&lt;br /&gt;
LABEL_AGREE = 'Strongly agree' # label for scored question if agree&lt;br /&gt;
LABEL_DISAGREE = 'Strongly disagree' # label for scored question if disagree&lt;br /&gt;
WEIGHT = 1  # question weight&lt;br /&gt;
SIZE_CRITERION = '50, 3' # size of the question box if it's a criterion&lt;br /&gt;
SIZE_ALT_DROPDOWN = '0|1|2|3|4|5' # alternative to size if question is a dropdown&lt;br /&gt;
SIZE_TXT_AREA = '60, 5' # size of question box if text area&lt;br /&gt;
SIZE_TXT_FIELD = '30' # size of question box if text field&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Unsafe Reflection====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Unsafe reflection method const_get called with parameter value&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
Remove the unsafe reflection through using a variable that checks for null values. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question_type = params[:question][:type] unless params[:question][:type].nil?&lt;br /&gt;
question = Object.const_get(question_type).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: question_type, break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed unnecessary method 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method create_questionnaire, had no apparent calls to it. Aside from assigning a creator ID, it is similar in functionality to create, so we assume that the method was at some point created as a duplicate.  We remove the method to make the code dry. &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we remove:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_questionnaire&lt;br /&gt;
    @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
    # Create Quiz content has been moved to Quiz Questionnaire Controller&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
      @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) &lt;br /&gt;
                                       if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      save&lt;br /&gt;
&lt;br /&gt;
      redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Break up create method into new 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The create method itself was 49 lines long.  This is too long to be viewable at a glance.  Breaking it up into a second private method 'create_questionnaire' to handle attribute assigning and node creation.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire.private = questionnaire_private&lt;br /&gt;
        @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
        @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
        @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
        @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
        @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
        # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
        # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
        # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
        if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
          display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
        @questionnaire.display_type = display_type&lt;br /&gt;
        @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
        @questionnaire.save&lt;br /&gt;
        # Create node&lt;br /&gt;
        tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
        parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
        QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        create_questionnaire questionnaire_private, display_type&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create_questions questionnaire_private, display_type&lt;br /&gt;
    @questionnaire.private = questionnaire_private&lt;br /&gt;
    @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
    @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
    @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
    @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
    @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
    # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
    # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
    # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
    if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
      display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    @questionnaire.display_type = display_type&lt;br /&gt;
    @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
    @questionnaire.save&lt;br /&gt;
    tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
    parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
    # Create node&lt;br /&gt;
    QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use each_key instead of keys.each====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code uses keys.each to iterate through the hash.  Keys.each is useful for modifying a hash, but in this implementation this is not necessary.  So, each_key is used to improve performance timing.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].keys.each do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].each_key do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split lines of code to fit within recommended 160 character length====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Some of the lines of code exceed the recommended 160 characters per line.  To remediate, we simply split code across multiple lines and indent accordingly to maintain readability.   &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id, seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,&lt;br /&gt;
                                                                   seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed useless assignment of variable in save method====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code included assignments of variables that were not used throughout the file.  We assume that these variables were created to implement functionality that has since been removed through previous refactor attempts.  In any case, we remove the variable keep the code dry.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    # We do not create node for quiz questionnaires&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
      p_folder = TreeFolder.find_by(name: @questionnaire.display_type)&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: p_folder.id)&lt;br /&gt;
      # create_new_node_if_necessary(parent)&lt;br /&gt;
    end&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We remove the unnecessary variables and comments, resulting in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Created new method 'save_question_hash'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The same do loop for hash iteration to update questions for a questionnaire existed in both the public methods 'update' and 'save_all_questions' methods.  In order to remove repetition and make the code dry, this do loop was refactored into its own method 'save_question_hash'.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_all_questions&lt;br /&gt;
    questionnaire_id = params[:id]&lt;br /&gt;
    begin&lt;br /&gt;
      if params[:save]&lt;br /&gt;
        params[:question].each_pair do |k, v|&lt;br /&gt;
          @question = Question.find(k)&lt;br /&gt;
          # example of 'v' value&lt;br /&gt;
          # {&amp;quot;seq&amp;quot;=&amp;gt;&amp;quot;1.0&amp;quot;, &amp;quot;txt&amp;quot;=&amp;gt;&amp;quot;WOW&amp;quot;, &amp;quot;weight&amp;quot;=&amp;gt;&amp;quot;1&amp;quot;, &amp;quot;size&amp;quot;=&amp;gt;&amp;quot;50,3&amp;quot;, &amp;quot;max_label&amp;quot;=&amp;gt;&amp;quot;Strong agree&amp;quot;, &amp;quot;min_label&amp;quot;=&amp;gt;&amp;quot;Not agree&amp;quot;}&lt;br /&gt;
          v.each_pair do |key, value|&lt;br /&gt;
            @question.send(key + '=', value) if @question.send(key) != value&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          @question.save&lt;br /&gt;
          flash[:success] = 'All questions have been successfully saved!'&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = $ERROR_INFO&lt;br /&gt;
    end&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We refactor the do loop into its own method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_question_hash(params)&lt;br /&gt;
    params[:question].each_pair do |k, v|&lt;br /&gt;
      @question = Question.find(k)&lt;br /&gt;
      v.each_pair do |key, value|&lt;br /&gt;
        @question.send(key + '=', value) if @question.send(key) != value&lt;br /&gt;
      end&lt;br /&gt;
      @question.save&lt;br /&gt;
      flash[:success] = 'All questions have been successfully saved!'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Testing Plan ===&lt;br /&gt;
In order to evaluate the changes to Expertiza throughout the OSS project two different methods were used. The first being automatic testing using RSpec and the second being manual testing through accessing the Expertiza project on one's local machine. More in depth discussion of these tests can be found below.&lt;br /&gt;
====RSpec Testing====&lt;br /&gt;
In many cases the issues were resolved by editing a few lines of code within various methods without the need for additional methods. Thus, adding more test was not needed in these cases. However, in order to ensure the code edits didn't cause any previously crafted test to fail an RSpec test was ran before each commit. If and only if all test passed could the commit be pushed. &lt;br /&gt;
&lt;br /&gt;
The command utilized to test the questionnaires controller is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
However, if a VCL was utilized for development this following command was used instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec /home/[UNITYID]/expertiza/spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In one case the create_questionnaire method was removed, thus in order to keep the set of tests clean the following test block was removed from the testing file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#create_questionnaire and #save' do&lt;br /&gt;
    context 'when quiz is valid' do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        # create_quiz_questionnaire&lt;br /&gt;
        allow_any_instance_of(QuestionnairesController).to receive(:valid_quiz).and_return('valid')&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when questionnaire type is not QuizQuestionnaire' do&lt;br /&gt;
        it 'redirects to submitted_content#edit page' do&lt;br /&gt;
          params = {aid: 1,&lt;br /&gt;
                    pid: 1,&lt;br /&gt;
                    questionnaire: {name: 'Test questionnaire',&lt;br /&gt;
                                    type: 'ReviewQuestionnaire'}}&lt;br /&gt;
          # create_questionnaire&lt;br /&gt;
          allow(ReviewQuestionnaire).to receive(:new).with(any_args).and_return(review_questionnaire)&lt;br /&gt;
          session = {user: build(:teaching_assistant, id: 1)}&lt;br /&gt;
          allow(Ta).to receive(:get_my_instructor).with(1).and_return(6)&lt;br /&gt;
          # save&lt;br /&gt;
          allow(TreeFolder).to receive(:find_by).with(name: 'Review').and_return(double('TreeFolder', id: 1))&lt;br /&gt;
          allow(FolderNode).to receive(:find_by).with(node_object_id: 1).and_return(double('FolderNode'))&lt;br /&gt;
          allow_any_instance_of(QuestionnairesController).to receive(:undo_link).with(any_args).and_return('')&lt;br /&gt;
          post :create_questionnaire, params, session&lt;br /&gt;
          expect(flash[:note]).to be nil&lt;br /&gt;
          expect(response).to redirect_to('/tree_display/list')&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).private).to eq false&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).name).to eq 'Test questionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).min_question_score).to eq 0&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).max_question_score).to eq 5&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).type).to eq 'ReviewQuestionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).instructor_id).to eq 6&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Manual Testing====&lt;br /&gt;
'''Test Log in'''&lt;br /&gt;
&lt;br /&gt;
Website url: http://152.46.18.99:8080/&lt;br /&gt;
&lt;br /&gt;
Log in: instructor6&lt;br /&gt;
&lt;br /&gt;
Password: Password&lt;br /&gt;
&lt;br /&gt;
'''Test Create questionnaire'''&lt;br /&gt;
&lt;br /&gt;
1. After logging in click the Questionnaires tab.&lt;br /&gt;
&lt;br /&gt;
2. Select the plus sign for Review&lt;br /&gt;
&lt;br /&gt;
3. Enter &amp;quot;test1&amp;quot; for name (or something similiar), 0 for min, 10 for max, and no for review private.&lt;br /&gt;
&lt;br /&gt;
4. Select Create&lt;br /&gt;
&lt;br /&gt;
'''Test edit/add questions:'''&lt;br /&gt;
&lt;br /&gt;
5. Change dropbox of question type to TextArea, select Add &amp;quot;1&amp;quot; more. Press the add button.&lt;br /&gt;
&lt;br /&gt;
6. Change dropbox of question type to Criterion, select Add &amp;quot;2&amp;quot; more. Press the add button.&lt;br /&gt;
&lt;br /&gt;
7. Edit question content: &amp;quot;Test question Textarea&amp;quot;, &amp;quot;Test question Criterion1&amp;quot;, and &amp;quot;Test question Criterion2&amp;quot; in that order.&lt;br /&gt;
&lt;br /&gt;
8. Press Save review questionnaire. &lt;br /&gt;
&lt;br /&gt;
9. Refresh page. All entries should still be available.&lt;br /&gt;
&lt;br /&gt;
10. Select edit or view advice.&lt;br /&gt;
&lt;br /&gt;
11. From descending order fill the boxes with the associated number. i.e. the first box has a 5 above it. Insert 5 in the box. Do this for both criterion.&lt;br /&gt;
&lt;br /&gt;
12. Select save and redisplay advice, then press Back to Questionnaire&lt;br /&gt;
&lt;br /&gt;
13. Going back to Edit/view advice shows the same numbers inputted earlier.&lt;br /&gt;
&lt;br /&gt;
'''Test View Questionnaire'''&lt;br /&gt;
&lt;br /&gt;
14. Select back&lt;br /&gt;
&lt;br /&gt;
15. Click on the name Review: This should show a drop down showing different reviews made.&lt;br /&gt;
&lt;br /&gt;
16. Find the review that was created.&lt;br /&gt;
&lt;br /&gt;
17. Select the view icon to the right. The information should match what was created earlier.&lt;br /&gt;
&lt;br /&gt;
'''Test Delete Questionnaire'''&lt;br /&gt;
&lt;br /&gt;
18. Select Back.&lt;br /&gt;
&lt;br /&gt;
19. Repeat steps 15-16&lt;br /&gt;
&lt;br /&gt;
20. Select the big red X for delete. When prompted, select YES&lt;br /&gt;
&lt;br /&gt;
21. Click on the name Review. The Questionnaire created previously will not be present anymore&lt;br /&gt;
&lt;br /&gt;
These manual tests demonstrate some of the functionality of the questionnaire controller. Feel free to try your own test cases.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
*Code Refactoring Best Practices[https://www.altexsoft.com/blog/engineering/code-refactoring-best-practices-when-and-when-not-to-do-it/]&lt;br /&gt;
*Expertiza on Github[https://github.com/expertiza/expertiza]&lt;br /&gt;
*Expertiza Project Fork[https://github.com/Sattlert2/expertiza/tree/master]&lt;br /&gt;
*Expertiza Website[https://expertiza.ncsu.edu/]&lt;br /&gt;
*RSpec Documentation[https://relishapp.com/rspec]&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=132235</id>
		<title>CSC/ECE 517 Spring 2020 / E2001 Refactor Questionnaires Controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=132235"/>
		<updated>2020-03-30T17:51:06Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Manual Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E2001 Refactor questionnaires_controller.rb ==&lt;br /&gt;
This page provides a description of the Expertiza based OSS project&lt;br /&gt;
__TOC__&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project. &lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
=== About Questionnaires Controller ===&lt;br /&gt;
Questionnaire controller is the controller for the Questionnaire object. A Questionnaire can be of several types including the following:&lt;br /&gt;
* Review&lt;br /&gt;
* Metareview&lt;br /&gt;
* Author feedback&lt;br /&gt;
* Teammate Review&lt;br /&gt;
* Survey&lt;br /&gt;
* Assignment&lt;br /&gt;
* Global Survey&lt;br /&gt;
* Course Survey&lt;br /&gt;
* Quiz&lt;br /&gt;
&lt;br /&gt;
Of these several different types of questionnaire's the questions, that can be added, have a different formats including:&lt;br /&gt;
* Criterion &lt;br /&gt;
* Drop down (multiple choice)&lt;br /&gt;
* Text box (short question)&lt;br /&gt;
* Text area (long question)&lt;br /&gt;
&lt;br /&gt;
Within the controller itself the object can be copied (clone the given questionnaire), created, viewed, edited, updated, deleted, questions can be added, saved, or removed, and creating a questionnaire node for assignming questionnaire attributes.&lt;br /&gt;
&lt;br /&gt;
The next section explores the database relationships with questionnaires_controller.rb.&lt;br /&gt;
&lt;br /&gt;
===Database Relationships===&lt;br /&gt;
The following diagram visualizes connections in our database.  The relationships between relevant tables that are touching questionnaire.rb are shown.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_relationship.png]]&lt;br /&gt;
&lt;br /&gt;
=== Problem Statement ===&lt;br /&gt;
'''Background:''' In Expertiza, Questionnaire is a super-class utilized by all questionnaires, including rubrics, quizzes, and surveys. Rubrics are used to assess things such as project submissions and project teammates. All of the above-mentioned questionnaires are sub-classes of the Questionnaire super-class. Since this super-class is used in a multitude of locations ensuring that there are no issues in the code is very important since an error can cause malfunctions throughout Expertiza.&lt;br /&gt;
&lt;br /&gt;
'''Problem:''' Questionnaires controller has been refactored repeatedly over the past few years, yet some improvements can still be made through refactoring to increase the quality and dryness of the code. &lt;br /&gt;
&lt;br /&gt;
These problems are as follows:&lt;br /&gt;
* Unsafe reflection method const_get called with parameter value &lt;br /&gt;
* Hardwired variables in add_new_questions and save_new_questions&lt;br /&gt;
* Unnecessary checks for QuizQuestionnaire, checks can be removed&lt;br /&gt;
* Use guard clause to enclose methods instead of conditional&lt;br /&gt;
* Removed unnecessary method 'create_questionnaire'&lt;br /&gt;
* Break up create method into new 'create_questionnaire'&lt;br /&gt;
* Use each_key instead of keys.each &lt;br /&gt;
* Split lines of code to fit within recommended 160 character length&lt;br /&gt;
* Removed useless assignment of variable in save method&lt;br /&gt;
* Resolved issues involving use of unsafe reflection&lt;br /&gt;
&lt;br /&gt;
=== Files Modified in Project ===&lt;br /&gt;
#app/controllers/questionnaires_controller.rb&lt;br /&gt;
#spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Issues and Improvements ===&lt;br /&gt;
====Use guard clause====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions, delete, and save_questions used conditional to wrap code instead of guard clause. Using guard clause can reduce complexity and number of lines in code.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def save_new_questions(questionnaire_id)&lt;br /&gt;
    if params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def save_new_questions(questionnaire_id)&lt;br /&gt;
    return unless params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====QuizQuestionnaire checks====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) create and save_new_questions have unnecessary checks for if question type is QuizQuestionnaire.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
We removed the check in both methods. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
 q.weight = 1 # setting the weight to 1 for quiz questionnaire since the model validates this field&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
q.weight = 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Hardwired Variables====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions and add_new_questions used hardwired variables. When applicable all values used should be stored as variables so the user knows the purpose of the variable, if that value is used in multiple areas it can be changed with a single change, and it's just messy. For instance both add_new_questions and save_new_questions used the same scalar value 1 for a similar task. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = 1&lt;br /&gt;
 question.max_label = 'Strongly agree'&lt;br /&gt;
 question.min_label = 'Strongly disagree'&lt;br /&gt;
end&lt;br /&gt;
question.size = '50, 3' if question.is_a? Criterion&lt;br /&gt;
question.alternatives = '0|1|2|3|4|5' if question.is_a? Dropdown&lt;br /&gt;
question.size = '60, 5' if question.is_a? TextArea&lt;br /&gt;
question.size = '30' if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To our code which incorporates constants.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = WEIGHT&lt;br /&gt;
 question.max_label = LABEL_AGREE&lt;br /&gt;
 question.min_label = LABEL_DISAGREE&lt;br /&gt;
end&lt;br /&gt;
question.size = SIZE_CRITERION if question.is_a? Criterion&lt;br /&gt;
question.alternatives = SIZE_ALT_DROPDOWN if question.is_a? Dropdown&lt;br /&gt;
question.size = SIZE_TXT_AREA if question.is_a? TextArea&lt;br /&gt;
question.size = SIZE_TXT_FIELD if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With our constants at the top of the code for easy accessibility:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Constants&lt;br /&gt;
# add_new_questions&lt;br /&gt;
LABEL_AGREE = 'Strongly agree' # label for scored question if agree&lt;br /&gt;
LABEL_DISAGREE = 'Strongly disagree' # label for scored question if disagree&lt;br /&gt;
WEIGHT = 1  # question weight&lt;br /&gt;
SIZE_CRITERION = '50, 3' # size of the question box if it's a criterion&lt;br /&gt;
SIZE_ALT_DROPDOWN = '0|1|2|3|4|5' # alternative to size if question is a dropdown&lt;br /&gt;
SIZE_TXT_AREA = '60, 5' # size of question box if text area&lt;br /&gt;
SIZE_TXT_FIELD = '30' # size of question box if text field&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Unsafe Reflection====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Unsafe reflection method const_get called with parameter value&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
Remove the unsafe reflection through using a variable that checks for null values. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question_type = params[:question][:type] unless params[:question][:type].nil?&lt;br /&gt;
question = Object.const_get(question_type).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: question_type, break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed unnecessary method 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method create_questionnaire, had no apparent calls to it. Aside from assigning a creator ID, it is similar in functionality to create, so we assume that the method was at some point created as a duplicate.  We remove the method to make the code dry. &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we remove:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_questionnaire&lt;br /&gt;
    @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
    # Create Quiz content has been moved to Quiz Questionnaire Controller&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
      @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) &lt;br /&gt;
                                       if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      save&lt;br /&gt;
&lt;br /&gt;
      redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Break up create method into new 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The create method itself was 49 lines long.  This is too long to be viewable at a glance.  Breaking it up into a second private method 'create_questionnaire' to handle attribute assigning and node creation.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire.private = questionnaire_private&lt;br /&gt;
        @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
        @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
        @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
        @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
        @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
        # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
        # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
        # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
        if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
          display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
        @questionnaire.display_type = display_type&lt;br /&gt;
        @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
        @questionnaire.save&lt;br /&gt;
        # Create node&lt;br /&gt;
        tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
        parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
        QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        create_questionnaire questionnaire_private, display_type&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create_questions questionnaire_private, display_type&lt;br /&gt;
    @questionnaire.private = questionnaire_private&lt;br /&gt;
    @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
    @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
    @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
    @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
    @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
    # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
    # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
    # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
    if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
      display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    @questionnaire.display_type = display_type&lt;br /&gt;
    @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
    @questionnaire.save&lt;br /&gt;
    tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
    parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
    # Create node&lt;br /&gt;
    QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use each_key instead of keys.each====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code uses keys.each to iterate through the hash.  Keys.each is useful for modifying a hash, but in this implementation this is not necessary.  So, each_key is used to improve performance timing.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].keys.each do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].each_key do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split lines of code to fit within recommended 160 character length====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Some of the lines of code exceed the recommended 160 characters per line.  To remediate, we simply split code across multiple lines and indent accordingly to maintain readability.   &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id, seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,&lt;br /&gt;
                                                                   seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed useless assignment of variable in save method====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code included assignments of variables that were not used throughout the file.  We assume that these variables were created to implement functionality that has since been removed through previous refactor attempts.  In any case, we remove the variable keep the code dry.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    # We do not create node for quiz questionnaires&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
      p_folder = TreeFolder.find_by(name: @questionnaire.display_type)&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: p_folder.id)&lt;br /&gt;
      # create_new_node_if_necessary(parent)&lt;br /&gt;
    end&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We remove the unnecessary variables and comments, resulting in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Created new method 'save_question_hash'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The same do loop for hash iteration to update questions for a questionnaire existed in both the public methods 'update' and 'save_all_questions' methods.  In order to remove repetition and make the code dry, this do loop was refactored into its own method 'save_question_hash'.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_all_questions&lt;br /&gt;
    questionnaire_id = params[:id]&lt;br /&gt;
    begin&lt;br /&gt;
      if params[:save]&lt;br /&gt;
        params[:question].each_pair do |k, v|&lt;br /&gt;
          @question = Question.find(k)&lt;br /&gt;
          # example of 'v' value&lt;br /&gt;
          # {&amp;quot;seq&amp;quot;=&amp;gt;&amp;quot;1.0&amp;quot;, &amp;quot;txt&amp;quot;=&amp;gt;&amp;quot;WOW&amp;quot;, &amp;quot;weight&amp;quot;=&amp;gt;&amp;quot;1&amp;quot;, &amp;quot;size&amp;quot;=&amp;gt;&amp;quot;50,3&amp;quot;, &amp;quot;max_label&amp;quot;=&amp;gt;&amp;quot;Strong agree&amp;quot;, &amp;quot;min_label&amp;quot;=&amp;gt;&amp;quot;Not agree&amp;quot;}&lt;br /&gt;
          v.each_pair do |key, value|&lt;br /&gt;
            @question.send(key + '=', value) if @question.send(key) != value&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          @question.save&lt;br /&gt;
          flash[:success] = 'All questions have been successfully saved!'&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = $ERROR_INFO&lt;br /&gt;
    end&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We refactor the do loop into its own method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_question_hash(params)&lt;br /&gt;
    params[:question].each_pair do |k, v|&lt;br /&gt;
      @question = Question.find(k)&lt;br /&gt;
      v.each_pair do |key, value|&lt;br /&gt;
        @question.send(key + '=', value) if @question.send(key) != value&lt;br /&gt;
      end&lt;br /&gt;
      @question.save&lt;br /&gt;
      flash[:success] = 'All questions have been successfully saved!'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Testing Plan ===&lt;br /&gt;
In order to evaluate the changes to Expertiza throughout the OSS project two different methods were used. The first being automatic testing using RSpec and the second being manual testing through accessing the Expertiza project on one's local machine. More in depth discussion of these tests can be found below.&lt;br /&gt;
====RSpec Testing====&lt;br /&gt;
In many cases the issues were resolved by editing a few lines of code within various methods without the need for additional methods. Thus, adding more test was not needed in these cases. However, in order to ensure the code edits didn't cause any previously crafted test to fail an RSpec test was ran before each commit. If and only if all test passed could the commit be pushed. &lt;br /&gt;
&lt;br /&gt;
The command utilized to test the questionnaires controller is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
However, if a VCL was utilized for development this following command was used instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec /home/[UNITYID]/expertiza/spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In one case the create_questionnaire method was removed, thus in order to keep the set of tests clean the following test block was removed from the testing file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#create_questionnaire and #save' do&lt;br /&gt;
    context 'when quiz is valid' do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        # create_quiz_questionnaire&lt;br /&gt;
        allow_any_instance_of(QuestionnairesController).to receive(:valid_quiz).and_return('valid')&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when questionnaire type is not QuizQuestionnaire' do&lt;br /&gt;
        it 'redirects to submitted_content#edit page' do&lt;br /&gt;
          params = {aid: 1,&lt;br /&gt;
                    pid: 1,&lt;br /&gt;
                    questionnaire: {name: 'Test questionnaire',&lt;br /&gt;
                                    type: 'ReviewQuestionnaire'}}&lt;br /&gt;
          # create_questionnaire&lt;br /&gt;
          allow(ReviewQuestionnaire).to receive(:new).with(any_args).and_return(review_questionnaire)&lt;br /&gt;
          session = {user: build(:teaching_assistant, id: 1)}&lt;br /&gt;
          allow(Ta).to receive(:get_my_instructor).with(1).and_return(6)&lt;br /&gt;
          # save&lt;br /&gt;
          allow(TreeFolder).to receive(:find_by).with(name: 'Review').and_return(double('TreeFolder', id: 1))&lt;br /&gt;
          allow(FolderNode).to receive(:find_by).with(node_object_id: 1).and_return(double('FolderNode'))&lt;br /&gt;
          allow_any_instance_of(QuestionnairesController).to receive(:undo_link).with(any_args).and_return('')&lt;br /&gt;
          post :create_questionnaire, params, session&lt;br /&gt;
          expect(flash[:note]).to be nil&lt;br /&gt;
          expect(response).to redirect_to('/tree_display/list')&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).private).to eq false&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).name).to eq 'Test questionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).min_question_score).to eq 0&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).max_question_score).to eq 5&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).type).to eq 'ReviewQuestionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).instructor_id).to eq 6&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Manual Testing====&lt;br /&gt;
Test Log in:&lt;br /&gt;
&lt;br /&gt;
Website url: http://152.46.18.99:8080/&lt;br /&gt;
&lt;br /&gt;
Log in: instructor6&lt;br /&gt;
&lt;br /&gt;
Password: Password&lt;br /&gt;
&lt;br /&gt;
Test Create questionnaire:&lt;br /&gt;
&lt;br /&gt;
1. After logging in click the Questionnaires tab.&lt;br /&gt;
&lt;br /&gt;
2. Select the plus sign for Review&lt;br /&gt;
&lt;br /&gt;
3. Enter &amp;quot;test1&amp;quot; for name (or something similiar), 0 for min, 10 for max, and no for review private.&lt;br /&gt;
&lt;br /&gt;
4. Select Create&lt;br /&gt;
&lt;br /&gt;
Test edit/add questions:&lt;br /&gt;
&lt;br /&gt;
5. Change dropbox of question type to TextArea, select Add &amp;quot;1&amp;quot; more. Press the add button.&lt;br /&gt;
&lt;br /&gt;
6. Change dropbox of question type to Criterion, select Add &amp;quot;2&amp;quot; more. Press the add button.&lt;br /&gt;
&lt;br /&gt;
7. Edit question content: &amp;quot;Test question Textarea&amp;quot;, &amp;quot;Test question Criterion1&amp;quot;, and &amp;quot;Test question Criterion2&amp;quot; in that order.&lt;br /&gt;
&lt;br /&gt;
8. Press Save review questionnaire. &lt;br /&gt;
&lt;br /&gt;
9. Refresh page. All entries should still be available.&lt;br /&gt;
&lt;br /&gt;
10. Select edit or view advice.&lt;br /&gt;
&lt;br /&gt;
11. From descending order fill the boxes with the associated number. i.e. the first box has a 5 above it. Insert 5 in the box. Do this for both criterion.&lt;br /&gt;
&lt;br /&gt;
12. Select save and redisplay advice, then press Back to Questionnaire&lt;br /&gt;
&lt;br /&gt;
13. Going back to Edit/view advice shows the same numbers inputted earlier.&lt;br /&gt;
&lt;br /&gt;
Test View Questionnaire&lt;br /&gt;
&lt;br /&gt;
14. Select back&lt;br /&gt;
&lt;br /&gt;
15. Click on the name Review: This should show a drop down showing different reviews made.&lt;br /&gt;
&lt;br /&gt;
16. Find the review that was created.&lt;br /&gt;
&lt;br /&gt;
17. Select the view icon to the right. The information should match what was created earlier.&lt;br /&gt;
&lt;br /&gt;
Test Delete Questionnaire&lt;br /&gt;
&lt;br /&gt;
18. Select Back.&lt;br /&gt;
&lt;br /&gt;
19. Repeat steps 15-16&lt;br /&gt;
&lt;br /&gt;
20. Select the big red X for delete. When prompted, select YES&lt;br /&gt;
&lt;br /&gt;
21. Click on the name Review. The Questionnaire created previously will not be present anymore&lt;br /&gt;
&lt;br /&gt;
These manual tests demonstrate some of the functionality of the questionnaire controller. Feel free to try your own test cases.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
*Code Refactoring Best Practices[https://www.altexsoft.com/blog/engineering/code-refactoring-best-practices-when-and-when-not-to-do-it/]&lt;br /&gt;
*Expertiza on Github[https://github.com/expertiza/expertiza]&lt;br /&gt;
*Expertiza Project Fork[https://github.com/Sattlert2/expertiza/tree/master]&lt;br /&gt;
*Expertiza Website[https://expertiza.ncsu.edu/]&lt;br /&gt;
*RSpec Documentation[https://relishapp.com/rspec]&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=132230</id>
		<title>CSC/ECE 517 Spring 2020 / E2001 Refactor Questionnaires Controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=132230"/>
		<updated>2020-03-30T17:44:35Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Manual Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E2001 Refactor questionnaires_controller.rb ==&lt;br /&gt;
This page provides a description of the Expertiza based OSS project&lt;br /&gt;
__TOC__&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project. &lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
=== About Questionnaires Controller ===&lt;br /&gt;
Questionnaire controller is the controller for the Questionnaire object. A Questionnaire can be of several types including the following:&lt;br /&gt;
* Review&lt;br /&gt;
* Metareview&lt;br /&gt;
* Author feedback&lt;br /&gt;
* Teammate Review&lt;br /&gt;
* Survey&lt;br /&gt;
* Assignment&lt;br /&gt;
* Global Survey&lt;br /&gt;
* Course Survey&lt;br /&gt;
* Quiz&lt;br /&gt;
&lt;br /&gt;
Of these several different types of questionnaire's the questions, that can be added, have a different formats including:&lt;br /&gt;
* Criterion &lt;br /&gt;
* Drop down (multiple choice)&lt;br /&gt;
* Text box (short question)&lt;br /&gt;
* Text area (long question)&lt;br /&gt;
&lt;br /&gt;
Within the controller itself the object can be copied (clone the given questionnaire), created, viewed, edited, updated, deleted, questions can be added, saved, or removed, and creating a questionnaire node for assignming questionnaire attributes.&lt;br /&gt;
&lt;br /&gt;
The next section explores the database relationships with questionnaires_controller.rb.&lt;br /&gt;
&lt;br /&gt;
===Database Relationships===&lt;br /&gt;
The following diagram visualizes connections in our database.  The relationships between relevant tables that are touching questionnaire.rb are shown.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_relationship.png]]&lt;br /&gt;
&lt;br /&gt;
=== Problem Statement ===&lt;br /&gt;
'''Background:''' In Expertiza, Questionnaire is a super-class utilized by all questionnaires, including rubrics, quizzes, and surveys. Rubrics are used to assess things such as project submissions and project teammates. All of the above-mentioned questionnaires are sub-classes of the Questionnaire super-class. Since this super-class is used in a multitude of locations ensuring that there are no issues in the code is very important since an error can cause malfunctions throughout Expertiza.&lt;br /&gt;
&lt;br /&gt;
'''Problem:''' Questionnaires controller has been refactored repeatedly over the past few years, yet some improvements can still be made through refactoring to increase the quality and dryness of the code. &lt;br /&gt;
&lt;br /&gt;
These problems are as follows:&lt;br /&gt;
* Unsafe reflection method const_get called with parameter value &lt;br /&gt;
* Hardwired variables in add_new_questions and save_new_questions&lt;br /&gt;
* Unnecessary checks for QuizQuestionnaire, checks can be removed&lt;br /&gt;
* Use guard clause to enclose methods instead of conditional&lt;br /&gt;
* Removed unnecessary method 'create_questionnaire'&lt;br /&gt;
* Break up create method into new 'create_questionnaire'&lt;br /&gt;
* Use each_key instead of keys.each &lt;br /&gt;
* Split lines of code to fit within recommended 160 character length&lt;br /&gt;
* Removed useless assignment of variable in save method&lt;br /&gt;
* Resolved issues involving use of unsafe reflection&lt;br /&gt;
&lt;br /&gt;
=== Files Modified in Project ===&lt;br /&gt;
#app/controllers/questionnaires_controller.rb&lt;br /&gt;
#spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Issues and Improvements ===&lt;br /&gt;
====Use guard clause====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions, delete, and save_questions used conditional to wrap code instead of guard clause. Using guard clause can reduce complexity and number of lines in code.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def save_new_questions(questionnaire_id)&lt;br /&gt;
    if params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def save_new_questions(questionnaire_id)&lt;br /&gt;
    return unless params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====QuizQuestionnaire checks====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) create and save_new_questions have unnecessary checks for if question type is QuizQuestionnaire.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
We removed the check in both methods. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
 q.weight = 1 # setting the weight to 1 for quiz questionnaire since the model validates this field&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
q.weight = 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Hardwired Variables====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions and add_new_questions used hardwired variables. When applicable all values used should be stored as variables so the user knows the purpose of the variable, if that value is used in multiple areas it can be changed with a single change, and it's just messy. For instance both add_new_questions and save_new_questions used the same scalar value 1 for a similar task. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = 1&lt;br /&gt;
 question.max_label = 'Strongly agree'&lt;br /&gt;
 question.min_label = 'Strongly disagree'&lt;br /&gt;
end&lt;br /&gt;
question.size = '50, 3' if question.is_a? Criterion&lt;br /&gt;
question.alternatives = '0|1|2|3|4|5' if question.is_a? Dropdown&lt;br /&gt;
question.size = '60, 5' if question.is_a? TextArea&lt;br /&gt;
question.size = '30' if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To our code which incorporates constants.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = WEIGHT&lt;br /&gt;
 question.max_label = LABEL_AGREE&lt;br /&gt;
 question.min_label = LABEL_DISAGREE&lt;br /&gt;
end&lt;br /&gt;
question.size = SIZE_CRITERION if question.is_a? Criterion&lt;br /&gt;
question.alternatives = SIZE_ALT_DROPDOWN if question.is_a? Dropdown&lt;br /&gt;
question.size = SIZE_TXT_AREA if question.is_a? TextArea&lt;br /&gt;
question.size = SIZE_TXT_FIELD if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With our constants at the top of the code for easy accessibility:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Constants&lt;br /&gt;
# add_new_questions&lt;br /&gt;
LABEL_AGREE = 'Strongly agree' # label for scored question if agree&lt;br /&gt;
LABEL_DISAGREE = 'Strongly disagree' # label for scored question if disagree&lt;br /&gt;
WEIGHT = 1  # question weight&lt;br /&gt;
SIZE_CRITERION = '50, 3' # size of the question box if it's a criterion&lt;br /&gt;
SIZE_ALT_DROPDOWN = '0|1|2|3|4|5' # alternative to size if question is a dropdown&lt;br /&gt;
SIZE_TXT_AREA = '60, 5' # size of question box if text area&lt;br /&gt;
SIZE_TXT_FIELD = '30' # size of question box if text field&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Unsafe Reflection====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Unsafe reflection method const_get called with parameter value&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
Remove the unsafe reflection through using a variable that checks for null values. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question_type = params[:question][:type] unless params[:question][:type].nil?&lt;br /&gt;
question = Object.const_get(question_type).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: question_type, break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed unnecessary method 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method create_questionnaire, had no apparent calls to it. Aside from assigning a creator ID, it is similar in functionality to create, so we assume that the method was at some point created as a duplicate.  We remove the method to make the code dry. &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we remove:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_questionnaire&lt;br /&gt;
    @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
    # Create Quiz content has been moved to Quiz Questionnaire Controller&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
      @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) &lt;br /&gt;
                                       if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      save&lt;br /&gt;
&lt;br /&gt;
      redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Break up create method into new 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The create method itself was 49 lines long.  This is too long to be viewable at a glance.  Breaking it up into a second private method 'create_questionnaire' to handle attribute assigning and node creation.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire.private = questionnaire_private&lt;br /&gt;
        @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
        @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
        @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
        @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
        @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
        # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
        # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
        # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
        if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
          display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
        @questionnaire.display_type = display_type&lt;br /&gt;
        @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
        @questionnaire.save&lt;br /&gt;
        # Create node&lt;br /&gt;
        tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
        parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
        QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        create_questionnaire questionnaire_private, display_type&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create_questions questionnaire_private, display_type&lt;br /&gt;
    @questionnaire.private = questionnaire_private&lt;br /&gt;
    @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
    @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
    @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
    @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
    @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
    # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
    # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
    # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
    if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
      display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    @questionnaire.display_type = display_type&lt;br /&gt;
    @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
    @questionnaire.save&lt;br /&gt;
    tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
    parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
    # Create node&lt;br /&gt;
    QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use each_key instead of keys.each====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code uses keys.each to iterate through the hash.  Keys.each is useful for modifying a hash, but in this implementation this is not necessary.  So, each_key is used to improve performance timing.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].keys.each do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].each_key do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split lines of code to fit within recommended 160 character length====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Some of the lines of code exceed the recommended 160 characters per line.  To remediate, we simply split code across multiple lines and indent accordingly to maintain readability.   &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id, seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,&lt;br /&gt;
                                                                   seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed useless assignment of variable in save method====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code included assignments of variables that were not used throughout the file.  We assume that these variables were created to implement functionality that has since been removed through previous refactor attempts.  In any case, we remove the variable keep the code dry.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    # We do not create node for quiz questionnaires&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
      p_folder = TreeFolder.find_by(name: @questionnaire.display_type)&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: p_folder.id)&lt;br /&gt;
      # create_new_node_if_necessary(parent)&lt;br /&gt;
    end&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We remove the unnecessary variables and comments, resulting in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Created new method 'save_question_hash'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The same do loop for hash iteration to update questions for a questionnaire existed in both the public methods 'update' and 'save_all_questions' methods.  In order to remove repetition and make the code dry, this do loop was refactored into its own method 'save_question_hash'.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_all_questions&lt;br /&gt;
    questionnaire_id = params[:id]&lt;br /&gt;
    begin&lt;br /&gt;
      if params[:save]&lt;br /&gt;
        params[:question].each_pair do |k, v|&lt;br /&gt;
          @question = Question.find(k)&lt;br /&gt;
          # example of 'v' value&lt;br /&gt;
          # {&amp;quot;seq&amp;quot;=&amp;gt;&amp;quot;1.0&amp;quot;, &amp;quot;txt&amp;quot;=&amp;gt;&amp;quot;WOW&amp;quot;, &amp;quot;weight&amp;quot;=&amp;gt;&amp;quot;1&amp;quot;, &amp;quot;size&amp;quot;=&amp;gt;&amp;quot;50,3&amp;quot;, &amp;quot;max_label&amp;quot;=&amp;gt;&amp;quot;Strong agree&amp;quot;, &amp;quot;min_label&amp;quot;=&amp;gt;&amp;quot;Not agree&amp;quot;}&lt;br /&gt;
          v.each_pair do |key, value|&lt;br /&gt;
            @question.send(key + '=', value) if @question.send(key) != value&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          @question.save&lt;br /&gt;
          flash[:success] = 'All questions have been successfully saved!'&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = $ERROR_INFO&lt;br /&gt;
    end&lt;br /&gt;
    ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We refactor the do loop into its own method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save_question_hash(params)&lt;br /&gt;
    params[:question].each_pair do |k, v|&lt;br /&gt;
      @question = Question.find(k)&lt;br /&gt;
      v.each_pair do |key, value|&lt;br /&gt;
        @question.send(key + '=', value) if @question.send(key) != value&lt;br /&gt;
      end&lt;br /&gt;
      @question.save&lt;br /&gt;
      flash[:success] = 'All questions have been successfully saved!'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Testing Plan ===&lt;br /&gt;
In order to evaluate the changes to Expertiza throughout the OSS project two different methods were used. The first being automatic testing using RSpec and the second being manual testing through accessing the Expertiza project on one's local machine. More in depth discussion of these tests can be found below.&lt;br /&gt;
====RSpec Testing====&lt;br /&gt;
In many cases the issues were resolved by editing a few lines of code within various methods without the need for additional methods. Thus, adding more test was not needed in these cases. However, in order to ensure the code edits didn't cause any previously crafted test to fail an RSpec test was ran before each commit. If and only if all test passed could the commit be pushed. &lt;br /&gt;
&lt;br /&gt;
The command utilized to test the questionnaires controller is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
However, if a VCL was utilized for development this following command was used instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec /home/[UNITYID]/expertiza/spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In one case the create_questionnaire method was removed, thus in order to keep the set of tests clean the following test block was removed from the testing file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#create_questionnaire and #save' do&lt;br /&gt;
    context 'when quiz is valid' do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        # create_quiz_questionnaire&lt;br /&gt;
        allow_any_instance_of(QuestionnairesController).to receive(:valid_quiz).and_return('valid')&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when questionnaire type is not QuizQuestionnaire' do&lt;br /&gt;
        it 'redirects to submitted_content#edit page' do&lt;br /&gt;
          params = {aid: 1,&lt;br /&gt;
                    pid: 1,&lt;br /&gt;
                    questionnaire: {name: 'Test questionnaire',&lt;br /&gt;
                                    type: 'ReviewQuestionnaire'}}&lt;br /&gt;
          # create_questionnaire&lt;br /&gt;
          allow(ReviewQuestionnaire).to receive(:new).with(any_args).and_return(review_questionnaire)&lt;br /&gt;
          session = {user: build(:teaching_assistant, id: 1)}&lt;br /&gt;
          allow(Ta).to receive(:get_my_instructor).with(1).and_return(6)&lt;br /&gt;
          # save&lt;br /&gt;
          allow(TreeFolder).to receive(:find_by).with(name: 'Review').and_return(double('TreeFolder', id: 1))&lt;br /&gt;
          allow(FolderNode).to receive(:find_by).with(node_object_id: 1).and_return(double('FolderNode'))&lt;br /&gt;
          allow_any_instance_of(QuestionnairesController).to receive(:undo_link).with(any_args).and_return('')&lt;br /&gt;
          post :create_questionnaire, params, session&lt;br /&gt;
          expect(flash[:note]).to be nil&lt;br /&gt;
          expect(response).to redirect_to('/tree_display/list')&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).private).to eq false&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).name).to eq 'Test questionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).min_question_score).to eq 0&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).max_question_score).to eq 5&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).type).to eq 'ReviewQuestionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).instructor_id).to eq 6&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Manual Testing====&lt;br /&gt;
Test Log in:&lt;br /&gt;
Website url: http://152.46.18.99:8080/&lt;br /&gt;
Log in: instructor6&lt;br /&gt;
Password: Password&lt;br /&gt;
&lt;br /&gt;
Test Create questionnaire:&lt;br /&gt;
1. After logging in click the Questionnaires tab.&lt;br /&gt;
2. Select the plus sign for Review&lt;br /&gt;
3. Enter &amp;quot;test1&amp;quot; for name (or something similiar), 0 for min, 10 for max, and no for review private.&lt;br /&gt;
4. Select Create&lt;br /&gt;
Test edit/add questions:&lt;br /&gt;
5. Change dropbox of question type to TextArea, select Add &amp;quot;1&amp;quot; more. Press the add button.&lt;br /&gt;
6. Change dropbox of question type to Criterion, select Add &amp;quot;2&amp;quot; more. Press the add button.&lt;br /&gt;
7. Edit question content: &amp;quot;Test question Textarea&amp;quot;, &amp;quot;Test question Criterion1&amp;quot;, and &amp;quot;Test question Criterion2&amp;quot; in that order.&lt;br /&gt;
8. Press Save review questionnaire. &lt;br /&gt;
9. Refresh page. All entries should still be available.&lt;br /&gt;
10. Select edit or view advice.&lt;br /&gt;
11. From descending order fill the boxes with the associated number. i.e. the first box has a 5 above it. Insert 5 in the box. Do this for both criterion.&lt;br /&gt;
12. Select save and redisplay advice, then press Back to Questionnaire&lt;br /&gt;
13. Going back to Edit/view advice shows the same numbers inputted earlier.&lt;br /&gt;
Test View Questionnaire&lt;br /&gt;
14. Select back&lt;br /&gt;
15. Click on the name Review: This should show a drop down showing different reviews made.&lt;br /&gt;
16. Find the review that was created.&lt;br /&gt;
17. Select the view icon to the right. The information should match what was imported earlier.&lt;br /&gt;
Test Delete Questionnaire&lt;br /&gt;
18. Select Back.&lt;br /&gt;
19. Repeat steps 15-16&lt;br /&gt;
20. Select the big red X for delete. When prompted, select YES&lt;br /&gt;
21. Click on the name Review. The Questionnaire created previously will not be present anymore&lt;br /&gt;
&lt;br /&gt;
These manual tests demonstrate some of the functionality of the questionnaire controller. Feel free to try your own test cases.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
*Code Refactoring Best Practices[https://www.altexsoft.com/blog/engineering/code-refactoring-best-practices-when-and-when-not-to-do-it/]&lt;br /&gt;
*Expertiza on Github[https://github.com/expertiza/expertiza]&lt;br /&gt;
*Expertiza Project Fork[https://github.com/Sattlert2/expertiza/tree/master]&lt;br /&gt;
*Expertiza Website[https://expertiza.ncsu.edu/]&lt;br /&gt;
*RSpec Documentation[https://relishapp.com/rspec]&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=132169</id>
		<title>CSC/ECE 517 Spring 2020 / E2001 Refactor Questionnaires Controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=132169"/>
		<updated>2020-03-29T18:41:32Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E2001 Refactor questionnaires_controller.rb ==&lt;br /&gt;
This page provides a description of the Expertiza based OSS project&lt;br /&gt;
__TOC__&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project. &lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
=== About Questionnaires Controller ===&lt;br /&gt;
Questionnaire controller is the controller for the Questionnaire object. A Questionnaire can be of several types including the following:&lt;br /&gt;
* Review&lt;br /&gt;
* Metareview&lt;br /&gt;
* Author feedback&lt;br /&gt;
* Teammate Review&lt;br /&gt;
* Survey&lt;br /&gt;
* Assignment&lt;br /&gt;
* Global Survey&lt;br /&gt;
* Course Survey&lt;br /&gt;
* Quiz&lt;br /&gt;
&lt;br /&gt;
Of these several different types of questionnaire's the questions, that can be added, have a different formats including:&lt;br /&gt;
* Criterion &lt;br /&gt;
* Drop down (multiple choice)&lt;br /&gt;
* Text box (short question)&lt;br /&gt;
* Text area (long question)&lt;br /&gt;
&lt;br /&gt;
Within the controller itself the object can be copied (clone the given questionnaire), created, viewed, edited, updated, deleted, questions can be added, saved, or removed, and creating a questionnaire node for assignming questionnaire attributes.&lt;br /&gt;
&lt;br /&gt;
The next section explores the database relationships with questionnaires_controller.rb.&lt;br /&gt;
&lt;br /&gt;
===Database Relationships===&lt;br /&gt;
The following diagram visualizes connections in our database.  The relationships between relevant tables that are touching questionnaire.rb are shown.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_relationship.png]]&lt;br /&gt;
&lt;br /&gt;
=== Problem Statement ===&lt;br /&gt;
'''Background:''' In Expertiza, Questionnaire is a super-class utilized by all questionnaires, including rubrics, quizzes, and surveys. Rubrics are used to assess things such as project submissions and project teammates. All of the above-mentioned questionnaires are sub-classes of the Questionnaire super-class. Since this super-class is used in a multitude of locations ensuring that there are no issues in the code is very important since an error can cause malfunctions throughout Expertiza.&lt;br /&gt;
&lt;br /&gt;
'''Problem:''' Questionnaires controller has been refactored repeatedly over the past few years, yet some improvements can still be made through refactoring to increase the quality and dryness of the code. &lt;br /&gt;
&lt;br /&gt;
These problems are as follows:&lt;br /&gt;
* Unsafe reflection method const_get called with parameter value &lt;br /&gt;
* Hardwired variables in add_new_questions and save_new_questions&lt;br /&gt;
* Unnecessary checks for QuizQuestionnaire, checks can be removed&lt;br /&gt;
* Use guard clause to enclose methods instead of conditional&lt;br /&gt;
* Removed unnecessary method 'create_questionnaire'&lt;br /&gt;
* Break up create method into new 'create_questionnaire'&lt;br /&gt;
* Use each_key instead of keys.each &lt;br /&gt;
* Split lines of code to fit within recommended 160 character length&lt;br /&gt;
* Removed useless assignment of variable in save method&lt;br /&gt;
* Resolved issues involving use of unsafe reflection&lt;br /&gt;
&lt;br /&gt;
=== Files Modified in Project ===&lt;br /&gt;
#app/controllers/questionnaires_controller.rb&lt;br /&gt;
#spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Issues and Improvements ===&lt;br /&gt;
====Use guard clause====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions, delete, and save_questions used conditional to wrap code instead of guard clause. Using guard clause can reduce complexity and number of lines in code.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def save_new_questions(questionnaire_id)&lt;br /&gt;
    if params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def save_new_questions(questionnaire_id)&lt;br /&gt;
    return unless params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====QuizQuestionnaire checks====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) create and save_new_questions have unnecessary checks for if question type is QuizQuestionnaire.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
We removed the check in both methods. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
 q.weight = 1 # setting the weight to 1 for quiz questionnaire since the model validates this field&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
q.weight = 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Hardwired Variables====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions and add_new_questions used hardwired variables. When applicable all values used should be stored as variables so the user knows the purpose of the variable, if that value is used in multiple areas it can be changed with a single change, and it's just messy. For instance both add_new_questions and save_new_questions used the same scalar value 1 for a similar task. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = 1&lt;br /&gt;
 question.max_label = 'Strongly agree'&lt;br /&gt;
 question.min_label = 'Strongly disagree'&lt;br /&gt;
end&lt;br /&gt;
question.size = '50, 3' if question.is_a? Criterion&lt;br /&gt;
question.alternatives = '0|1|2|3|4|5' if question.is_a? Dropdown&lt;br /&gt;
question.size = '60, 5' if question.is_a? TextArea&lt;br /&gt;
question.size = '30' if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To our code which incorporates constants.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = WEIGHT&lt;br /&gt;
 question.max_label = LABEL_AGREE&lt;br /&gt;
 question.min_label = LABEL_DISAGREE&lt;br /&gt;
end&lt;br /&gt;
question.size = SIZE_CRITERION if question.is_a? Criterion&lt;br /&gt;
question.alternatives = SIZE_ALT_DROPDOWN if question.is_a? Dropdown&lt;br /&gt;
question.size = SIZE_TXT_AREA if question.is_a? TextArea&lt;br /&gt;
question.size = SIZE_TXT_FIELD if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With our constants at the top of the code for easy accessibility:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Constants&lt;br /&gt;
# add_new_questions&lt;br /&gt;
LABEL_AGREE = 'Strongly agree' # label for scored question if agree&lt;br /&gt;
LABEL_DISAGREE = 'Strongly disagree' # label for scored question if disagree&lt;br /&gt;
WEIGHT = 1  # question weight&lt;br /&gt;
SIZE_CRITERION = '50, 3' # size of the question box if it's a criterion&lt;br /&gt;
SIZE_ALT_DROPDOWN = '0|1|2|3|4|5' # alternative to size if question is a dropdown&lt;br /&gt;
SIZE_TXT_AREA = '60, 5' # size of question box if text area&lt;br /&gt;
SIZE_TXT_FIELD = '30' # size of question box if text field&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Unsafe Reflection====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Unsafe reflection method const_get called with parameter value&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
Remove the unsafe reflection through using a variable that checks for null values. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question_type = params[:question][:type] unless params[:question][:type].nil?&lt;br /&gt;
question = Object.const_get(question_type).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: question_type, break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed unnecessary method 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method create_questionnaire, had no apparent calls to it. Aside from assigning a creator ID, it is similar in functionality to create, so we assume that the method was at some point created as a duplicate.  We remove the method to make the code dry. &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we remove:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_questionnaire&lt;br /&gt;
    @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
    # Create Quiz content has been moved to Quiz Questionnaire Controller&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
      @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) &lt;br /&gt;
                                       if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      save&lt;br /&gt;
&lt;br /&gt;
      redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Break up create method into new 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The create method itself was 49 lines long.  This is too long to be viewable at a glance.  Breaking it up into a second private method 'create_questionnaire' to handle attribute assigning and node creation.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire.private = questionnaire_private&lt;br /&gt;
        @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
        @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
        @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
        @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
        @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
        # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
        # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
        # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
        if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
          display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
        @questionnaire.display_type = display_type&lt;br /&gt;
        @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
        @questionnaire.save&lt;br /&gt;
        # Create node&lt;br /&gt;
        tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
        parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
        QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        create_questionnaire questionnaire_private, display_type&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create_questions questionnaire_private, display_type&lt;br /&gt;
    @questionnaire.private = questionnaire_private&lt;br /&gt;
    @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
    @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
    @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
    @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
    @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
    # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
    # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
    # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
    if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
      display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    @questionnaire.display_type = display_type&lt;br /&gt;
    @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
    @questionnaire.save&lt;br /&gt;
    tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
    parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
    # Create node&lt;br /&gt;
    QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use each_key instead of keys.each====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code uses keys.each to iterate through the hash.  Keys.each is useful for modifying a hash, but in this implementation this is not necessary.  So, each_key is used to improve performance timing.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].keys.each do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].each_key do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split lines of code to fit within recommended 160 character length====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Some of the lines of code exceed the recommended 160 characters per line.  To remediate, we simply split code across multiple lines and indent accordingly to maintain readability.   &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id, seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,&lt;br /&gt;
                                                                   seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed useless assignment of variable in save method====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code included assignments of variables that were not used throughout the file.  We assume that these variables were created to implement functionality that has since been removed through previous refactor attempts.  In any case, we remove the variable keep the code dry.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    # We do not create node for quiz questionnaires&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
      p_folder = TreeFolder.find_by(name: @questionnaire.display_type)&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: p_folder.id)&lt;br /&gt;
      # create_new_node_if_necessary(parent)&lt;br /&gt;
    end&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We remove the unnecessary variables and comments, resulting in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Testing Plan ===&lt;br /&gt;
In order to evaluate the changes to Expertiza throughout the OSS project two different methods were used. The first being automatic testing using RSpec and the second being manual testing through accessing the Expertiza project on one's local machine. More in depth discussion of these tests can be found below.&lt;br /&gt;
====RSpec Testing====&lt;br /&gt;
In many cases the issues were resolved by editing a few lines of code within various methods without the need for additional methods. Thus, adding more test was not needed in these cases. However, in order to ensure the code edits didn't cause any previously crafted test to fail an RSpec test was ran before each commit. If and only if all test passed could the commit be pushed. &lt;br /&gt;
&lt;br /&gt;
The command utilized to test the questionnaires controller is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
However, if a VCL was utilized for development this following command was used instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec /home/[UNITYID]/expertiza/spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In one case the create_questionnaire method was removed, thus in order to keep the set of tests clean the following test block was removed from the testing file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#create_questionnaire and #save' do&lt;br /&gt;
    context 'when quiz is valid' do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        # create_quiz_questionnaire&lt;br /&gt;
        allow_any_instance_of(QuestionnairesController).to receive(:valid_quiz).and_return('valid')&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when questionnaire type is not QuizQuestionnaire' do&lt;br /&gt;
        it 'redirects to submitted_content#edit page' do&lt;br /&gt;
          params = {aid: 1,&lt;br /&gt;
                    pid: 1,&lt;br /&gt;
                    questionnaire: {name: 'Test questionnaire',&lt;br /&gt;
                                    type: 'ReviewQuestionnaire'}}&lt;br /&gt;
          # create_questionnaire&lt;br /&gt;
          allow(ReviewQuestionnaire).to receive(:new).with(any_args).and_return(review_questionnaire)&lt;br /&gt;
          session = {user: build(:teaching_assistant, id: 1)}&lt;br /&gt;
          allow(Ta).to receive(:get_my_instructor).with(1).and_return(6)&lt;br /&gt;
          # save&lt;br /&gt;
          allow(TreeFolder).to receive(:find_by).with(name: 'Review').and_return(double('TreeFolder', id: 1))&lt;br /&gt;
          allow(FolderNode).to receive(:find_by).with(node_object_id: 1).and_return(double('FolderNode'))&lt;br /&gt;
          allow_any_instance_of(QuestionnairesController).to receive(:undo_link).with(any_args).and_return('')&lt;br /&gt;
          post :create_questionnaire, params, session&lt;br /&gt;
          expect(flash[:note]).to be nil&lt;br /&gt;
          expect(response).to redirect_to('/tree_display/list')&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).private).to eq false&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).name).to eq 'Test questionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).min_question_score).to eq 0&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).max_question_score).to eq 5&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).type).to eq 'ReviewQuestionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).instructor_id).to eq 6&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Manual Testing====&lt;br /&gt;
Manual testing was performed by running Expertiza on the local machine and creating the various types of questionnaires (i.e. rubrics, quizzes, and surveys) in the various locations they occurred albeit non-exhaustively . If a questionnaire was created and could be updated without throwing an error it was determined that the refactoring on the questionnaires controller had succeeded. This process was performed and confirmed by all team members in order to ensure accuracy.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
*Code Refactoring Best Practices[https://www.altexsoft.com/blog/engineering/code-refactoring-best-practices-when-and-when-not-to-do-it/]&lt;br /&gt;
*Expertiza on Github[https://github.com/expertiza/expertiza]&lt;br /&gt;
*Expertiza Project Fork[https://github.com/Sattlert2/expertiza/tree/master]&lt;br /&gt;
*Expertiza Website[https://expertiza.ncsu.edu/]&lt;br /&gt;
*RSpec Documentation[https://relishapp.com/rspec]&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=132168</id>
		<title>CSC/ECE 517 Spring 2020 / E2001 Refactor Questionnaires Controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=132168"/>
		<updated>2020-03-29T18:36:49Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* About Questionnaires Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E2001 Refactor questionnaires_controller.rb ==&lt;br /&gt;
This page provides a description of the Expertiza based OSS project&lt;br /&gt;
__TOC__&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project. &lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
=== About Questionnaires Controller ===&lt;br /&gt;
Questionnaire controller is the controller for the Questionnaire object. A Questionnaire can be of several types including the following:&lt;br /&gt;
* Review&lt;br /&gt;
* Metareview&lt;br /&gt;
* Author feedback&lt;br /&gt;
* Teammate Review&lt;br /&gt;
* Survey&lt;br /&gt;
* Assignment&lt;br /&gt;
* Global Survey&lt;br /&gt;
* Course Survey&lt;br /&gt;
* Quiz&lt;br /&gt;
&lt;br /&gt;
Of these several different types of questionnaire's the questions, that can be added, have a different formats including:&lt;br /&gt;
* Criterion &lt;br /&gt;
* Drop down (multiple choice)&lt;br /&gt;
* Text box (short question)&lt;br /&gt;
* Text area (long question)&lt;br /&gt;
&lt;br /&gt;
Within the controller itself the object can be copied (clone the given questionnaire), created, viewed, edited, updated, deleted, questions can be added, saved, or removed, and creating a questionnaire node for assignming questionnaire attributes.&lt;br /&gt;
&lt;br /&gt;
The next section explores the database relationships with questionnaires_controller.rb.&lt;br /&gt;
&lt;br /&gt;
===Database===&lt;br /&gt;
The following diagram visualizes connections in our database.  The relationships between relevant tables that are touching questionnaire.rb are shown.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_relationship.png]]&lt;br /&gt;
&lt;br /&gt;
=== Problem Statement ===&lt;br /&gt;
'''Background:''' In Expertiza, Questionnaire is a super-class utilized by all questionnaires, including rubrics, quizzes, and surveys. Rubrics are used to assess things such as project submissions and project teammates. All of the above-mentioned questionnaires are sub-classes of the Questionnaire super-class. Since this super-class is used in a multitude of locations ensuring that there are no issues in the code is very important since an error can cause malfunctions throughout Expertiza.&lt;br /&gt;
&lt;br /&gt;
'''Problem:''' Questionnaires controller has been refactored repeatedly over the past few years, yet some improvements can still be made through refactoring to increase the quality and dryness of the code. &lt;br /&gt;
&lt;br /&gt;
These problems are as follows:&lt;br /&gt;
* Unsafe reflection method const_get called with parameter value &lt;br /&gt;
* Hardwired variables in add_new_questions and save_new_questions&lt;br /&gt;
* Unnecessary checks for QuizQuestionnaire, checks can be removed&lt;br /&gt;
* Use guard clause to enclose methods instead of conditional&lt;br /&gt;
* Removed unnecessary method 'create_questionnaire'&lt;br /&gt;
* Break up create method into new 'create_questionnaire'&lt;br /&gt;
* Use each_key instead of keys.each &lt;br /&gt;
* Split lines of code to fit within recommended 160 character length&lt;br /&gt;
* Removed useless assignment of variable in save method&lt;br /&gt;
* Resolved issues involving use of unsafe reflection&lt;br /&gt;
&lt;br /&gt;
=== Files Modified in Project ===&lt;br /&gt;
#app/controllers/questionnaires_controller.rb&lt;br /&gt;
#spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Issues and Improvements ===&lt;br /&gt;
====Use guard clause====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions, delete, and save_questions used conditional to wrap code instead of guard clause. Using guard clause can reduce complexity and number of lines in code.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def save_new_questions(questionnaire_id)&lt;br /&gt;
    if params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def save_new_questions(questionnaire_id)&lt;br /&gt;
    return unless params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====QuizQuestionnaire checks====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) create and save_new_questions have unnecessary checks for if question type is QuizQuestionnaire.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
We removed the check in both methods. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
 q.weight = 1 # setting the weight to 1 for quiz questionnaire since the model validates this field&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
q.weight = 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Hardwired Variables====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions and add_new_questions used hardwired variables. When applicable all values used should be stored as variables so the user knows the purpose of the variable, if that value is used in multiple areas it can be changed with a single change, and it's just messy. For instance both add_new_questions and save_new_questions used the same scalar value 1 for a similar task. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = 1&lt;br /&gt;
 question.max_label = 'Strongly agree'&lt;br /&gt;
 question.min_label = 'Strongly disagree'&lt;br /&gt;
end&lt;br /&gt;
question.size = '50, 3' if question.is_a? Criterion&lt;br /&gt;
question.alternatives = '0|1|2|3|4|5' if question.is_a? Dropdown&lt;br /&gt;
question.size = '60, 5' if question.is_a? TextArea&lt;br /&gt;
question.size = '30' if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To our code which incorporates constants.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = WEIGHT&lt;br /&gt;
 question.max_label = LABEL_AGREE&lt;br /&gt;
 question.min_label = LABEL_DISAGREE&lt;br /&gt;
end&lt;br /&gt;
question.size = SIZE_CRITERION if question.is_a? Criterion&lt;br /&gt;
question.alternatives = SIZE_ALT_DROPDOWN if question.is_a? Dropdown&lt;br /&gt;
question.size = SIZE_TXT_AREA if question.is_a? TextArea&lt;br /&gt;
question.size = SIZE_TXT_FIELD if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With our constants at the top of the code for easy accessibility:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Constants&lt;br /&gt;
# add_new_questions&lt;br /&gt;
LABEL_AGREE = 'Strongly agree' # label for scored question if agree&lt;br /&gt;
LABEL_DISAGREE = 'Strongly disagree' # label for scored question if disagree&lt;br /&gt;
WEIGHT = 1  # question weight&lt;br /&gt;
SIZE_CRITERION = '50, 3' # size of the question box if it's a criterion&lt;br /&gt;
SIZE_ALT_DROPDOWN = '0|1|2|3|4|5' # alternative to size if question is a dropdown&lt;br /&gt;
SIZE_TXT_AREA = '60, 5' # size of question box if text area&lt;br /&gt;
SIZE_TXT_FIELD = '30' # size of question box if text field&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Unsafe Reflection====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Unsafe reflection method const_get called with parameter value&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
Remove the unsafe reflection through using a variable that checks for null values. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question_type = params[:question][:type] unless params[:question][:type].nil?&lt;br /&gt;
question = Object.const_get(question_type).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: question_type, break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed unnecessary method 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method create_questionnaire, had no apparent calls to it. Aside from assigning a creator ID, it is similar in functionality to create, so we assume that the method was at some point created as a duplicate.  We remove the method to make the code dry. &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we remove:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_questionnaire&lt;br /&gt;
    @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
    # Create Quiz content has been moved to Quiz Questionnaire Controller&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
      @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) &lt;br /&gt;
                                       if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      save&lt;br /&gt;
&lt;br /&gt;
      redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Break up create method into new 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The create method itself was 49 lines long.  This is too long to be viewable at a glance.  Breaking it up into a second private method 'create_questionnaire' to handle attribute assigning and node creation.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire.private = questionnaire_private&lt;br /&gt;
        @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
        @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
        @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
        @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
        @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
        # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
        # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
        # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
        if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
          display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
        @questionnaire.display_type = display_type&lt;br /&gt;
        @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
        @questionnaire.save&lt;br /&gt;
        # Create node&lt;br /&gt;
        tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
        parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
        QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        create_questionnaire questionnaire_private, display_type&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create_questions questionnaire_private, display_type&lt;br /&gt;
    @questionnaire.private = questionnaire_private&lt;br /&gt;
    @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
    @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
    @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
    @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
    @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
    # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
    # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
    # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
    if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
      display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    @questionnaire.display_type = display_type&lt;br /&gt;
    @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
    @questionnaire.save&lt;br /&gt;
    tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
    parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
    # Create node&lt;br /&gt;
    QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use each_key instead of keys.each====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code uses keys.each to iterate through the hash.  Keys.each is useful for modifying a hash, but in this implementation this is not necessary.  So, each_key is used to improve performance timing.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].keys.each do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].each_key do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split lines of code to fit within recommended 160 character length====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Some of the lines of code exceed the recommended 160 characters per line.  To remediate, we simply split code across multiple lines and indent accordingly to maintain readability.   &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id, seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,&lt;br /&gt;
                                                                   seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed useless assignment of variable in save method====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code included assignments of variables that were not used throughout the file.  We assume that these variables were created to implement functionality that has since been removed through previous refactor attempts.  In any case, we remove the variable keep the code dry.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    # We do not create node for quiz questionnaires&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
      p_folder = TreeFolder.find_by(name: @questionnaire.display_type)&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: p_folder.id)&lt;br /&gt;
      # create_new_node_if_necessary(parent)&lt;br /&gt;
    end&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We remove the unnecessary variables and comments, resulting in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Testing Plan ===&lt;br /&gt;
In order to evaluate the changes to Expertiza throughout the OSS project two different methods were used. The first being automatic testing using RSpec and the second being manual testing through accessing the Expertiza project on one's local machine. More in depth discussion of these tests can be found below.&lt;br /&gt;
====RSpec Testing====&lt;br /&gt;
In many cases the issues were resolved by editing a few lines of code within various methods without the need for additional methods. Thus, adding more test was not needed in these cases. However, in order to ensure the code edits didn't cause any previously crafted test to fail an RSpec test was ran before each commit. If and only if all test passed could the commit be pushed. &lt;br /&gt;
&lt;br /&gt;
The command utilized to test the questionnaires controller is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
However, if a VCL was utilized for development this following command was used instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec /home/[UNITYID]/expertiza/spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In one case the create_questionnaire method was removed, thus in order to keep the set of tests clean the following test block was removed from the testing file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#create_questionnaire and #save' do&lt;br /&gt;
    context 'when quiz is valid' do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        # create_quiz_questionnaire&lt;br /&gt;
        allow_any_instance_of(QuestionnairesController).to receive(:valid_quiz).and_return('valid')&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when questionnaire type is not QuizQuestionnaire' do&lt;br /&gt;
        it 'redirects to submitted_content#edit page' do&lt;br /&gt;
          params = {aid: 1,&lt;br /&gt;
                    pid: 1,&lt;br /&gt;
                    questionnaire: {name: 'Test questionnaire',&lt;br /&gt;
                                    type: 'ReviewQuestionnaire'}}&lt;br /&gt;
          # create_questionnaire&lt;br /&gt;
          allow(ReviewQuestionnaire).to receive(:new).with(any_args).and_return(review_questionnaire)&lt;br /&gt;
          session = {user: build(:teaching_assistant, id: 1)}&lt;br /&gt;
          allow(Ta).to receive(:get_my_instructor).with(1).and_return(6)&lt;br /&gt;
          # save&lt;br /&gt;
          allow(TreeFolder).to receive(:find_by).with(name: 'Review').and_return(double('TreeFolder', id: 1))&lt;br /&gt;
          allow(FolderNode).to receive(:find_by).with(node_object_id: 1).and_return(double('FolderNode'))&lt;br /&gt;
          allow_any_instance_of(QuestionnairesController).to receive(:undo_link).with(any_args).and_return('')&lt;br /&gt;
          post :create_questionnaire, params, session&lt;br /&gt;
          expect(flash[:note]).to be nil&lt;br /&gt;
          expect(response).to redirect_to('/tree_display/list')&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).private).to eq false&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).name).to eq 'Test questionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).min_question_score).to eq 0&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).max_question_score).to eq 5&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).type).to eq 'ReviewQuestionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).instructor_id).to eq 6&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Manual Testing====&lt;br /&gt;
Manual testing was performed by running Expertiza on the local machine and creating the various types of questionnaires (i.e. rubrics, quizzes, and surveys) in the various locations they occurred albeit non-exhaustively . If a questionnaire was created and could be updated without throwing an error it was determined that the refactoring on the questionnaires controller had succeeded. This process was performed and confirmed by all team members in order to ensure accuracy.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
*Code Refactoring Best Practices[https://www.altexsoft.com/blog/engineering/code-refactoring-best-practices-when-and-when-not-to-do-it/]&lt;br /&gt;
*Expertiza on Github[https://github.com/expertiza/expertiza]&lt;br /&gt;
*Expertiza Project Fork[https://github.com/Sattlert2/expertiza/tree/master]&lt;br /&gt;
*Expertiza Website[https://expertiza.ncsu.edu/]&lt;br /&gt;
*RSpec Documentation[https://relishapp.com/rspec]&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=132167</id>
		<title>CSC/ECE 517 Spring 2020 / E2001 Refactor Questionnaires Controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=132167"/>
		<updated>2020-03-29T18:35:36Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* About Questionnaires Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E2001 Refactor questionnaires_controller.rb ==&lt;br /&gt;
This page provides a description of the Expertiza based OSS project&lt;br /&gt;
__TOC__&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project. &lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
=== About Questionnaires Controller ===&lt;br /&gt;
Questionnaire controller is the controller for the Questionnaire object. A Questionnaire can be of several types including the following:&lt;br /&gt;
* Review&lt;br /&gt;
* Metareview&lt;br /&gt;
* Author feedback&lt;br /&gt;
* Teammate Review&lt;br /&gt;
* Survey&lt;br /&gt;
* Assignment&lt;br /&gt;
* Global Survey&lt;br /&gt;
* Course Survey&lt;br /&gt;
* Quiz&lt;br /&gt;
&lt;br /&gt;
Of these several different types of questionnaire's the questions can have a different formats including:&lt;br /&gt;
* Criterion &lt;br /&gt;
* Drop down (multiple choice)&lt;br /&gt;
* Text box (short question)&lt;br /&gt;
* Text area (long question)&lt;br /&gt;
&lt;br /&gt;
Within the controller itself the object can be copied (clone the given questionnaire), created, viewed, edited, updated, deleted, questions can be added, saved, or removed, and creating a questionnaire node for assignming questionnaire attributes.&lt;br /&gt;
&lt;br /&gt;
The next section explores the database relationships with questionnaires_controller.rb.&lt;br /&gt;
&lt;br /&gt;
===Database===&lt;br /&gt;
The following diagram visualizes connections in our database.  The relationships between relevant tables that are touching questionnaire.rb are shown.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_relationship.png]]&lt;br /&gt;
&lt;br /&gt;
=== Problem Statement ===&lt;br /&gt;
'''Background:''' In Expertiza, Questionnaire is a super-class utilized by all questionnaires, including rubrics, quizzes, and surveys. Rubrics are used to assess things such as project submissions and project teammates. All of the above-mentioned questionnaires are sub-classes of the Questionnaire super-class. Since this super-class is used in a multitude of locations ensuring that there are no issues in the code is very important since an error can cause malfunctions throughout Expertiza.&lt;br /&gt;
&lt;br /&gt;
'''Problem:''' Questionnaires controller has been refactored repeatedly over the past few years, yet some improvements can still be made through refactoring to increase the quality and dryness of the code. &lt;br /&gt;
&lt;br /&gt;
These problems are as follows:&lt;br /&gt;
* Unsafe reflection method const_get called with parameter value &lt;br /&gt;
* Hardwired variables in add_new_questions and save_new_questions&lt;br /&gt;
* Unnecessary checks for QuizQuestionnaire, checks can be removed&lt;br /&gt;
* Use guard clause to enclose methods instead of conditional&lt;br /&gt;
* Removed unnecessary method 'create_questionnaire'&lt;br /&gt;
* Break up create method into new 'create_questionnaire'&lt;br /&gt;
* Use each_key instead of keys.each &lt;br /&gt;
* Split lines of code to fit within recommended 160 character length&lt;br /&gt;
* Removed useless assignment of variable in save method&lt;br /&gt;
* Resolved issues involving use of unsafe reflection&lt;br /&gt;
&lt;br /&gt;
=== Files Modified in Project ===&lt;br /&gt;
#app/controllers/questionnaires_controller.rb&lt;br /&gt;
#spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Issues and Improvements ===&lt;br /&gt;
====Use guard clause====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions, delete, and save_questions used conditional to wrap code instead of guard clause. Using guard clause can reduce complexity and number of lines in code.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def save_new_questions(questionnaire_id)&lt;br /&gt;
    if params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def save_new_questions(questionnaire_id)&lt;br /&gt;
    return unless params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====QuizQuestionnaire checks====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) create and save_new_questions have unnecessary checks for if question type is QuizQuestionnaire.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
We removed the check in both methods. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
 q.weight = 1 # setting the weight to 1 for quiz questionnaire since the model validates this field&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
q.weight = 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Hardwired Variables====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions and add_new_questions used hardwired variables. When applicable all values used should be stored as variables so the user knows the purpose of the variable, if that value is used in multiple areas it can be changed with a single change, and it's just messy. For instance both add_new_questions and save_new_questions used the same scalar value 1 for a similar task. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = 1&lt;br /&gt;
 question.max_label = 'Strongly agree'&lt;br /&gt;
 question.min_label = 'Strongly disagree'&lt;br /&gt;
end&lt;br /&gt;
question.size = '50, 3' if question.is_a? Criterion&lt;br /&gt;
question.alternatives = '0|1|2|3|4|5' if question.is_a? Dropdown&lt;br /&gt;
question.size = '60, 5' if question.is_a? TextArea&lt;br /&gt;
question.size = '30' if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To our code which incorporates constants.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = WEIGHT&lt;br /&gt;
 question.max_label = LABEL_AGREE&lt;br /&gt;
 question.min_label = LABEL_DISAGREE&lt;br /&gt;
end&lt;br /&gt;
question.size = SIZE_CRITERION if question.is_a? Criterion&lt;br /&gt;
question.alternatives = SIZE_ALT_DROPDOWN if question.is_a? Dropdown&lt;br /&gt;
question.size = SIZE_TXT_AREA if question.is_a? TextArea&lt;br /&gt;
question.size = SIZE_TXT_FIELD if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With our constants at the top of the code for easy accessibility:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Constants&lt;br /&gt;
# add_new_questions&lt;br /&gt;
LABEL_AGREE = 'Strongly agree' # label for scored question if agree&lt;br /&gt;
LABEL_DISAGREE = 'Strongly disagree' # label for scored question if disagree&lt;br /&gt;
WEIGHT = 1  # question weight&lt;br /&gt;
SIZE_CRITERION = '50, 3' # size of the question box if it's a criterion&lt;br /&gt;
SIZE_ALT_DROPDOWN = '0|1|2|3|4|5' # alternative to size if question is a dropdown&lt;br /&gt;
SIZE_TXT_AREA = '60, 5' # size of question box if text area&lt;br /&gt;
SIZE_TXT_FIELD = '30' # size of question box if text field&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Unsafe Reflection====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Unsafe reflection method const_get called with parameter value&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
Remove the unsafe reflection through using a variable that checks for null values. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question_type = params[:question][:type] unless params[:question][:type].nil?&lt;br /&gt;
question = Object.const_get(question_type).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: question_type, break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed unnecessary method 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method create_questionnaire, had no apparent calls to it. Aside from assigning a creator ID, it is similar in functionality to create, so we assume that the method was at some point created as a duplicate.  We remove the method to make the code dry. &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we remove:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_questionnaire&lt;br /&gt;
    @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
    # Create Quiz content has been moved to Quiz Questionnaire Controller&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
      @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) &lt;br /&gt;
                                       if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      save&lt;br /&gt;
&lt;br /&gt;
      redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Break up create method into new 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The create method itself was 49 lines long.  This is too long to be viewable at a glance.  Breaking it up into a second private method 'create_questionnaire' to handle attribute assigning and node creation.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire.private = questionnaire_private&lt;br /&gt;
        @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
        @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
        @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
        @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
        @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
        # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
        # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
        # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
        if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
          display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
        @questionnaire.display_type = display_type&lt;br /&gt;
        @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
        @questionnaire.save&lt;br /&gt;
        # Create node&lt;br /&gt;
        tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
        parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
        QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        create_questionnaire questionnaire_private, display_type&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create_questions questionnaire_private, display_type&lt;br /&gt;
    @questionnaire.private = questionnaire_private&lt;br /&gt;
    @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
    @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
    @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
    @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
    @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
    # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
    # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
    # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
    if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
      display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    @questionnaire.display_type = display_type&lt;br /&gt;
    @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
    @questionnaire.save&lt;br /&gt;
    tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
    parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
    # Create node&lt;br /&gt;
    QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use each_key instead of keys.each====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code uses keys.each to iterate through the hash.  Keys.each is useful for modifying a hash, but in this implementation this is not necessary.  So, each_key is used to improve performance timing.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].keys.each do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].each_key do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split lines of code to fit within recommended 160 character length====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Some of the lines of code exceed the recommended 160 characters per line.  To remediate, we simply split code across multiple lines and indent accordingly to maintain readability.   &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id, seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,&lt;br /&gt;
                                                                   seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed useless assignment of variable in save method====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code included assignments of variables that were not used throughout the file.  We assume that these variables were created to implement functionality that has since been removed through previous refactor attempts.  In any case, we remove the variable keep the code dry.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    # We do not create node for quiz questionnaires&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
      p_folder = TreeFolder.find_by(name: @questionnaire.display_type)&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: p_folder.id)&lt;br /&gt;
      # create_new_node_if_necessary(parent)&lt;br /&gt;
    end&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We remove the unnecessary variables and comments, resulting in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Testing Plan ===&lt;br /&gt;
In order to evaluate the changes to Expertiza throughout the OSS project two different methods were used. The first being automatic testing using RSpec and the second being manual testing through accessing the Expertiza project on one's local machine. More in depth discussion of these tests can be found below.&lt;br /&gt;
====RSpec Testing====&lt;br /&gt;
In many cases the issues were resolved by editing a few lines of code within various methods without the need for additional methods. Thus, adding more test was not needed in these cases. However, in order to ensure the code edits didn't cause any previously crafted test to fail an RSpec test was ran before each commit. If and only if all test passed could the commit be pushed. &lt;br /&gt;
&lt;br /&gt;
The command utilized to test the questionnaires controller is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
However, if a VCL was utilized for development this following command was used instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec /home/[UNITYID]/expertiza/spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In one case the create_questionnaire method was removed, thus in order to keep the set of tests clean the following test block was removed from the testing file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#create_questionnaire and #save' do&lt;br /&gt;
    context 'when quiz is valid' do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        # create_quiz_questionnaire&lt;br /&gt;
        allow_any_instance_of(QuestionnairesController).to receive(:valid_quiz).and_return('valid')&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when questionnaire type is not QuizQuestionnaire' do&lt;br /&gt;
        it 'redirects to submitted_content#edit page' do&lt;br /&gt;
          params = {aid: 1,&lt;br /&gt;
                    pid: 1,&lt;br /&gt;
                    questionnaire: {name: 'Test questionnaire',&lt;br /&gt;
                                    type: 'ReviewQuestionnaire'}}&lt;br /&gt;
          # create_questionnaire&lt;br /&gt;
          allow(ReviewQuestionnaire).to receive(:new).with(any_args).and_return(review_questionnaire)&lt;br /&gt;
          session = {user: build(:teaching_assistant, id: 1)}&lt;br /&gt;
          allow(Ta).to receive(:get_my_instructor).with(1).and_return(6)&lt;br /&gt;
          # save&lt;br /&gt;
          allow(TreeFolder).to receive(:find_by).with(name: 'Review').and_return(double('TreeFolder', id: 1))&lt;br /&gt;
          allow(FolderNode).to receive(:find_by).with(node_object_id: 1).and_return(double('FolderNode'))&lt;br /&gt;
          allow_any_instance_of(QuestionnairesController).to receive(:undo_link).with(any_args).and_return('')&lt;br /&gt;
          post :create_questionnaire, params, session&lt;br /&gt;
          expect(flash[:note]).to be nil&lt;br /&gt;
          expect(response).to redirect_to('/tree_display/list')&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).private).to eq false&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).name).to eq 'Test questionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).min_question_score).to eq 0&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).max_question_score).to eq 5&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).type).to eq 'ReviewQuestionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).instructor_id).to eq 6&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Manual Testing====&lt;br /&gt;
Manual testing was performed by running Expertiza on the local machine and creating the various types of questionnaires (i.e. rubrics, quizzes, and surveys) in the various locations they occurred albeit non-exhaustively . If a questionnaire was created and could be updated without throwing an error it was determined that the refactoring on the questionnaires controller had succeeded. This process was performed and confirmed by all team members in order to ensure accuracy.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
*Code Refactoring Best Practices[https://www.altexsoft.com/blog/engineering/code-refactoring-best-practices-when-and-when-not-to-do-it/]&lt;br /&gt;
*Expertiza on Github[https://github.com/expertiza/expertiza]&lt;br /&gt;
*Expertiza Project Fork[https://github.com/Sattlert2/expertiza/tree/master]&lt;br /&gt;
*Expertiza Website[https://expertiza.ncsu.edu/]&lt;br /&gt;
*RSpec Documentation[https://relishapp.com/rspec]&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=132166</id>
		<title>CSC/ECE 517 Spring 2020 / E2001 Refactor Questionnaires Controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=132166"/>
		<updated>2020-03-29T18:33:39Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* E2001 Refactor questionnaires_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E2001 Refactor questionnaires_controller.rb ==&lt;br /&gt;
This page provides a description of the Expertiza based OSS project&lt;br /&gt;
__TOC__&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project. &lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
=== About Questionnaires Controller ===&lt;br /&gt;
Questionnaire controller is the controller for the Questionnaire object. A Questionnaire can be of several types including the following:&lt;br /&gt;
* Review&lt;br /&gt;
* Metareview&lt;br /&gt;
* Author feedback&lt;br /&gt;
* Teammate Review&lt;br /&gt;
* Survey&lt;br /&gt;
* Assignment&lt;br /&gt;
* Global Survey&lt;br /&gt;
* Course Survey&lt;br /&gt;
* Quiz&lt;br /&gt;
&lt;br /&gt;
Of these several different types of questionnaire's they can all have a different format including:&lt;br /&gt;
* Criterion &lt;br /&gt;
* Drop down (multiple choice)&lt;br /&gt;
* Text box (short question)&lt;br /&gt;
* Text area (long question)&lt;br /&gt;
&lt;br /&gt;
Within the controller itself the object can be copied (clone the given questionnaire), created, viewed, edited, updated, deleted, questions can be added, saved, or removed, and creating a questionnaire node for assignming questionnaire attributes.&lt;br /&gt;
&lt;br /&gt;
The next section explores the database relationships with questionnaires_controller.rb.&lt;br /&gt;
&lt;br /&gt;
===Database===&lt;br /&gt;
The following diagram visualizes connections in our database.  The relationships between relevant tables that are touching questionnaire.rb are shown.&lt;br /&gt;
&lt;br /&gt;
[[File:Db_relationship.png]]&lt;br /&gt;
&lt;br /&gt;
=== Problem Statement ===&lt;br /&gt;
'''Background:''' In Expertiza, Questionnaire is a super-class utilized by all questionnaires, including rubrics, quizzes, and surveys. Rubrics are used to assess things such as project submissions and project teammates. All of the above-mentioned questionnaires are sub-classes of the Questionnaire super-class. Since this super-class is used in a multitude of locations ensuring that there are no issues in the code is very important since an error can cause malfunctions throughout Expertiza.&lt;br /&gt;
&lt;br /&gt;
'''Problem:''' Questionnaires controller has been refactored repeatedly over the past few years, yet some improvements can still be made through refactoring to increase the quality and dryness of the code. &lt;br /&gt;
&lt;br /&gt;
These problems are as follows:&lt;br /&gt;
* Unsafe reflection method const_get called with parameter value &lt;br /&gt;
* Hardwired variables in add_new_questions and save_new_questions&lt;br /&gt;
* Unnecessary checks for QuizQuestionnaire, checks can be removed&lt;br /&gt;
* Use guard clause to enclose methods instead of conditional&lt;br /&gt;
* Removed unnecessary method 'create_questionnaire'&lt;br /&gt;
* Break up create method into new 'create_questionnaire'&lt;br /&gt;
* Use each_key instead of keys.each &lt;br /&gt;
* Split lines of code to fit within recommended 160 character length&lt;br /&gt;
* Removed useless assignment of variable in save method&lt;br /&gt;
* Resolved issues involving use of unsafe reflection&lt;br /&gt;
&lt;br /&gt;
=== Files Modified in Project ===&lt;br /&gt;
#app/controllers/questionnaires_controller.rb&lt;br /&gt;
#spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Issues and Improvements ===&lt;br /&gt;
====Use guard clause====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions, delete, and save_questions used conditional to wrap code instead of guard clause. Using guard clause can reduce complexity and number of lines in code.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def save_new_questions(questionnaire_id)&lt;br /&gt;
    if params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def save_new_questions(questionnaire_id)&lt;br /&gt;
    return unless params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====QuizQuestionnaire checks====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) create and save_new_questions have unnecessary checks for if question type is QuizQuestionnaire.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
We removed the check in both methods. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
 q.weight = 1 # setting the weight to 1 for quiz questionnaire since the model validates this field&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
q.weight = 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Hardwired Variables====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions and add_new_questions used hardwired variables. When applicable all values used should be stored as variables so the user knows the purpose of the variable, if that value is used in multiple areas it can be changed with a single change, and it's just messy. For instance both add_new_questions and save_new_questions used the same scalar value 1 for a similar task. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = 1&lt;br /&gt;
 question.max_label = 'Strongly agree'&lt;br /&gt;
 question.min_label = 'Strongly disagree'&lt;br /&gt;
end&lt;br /&gt;
question.size = '50, 3' if question.is_a? Criterion&lt;br /&gt;
question.alternatives = '0|1|2|3|4|5' if question.is_a? Dropdown&lt;br /&gt;
question.size = '60, 5' if question.is_a? TextArea&lt;br /&gt;
question.size = '30' if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To our code which incorporates constants.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = WEIGHT&lt;br /&gt;
 question.max_label = LABEL_AGREE&lt;br /&gt;
 question.min_label = LABEL_DISAGREE&lt;br /&gt;
end&lt;br /&gt;
question.size = SIZE_CRITERION if question.is_a? Criterion&lt;br /&gt;
question.alternatives = SIZE_ALT_DROPDOWN if question.is_a? Dropdown&lt;br /&gt;
question.size = SIZE_TXT_AREA if question.is_a? TextArea&lt;br /&gt;
question.size = SIZE_TXT_FIELD if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With our constants at the top of the code for easy accessibility:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Constants&lt;br /&gt;
# add_new_questions&lt;br /&gt;
LABEL_AGREE = 'Strongly agree' # label for scored question if agree&lt;br /&gt;
LABEL_DISAGREE = 'Strongly disagree' # label for scored question if disagree&lt;br /&gt;
WEIGHT = 1  # question weight&lt;br /&gt;
SIZE_CRITERION = '50, 3' # size of the question box if it's a criterion&lt;br /&gt;
SIZE_ALT_DROPDOWN = '0|1|2|3|4|5' # alternative to size if question is a dropdown&lt;br /&gt;
SIZE_TXT_AREA = '60, 5' # size of question box if text area&lt;br /&gt;
SIZE_TXT_FIELD = '30' # size of question box if text field&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Unsafe Reflection====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Unsafe reflection method const_get called with parameter value&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
Remove the unsafe reflection through using a variable that checks for null values. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question_type = params[:question][:type] unless params[:question][:type].nil?&lt;br /&gt;
question = Object.const_get(question_type).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: question_type, break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed unnecessary method 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method create_questionnaire, had no apparent calls to it. Aside from assigning a creator ID, it is similar in functionality to create, so we assume that the method was at some point created as a duplicate.  We remove the method to make the code dry. &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we remove:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_questionnaire&lt;br /&gt;
    @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
    # Create Quiz content has been moved to Quiz Questionnaire Controller&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
      @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) &lt;br /&gt;
                                       if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      save&lt;br /&gt;
&lt;br /&gt;
      redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Break up create method into new 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The create method itself was 49 lines long.  This is too long to be viewable at a glance.  Breaking it up into a second private method 'create_questionnaire' to handle attribute assigning and node creation.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire.private = questionnaire_private&lt;br /&gt;
        @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
        @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
        @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
        @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
        @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
        # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
        # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
        # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
        if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
          display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
        @questionnaire.display_type = display_type&lt;br /&gt;
        @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
        @questionnaire.save&lt;br /&gt;
        # Create node&lt;br /&gt;
        tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
        parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
        QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        create_questionnaire questionnaire_private, display_type&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create_questions questionnaire_private, display_type&lt;br /&gt;
    @questionnaire.private = questionnaire_private&lt;br /&gt;
    @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
    @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
    @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
    @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
    @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
    # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
    # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
    # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
    if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
      display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    @questionnaire.display_type = display_type&lt;br /&gt;
    @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
    @questionnaire.save&lt;br /&gt;
    tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
    parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
    # Create node&lt;br /&gt;
    QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use each_key instead of keys.each====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code uses keys.each to iterate through the hash.  Keys.each is useful for modifying a hash, but in this implementation this is not necessary.  So, each_key is used to improve performance timing.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].keys.each do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].each_key do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split lines of code to fit within recommended 160 character length====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Some of the lines of code exceed the recommended 160 characters per line.  To remediate, we simply split code across multiple lines and indent accordingly to maintain readability.   &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id, seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,&lt;br /&gt;
                                                                   seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed useless assignment of variable in save method====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code included assignments of variables that were not used throughout the file.  We assume that these variables were created to implement functionality that has since been removed through previous refactor attempts.  In any case, we remove the variable keep the code dry.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    # We do not create node for quiz questionnaires&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
      p_folder = TreeFolder.find_by(name: @questionnaire.display_type)&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: p_folder.id)&lt;br /&gt;
      # create_new_node_if_necessary(parent)&lt;br /&gt;
    end&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We remove the unnecessary variables and comments, resulting in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Testing Plan ===&lt;br /&gt;
In order to evaluate the changes to Expertiza throughout the OSS project two different methods were used. The first being automatic testing using RSpec and the second being manual testing through accessing the Expertiza project on one's local machine. More in depth discussion of these tests can be found below.&lt;br /&gt;
====RSpec Testing====&lt;br /&gt;
In many cases the issues were resolved by editing a few lines of code within various methods without the need for additional methods. Thus, adding more test was not needed in these cases. However, in order to ensure the code edits didn't cause any previously crafted test to fail an RSpec test was ran before each commit. If and only if all test passed could the commit be pushed. &lt;br /&gt;
&lt;br /&gt;
The command utilized to test the questionnaires controller is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
However, if a VCL was utilized for development this following command was used instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec /home/[UNITYID]/expertiza/spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In one case the create_questionnaire method was removed, thus in order to keep the set of tests clean the following test block was removed from the testing file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#create_questionnaire and #save' do&lt;br /&gt;
    context 'when quiz is valid' do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        # create_quiz_questionnaire&lt;br /&gt;
        allow_any_instance_of(QuestionnairesController).to receive(:valid_quiz).and_return('valid')&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when questionnaire type is not QuizQuestionnaire' do&lt;br /&gt;
        it 'redirects to submitted_content#edit page' do&lt;br /&gt;
          params = {aid: 1,&lt;br /&gt;
                    pid: 1,&lt;br /&gt;
                    questionnaire: {name: 'Test questionnaire',&lt;br /&gt;
                                    type: 'ReviewQuestionnaire'}}&lt;br /&gt;
          # create_questionnaire&lt;br /&gt;
          allow(ReviewQuestionnaire).to receive(:new).with(any_args).and_return(review_questionnaire)&lt;br /&gt;
          session = {user: build(:teaching_assistant, id: 1)}&lt;br /&gt;
          allow(Ta).to receive(:get_my_instructor).with(1).and_return(6)&lt;br /&gt;
          # save&lt;br /&gt;
          allow(TreeFolder).to receive(:find_by).with(name: 'Review').and_return(double('TreeFolder', id: 1))&lt;br /&gt;
          allow(FolderNode).to receive(:find_by).with(node_object_id: 1).and_return(double('FolderNode'))&lt;br /&gt;
          allow_any_instance_of(QuestionnairesController).to receive(:undo_link).with(any_args).and_return('')&lt;br /&gt;
          post :create_questionnaire, params, session&lt;br /&gt;
          expect(flash[:note]).to be nil&lt;br /&gt;
          expect(response).to redirect_to('/tree_display/list')&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).private).to eq false&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).name).to eq 'Test questionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).min_question_score).to eq 0&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).max_question_score).to eq 5&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).type).to eq 'ReviewQuestionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).instructor_id).to eq 6&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Manual Testing====&lt;br /&gt;
Manual testing was performed by running Expertiza on the local machine and creating the various types of questionnaires (i.e. rubrics, quizzes, and surveys) in the various locations they occurred albeit non-exhaustively . If a questionnaire was created and could be updated without throwing an error it was determined that the refactoring on the questionnaires controller had succeeded. This process was performed and confirmed by all team members in order to ensure accuracy.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
*Code Refactoring Best Practices[https://www.altexsoft.com/blog/engineering/code-refactoring-best-practices-when-and-when-not-to-do-it/]&lt;br /&gt;
*Expertiza on Github[https://github.com/expertiza/expertiza]&lt;br /&gt;
*Expertiza Project Fork[https://github.com/Sattlert2/expertiza/tree/master]&lt;br /&gt;
*Expertiza Website[https://expertiza.ncsu.edu/]&lt;br /&gt;
*RSpec Documentation[https://relishapp.com/rspec]&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=131771</id>
		<title>CSC/ECE 517 Spring 2020 / E2001 Refactor Questionnaires Controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=131771"/>
		<updated>2020-03-23T19:03:19Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* Database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E2000 Refactor questionnaires_controller.rb ==&lt;br /&gt;
This page provides a description of the Expertiza based OSS project&lt;br /&gt;
__TOC__&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project. &lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
=== Problem Statement ===&lt;br /&gt;
'''Background:''' In Expertiza, Questionnaire is a super-class utilized by all questionnaires, including rubrics, quizzes, and surveys. Rubrics are used to assess things such as project submissions and project teammates. All of the above-mentioned questionnaires are sub-classes of the Questionnaire super-class. Since this super-class is used in a multitude of locations ensuring that there are no issues in the code is very important since an error can cause malfunctions throughout Expertiza.&lt;br /&gt;
&lt;br /&gt;
'''Problem:''' Questionnaires controller has been refactored repeatedly over the past few years, yet some improvements can still be made through refactoring to increase the quality and dryness of the code. &lt;br /&gt;
&lt;br /&gt;
These problems are as follows:&lt;br /&gt;
* Unsafe reflection method const_get called with parameter value &lt;br /&gt;
* Hardwired variables in add_new_questions and save_new_questions&lt;br /&gt;
* Unnecessary checks for QuizQuestionnaire, checks can be removed&lt;br /&gt;
* Use guard clause to enclose methods instead of conditional&lt;br /&gt;
* Removed unnecessary method 'create_questionnaire'&lt;br /&gt;
* Break up create method into new 'create_questionnaire'&lt;br /&gt;
* Use each_key instead of keys.each &lt;br /&gt;
* Split lines of code to fit within recommended 160 character length&lt;br /&gt;
* Removed useless assignment of variable in save method&lt;br /&gt;
* Resolved issues involving use of unsafe reflection&lt;br /&gt;
&lt;br /&gt;
=== Files Modified in Project ===&lt;br /&gt;
#app/controllers/questionnaires_controller.rb&lt;br /&gt;
#spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Issues and Improvements ===&lt;br /&gt;
====Use guard clause====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions, delete, and save_questions used conditional to wrap code instead of guard clause. Using guard clause can reduce complexity and number of lines in code.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def save_new_questions(questionnaire_id)&lt;br /&gt;
    if params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def save_new_questions(questionnaire_id)&lt;br /&gt;
    return unless params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====QuizQuestionnaire checks====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) create and save_new_questions have unnecessary checks for if question type is QuizQuestionnaire.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
We removed the check in both methods. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
 q.weight = 1 # setting the weight to 1 for quiz questionnaire since the model validates this field&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
q.weight = 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Hardwired Variables====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions and add_new_questions used hardwired variables. When applicable all values used should be stored as variables so the user knows the purpose of the variable, if that value is used in multiple areas it can be changed with a single change, and it's just messy. For instance both add_new_questions and save_new_questions used the same scalar value 1 for a similar task. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = 1&lt;br /&gt;
 question.max_label = 'Strongly agree'&lt;br /&gt;
 question.min_label = 'Strongly disagree'&lt;br /&gt;
end&lt;br /&gt;
question.size = '50, 3' if question.is_a? Criterion&lt;br /&gt;
question.alternatives = '0|1|2|3|4|5' if question.is_a? Dropdown&lt;br /&gt;
question.size = '60, 5' if question.is_a? TextArea&lt;br /&gt;
question.size = '30' if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To our code which incorporates constants.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = WEIGHT&lt;br /&gt;
 question.max_label = LABEL_AGREE&lt;br /&gt;
 question.min_label = LABEL_DISAGREE&lt;br /&gt;
end&lt;br /&gt;
question.size = SIZE_CRITERION if question.is_a? Criterion&lt;br /&gt;
question.alternatives = SIZE_ALT_DROPDOWN if question.is_a? Dropdown&lt;br /&gt;
question.size = SIZE_TXT_AREA if question.is_a? TextArea&lt;br /&gt;
question.size = SIZE_TXT_FIELD if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With our constants at the top of the code for easy accessibility:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Constants&lt;br /&gt;
# add_new_questions&lt;br /&gt;
LABEL_AGREE = 'Strongly agree' # label for scored question if agree&lt;br /&gt;
LABEL_DISAGREE = 'Strongly disagree' # label for scored question if disagree&lt;br /&gt;
WEIGHT = 1  # question weight&lt;br /&gt;
SIZE_CRITERION = '50, 3' # size of the question box if it's a criterion&lt;br /&gt;
SIZE_ALT_DROPDOWN = '0|1|2|3|4|5' # alternative to size if question is a dropdown&lt;br /&gt;
SIZE_TXT_AREA = '60, 5' # size of question box if text area&lt;br /&gt;
SIZE_TXT_FIELD = '30' # size of question box if text field&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Unsafe Reflection====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Unsafe reflection method const_get called with parameter value&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
Remove the unsafe reflection through using a variable that checks for null values. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question_type = params[:question][:type] unless params[:question][:type].nil?&lt;br /&gt;
question = Object.const_get(question_type).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: question_type, break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed unnecessary method 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method create_questionnaire, had no apparent calls to it. Aside from assigning a creator ID, it is similar in functionality to create, so we assume that the method was at some point created as a duplicate.  We remove the method to make the code dry. &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we remove:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_questionnaire&lt;br /&gt;
    @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
    # Create Quiz content has been moved to Quiz Questionnaire Controller&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
      @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) &lt;br /&gt;
                                       if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      save&lt;br /&gt;
&lt;br /&gt;
      redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Break up create method into new 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The create method itself was 49 lines long.  This is too long to be viewable at a glance.  Breaking it up into a second private method 'create_questionnaire' to handle attribute assigning and node creation.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire.private = questionnaire_private&lt;br /&gt;
        @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
        @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
        @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
        @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
        @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
        # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
        # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
        # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
        if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
          display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
        @questionnaire.display_type = display_type&lt;br /&gt;
        @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
        @questionnaire.save&lt;br /&gt;
        # Create node&lt;br /&gt;
        tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
        parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
        QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        create_questionnaire questionnaire_private, display_type&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create_questions questionnaire_private, display_type&lt;br /&gt;
    @questionnaire.private = questionnaire_private&lt;br /&gt;
    @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
    @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
    @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
    @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
    @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
    # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
    # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
    # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
    if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
      display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    @questionnaire.display_type = display_type&lt;br /&gt;
    @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
    @questionnaire.save&lt;br /&gt;
    tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
    parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
    # Create node&lt;br /&gt;
    QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use each_key instead of keys.each====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code uses keys.each to iterate through the hash.  Keys.each is useful for modifying a hash, but in this implementation this is not necessary.  So, each_key is used to improve performance timing.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].keys.each do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].each_key do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split lines of code to fit within recommended 160 character length====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Some of the lines of code exceed the recommended 160 characters per line.  To remediate, we simply split code across multiple lines and indent accordingly to maintain readability.   &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id, seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,&lt;br /&gt;
                                                                   seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed useless assignment of variable in save method====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code included assignments of variables that were not used throughout the file.  We assume that these variables were created to implement functionality that has since been removed through previous refactor attempts.  In any case, we remove the variable keep the code dry.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    # We do not create node for quiz questionnaires&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
      p_folder = TreeFolder.find_by(name: @questionnaire.display_type)&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: p_folder.id)&lt;br /&gt;
      # create_new_node_if_necessary(parent)&lt;br /&gt;
    end&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We remove the unnecessary variables and comments, resulting in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Testing Plan ===&lt;br /&gt;
In order to evaluate the changes to Expertiza throughout the OSS project two different methods were used. The first being automatic testing using RSpec and the second being manual testing through accessing the Expertiza project on one's local machine. More in depth discussion of these tests can be found below.&lt;br /&gt;
====RSpec Testing====&lt;br /&gt;
In many cases the issues were resolved by editing a few lines of code within various methods without the need for additional methods. Thus, adding more test was not needed in these cases. However, in order to ensure the code edits didn't cause any previously crafted test to fail an RSpec test was ran before each commit. If and only if all test passed could the commit be pushed. &lt;br /&gt;
&lt;br /&gt;
The command utilized to test the questionnaires controller is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
However, if a VCL was utilized for development this following command was used instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec /home/[UNITYID]/expertiza/spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In one case the create_questionnaire method was removed, thus in order to keep the set of tests clean the following test block was removed from the testing file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#create_questionnaire and #save' do&lt;br /&gt;
    context 'when quiz is valid' do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        # create_quiz_questionnaire&lt;br /&gt;
        allow_any_instance_of(QuestionnairesController).to receive(:valid_quiz).and_return('valid')&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when questionnaire type is not QuizQuestionnaire' do&lt;br /&gt;
        it 'redirects to submitted_content#edit page' do&lt;br /&gt;
          params = {aid: 1,&lt;br /&gt;
                    pid: 1,&lt;br /&gt;
                    questionnaire: {name: 'Test questionnaire',&lt;br /&gt;
                                    type: 'ReviewQuestionnaire'}}&lt;br /&gt;
          # create_questionnaire&lt;br /&gt;
          allow(ReviewQuestionnaire).to receive(:new).with(any_args).and_return(review_questionnaire)&lt;br /&gt;
          session = {user: build(:teaching_assistant, id: 1)}&lt;br /&gt;
          allow(Ta).to receive(:get_my_instructor).with(1).and_return(6)&lt;br /&gt;
          # save&lt;br /&gt;
          allow(TreeFolder).to receive(:find_by).with(name: 'Review').and_return(double('TreeFolder', id: 1))&lt;br /&gt;
          allow(FolderNode).to receive(:find_by).with(node_object_id: 1).and_return(double('FolderNode'))&lt;br /&gt;
          allow_any_instance_of(QuestionnairesController).to receive(:undo_link).with(any_args).and_return('')&lt;br /&gt;
          post :create_questionnaire, params, session&lt;br /&gt;
          expect(flash[:note]).to be nil&lt;br /&gt;
          expect(response).to redirect_to('/tree_display/list')&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).private).to eq false&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).name).to eq 'Test questionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).min_question_score).to eq 0&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).max_question_score).to eq 5&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).type).to eq 'ReviewQuestionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).instructor_id).to eq 6&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Manual Testing====&lt;br /&gt;
Manual testing was performed by running Expertiza on the local machine and creating the various types of questionnaires (i.e. rubrics, quizzes, and surveys) in the various locations they occurred albeit non-exhaustively . If a questionnaire was created and could be updated without throwing an error it was determined that the refactoring on the questionnaires controller had succeeded. This process was performed and confirmed by all team members in order to ensure accuracy.&lt;br /&gt;
&lt;br /&gt;
===Database===&lt;br /&gt;
Left Blank intentionally&lt;br /&gt;
[[File:Db_relationship.png]]&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
*Code Refactoring Best Practices[https://www.altexsoft.com/blog/engineering/code-refactoring-best-practices-when-and-when-not-to-do-it/]&lt;br /&gt;
*Expertiza on Github[https://github.com/expertiza/expertiza]&lt;br /&gt;
*Expertiza Project Fork[https://github.com/Sattlert2/expertiza/tree/master]&lt;br /&gt;
*Expertiza Website[https://expertiza.ncsu.edu/]&lt;br /&gt;
*RSpec Documentation[https://relishapp.com/rspec]&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Db_relationship.png&amp;diff=131770</id>
		<title>File:Db relationship.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Db_relationship.png&amp;diff=131770"/>
		<updated>2020-03-23T19:02:19Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: Relationship of the questionnaire database with other databases.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Relationship of the questionnaire database with other databases.&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=131767</id>
		<title>CSC/ECE 517 Spring 2020 / E2001 Refactor Questionnaires Controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2020_/_E2001_Refactor_Questionnaires_Controller&amp;diff=131767"/>
		<updated>2020-03-23T18:59:35Z</updated>

		<summary type="html">&lt;p&gt;Tsattle: /* E2000 Refactor questionnaires_controller.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== E2000 Refactor questionnaires_controller.rb ==&lt;br /&gt;
This page provides a description of the Expertiza based OSS project&lt;br /&gt;
__TOC__&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
Expertiza is an open source software project created using Ruby on Rails. Expertiza allows instructors to craft new assignments and edit existing ones. This flexibility ensures that each round of students gets an experience that is appropriate to the given situation. It also allows the instructor to create a list of project options and have the students bid for their favorite project. &lt;br /&gt;
&lt;br /&gt;
While their are a plethora of benefits for instructors, students also gain some benefits when using Expertiza. They are able to form teams and keep track of the past peers they have worked with, and are also able to manage the progress and submission of their assignments.&lt;br /&gt;
&lt;br /&gt;
=== Problem Statement ===&lt;br /&gt;
'''Background:''' In Expertiza, Questionnaire is a super-class utilized by all questionnaires, including rubrics, quizzes, and surveys. Rubrics are used to assess things such as project submissions and project teammates. All of the above-mentioned questionnaires are sub-classes of the Questionnaire super-class. Since this super-class is used in a multitude of locations ensuring that there are no issues in the code is very important since an error can cause malfunctions throughout Expertiza.&lt;br /&gt;
&lt;br /&gt;
'''Problem:''' Questionnaires controller has been refactored repeatedly over the past few years, yet some improvements can still be made through refactoring to increase the quality and dryness of the code. &lt;br /&gt;
&lt;br /&gt;
These problems are as follows:&lt;br /&gt;
* Unsafe reflection method const_get called with parameter value &lt;br /&gt;
* Hardwired variables in add_new_questions and save_new_questions&lt;br /&gt;
* Unnecessary checks for QuizQuestionnaire, checks can be removed&lt;br /&gt;
* Use guard clause to enclose methods instead of conditional&lt;br /&gt;
* Removed unnecessary method 'create_questionnaire'&lt;br /&gt;
* Break up create method into new 'create_questionnaire'&lt;br /&gt;
* Use each_key instead of keys.each &lt;br /&gt;
* Split lines of code to fit within recommended 160 character length&lt;br /&gt;
* Removed useless assignment of variable in save method&lt;br /&gt;
* Resolved issues involving use of unsafe reflection&lt;br /&gt;
&lt;br /&gt;
=== Files Modified in Project ===&lt;br /&gt;
#app/controllers/questionnaires_controller.rb&lt;br /&gt;
#spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Issues and Improvements ===&lt;br /&gt;
====Use guard clause====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions, delete, and save_questions used conditional to wrap code instead of guard clause. Using guard clause can reduce complexity and number of lines in code.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def save_new_questions(questionnaire_id)&lt;br /&gt;
    if params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def save_new_questions(questionnaire_id)&lt;br /&gt;
    return unless params[:new_question]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====QuizQuestionnaire checks====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) create and save_new_questions have unnecessary checks for if question type is QuizQuestionnaire.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
We removed the check in both methods. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if @questionnaire.type == &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
 q.weight = 1 # setting the weight to 1 for quiz questionnaire since the model validates this field&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
q.weight = 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Hardwired Variables====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method(s) save_new_questions and add_new_questions used hardwired variables. When applicable all values used should be stored as variables so the user knows the purpose of the variable, if that value is used in multiple areas it can be changed with a single change, and it's just messy. For instance both add_new_questions and save_new_questions used the same scalar value 1 for a similar task. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = 1&lt;br /&gt;
 question.max_label = 'Strongly agree'&lt;br /&gt;
 question.min_label = 'Strongly disagree'&lt;br /&gt;
end&lt;br /&gt;
question.size = '50, 3' if question.is_a? Criterion&lt;br /&gt;
question.alternatives = '0|1|2|3|4|5' if question.is_a? Dropdown&lt;br /&gt;
question.size = '60, 5' if question.is_a? TextArea&lt;br /&gt;
question.size = '30' if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To our code which incorporates constants.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if question.is_a? ScoredQuestion&lt;br /&gt;
 question.weight = WEIGHT&lt;br /&gt;
 question.max_label = LABEL_AGREE&lt;br /&gt;
 question.min_label = LABEL_DISAGREE&lt;br /&gt;
end&lt;br /&gt;
question.size = SIZE_CRITERION if question.is_a? Criterion&lt;br /&gt;
question.alternatives = SIZE_ALT_DROPDOWN if question.is_a? Dropdown&lt;br /&gt;
question.size = SIZE_TXT_AREA if question.is_a? TextArea&lt;br /&gt;
question.size = SIZE_TXT_FIELD if question.is_a? TextField&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With our constants at the top of the code for easy accessibility:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Constants&lt;br /&gt;
# add_new_questions&lt;br /&gt;
LABEL_AGREE = 'Strongly agree' # label for scored question if agree&lt;br /&gt;
LABEL_DISAGREE = 'Strongly disagree' # label for scored question if disagree&lt;br /&gt;
WEIGHT = 1  # question weight&lt;br /&gt;
SIZE_CRITERION = '50, 3' # size of the question box if it's a criterion&lt;br /&gt;
SIZE_ALT_DROPDOWN = '0|1|2|3|4|5' # alternative to size if question is a dropdown&lt;br /&gt;
SIZE_TXT_AREA = '60, 5' # size of question box if text area&lt;br /&gt;
SIZE_TXT_FIELD = '30' # size of question box if text field&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Unsafe Reflection====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Unsafe reflection method const_get called with parameter value&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
Remove the unsafe reflection through using a variable that checks for null values. We go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
question_type = params[:question][:type] unless params[:question][:type].nil?&lt;br /&gt;
question = Object.const_get(question_type).create(txt: '', questionnaire_id: questionnaire_id,seq: i, type: question_type, break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed unnecessary method 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Method create_questionnaire, had no apparent calls to it. Aside from assigning a creator ID, it is similar in functionality to create, so we assume that the method was at some point created as a duplicate.  We remove the method to make the code dry. &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we remove:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_questionnaire&lt;br /&gt;
    @questionnaire = Object.const_get(params[:questionnaire][:type]).new(questionnaire_params)&lt;br /&gt;
    # Create Quiz content has been moved to Quiz Questionnaire Controller&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot; # checking if it is a quiz questionnaire&lt;br /&gt;
      @questionnaire.instructor_id = Ta.get_my_instructor(session[:user].id) &lt;br /&gt;
                                       if session[:user].role.name == &amp;quot;Teaching Assistant&amp;quot;&lt;br /&gt;
      save&lt;br /&gt;
&lt;br /&gt;
      redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Break up create method into new 'create_questionnaire'====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The create method itself was 49 lines long.  This is too long to be viewable at a glance.  Breaking it up into a second private method 'create_questionnaire' to handle attribute assigning and node creation.&lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire.private = questionnaire_private&lt;br /&gt;
        @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
        @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
        @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
        @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
        @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
        # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
        # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
        # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
        if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
          display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
        @questionnaire.display_type = display_type&lt;br /&gt;
        @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
        @questionnaire.save&lt;br /&gt;
        # Create node&lt;br /&gt;
        tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
        parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
        QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create&lt;br /&gt;
    if params[:questionnaire][:name].blank?&lt;br /&gt;
      flash[:error] = 'A rubric or survey must have a title.'&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]&lt;br /&gt;
    else&lt;br /&gt;
      questionnaire_private = params[:questionnaire][:private] == 'true'&lt;br /&gt;
      display_type = params[:questionnaire][:type].split('Questionnaire')[0]&lt;br /&gt;
      begin&lt;br /&gt;
        @questionnaire = Object.const_get(params[:questionnaire][:type]).new if Questionnaire::QUESTIONNAIRE_TYPES.include? params[:questionnaire][:type]&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      begin&lt;br /&gt;
        create_questionnaire questionnaire_private, display_type&lt;br /&gt;
        flash[:success] = 'You have successfully created a questionnaire!'&lt;br /&gt;
      rescue StandardError&lt;br /&gt;
        flash[:error] = $ERROR_INFO&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to controller: 'questionnaires', action: 'edit', id: @questionnaire.id&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create_questions questionnaire_private, display_type&lt;br /&gt;
    @questionnaire.private = questionnaire_private&lt;br /&gt;
    @questionnaire.name = params[:questionnaire][:name]&lt;br /&gt;
    @questionnaire.instructor_id = session[:user].id&lt;br /&gt;
    @questionnaire.min_question_score = params[:questionnaire][:min_question_score]&lt;br /&gt;
    @questionnaire.max_question_score = params[:questionnaire][:max_question_score]&lt;br /&gt;
    @questionnaire.type = params[:questionnaire][:type]&lt;br /&gt;
    # Zhewei: Right now, the display_type in 'questionnaires' table and name in 'tree_folders' table are not consistent.&lt;br /&gt;
    # In the future, we need to write migration files to make them consistency.&lt;br /&gt;
    # E1903 : We are not sure of other type of cases, so have added a if statement. If there are only 5 cases, remove the if statement&lt;br /&gt;
    if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey].include?(display_type)&lt;br /&gt;
      display_type = (display_type.split /(?=[A-Z])/).join(&amp;quot;%&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    @questionnaire.display_type = display_type&lt;br /&gt;
    @questionnaire.instruction_loc = Questionnaire::DEFAULT_QUESTIONNAIRE_URL&lt;br /&gt;
    @questionnaire.save&lt;br /&gt;
    tree_folder = TreeFolder.where(['name like ?', @questionnaire.display_type]).first&lt;br /&gt;
    parent = FolderNode.find_by(node_object_id: tree_folder.id)&lt;br /&gt;
    # Create node&lt;br /&gt;
    QuestionnaireNode.create(parent_id: parent.id, node_object_id: @questionnaire.id, type: 'QuestionnaireNode')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use each_key instead of keys.each====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code uses keys.each to iterate through the hash.  Keys.each is useful for modifying a hash, but in this implementation this is not necessary.  So, each_key is used to improve performance timing.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].keys.each do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  params[:new_question].each_key do |question_key|&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Split lines of code to fit within recommended 160 character length====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
Some of the lines of code exceed the recommended 160 characters per line.  To remediate, we simply split code across multiple lines and indent accordingly to maintain readability.   &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, we go from:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id, seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 question = Object.const_get(params[:question][:type]).create(txt: '', questionnaire_id: questionnaire_id,&lt;br /&gt;
                                                                   seq: i, type: params[:question][:type], break_before: true)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Removed useless assignment of variable in save method====&lt;br /&gt;
&lt;br /&gt;
'''Problem'''&lt;br /&gt;
&lt;br /&gt;
The existing code included assignments of variables that were not used throughout the file.  We assume that these variables were created to implement functionality that has since been removed through previous refactor attempts.  In any case, we remove the variable keep the code dry.  &lt;br /&gt;
&lt;br /&gt;
'''Solution'''&lt;br /&gt;
&lt;br /&gt;
For example, in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    # We do not create node for quiz questionnaires&lt;br /&gt;
    if @questionnaire.type != &amp;quot;QuizQuestionnaire&amp;quot;&lt;br /&gt;
      p_folder = TreeFolder.find_by(name: @questionnaire.display_type)&lt;br /&gt;
      parent = FolderNode.find_by(node_object_id: p_folder.id)&lt;br /&gt;
      # create_new_node_if_necessary(parent)&lt;br /&gt;
    end&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We remove the unnecessary variables and comments, resulting in the following method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   def save&lt;br /&gt;
    @questionnaire.save!&lt;br /&gt;
    save_questions @questionnaire.id if !@questionnaire.id.nil? and @questionnaire.id &amp;gt; 0&lt;br /&gt;
    undo_link(&amp;quot;Questionnaire \&amp;quot;#{@questionnaire.name}\&amp;quot; has been updated successfully. &amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Testing Plan ===&lt;br /&gt;
In order to evaluate the changes to Expertiza throughout the OSS project two different methods were used. The first being automatic testing using RSpec and the second being manual testing through accessing the Expertiza project on one's local machine. More in depth discussion of these tests can be found below.&lt;br /&gt;
====RSpec Testing====&lt;br /&gt;
In many cases the issues were resolved by editing a few lines of code within various methods without the need for additional methods. Thus, adding more test was not needed in these cases. However, in order to ensure the code edits didn't cause any previously crafted test to fail an RSpec test was ran before each commit. If and only if all test passed could the commit be pushed. &lt;br /&gt;
&lt;br /&gt;
The command utilized to test the questionnaires controller is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
However, if a VCL was utilized for development this following command was used instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rspec /home/[UNITYID]/expertiza/spec/controllers/questionnaires_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In one case the create_questionnaire method was removed, thus in order to keep the set of tests clean the following test block was removed from the testing file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#create_questionnaire and #save' do&lt;br /&gt;
    context 'when quiz is valid' do&lt;br /&gt;
      before(:each) do&lt;br /&gt;
        # create_quiz_questionnaire&lt;br /&gt;
        allow_any_instance_of(QuestionnairesController).to receive(:valid_quiz).and_return('valid')&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      context 'when questionnaire type is not QuizQuestionnaire' do&lt;br /&gt;
        it 'redirects to submitted_content#edit page' do&lt;br /&gt;
          params = {aid: 1,&lt;br /&gt;
                    pid: 1,&lt;br /&gt;
                    questionnaire: {name: 'Test questionnaire',&lt;br /&gt;
                                    type: 'ReviewQuestionnaire'}}&lt;br /&gt;
          # create_questionnaire&lt;br /&gt;
          allow(ReviewQuestionnaire).to receive(:new).with(any_args).and_return(review_questionnaire)&lt;br /&gt;
          session = {user: build(:teaching_assistant, id: 1)}&lt;br /&gt;
          allow(Ta).to receive(:get_my_instructor).with(1).and_return(6)&lt;br /&gt;
          # save&lt;br /&gt;
          allow(TreeFolder).to receive(:find_by).with(name: 'Review').and_return(double('TreeFolder', id: 1))&lt;br /&gt;
          allow(FolderNode).to receive(:find_by).with(node_object_id: 1).and_return(double('FolderNode'))&lt;br /&gt;
          allow_any_instance_of(QuestionnairesController).to receive(:undo_link).with(any_args).and_return('')&lt;br /&gt;
          post :create_questionnaire, params, session&lt;br /&gt;
          expect(flash[:note]).to be nil&lt;br /&gt;
          expect(response).to redirect_to('/tree_display/list')&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).private).to eq false&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).name).to eq 'Test questionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).min_question_score).to eq 0&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).max_question_score).to eq 5&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).type).to eq 'ReviewQuestionnaire'&lt;br /&gt;
          expect(controller.instance_variable_get(:@questionnaire).instructor_id).to eq 6&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Manual Testing====&lt;br /&gt;
Manual testing was performed by running Expertiza on the local machine and creating the various types of questionnaires (i.e. rubrics, quizzes, and surveys) in the various locations they occurred albeit non-exhaustively . If a questionnaire was created and could be updated without throwing an error it was determined that the refactoring on the questionnaires controller had succeeded. This process was performed and confirmed by all team members in order to ensure accuracy.&lt;br /&gt;
&lt;br /&gt;
===Database===&lt;br /&gt;
Left Blank intentionally&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
*Code Refactoring Best Practices[https://www.altexsoft.com/blog/engineering/code-refactoring-best-practices-when-and-when-not-to-do-it/]&lt;br /&gt;
*Expertiza on Github[https://github.com/expertiza/expertiza]&lt;br /&gt;
*Expertiza Project Fork[https://github.com/Sattlert2/expertiza/tree/master]&lt;br /&gt;
*Expertiza Website[https://expertiza.ncsu.edu/]&lt;br /&gt;
*RSpec Documentation[https://relishapp.com/rspec]&lt;/div&gt;</summary>
		<author><name>Tsattle</name></author>
	</entry>
</feed>