<?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=Jgu7</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=Jgu7"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Jgu7"/>
	<updated>2026-06-02T21:25:04Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92549</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92549"/>
		<updated>2014-12-05T17:27:22Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Files Involved */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case to underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactor Getter and Setter Accessor'''&lt;br /&gt;
|&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/view.html.erb&lt;br /&gt;
|-&lt;br /&gt;
| '''Reduce Local Variables In Views'''&lt;br /&gt;
| &lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
*views/grades/_scores_header.html.erb&lt;br /&gt;
*views/grades/_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| '''Calculations Found in Views'''&lt;br /&gt;
| &lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using encapsulation to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to encapsulate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*After confirmation with Professor and TAs, we no longer need to check the existence of the topic.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
&lt;br /&gt;
We find that there are some calculations in the views('''_participant.html.erb'''). The main function of these calculations in the _participant.html.erb is to curve the teams' total score. It gets the value of total_score from the instance variable('''@pscore''') and computes them in the views.&lt;br /&gt;
&lt;br /&gt;
The whole project utilizes the MVC design pattern to achieve a clean separation among three components(Model-View-Controller). However, the above calculations violate the MVC design pattern and ruin the program's structure. Meanwhile, it will increase the workload of the views and decrease performance of the website.&lt;br /&gt;
&lt;br /&gt;
In order to implement the MVC design pattern much better and improve the performance of the website, we move these calculations to the model to avoid these problems. In current system, the participant's total score is obtained by calling the '''participant.scores''' method in gradesController, so we move these calculations into scores method which is declared in the model of '''assignment_participant.rb'''. &lt;br /&gt;
&lt;br /&gt;
By testing, our solution solves the above problem effectively. Meanwhile, we adopt single responsibility principle and DRY principle to simplify our code.&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
&lt;br /&gt;
In the '''grade/_participant.html.erb''' file, there are plenty of local variables such as min, max and avg. When we need to return the grades of a student for different type of reviews, we need to create different variables. This not only ruins the readability of the code, but also tends to cause problem for future maintenance and development. Since min, max and avg are the mostly used variables, we created a new data structure '''Rscore''' in this file, which encapsulated all these three variables. Whenever we need the value of min, max and avg, we can get those information directly from '''Rscore'''.&lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code look cleaner.&lt;br /&gt;
&lt;br /&gt;
Furthermore, '''pscore''' is a complicated data structure. It consists of huge hash tables, with each hash table contains another hash table as its value. This situation makes polymorphism pretty hard to implement,if we are not allowed to modify the data structure of the score, which is the  basic structure of the system.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1ncwlrTEZ1taP6ZvMc_GqP4jcAchE03zXSnZwvzgfeDw/edit?usp=sharing ''Requirement for E147'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
[http://youtu.be/RPfzaGtJtQc ''Youtube Demo'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92548</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92548"/>
		<updated>2014-12-05T17:25:16Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Files Involved */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case to underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactor Getter and Setter Accessor'''&lt;br /&gt;
|&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/view.html.erb&lt;br /&gt;
|-&lt;br /&gt;
| '''Reduce Local Variables In Views'''&lt;br /&gt;
| &lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
*views/grades/_scores_header.html.erb&lt;br /&gt;
*views/grades/_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| '''Calculations Found in Views''':&lt;br /&gt;
| &lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using encapsulation to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to encapsulate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*After confirmation with Professor and TAs, we no longer need to check the existence of the topic.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
&lt;br /&gt;
We find that there are some calculations in the views('''_participant.html.erb'''). The main function of these calculations in the _participant.html.erb is to curve the teams' total score. It gets the value of total_score from the instance variable('''@pscore''') and computes them in the views.&lt;br /&gt;
&lt;br /&gt;
The whole project utilizes the MVC design pattern to achieve a clean separation among three components(Model-View-Controller). However, the above calculations violate the MVC design pattern and ruin the program's structure. Meanwhile, it will increase the workload of the views and decrease performance of the website.&lt;br /&gt;
&lt;br /&gt;
In order to implement the MVC design pattern much better and improve the performance of the website, we move these calculations to the model to avoid these problems. In current system, the participant's total score is obtained by calling the '''participant.scores''' method in gradesController, so we move these calculations into scores method which is declared in the model of '''assignment_participant.rb'''. &lt;br /&gt;
&lt;br /&gt;
By testing, our solution solves the above problem effectively. Meanwhile, we adopt single responsibility principle and DRY principle to simplify our code.&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
&lt;br /&gt;
In the '''grade/_participant.html.erb''' file, there are plenty of local variables such as min, max and avg. When we need to return the grades of a student for different type of reviews, we need to create different variables. This not only ruins the readability of the code, but also tends to cause problem for future maintenance and development. Since min, max and avg are the mostly used variables, we created a new data structure '''Rscore''' in this file, which encapsulated all these three variables. Whenever we need the value of min, max and avg, we can get those information directly from '''Rscore'''.&lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code look cleaner.&lt;br /&gt;
&lt;br /&gt;
Furthermore, '''pscore''' is a complicated data structure. It consists of huge hash tables, with each hash table contains another hash table as its value. This situation makes polymorphism pretty hard to implement,if we are not allowed to modify the data structure of the score, which is the  basic structure of the system.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1ncwlrTEZ1taP6ZvMc_GqP4jcAchE03zXSnZwvzgfeDw/edit?usp=sharing ''Requirement for E147'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
[http://youtu.be/RPfzaGtJtQc ''Youtube Demo'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92547</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92547"/>
		<updated>2014-12-05T17:25:00Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Files Involved */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case to underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactor Getter and Setter Accessor'''&lt;br /&gt;
|*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/view.html.erb&lt;br /&gt;
|-&lt;br /&gt;
| '''Reduce Local Variables In Views'''&lt;br /&gt;
| &lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
*views/grades/_scores_header.html.erb&lt;br /&gt;
*views/grades/_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| '''Calculations Found in Views''':&lt;br /&gt;
| &lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using encapsulation to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to encapsulate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*After confirmation with Professor and TAs, we no longer need to check the existence of the topic.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
&lt;br /&gt;
We find that there are some calculations in the views('''_participant.html.erb'''). The main function of these calculations in the _participant.html.erb is to curve the teams' total score. It gets the value of total_score from the instance variable('''@pscore''') and computes them in the views.&lt;br /&gt;
&lt;br /&gt;
The whole project utilizes the MVC design pattern to achieve a clean separation among three components(Model-View-Controller). However, the above calculations violate the MVC design pattern and ruin the program's structure. Meanwhile, it will increase the workload of the views and decrease performance of the website.&lt;br /&gt;
&lt;br /&gt;
In order to implement the MVC design pattern much better and improve the performance of the website, we move these calculations to the model to avoid these problems. In current system, the participant's total score is obtained by calling the '''participant.scores''' method in gradesController, so we move these calculations into scores method which is declared in the model of '''assignment_participant.rb'''. &lt;br /&gt;
&lt;br /&gt;
By testing, our solution solves the above problem effectively. Meanwhile, we adopt single responsibility principle and DRY principle to simplify our code.&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
&lt;br /&gt;
In the '''grade/_participant.html.erb''' file, there are plenty of local variables such as min, max and avg. When we need to return the grades of a student for different type of reviews, we need to create different variables. This not only ruins the readability of the code, but also tends to cause problem for future maintenance and development. Since min, max and avg are the mostly used variables, we created a new data structure '''Rscore''' in this file, which encapsulated all these three variables. Whenever we need the value of min, max and avg, we can get those information directly from '''Rscore'''.&lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code look cleaner.&lt;br /&gt;
&lt;br /&gt;
Furthermore, '''pscore''' is a complicated data structure. It consists of huge hash tables, with each hash table contains another hash table as its value. This situation makes polymorphism pretty hard to implement,if we are not allowed to modify the data structure of the score, which is the  basic structure of the system.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1ncwlrTEZ1taP6ZvMc_GqP4jcAchE03zXSnZwvzgfeDw/edit?usp=sharing ''Requirement for E147'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
[http://youtu.be/RPfzaGtJtQc ''Youtube Demo'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92546</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92546"/>
		<updated>2014-12-05T17:18:49Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Files Involved */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case to underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactor Getter and Setter Accessor'''&lt;br /&gt;
|*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/view.html.erb&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
'''Refactor Getter and Setter Accessor''':&lt;br /&gt;
&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Reduce Local Variables In Views''':&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
*views/grades/_scores_header.html.erb&lt;br /&gt;
*views/grades/_submitted_work.html.erb&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using encapsulation to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to encapsulate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*After confirmation with Professor and TAs, we no longer need to check the existence of the topic.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
&lt;br /&gt;
We find that there are some calculations in the views('''_participant.html.erb'''). The main function of these calculations in the _participant.html.erb is to curve the teams' total score. It gets the value of total_score from the instance variable('''@pscore''') and computes them in the views.&lt;br /&gt;
&lt;br /&gt;
The whole project utilizes the MVC design pattern to achieve a clean separation among three components(Model-View-Controller). However, the above calculations violate the MVC design pattern and ruin the program's structure. Meanwhile, it will increase the workload of the views and decrease performance of the website.&lt;br /&gt;
&lt;br /&gt;
In order to implement the MVC design pattern much better and improve the performance of the website, we move these calculations to the model to avoid these problems. In current system, the participant's total score is obtained by calling the '''participant.scores''' method in gradesController, so we move these calculations into scores method which is declared in the model of '''assignment_participant.rb'''. &lt;br /&gt;
&lt;br /&gt;
By testing, our solution solves the above problem effectively. Meanwhile, we adopt single responsibility principle and DRY principle to simplify our code.&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
&lt;br /&gt;
In the '''grade/_participant.html.erb''' file, there are plenty of local variables such as min, max and avg. When we need to return the grades of a student for different type of reviews, we need to create different variables. This not only ruins the readability of the code, but also tends to cause problem for future maintenance and development. Since min, max and avg are the mostly used variables, we created a new data structure '''Rscore''' in this file, which encapsulated all these three variables. Whenever we need the value of min, max and avg, we can get those information directly from '''Rscore'''.&lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code look cleaner.&lt;br /&gt;
&lt;br /&gt;
Furthermore, '''pscore''' is a complicated data structure. It consists of huge hash tables, with each hash table contains another hash table as its value. This situation makes polymorphism pretty hard to implement,if we are not allowed to modify the data structure of the score, which is the  basic structure of the system.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1ncwlrTEZ1taP6ZvMc_GqP4jcAchE03zXSnZwvzgfeDw/edit?usp=sharing ''Requirement for E147'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
[http://youtu.be/RPfzaGtJtQc ''Youtube Demo'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92545</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92545"/>
		<updated>2014-12-05T17:17:14Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Files Involved */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case to underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactor Getter and Setter Accessor'''&lt;br /&gt;
| *models/participant.rb&lt;br /&gt;
|*models/rscore.rb&lt;br /&gt;
|*models/assignment_participant.rb&lt;br /&gt;
|*models/assignment.rb&lt;br /&gt;
|*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
|*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
|*models/course.rb&lt;br /&gt;
&lt;br /&gt;
|*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
|*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
|*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
|*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
|*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
|*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
|*views/grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
|*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
|*views/grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
|*views/grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
|*views/grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
|*views/grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
|*views/response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
|*views/response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
|*views/response/view.html.erb&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
'''Refactor Getter and Setter Accessor''':&lt;br /&gt;
&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Reduce Local Variables In Views''':&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
*views/grades/_scores_header.html.erb&lt;br /&gt;
*views/grades/_submitted_work.html.erb&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using encapsulation to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to encapsulate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*After confirmation with Professor and TAs, we no longer need to check the existence of the topic.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
&lt;br /&gt;
We find that there are some calculations in the views('''_participant.html.erb'''). The main function of these calculations in the _participant.html.erb is to curve the teams' total score. It gets the value of total_score from the instance variable('''@pscore''') and computes them in the views.&lt;br /&gt;
&lt;br /&gt;
The whole project utilizes the MVC design pattern to achieve a clean separation among three components(Model-View-Controller). However, the above calculations violate the MVC design pattern and ruin the program's structure. Meanwhile, it will increase the workload of the views and decrease performance of the website.&lt;br /&gt;
&lt;br /&gt;
In order to implement the MVC design pattern much better and improve the performance of the website, we move these calculations to the model to avoid these problems. In current system, the participant's total score is obtained by calling the '''participant.scores''' method in gradesController, so we move these calculations into scores method which is declared in the model of '''assignment_participant.rb'''. &lt;br /&gt;
&lt;br /&gt;
By testing, our solution solves the above problem effectively. Meanwhile, we adopt single responsibility principle and DRY principle to simplify our code.&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
&lt;br /&gt;
In the '''grade/_participant.html.erb''' file, there are plenty of local variables such as min, max and avg. When we need to return the grades of a student for different type of reviews, we need to create different variables. This not only ruins the readability of the code, but also tends to cause problem for future maintenance and development. Since min, max and avg are the mostly used variables, we created a new data structure '''Rscore''' in this file, which encapsulated all these three variables. Whenever we need the value of min, max and avg, we can get those information directly from '''Rscore'''.&lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code look cleaner.&lt;br /&gt;
&lt;br /&gt;
Furthermore, '''pscore''' is a complicated data structure. It consists of huge hash tables, with each hash table contains another hash table as its value. This situation makes polymorphism pretty hard to implement,if we are not allowed to modify the data structure of the score, which is the  basic structure of the system.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1ncwlrTEZ1taP6ZvMc_GqP4jcAchE03zXSnZwvzgfeDw/edit?usp=sharing ''Requirement for E147'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
[http://youtu.be/RPfzaGtJtQc ''Youtube Demo'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92544</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92544"/>
		<updated>2014-12-05T17:13:56Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Files Involved */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case to underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
&lt;br /&gt;
'''Refactor Getter and Setter Accessor''':&lt;br /&gt;
&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Reduce Local Variables In Views''':&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
*views/grades/_scores_header.html.erb&lt;br /&gt;
*views/grades/_submitted_work.html.erb&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using encapsulation to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to encapsulate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*After confirmation with Professor and TAs, we no longer need to check the existence of the topic.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
&lt;br /&gt;
We find that there are some calculations in the views('''_participant.html.erb'''). The main function of these calculations in the _participant.html.erb is to curve the teams' total score. It gets the value of total_score from the instance variable('''@pscore''') and computes them in the views.&lt;br /&gt;
&lt;br /&gt;
The whole project utilizes the MVC design pattern to achieve a clean separation among three components(Model-View-Controller). However, the above calculations violate the MVC design pattern and ruin the program's structure. Meanwhile, it will increase the workload of the views and decrease performance of the website.&lt;br /&gt;
&lt;br /&gt;
In order to implement the MVC design pattern much better and improve the performance of the website, we move these calculations to the model to avoid these problems. In current system, the participant's total score is obtained by calling the '''participant.scores''' method in gradesController, so we move these calculations into scores method which is declared in the model of '''assignment_participant.rb'''. &lt;br /&gt;
&lt;br /&gt;
By testing, our solution solves the above problem effectively. Meanwhile, we adopt single responsibility principle and DRY principle to simplify our code.&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
&lt;br /&gt;
In the '''grade/_participant.html.erb''' file, there are plenty of local variables such as min, max and avg. When we need to return the grades of a student for different type of reviews, we need to create different variables. This not only ruins the readability of the code, but also tends to cause problem for future maintenance and development. Since min, max and avg are the mostly used variables, we created a new data structure '''Rscore''' in this file, which encapsulated all these three variables. Whenever we need the value of min, max and avg, we can get those information directly from '''Rscore'''.&lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code look cleaner.&lt;br /&gt;
&lt;br /&gt;
Furthermore, '''pscore''' is a complicated data structure. It consists of huge hash tables, with each hash table contains another hash table as its value. This situation makes polymorphism pretty hard to implement,if we are not allowed to modify the data structure of the score, which is the  basic structure of the system.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1ncwlrTEZ1taP6ZvMc_GqP4jcAchE03zXSnZwvzgfeDw/edit?usp=sharing ''Requirement for E147'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
[http://youtu.be/RPfzaGtJtQc ''Youtube Demo'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92543</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92543"/>
		<updated>2014-12-05T17:08:27Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Files Involved */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case to underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
&lt;br /&gt;
'''Refactor Getter and Setter Accessor''':&lt;br /&gt;
&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Reduce Local Variables In Views''':&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using encapsulation to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to encapsulate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*After confirmation with Professor and TAs, we no longer need to check the existence of the topic.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
&lt;br /&gt;
We find that there are some calculations in the views('''_participant.html.erb'''). The main function of these calculations in the _participant.html.erb is to curve the teams' total score. It gets the value of total_score from the instance variable('''@pscore''') and computes them in the views.&lt;br /&gt;
&lt;br /&gt;
The whole project utilizes the MVC design pattern to achieve a clean separation among three components(Model-View-Controller). However, the above calculations violate the MVC design pattern and ruin the program's structure. Meanwhile, it will increase the workload of the views and decrease performance of the website.&lt;br /&gt;
&lt;br /&gt;
In order to implement the MVC design pattern much better and improve the performance of the website, we move these calculations to the model to avoid these problems. In current system, the participant's total score is obtained by calling the '''participant.scores''' method in gradesController, so we move these calculations into scores method which is declared in the model of '''assignment_participant.rb'''. &lt;br /&gt;
&lt;br /&gt;
By testing, our solution solves the above problem effectively. Meanwhile, we adopt single responsibility principle and DRY principle to simplify our code.&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
&lt;br /&gt;
In the '''grade/_participant.html.erb''' file, there are plenty of local variables such as min, max and avg. When we need to return the grades of a student for different type of reviews, we need to create different variables. This not only ruins the readability of the code, but also tends to cause problem for future maintenance and development. Since min, max and avg are the mostly used variables, we created a new data structure '''Rscore''' in this file, which encapsulated all these three variables. Whenever we need the value of min, max and avg, we can get those information directly from '''Rscore'''.&lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code look cleaner.&lt;br /&gt;
&lt;br /&gt;
Furthermore, '''pscore''' is a complicated data structure. It consists of huge hash tables, with each hash table contains another hash table as its value. This situation makes polymorphism pretty hard to implement,if we are not allowed to modify the data structure of the score, which is the  basic structure of the system.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1ncwlrTEZ1taP6ZvMc_GqP4jcAchE03zXSnZwvzgfeDw/edit?usp=sharing ''Requirement for E147'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
[http://youtu.be/RPfzaGtJtQc ''Youtube Demo'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92542</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92542"/>
		<updated>2014-12-05T17:07:55Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Files Involved */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case to underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
&lt;br /&gt;
'''Refactor Getter and Setter Accessor''':&lt;br /&gt;
&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Reduce Local Variables In Views''':&lt;br /&gt;
&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using encapsulation to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to encapsulate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*After confirmation with Professor and TAs, we no longer need to check the existence of the topic.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
&lt;br /&gt;
We find that there are some calculations in the views('''_participant.html.erb'''). The main function of these calculations in the _participant.html.erb is to curve the teams' total score. It gets the value of total_score from the instance variable('''@pscore''') and computes them in the views.&lt;br /&gt;
&lt;br /&gt;
The whole project utilizes the MVC design pattern to achieve a clean separation among three components(Model-View-Controller). However, the above calculations violate the MVC design pattern and ruin the program's structure. Meanwhile, it will increase the workload of the views and decrease performance of the website.&lt;br /&gt;
&lt;br /&gt;
In order to implement the MVC design pattern much better and improve the performance of the website, we move these calculations to the model to avoid these problems. In current system, the participant's total score is obtained by calling the '''participant.scores''' method in gradesController, so we move these calculations into scores method which is declared in the model of '''assignment_participant.rb'''. &lt;br /&gt;
&lt;br /&gt;
By testing, our solution solves the above problem effectively. Meanwhile, we adopt single responsibility principle and DRY principle to simplify our code.&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
&lt;br /&gt;
In the '''grade/_participant.html.erb''' file, there are plenty of local variables such as min, max and avg. When we need to return the grades of a student for different type of reviews, we need to create different variables. This not only ruins the readability of the code, but also tends to cause problem for future maintenance and development. Since min, max and avg are the mostly used variables, we created a new data structure '''Rscore''' in this file, which encapsulated all these three variables. Whenever we need the value of min, max and avg, we can get those information directly from '''Rscore'''.&lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code look cleaner.&lt;br /&gt;
&lt;br /&gt;
Furthermore, '''pscore''' is a complicated data structure. It consists of huge hash tables, with each hash table contains another hash table as its value. This situation makes polymorphism pretty hard to implement,if we are not allowed to modify the data structure of the score, which is the  basic structure of the system.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1ncwlrTEZ1taP6ZvMc_GqP4jcAchE03zXSnZwvzgfeDw/edit?usp=sharing ''Requirement for E147'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
[http://youtu.be/RPfzaGtJtQc ''Youtube Demo'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92541</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92541"/>
		<updated>2014-12-05T17:05:48Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Files Involved */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case to underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
&lt;br /&gt;
'''Refactor Getter and Setter Accessor''':&lt;br /&gt;
&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*views/response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*views/grades/_participant.html.erb&lt;br /&gt;
*views/grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using encapsulation to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to encapsulate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*After confirmation with Professor and TAs, we no longer need to check the existence of the topic.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
&lt;br /&gt;
We find that there are some calculations in the views('''_participant.html.erb'''). The main function of these calculations in the _participant.html.erb is to curve the teams' total score. It gets the value of total_score from the instance variable('''@pscore''') and computes them in the views.&lt;br /&gt;
&lt;br /&gt;
The whole project utilizes the MVC design pattern to achieve a clean separation among three components(Model-View-Controller). However, the above calculations violate the MVC design pattern and ruin the program's structure. Meanwhile, it will increase the workload of the views and decrease performance of the website.&lt;br /&gt;
&lt;br /&gt;
In order to implement the MVC design pattern much better and improve the performance of the website, we move these calculations to the model to avoid these problems. In current system, the participant's total score is obtained by calling the '''participant.scores''' method in gradesController, so we move these calculations into scores method which is declared in the model of '''assignment_participant.rb'''. &lt;br /&gt;
&lt;br /&gt;
By testing, our solution solves the above problem effectively. Meanwhile, we adopt single responsibility principle and DRY principle to simplify our code.&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
&lt;br /&gt;
In the '''grade/_participant.html.erb''' file, there are plenty of local variables such as min, max and avg. When we need to return the grades of a student for different type of reviews, we need to create different variables. This not only ruins the readability of the code, but also tends to cause problem for future maintenance and development. Since min, max and avg are the mostly used variables, we created a new data structure '''Rscore''' in this file, which encapsulated all these three variables. Whenever we need the value of min, max and avg, we can get those information directly from '''Rscore'''.&lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code look cleaner.&lt;br /&gt;
&lt;br /&gt;
Furthermore, '''pscore''' is a complicated data structure. It consists of huge hash tables, with each hash table contains another hash table as its value. This situation makes polymorphism pretty hard to implement,if we are not allowed to modify the data structure of the score, which is the  basic structure of the system.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1ncwlrTEZ1taP6ZvMc_GqP4jcAchE03zXSnZwvzgfeDw/edit?usp=sharing ''Requirement for E147'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
[http://youtu.be/RPfzaGtJtQc ''Youtube Demo'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92540</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92540"/>
		<updated>2014-12-05T17:04:19Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Files Involved */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case to underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
&lt;br /&gt;
'''Refactor Getter and Setter Accessor''':&lt;br /&gt;
'''Model''':&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
'''Controller''':&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''View''':&lt;br /&gt;
&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using encapsulation to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to encapsulate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*After confirmation with Professor and TAs, we no longer need to check the existence of the topic.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
&lt;br /&gt;
We find that there are some calculations in the views('''_participant.html.erb'''). The main function of these calculations in the _participant.html.erb is to curve the teams' total score. It gets the value of total_score from the instance variable('''@pscore''') and computes them in the views.&lt;br /&gt;
&lt;br /&gt;
The whole project utilizes the MVC design pattern to achieve a clean separation among three components(Model-View-Controller). However, the above calculations violate the MVC design pattern and ruin the program's structure. Meanwhile, it will increase the workload of the views and decrease performance of the website.&lt;br /&gt;
&lt;br /&gt;
In order to implement the MVC design pattern much better and improve the performance of the website, we move these calculations to the model to avoid these problems. In current system, the participant's total score is obtained by calling the '''participant.scores''' method in gradesController, so we move these calculations into scores method which is declared in the model of '''assignment_participant.rb'''. &lt;br /&gt;
&lt;br /&gt;
By testing, our solution solves the above problem effectively. Meanwhile, we adopt single responsibility principle and DRY principle to simplify our code.&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
&lt;br /&gt;
In the '''grade/_participant.html.erb''' file, there are plenty of local variables such as min, max and avg. When we need to return the grades of a student for different type of reviews, we need to create different variables. This not only ruins the readability of the code, but also tends to cause problem for future maintenance and development. Since min, max and avg are the mostly used variables, we created a new data structure '''Rscore''' in this file, which encapsulated all these three variables. Whenever we need the value of min, max and avg, we can get those information directly from '''Rscore'''.&lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code look cleaner.&lt;br /&gt;
&lt;br /&gt;
Furthermore, '''pscore''' is a complicated data structure. It consists of huge hash tables, with each hash table contains another hash table as its value. This situation makes polymorphism pretty hard to implement,if we are not allowed to modify the data structure of the score, which is the  basic structure of the system.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1ncwlrTEZ1taP6ZvMc_GqP4jcAchE03zXSnZwvzgfeDw/edit?usp=sharing ''Requirement for E147'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
[http://youtu.be/RPfzaGtJtQc ''Youtube Demo'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92539</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92539"/>
		<updated>2014-12-05T17:03:44Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Files Involved */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case to underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
&lt;br /&gt;
'''Refactor Getter and Setter Accessor'''&lt;br /&gt;
'''Model''':&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
'''Controller''':&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''View''':&lt;br /&gt;
&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using encapsulation to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to encapsulate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*After confirmation with Professor and TAs, we no longer need to check the existence of the topic.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
&lt;br /&gt;
We find that there are some calculations in the views('''_participant.html.erb'''). The main function of these calculations in the _participant.html.erb is to curve the teams' total score. It gets the value of total_score from the instance variable('''@pscore''') and computes them in the views.&lt;br /&gt;
&lt;br /&gt;
The whole project utilizes the MVC design pattern to achieve a clean separation among three components(Model-View-Controller). However, the above calculations violate the MVC design pattern and ruin the program's structure. Meanwhile, it will increase the workload of the views and decrease performance of the website.&lt;br /&gt;
&lt;br /&gt;
In order to implement the MVC design pattern much better and improve the performance of the website, we move these calculations to the model to avoid these problems. In current system, the participant's total score is obtained by calling the '''participant.scores''' method in gradesController, so we move these calculations into scores method which is declared in the model of '''assignment_participant.rb'''. &lt;br /&gt;
&lt;br /&gt;
By testing, our solution solves the above problem effectively. Meanwhile, we adopt single responsibility principle and DRY principle to simplify our code.&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
&lt;br /&gt;
In the '''grade/_participant.html.erb''' file, there are plenty of local variables such as min, max and avg. When we need to return the grades of a student for different type of reviews, we need to create different variables. This not only ruins the readability of the code, but also tends to cause problem for future maintenance and development. Since min, max and avg are the mostly used variables, we created a new data structure '''Rscore''' in this file, which encapsulated all these three variables. Whenever we need the value of min, max and avg, we can get those information directly from '''Rscore'''.&lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code look cleaner.&lt;br /&gt;
&lt;br /&gt;
Furthermore, '''pscore''' is a complicated data structure. It consists of huge hash tables, with each hash table contains another hash table as its value. This situation makes polymorphism pretty hard to implement,if we are not allowed to modify the data structure of the score, which is the  basic structure of the system.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[https://docs.google.com/document/d/1ncwlrTEZ1taP6ZvMc_GqP4jcAchE03zXSnZwvzgfeDw/edit?usp=sharing ''Requirement for E147'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
[http://youtu.be/RPfzaGtJtQc ''Youtube Demo'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92359</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92359"/>
		<updated>2014-12-03T02:52:43Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* The function of the calculation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
'''Model''':&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
'''Controller''':&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''View''':&lt;br /&gt;
&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using inheritance to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to delegate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
====Why move calculation from view to model====&lt;br /&gt;
First, MVC-Model-View-Controller - is a design pattern for the architecture of web applications. It is a widely adopted pattern, across many languages and implementation frameworks, whose purpose is to achieve a clean separation between three components of most any web application. &lt;br /&gt;
&lt;br /&gt;
Second, more calculation in the view will decrease the speed and performance of the website.&lt;br /&gt;
&lt;br /&gt;
====The function of the calculation====&lt;br /&gt;
In the file of _participant.html.erb show all team's score. Before that, the view gets the total score from @pscore, and curves the total score in the view. &lt;br /&gt;
The calculation is in the /views/grades/_participant.html.erb. The main function is to curve the total score. We move these calculation into the method of  /model/assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
why use mvc&lt;br /&gt;
calculation's function &lt;br /&gt;
why put them in the model&lt;br /&gt;
&lt;br /&gt;
===OOP===&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
&lt;br /&gt;
In the original code, there are plenty of local variables such as min, max and avg. This not only ruins the readability of the code, but also tends to cause problem for future development. Since min, max and avg are the mostly used variables, we created a new data structure Rscore, which encapsulate all these three variables. Whenever we need the value of min, max and avg, we can get those from Rscore.&lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code looks cleaner.&lt;br /&gt;
&lt;br /&gt;
What is more, pscore is a complicated data structure. It is a huge hash table, which contains at least two more level of hash tables in it. This situation makes polymorphism pretty hard to implement, since we can't do it without changing some basic structure of the design.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92358</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92358"/>
		<updated>2014-12-03T02:46:46Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* The function of the calculation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
'''Model''':&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
'''Controller''':&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''View''':&lt;br /&gt;
&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using inheritance to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to delegate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
====Why move calculation from view to model====&lt;br /&gt;
First, MVC-Model-View-Controller - is a design pattern for the architecture of web applications. It is a widely adopted pattern, across many languages and implementation frameworks, whose purpose is to achieve a clean separation between three components of most any web application. &lt;br /&gt;
&lt;br /&gt;
Second, more calculation in the view will decrease the speed and performance of the website.&lt;br /&gt;
&lt;br /&gt;
====The function of the calculation====&lt;br /&gt;
The view of _participant.html.erb show all team's score. Before that, the view gets the total score from @pscore, and curves the total score in the view. &lt;br /&gt;
The calculation is in the /views/grades/_participant.html.erb. The main function is to curve the total score. We move these calculation into the method of  /model/assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
why use mvc&lt;br /&gt;
calculation's function &lt;br /&gt;
why put them in the model&lt;br /&gt;
&lt;br /&gt;
===OOP===&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
&lt;br /&gt;
In the original code, there are plenty of local variables such as min, max and avg. This not only ruins the readability of the code, but also tends to cause problem for future development. Since min, max and avg are the mostly used variables, we created a new data structure Rscore, which encapsulate all these three variables. Whenever we need the value of min, max and avg, we can get those from Rscore.&lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code looks cleaner.&lt;br /&gt;
&lt;br /&gt;
What is more, pscore is a complicated data structure. It is a huge hash table, which contains at least two more level of hash tables in it. This situation makes polymorphism pretty hard to implement, since we can't do it without changing some basic structure of the design.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92357</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92357"/>
		<updated>2014-12-03T02:37:09Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Why move calculation from view to model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
'''Model''':&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
'''Controller''':&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''View''':&lt;br /&gt;
&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using inheritance to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to delegate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
====Why move calculation from view to model====&lt;br /&gt;
First, MVC-Model-View-Controller - is a design pattern for the architecture of web applications. It is a widely adopted pattern, across many languages and implementation frameworks, whose purpose is to achieve a clean separation between three components of most any web application. &lt;br /&gt;
&lt;br /&gt;
Second, more calculation in the view will decrease the speed and performance of the website.&lt;br /&gt;
&lt;br /&gt;
====The function of the calculation====&lt;br /&gt;
The calculation is in the /views/grades/_participant.html.erb. The main function is to curve the total score. We move these calculation into the method of  /model/assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
why use mvc&lt;br /&gt;
calculation's function &lt;br /&gt;
why put them in the model&lt;br /&gt;
&lt;br /&gt;
===OOP===&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
&lt;br /&gt;
In the original code, there are plenty of local variables such as min, max and avg. This not only ruins the readability of the code, but also tends to cause problem for future development. Since min, max and avg are the mostly used variables, we created a new data structure Rscore, which encapsulate all these three variables. Whenever we need the value of min, max and avg, we can get those from Rscore.&lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code looks cleaner.&lt;br /&gt;
&lt;br /&gt;
What is more, pscore is a complicated data structure. It is a huge hash table, which contains at least two more level of hash tables in it. This situation makes polymorphism pretty hard to implement, since we can't do it without changing some basic structure of the design.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92356</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92356"/>
		<updated>2014-12-03T02:31:38Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* The function of the calculation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
'''Model''':&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
'''Controller''':&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''View''':&lt;br /&gt;
&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using inheritance to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to delegate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
====Why move calculation from view to model====&lt;br /&gt;
First, MVC-Model-View-Controller - is a design pattern for the architecture of web applications. It is a widely adopted pattern, across many languages and implementation frameworks, whose purpose is to achieve a clean separation between three components of most any web application. &lt;br /&gt;
&lt;br /&gt;
Second, more calculation in the view will decrease the speed and performance of client terminal.&lt;br /&gt;
&lt;br /&gt;
====The function of the calculation====&lt;br /&gt;
The calculation is in the /views/grades/_participant.html.erb. The main function is to curve the total score. We move these calculation into the method of  /model/assignment_participant.rb. &lt;br /&gt;
&lt;br /&gt;
why use mvc&lt;br /&gt;
calculation's function &lt;br /&gt;
why put them in the model&lt;br /&gt;
&lt;br /&gt;
===OOP===&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
&lt;br /&gt;
In the original code, there are plenty of local variables such as min, max and avg. This not only ruins the readability of the code, but also tends to cause problem for future development. Since min, max and avg are the mostly used variables, we created a new data structure Rscore, which encapsulate all these three variables. Whenever we need the value of min, max and avg, we can get those from Rscore.&lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code looks cleaner.&lt;br /&gt;
&lt;br /&gt;
What is more, pscore is a complicated data structure. It is a huge hash table, which contains at least two more level of hash tables in it. This situation makes polymorphism pretty hard to implement, since we can't do it without changing some basic structure of the design.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92354</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92354"/>
		<updated>2014-12-03T02:24:06Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* The function of the calculation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
'''Model''':&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
'''Controller''':&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''View''':&lt;br /&gt;
&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using inheritance to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to delegate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
====Why move calculation from view to model====&lt;br /&gt;
First, MVC-Model-View-Controller - is a design pattern for the architecture of web applications. It is a widely adopted pattern, across many languages and implementation frameworks, whose purpose is to achieve a clean separation between three components of most any web application. &lt;br /&gt;
&lt;br /&gt;
Second, more calculation in the view will decrease the speed and performance of client terminal.&lt;br /&gt;
&lt;br /&gt;
====The function of the calculation====&lt;br /&gt;
The calculation is in the /views/grades/_participant.html.erb. The main function is to curve the total score. &lt;br /&gt;
&lt;br /&gt;
why use mvc&lt;br /&gt;
calculation's function &lt;br /&gt;
why put them in the model&lt;br /&gt;
&lt;br /&gt;
===OOP===&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
&lt;br /&gt;
In the original code, there are plenty of local variables such as min, max and avg. This not only ruins the readability of the code, but also tends to cause problem for future development. Since min, max and avg are the mostly used variables, we created a new data structure Rscore, which put all these three variables together. &lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code looks cleaner.&lt;br /&gt;
What is more, pscore is a complicated data structure, it is a huge hash table, which contains at least two more hash tables in it.&lt;br /&gt;
This situation makes polymorphism not only hard to implement, but also&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92351</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92351"/>
		<updated>2014-12-03T02:16:43Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Why move calculation from view to model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
'''Model''':&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
'''Controller''':&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''View''':&lt;br /&gt;
&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using inheritance to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to delegate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
====Why move calculation from view to model====&lt;br /&gt;
First, MVC-Model-View-Controller - is a design pattern for the architecture of web applications. It is a widely adopted pattern, across many languages and implementation frameworks, whose purpose is to achieve a clean separation between three components of most any web application. &lt;br /&gt;
&lt;br /&gt;
Second, more calculation in the view will decrease the speed and performance of client terminal.&lt;br /&gt;
&lt;br /&gt;
====The function of the calculation====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
why use mvc&lt;br /&gt;
calculation's function &lt;br /&gt;
why put them in the model&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
Set up a new data structure, Rscore, and use this data structure to delegate score in all the views.&lt;br /&gt;
&lt;br /&gt;
In the original code, there are plenty of local variables such as min, max and avg. This not only ruins the readability of the code, but also tends to cause problem for future development. Since min, max and avg are the mostly used variables, we created a new data structure Rscore, which put all these three variables together. &lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code looks cleaner.&lt;br /&gt;
What is more, pscore is a complicated data structure, it is a huge hash table, which contains at least two more hash tables in it.&lt;br /&gt;
This situation makes polymorphism not only hard to implement, but also&lt;br /&gt;
&lt;br /&gt;
===OOP===&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92348</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92348"/>
		<updated>2014-12-03T02:06:20Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Why move calculation from view to model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.189:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
'''Model''':&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
'''Controller''':&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''View''':&lt;br /&gt;
&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using inheritance to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to delegate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
====Why move calculation from view to model====&lt;br /&gt;
First, MVC-Model-View-Controller - is a design pattern for the architecture of web applications. It is a widely adopted pattern, across many languages and implementation frameworks, whose purpose is to achieve a clean separation between three components of most any web application. &lt;br /&gt;
Second, more calculation in the view will decrease the speed and performance of client terminal.&lt;br /&gt;
====The function of the calculation====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
why use mvc&lt;br /&gt;
calculation's function &lt;br /&gt;
why put them in the model&lt;br /&gt;
&lt;br /&gt;
===OOP===&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
Set up a new data structure, Rscore, and use this data structure to delegate score in all the views.&lt;br /&gt;
&lt;br /&gt;
In the original code, there are plenty of local variables such as min, max and avg. This not only ruins the readability of the code, but also tends to cause problem for future development. Since min, max and avg are the mostly used variables, we created a new data structure Rscore, which put all these three variables together. &lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code looks cleaner.&lt;br /&gt;
What is more, pscore is a complicated data structure, it is a huge hash table, which contains at least two more hash tables in it.&lt;br /&gt;
This situation makes polymorphism not only hard to implement, but also&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92346</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92346"/>
		<updated>2014-12-03T02:04:06Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Log in to MySql */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
==Set Up Environment==&lt;br /&gt;
&lt;br /&gt;
===User Guide===&lt;br /&gt;
Current System (After Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.46.18.10:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
Original System (Before Refactoring Grades_controller):&lt;br /&gt;
&lt;br /&gt;
http://152.1.13.97:3000/&lt;br /&gt;
&lt;br /&gt;
 Instructor: user6 Password: test&lt;br /&gt;
&lt;br /&gt;
Student: user1600 and user1601 Password: test&lt;br /&gt;
&lt;br /&gt;
All our test result based on the following test cases on expertiza, please follow these step to get it.&lt;br /&gt;
&lt;br /&gt;
Instructor: (Searching &amp;quot;Program 2&amp;quot; using &amp;quot;Ctrl + F&amp;quot; will be convinient for you.)&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;view scores.&lt;br /&gt;
&lt;br /&gt;
Student:&lt;br /&gt;
&lt;br /&gt;
 Steps: Login -&amp;gt; Assignments-&amp;gt;Program 2 style -&amp;gt;Your scores.&lt;br /&gt;
&lt;br /&gt;
===Set Up Environment Locally===&lt;br /&gt;
====Get Expertiza from Github====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;git clone https://github.com/maxlpy/expertiza.git&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Use rvm to install ruby-2.1.0====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;curl -L https://get.rvm.io | bash -s stable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;source ~/.rvm/scripts/rvm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;echo &amp;quot;source ~/.rvm/scripts/rvm&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm install 2.1.0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rvm use 2.1.0 --default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ruby -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Install Bundled Gems====&lt;br /&gt;
Set JAVA_HOME for the rjb gem:&lt;br /&gt;
Your path may be different. You can generally find out the path by looking at the symbolic link at /etc/alternatives/java&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;ls -la /etc/alternatives/java&amp;lt;/pre&amp;gt;&lt;br /&gt;
This outputs something like '/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java'. Only part of this path may need to be set to JAVA_HOME. In this instance, it is '/usr/lib/jvm/java-6-openjdk-amd64'.&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Set Up the Database====&lt;br /&gt;
=====Enable and Start the MySql Daemon=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld enable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;sudo service mysqld start&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Set the MySql Root Password=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysqladmin -u root password&amp;lt;/pre&amp;gt;&lt;br /&gt;
=====Log in to MySql=====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;mysql -uroot -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Create the Databases====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:create:all&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Build the Expertiza Database====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rake db:migrate&amp;lt;/pre&amp;gt;&lt;br /&gt;
====Start Expertiza service====&lt;br /&gt;
&amp;lt;pre style=&amp;quot;white-space:normal;&amp;quot;&amp;gt;rails server&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
'''Model''':&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
'''Controller''':&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''View''':&lt;br /&gt;
&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using inheritance to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to delegate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
====Why move calculation from view to model====&lt;br /&gt;
First, MVC-Model-View-Controller - is a design pattern for the architecture of web applications. It is a widely adopted pattern, across many languages and implementation frameworks, whose purpose is to achieve a clean separation between three components of most any web application. &lt;br /&gt;
Second, more calculation in the view will decrease the speed and performance of client terminal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
why use mvc&lt;br /&gt;
calculation's function &lt;br /&gt;
why put them in the model&lt;br /&gt;
&lt;br /&gt;
===OOP===&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
Set up a new data structure, Rscore, and use this data structure to delegate score in all the views.&lt;br /&gt;
&lt;br /&gt;
In the original code, there are plenty of local variables such as min, max and avg. This not only ruins the readability of the code, but also tends to cause problem for future development. Since min, max and avg are the mostly used variables, we created a new data structure Rscore, which put all these three variables together. &lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code looks cleaner.&lt;br /&gt;
What is more, pscore is a complicated data structure, it is a huge hash table, which contains at least two more hash tables in it.&lt;br /&gt;
This situation makes polymorphism not only hard to implement, but also&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92344</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92344"/>
		<updated>2014-12-03T02:03:55Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Why move calculation from view to model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
'''Model''':&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
'''Controller''':&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''View''':&lt;br /&gt;
&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using inheritance to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to delegate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, encapsulation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
====Why move calculation from view to model====&lt;br /&gt;
First, MVC-Model-View-Controller - is a design pattern for the architecture of web applications. It is a widely adopted pattern, across many languages and implementation frameworks, whose purpose is to achieve a clean separation between three components of most any web application. &lt;br /&gt;
Second, more calculation in the view will decrease the speed and performance of client terminal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
why use mvc&lt;br /&gt;
calculation's function &lt;br /&gt;
why put them in the model&lt;br /&gt;
&lt;br /&gt;
===OOP===&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Encapsulation===&lt;br /&gt;
Set up a new data structure, Rscore, and use this data structure to delegate score in all the views.&lt;br /&gt;
&lt;br /&gt;
In the original code, there are plenty of local variables such as min, max and avg. This not only ruins the readability of the code, but also tends to cause problem for future development. Since min, max and avg are the mostly used variables, we created a new data structure Rscore, which put all these three variables together. &lt;br /&gt;
&lt;br /&gt;
In the project specification, it suggested that we use polymorphism to reduce the redundant local variables. However, we found that this simple data structure will suffice without bothering to use polymorphism, and it makes the code looks cleaner.&lt;br /&gt;
What is more, pscore is a complicated data structure, it is a huge hash table, which contains at least two more hash tables in it.&lt;br /&gt;
This situation makes polymorphism not only hard to implement, but also&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92341</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92341"/>
		<updated>2014-12-03T02:00:57Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Moving calculation from view to model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
'''Model''':&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
'''Controller''':&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''View''':&lt;br /&gt;
&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using inheritance to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to delegate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, delegation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
====Why move calculation from view to model====&lt;br /&gt;
First, MVC-Model-View-Controller - is a design pattern for the architecture of web applications. It is a widely adopted pattern, across many languages and implementation frameworks, whose purpose is to achieve a clean separation between three components of most any web application. &lt;br /&gt;
Second, &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
why use mvc&lt;br /&gt;
calculation's function &lt;br /&gt;
why put them in the model&lt;br /&gt;
&lt;br /&gt;
===OOP===&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Delegation===&lt;br /&gt;
Set up a new data structure, Rscore, and use this data structure to delegate score in all the views.&lt;br /&gt;
In pscore, &lt;br /&gt;
2. delegation&lt;br /&gt;
3. why not polymorphism. simple data structure can work out.&lt;br /&gt;
4 pscore is a complicated data structure, it is a huge hash table.&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92340</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92340"/>
		<updated>2014-12-03T01:55:30Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Details of Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
'''Model''':&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
'''Controller''':&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''View''':&lt;br /&gt;
&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using inheritance to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to delegate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, delegation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
===Moving calculation from view to model===&lt;br /&gt;
===OOP===&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Delegation===&lt;br /&gt;
Set up a new data structure, Rscore, and use this data structure to delegate score in all the views.&lt;br /&gt;
In pscore, &lt;br /&gt;
2. delegation&lt;br /&gt;
3. why not polymorphism. simple data structure can work out.&lt;br /&gt;
4 pscore is a complicated data structure, it is a huge hash table.&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92339</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92339"/>
		<updated>2014-12-03T01:53:49Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* What we have done */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
'''Model''':&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
'''Controller''':&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''View''':&lt;br /&gt;
&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using inheritance to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to delegate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, delegation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Details of Implementation==&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Delegation===&lt;br /&gt;
Set up a new data structure, Rscore, and use this data structure to delegate score in all the views.&lt;br /&gt;
In pscore, &lt;br /&gt;
2. delegation&lt;br /&gt;
3. why not polymorphism. simple data structure can work out.&lt;br /&gt;
4 pscore is a complicated data structure, it is a huge hash table.&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92334</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=92334"/>
		<updated>2014-12-03T01:04:26Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Files Involved */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
'''E1472: Connect changes to score model with changes to score views'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
===A way to query db models to return scores, without UI changes===&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
===UI changes for reporting scores===&lt;br /&gt;
&lt;br /&gt;
The grades_controller class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn't have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Files Involved===&lt;br /&gt;
'''Model''':&lt;br /&gt;
*models/participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/rscore.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/assignment_team.rb&lt;br /&gt;
&lt;br /&gt;
*models/course.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_participant.rb&lt;br /&gt;
&lt;br /&gt;
*models/course_team.rb&lt;br /&gt;
&lt;br /&gt;
'''Controller''':&lt;br /&gt;
*controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/scores_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignments_controller.rb&lt;br /&gt;
&lt;br /&gt;
*controllers/assignment_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''View''':&lt;br /&gt;
&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_metareview.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_scores_submitted_work.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/_tabbing.html.erb&lt;br /&gt;
&lt;br /&gt;
*grades/edit.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_review.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/_submitted_files.html.erb&lt;br /&gt;
&lt;br /&gt;
*response/view.html.erb&lt;br /&gt;
&lt;br /&gt;
'''Calculations Found in Views''':&lt;br /&gt;
*grades/_participant.html.erb&lt;br /&gt;
*grades/_scores_author_feedback.html.erb&lt;br /&gt;
&lt;br /&gt;
===What we are going to do===&lt;br /&gt;
&lt;br /&gt;
*Modify the setters and getters in the models/participant.rb by refactoring&lt;br /&gt;
&lt;br /&gt;
*Modify the camel-case variables to underscores to match the Ruby convention in views/grades/... , models/participant.rb and controllers/grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
*Modify the data structure of the score, instead of using pScore which contains lots of hash tables in it, we set up a new object, '''Rscore''', which only consists of max, min and average fields of each reviews. Also, using inheritance to implement this data structure to avoid check review type. &lt;br /&gt;
&lt;br /&gt;
*delete checking for topics in views&lt;br /&gt;
&lt;br /&gt;
*Move the calculations in the views to the model so that there won't be many calculations in the views of MVC framework.(Model file:'''assignment_participant.rb''')&lt;br /&gt;
&lt;br /&gt;
===What we have done===&lt;br /&gt;
&lt;br /&gt;
*We modified the camel-case variables in views/grade to Ruby convention by replacing them with under_score format while keeping the camel-case in JavaScript, as in JavaScript the camel-case should be its convention.&lt;br /&gt;
&lt;br /&gt;
*We set up new data structure Rscore to delegate the score and reduce the local variables.&lt;br /&gt;
&lt;br /&gt;
*We analysed the system and found out that polymorphism for Rscore is not necessary, delegation will handle all the usages.&lt;br /&gt;
&lt;br /&gt;
*We moved the calculations in the views into model file,'''assignment_participants.rb''', which follows the single responsibility principle and DRY principle.&lt;br /&gt;
&lt;br /&gt;
*We modified the response_map to expedite the rendering speed of showing scores.&lt;br /&gt;
&lt;br /&gt;
==Design Pattern and System Architecture==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Expertiza003.png‎|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
===MVC design pattern===&lt;br /&gt;
Responsibility of view_my_scores html.erb is to display all the scores with respect to a participant and an assignment. For achieving optimal functionality, a good amount of refactoring had to be done in the views that were responsible for displaying the results to a user.(By removing all the calculations in the views to models)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apart from the template methods that are present in other controller class, the grades_controller specifically has two more important methods: view and view_my_scores.&lt;br /&gt;
&lt;br /&gt;
*'''view method''': handle the functionality of viewing the assignments of the whole class. Understandably, this is done through an admin/instructor's profile as only they have the privilege of viewing all participants' scores.&lt;br /&gt;
&lt;br /&gt;
*'''view_my_scores''': take care of displaying the scores pertaining to an assignment to a single user.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scores.rb has two methods which are responsible to compute scores for the participants based on assignments and courses.&lt;br /&gt;
&lt;br /&gt;
*'''get_total_scores()''' method: make multiple sequential queries to the database to calculate scores. &lt;br /&gt;
&lt;br /&gt;
*Model class PartcipantScores.rb and AssignmentScores.rb have been created to retrieve the scores for participant and assignment respectively.&lt;br /&gt;
&lt;br /&gt;
===DRY Principle===&lt;br /&gt;
This ensures that information is not repeated in the application. We use DRY Principle to design our object and modify all other work.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
===Delegation===&lt;br /&gt;
Set up a new data structure, Rscore, and use this data structure to delegate score in all the views.&lt;br /&gt;
&lt;br /&gt;
===Single Responsibility Principle===&lt;br /&gt;
This ensures that every controller and model method will be responsible in performing exactly one functionality.(By setting up Rscore data structure)&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
&lt;br /&gt;
[[File:Use_case_2.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 100%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
|-&lt;br /&gt;
| Admin&lt;br /&gt;
| This actor has the same responsibility as Instructor along with the ability to create instructor(however, this is not our concern here).&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following table is showing the use case of different users of the expertiza and how they interact with it. For example, when a student want to view his/her grades, there must be something in the database (precondition). He will need to login, and choose one of the assignments which he want to view grade on. He can also see the review of his work.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name !! Actor !! Other Participants || Precondition || Primary Sequence&lt;br /&gt;
|-&lt;br /&gt;
| Student views his team score || Student || None || At least team's score exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| TA views teams' review || TA || None||At least team's review exists. || &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
|-&lt;br /&gt;
| Instructor/ Teaching Assistant/ Admin views the list of teams scores || Instructor/ Teaching Assistant/ Admin || None || At least one team's score exists.|| &lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:Objected Oriented Design.png|frame|center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
===Create object to avoid local variables===&lt;br /&gt;
Create rscore class in models (rscore.rb):  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Rscore&lt;br /&gt;
  attr_accessor :my_max,:my_min,:my_avg,:my_type&lt;br /&gt;
&lt;br /&gt;
  def initialize(my_score,type)&lt;br /&gt;
    @my_max=my_score[type][:scores][:max]&lt;br /&gt;
    @my_min=my_score[type][:scores][:min]&lt;br /&gt;
    @my_avg=my_score[type][:scores][:avg]&lt;br /&gt;
    @my_type=type&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Use instance variables in views===&lt;br /&gt;
In grades/_participant.html.erb, we create an object that has max, min, and avg fields for each kind of reviews, and pass the kind of review when referring to a max, min, or avg field.&lt;br /&gt;
&lt;br /&gt;
'''Before:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
  	s_max = pscore[:review][:scores][:max]&lt;br /&gt;
  	s_min = pscore[:review][:scores][:min] &lt;br /&gt;
  	s_avg = pscore[:review][:scores][:avg] &lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    r_max = pscore[:metareview][:scores][:max]&lt;br /&gt;
  	r_min = pscore[:metareview][:scores][:min] &lt;br /&gt;
  	r_avg = pscore[:metareview][:scores][:avg]&lt;br /&gt;
  end &lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
  	f_max = pscore[:feedback][:scores][:max]&lt;br /&gt;
  	f_min = pscore[:feedback][:scores][:min] &lt;br /&gt;
  	f_avg = pscore[:feedback][:scores][:avg]&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
  	tr_max = pscore[:teammate][:scores][:max]&lt;br /&gt;
  	tr_min = pscore[:teammate][:scores][:min] &lt;br /&gt;
  	tr_avg = pscore[:teammate][:scores][:avg]   &lt;br /&gt;
  end &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After:'''(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if pscore[:review]&lt;br /&gt;
    @rscore_review=Rscore.new(pscore,:review)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:metareview]&lt;br /&gt;
    @rscore_metareview=Rscore.new(pscore,:metareview)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:feedback]&lt;br /&gt;
    @rscore_feedback=Rscore.new(pscore,:feedback)&lt;br /&gt;
  end&lt;br /&gt;
  if pscore[:teammate]&lt;br /&gt;
    @rscore_teammate=Rscore.new(pscore,:teammate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Moving Calculation from view to model==&lt;br /&gt;
We move lots of calculations from views to model.&lt;br /&gt;
&lt;br /&gt;
'''Before''':(views/grades/_participant.html.erb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% if controller.action_name == 'view' or controller.action_name == &amp;quot;view_my_scores&amp;quot; %&amp;gt;&lt;br /&gt;
    	&amp;lt;TD ALIGN=&amp;quot;CENTER&amp;quot;&amp;gt;&lt;br /&gt;
    	&amp;lt;% if stage == &amp;quot;Finished&amp;quot; %&amp;gt;&lt;br /&gt;
        &amp;lt;% if participant.grade&lt;br /&gt;
          total_score = participant.grade&lt;br /&gt;
          title = &amp;quot;A score in blue indicates that the value was overwritten by the instructor or teaching assistant.&amp;quot;&lt;br /&gt;
        else&lt;br /&gt;
          total_score = pscore[:total_score] &lt;br /&gt;
          title = nil&lt;br /&gt;
        end %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
            &amp;lt;% hardline = 85&lt;br /&gt;
               if tr_avg &amp;gt; hardline&lt;br /&gt;
                 total_score = total_score + 0.05*total_score&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 40&lt;br /&gt;
                 total_score = total_score - 10&lt;br /&gt;
               elsif tr_avg &amp;lt; hardline and (hardline -tr_avg) &amp;gt; 20&lt;br /&gt;
                 total_score = total_score - (hardline -tr_avg)*0.5&lt;br /&gt;
            %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
              &amp;lt;% if total_score&amp;gt;100&lt;br /&gt;
              total_score = 100&lt;br /&gt;
              %&amp;gt;&lt;br /&gt;
            &amp;lt;%end%&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;% if title %&amp;gt;title=&amp;quot;&amp;lt;%=title%&amp;gt;&amp;quot; style=&amp;quot;color:#0033FF&amp;quot;&amp;lt;% end %&amp;gt;&amp;gt;&amp;lt;%= sprintf(&amp;quot;%.2f&amp;quot;,total_score) %&amp;gt;&amp;lt;%= score_postfix %&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After''':(model/assignment_participant.rb)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    # move lots of calculation from view(_participant.html.erb) to model&lt;br /&gt;
    if self.grade&lt;br /&gt;
      scores[:total_score] = self.grade&lt;br /&gt;
    end&lt;br /&gt;
    else&lt;br /&gt;
      total_score = scores[:total_score]&lt;br /&gt;
      hardline = 85&lt;br /&gt;
      if scores[:teammate][:scores][:avg].to_f &amp;gt; hardline&lt;br /&gt;
        total_score = total_score + 0.05*total_score&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 40&lt;br /&gt;
        total_score = total_score - 10&lt;br /&gt;
      elsif scores[:teammate][:scores][:avg].to_f &amp;lt; hardline and (hardline - scores[:teammate][:scores][:avg].to_f) &amp;gt; 20&lt;br /&gt;
        total_score = total_score - (hardline - scores[:teammate][:scores][:avg].to_f)*0.5&lt;br /&gt;
      end&lt;br /&gt;
      if total_score &amp;gt; 100&lt;br /&gt;
        total_score = 100&lt;br /&gt;
      end&lt;br /&gt;
      scores[:total_score] = total_score&lt;br /&gt;
    scores&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Speeding up view score's function==&lt;br /&gt;
At the beginning of the final project, the function of viewing scores is very slow by students and instructor. Our team found the real factor which lead to the slow problem and solved it in an easy approach. &lt;br /&gt;
===Optimize response searching method in the model===&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Test Result===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Snapshots==&lt;br /&gt;
===Instructor Login===&lt;br /&gt;
[[File:Screens1.png|frame|center|]]&lt;br /&gt;
===Select Assignment===&lt;br /&gt;
[[File:Screens3.png|frame|center|]]&lt;br /&gt;
===View Scores===&lt;br /&gt;
[[File:Screens4.png|frame|center|]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
&lt;br /&gt;
We will stick to the UI design of the grades view and see what else we can do to further improve the performance of the system. We are trying to figure out other reasons that may lead to the bad performance in addition to the two main reasons mentioned and solved in E804 and E805 projects.&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=91642</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=91642"/>
		<updated>2014-11-11T00:15:02Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Objected Oriented Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
E1472: Connect changes to score model with changes to score views&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
'''A way to query db models to return scores, without UI changes'''&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
'''UI changes for reporting scores'''&lt;br /&gt;
&lt;br /&gt;
The GradesController class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn’t have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
[[File:usecase_score.png|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Student views his team score&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Student&lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None&lt;br /&gt;
&lt;br /&gt;
'''Precondition:''' At least team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:'''&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Student views his team's review by other students&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Student&lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None&lt;br /&gt;
&lt;br /&gt;
'''Precondition:''' At least team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:'''&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Instructor or Teaching Assistant views the list of teams scores&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Instructor or Teaching Assistant&lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None&lt;br /&gt;
&lt;br /&gt;
'''Precondition''': At least one team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence''':&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:uml.png |center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score is declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=91641</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=91641"/>
		<updated>2014-11-11T00:14:01Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Objected Oriented Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
E1472: Connect changes to score model with changes to score views&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
'''A way to query db models to return scores, without UI changes'''&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
'''UI changes for reporting scores'''&lt;br /&gt;
&lt;br /&gt;
The GradesController class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn’t have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
[[File:usecase_score.png|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Student views his team score&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Student&lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None&lt;br /&gt;
&lt;br /&gt;
'''Precondition:''' At least team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:'''&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Student views his team's review by other students&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Student&lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None&lt;br /&gt;
&lt;br /&gt;
'''Precondition:''' At least team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:'''&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Instructor or Teaching Assistant views the list of teams scores&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Instructor or Teaching Assistant&lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None&lt;br /&gt;
&lt;br /&gt;
'''Precondition''': At least one team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence''':&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:uml.png |center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score are declared as subclass of RScore using ploymorphism. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=91638</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=91638"/>
		<updated>2014-11-11T00:12:13Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Objected Oriented Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
E1472: Connect changes to score model with changes to score views&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
'''A way to query db models to return scores, without UI changes'''&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
'''UI changes for reporting scores'''&lt;br /&gt;
&lt;br /&gt;
The GradesController class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn’t have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
[[File:usecase_score.png|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Student views his team score&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Student&lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None&lt;br /&gt;
&lt;br /&gt;
'''Precondition:''' At least team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:'''&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Student views his team's review by other students&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Student&lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None&lt;br /&gt;
&lt;br /&gt;
'''Precondition:''' At least team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:'''&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Instructor or Teaching Assistant views the list of teams scores&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Instructor or Teaching Assistant&lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None&lt;br /&gt;
&lt;br /&gt;
'''Precondition''': At least one team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence''':&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:uml.png |center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score are declared as subclass of RScore. The type field is specified in their initialize method.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Uml.png&amp;diff=91633</id>
		<title>File:Uml.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Uml.png&amp;diff=91633"/>
		<updated>2014-11-11T00:10:40Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: uploaded a new version of &amp;amp;quot;File:Uml.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=91632</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=91632"/>
		<updated>2014-11-11T00:10:23Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Objected Oriented Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
E1472: Connect changes to score model with changes to score views&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
'''A way to query db models to return scores, without UI changes'''&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
'''UI changes for reporting scores'''&lt;br /&gt;
&lt;br /&gt;
The GradesController class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn’t have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
[[File:usecase_score.png|center|]]&lt;br /&gt;
&lt;br /&gt;
The figure above mainly illustrates the process of viewing scores for different actors. The instructor and teaching assistant are able to view scores of all the team and could see the reviews of a selected team. Student actor can see his own scores and reviews.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Student views his team score&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Student&lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None&lt;br /&gt;
&lt;br /&gt;
'''Precondition:''' At least team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:'''&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Student views his team's review by other students&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Student&lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None&lt;br /&gt;
&lt;br /&gt;
'''Precondition:''' At least team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:'''&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
*Select show_review in score page&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Instructor or Teaching Assistant views the list of teams scores&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Instructor or Teaching Assistant&lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None&lt;br /&gt;
&lt;br /&gt;
'''Precondition''': At least one team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence''':&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution. &lt;br /&gt;
[[File:uml.png |center|]]&lt;br /&gt;
The RScore class stores the variables maximum,minimum, average review scores. Different type of reviews score are declared as subclass of RScore&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Uml.png&amp;diff=91627</id>
		<title>File:Uml.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Uml.png&amp;diff=91627"/>
		<updated>2014-11-10T23:02:42Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: uploaded a new version of &amp;amp;quot;File:Uml.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Uml.png&amp;diff=91625</id>
		<title>File:Uml.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Uml.png&amp;diff=91625"/>
		<updated>2014-11-10T23:00:12Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: uploaded a new version of &amp;amp;quot;File:Uml.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Uml.png&amp;diff=91624</id>
		<title>File:Uml.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Uml.png&amp;diff=91624"/>
		<updated>2014-11-10T22:59:24Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: uploaded a new version of &amp;amp;quot;File:Uml.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=91623</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=91623"/>
		<updated>2014-11-10T22:59:01Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Objected Oriented Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
E1472: Connect changes to score model with changes to score views&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
'''A way to query db models to return scores, without UI changes'''&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
'''UI changes for reporting scores'''&lt;br /&gt;
&lt;br /&gt;
The GradesController class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn’t have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
[[File:usecase_score.png|center|]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Student views his team score&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Student&lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None&lt;br /&gt;
&lt;br /&gt;
'''Precondition:''' At least team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:'''&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Instructor or Teaching Assistant viewing the list of teams scores&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Instructor or Teaching Assistant&lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None&lt;br /&gt;
&lt;br /&gt;
'''Precondition''': At least one team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence''':&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution&lt;br /&gt;
[[File:uml.png]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=91622</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=91622"/>
		<updated>2014-11-10T22:58:46Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Objected Oriented Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
E1472: Connect changes to score model with changes to score views&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
'''A way to query db models to return scores, without UI changes'''&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
'''UI changes for reporting scores'''&lt;br /&gt;
&lt;br /&gt;
The GradesController class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn’t have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
[[File:usecase_score.png|center|]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Student views his team score&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Student&lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None&lt;br /&gt;
&lt;br /&gt;
'''Precondition:''' At least team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:'''&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Instructor or Teaching Assistant viewing the list of teams scores&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Instructor or Teaching Assistant&lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None&lt;br /&gt;
&lt;br /&gt;
'''Precondition''': At least one team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence''':&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''Wiki page for E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''Wiki page for E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''Github link for E912'']&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=91620</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=91620"/>
		<updated>2014-11-10T22:55:17Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Objected Oriented Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
E1472: Connect changes to score model with changes to score views&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
'''A way to query db models to return scores, without UI changes'''&lt;br /&gt;
&lt;br /&gt;
These methods report grades to students and instructors.  The view method reports everyone’s grades to an instructor, and the view_my_scores method reports peer-review scores to a student. This code is very slow, due to many factors.  Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed. &lt;br /&gt;
&lt;br /&gt;
'''UI changes for reporting scores'''&lt;br /&gt;
&lt;br /&gt;
The GradesController class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn’t have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
[[File:usecase_score.png|center|]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Student views his team score&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Student&lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None&lt;br /&gt;
&lt;br /&gt;
'''Precondition:''' At least team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:'''&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Instructor or Teaching Assistant viewing the list of teams scores&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Instructor or Teaching Assistant&lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None&lt;br /&gt;
&lt;br /&gt;
'''Precondition''': At least one team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence''':&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution&lt;br /&gt;
[[File:uml.png]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''E912'']&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Uml.png&amp;diff=91618</id>
		<title>File:Uml.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Uml.png&amp;diff=91618"/>
		<updated>2014-11-10T22:54:28Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: uploaded a new version of &amp;amp;quot;File:Uml.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Uml.png&amp;diff=91615</id>
		<title>File:Uml.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Uml.png&amp;diff=91615"/>
		<updated>2014-11-10T22:53:51Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: uploaded a new version of &amp;amp;quot;File:Uml.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=91614</id>
		<title>CSC/ECE 517 Fall 2014/final E1472 gjfz</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1472_gjfz&amp;diff=91614"/>
		<updated>2014-11-10T22:52:39Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Objected Oriented Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Design Document==&lt;br /&gt;
E1472: Connect changes to score model with changes to score views&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities. One of the Expertiza features is to report scores to both students and the instructor. The student can see the feedback from other students, such as the max score, the min score and the average score.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
The GradesController class is responsible for displaying grades to students (via view_my_scores) and instructors or Teaching Assistant (via the view method).&lt;br /&gt;
We will modify the Score class, and reduce the number of variables in order to remove code duplication and improve the loading speed.&lt;br /&gt;
===What we need to do===&lt;br /&gt;
*Remove the get_ and set_ accessor names; just use Ruby accessors.&lt;br /&gt;
*Change camel-case vs. underscores to match the Ruby convention.&lt;br /&gt;
*In grades/_participant.html.erb, don’t create local variables in the view; rather, create an object that has max, min, and avg fields for each kind of reviews.  Try to avoid the need to check review type; instead, just pass the kind of review when referring to a max, min, or avg field and use polymorphism.&lt;br /&gt;
*Also, you shouldn’t have to check for the existence topic in the view; if it is null, a null string should just be returned.&lt;br /&gt;
*There are lots of calculations in the views, which should be moved to the model.&lt;br /&gt;
&lt;br /&gt;
== Use Case==&lt;br /&gt;
[[File:usecase_score.png|center|]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Actor&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Description&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Instructor&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Teaching Assistant&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of all the students(teams).&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Student&lt;br /&gt;
| This actor is responsible for viewing scores and reviews of his own or of his team. &lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name:''' Student views his team score&lt;br /&gt;
&lt;br /&gt;
'''Actor:''' Student&lt;br /&gt;
&lt;br /&gt;
'''Other Participants:''' None&lt;br /&gt;
&lt;br /&gt;
'''Precondition:''' At least team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence:'''&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select Your Scores button from an Assignment menu&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Name''': Instructor or Teaching Assistant viewing the list of teams scores&lt;br /&gt;
&lt;br /&gt;
'''Actor''': Instructor or Teaching Assistant&lt;br /&gt;
&lt;br /&gt;
'''Other Participants''': None&lt;br /&gt;
&lt;br /&gt;
'''Precondition''': At least one team's score exists.&lt;br /&gt;
&lt;br /&gt;
'''Primary Sequence''':&lt;br /&gt;
*Log in to Expertiza&lt;br /&gt;
*Choose Assignment from multiple Assignments&lt;br /&gt;
*Select View Scores button from an Assignment menu&lt;br /&gt;
&lt;br /&gt;
==Objected Oriented Design==&lt;br /&gt;
&lt;br /&gt;
The following class diagram shows a combination of new and existing classes along with the attributes and operations that are relevant to the implementation of this solution&lt;br /&gt;
[[File:uml.jpg]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E804_spb ''E804'']&lt;br /&gt;
&lt;br /&gt;
[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2013/oss_E805_kkn ''E805'']&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ajain2709/expertiza ''E912'']&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89836</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1466 gjf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89836"/>
		<updated>2014-10-27T03:16:32Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* conflict_notification Method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1466: Refactoring GradesController==&lt;br /&gt;
&lt;br /&gt;
This wiki deals with our implementation of a controller in expertiza: [https://github.com/expertiza/expertiza/blob/rails4/app/controllers/grades_controller.rb grade_controller]  for the Expertiza Project using Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Classes involved:''' grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''What it does:'''&lt;br /&gt;
&lt;br /&gt;
This class lists the grades of all the participants for an assignments and also their reviews. Instructor can edit scores, calculate penalties and send emails for conflicts.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&lt;br /&gt;
*Modify '''calculate_all_penalties''' method which is too complex and long.&lt;br /&gt;
*Put the '''get_body_text''' method in a mailer rather than in the grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactor '''view_my_scores''' method to '''grades_show''' and delete the unnecessary variables.&lt;br /&gt;
*Try not to query for reviews and meta reviews in '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
'''What we have done:'''&lt;br /&gt;
*Modify '''calculate_all_penalties''' method.&lt;br /&gt;
*Refactor the '''conflict_notification''' method to '''conflict_email''' method. &lt;br /&gt;
*Simplify sending email function and make it delegated to the mailer.&lt;br /&gt;
*Send a conflict email to the reviewer automatically when instructor click the button &amp;quot;email reviewer&amp;quot;.&lt;br /&gt;
*Remove '''get_body_text''' and '''send_grading_email''' method from grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactor '''view_my_scores''' method to '''grades_show''' method.&lt;br /&gt;
*Search for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
*Refactor '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
*Eliminat the search for reviews and meta reviews during the '''grades_show''' method.&lt;br /&gt;
*Delete unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
==Code Modification==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== calculate_all_penalties Method===&lt;br /&gt;
====Summary====&lt;br /&gt;
&lt;br /&gt;
We have modified the calculate_penalties method and implemented all the functions it originally has. After our modification the method shrinks from 45 lines to 32 lines of Ruby code. Originally, the method includes a lot of unnecessary if and unless statements which makes the method uneasy to read and seems to have a difficult logic to calculate the penalties. &lt;br /&gt;
&lt;br /&gt;
According to the [https://codeclimate.com codeclimate] which calculate the complexity of the method, originally, it has a complexity of '''85''', however, after we modified it, the complexity goes down to '''65'''. Please check at [https://codeclimate.com/github/expertiza/expertiza/GradesController original version],[https://codeclimate.com/github/maxlpy/expertiza/GradesController modified version]&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Used for loop with selective choice to create penalty attributes and put it into the '''CalculatedPenalty''' Table, instead of duplicating the almost same code.&lt;br /&gt;
&lt;br /&gt;
*Used Object-Oriented Design patterns of Ruby: let the array respond to the method '''min''' which returns the minimum number in the array and get the logical penalty other than using if statement.(max_penalty if total_penalty is larger than max_penalty,  total_penalty if total_penalty is smaller than max_penalty)&lt;br /&gt;
&lt;br /&gt;
*Eliminated the unnecessary if statements to make the code clear to read.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
&lt;br /&gt;
*Modify if statements:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(penalties[:submission].nil?)&lt;br /&gt;
      penalties[:submission]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:review].nil?)&lt;br /&gt;
      penalties[:review]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:meta_review].nil?)&lt;br /&gt;
      penalties[:meta_review]=0&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
penalties[:submission] = 0 if penalties[:submission].nil?&lt;br /&gt;
penalties[:review] = 0 if penalties[:review].nil?&lt;br /&gt;
penalties[:meta_review] = 0 if penalties[:meta_review].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Using Objected-oriented Pattern&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(@total_penalty &amp;gt; l_policy.max_penalty)&lt;br /&gt;
      @total_penalty = l_policy.max_penalty&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @total_penality=[l_policy.max_penalty,@total_penality].min&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Using loops rather than duplicate same code&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 penalty_attr1 = {:deadline_type_id =&amp;gt; 1,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:submission]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr1)&lt;br /&gt;
 penalty_attr2 = {:deadline_type_id =&amp;gt; 2,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr2)&lt;br /&gt;
 penalty_attr3 = {:deadline_type_id =&amp;gt; 5,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:meta_review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr3)&amp;quot;&lt;br /&gt;
 @all_penalties[participant.id] = Hash.new&lt;br /&gt;
       @all_penalties[participant.id][:submission] = penalties[:submission]&lt;br /&gt;
       @all_penalties[participant.id][:review] = penalties[:review]&lt;br /&gt;
       @all_penalties[participant.id][:meta_review] = penalties[:meta_review]&lt;br /&gt;
       @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 deadline_type=[1,2,5]&lt;br /&gt;
 penalty_type=[:submission,:review,:meta_review]&lt;br /&gt;
 if calculate_for_participants&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
           penalty_attr={:deadline_type_id=&amp;gt;deadline_type[i],:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[penalty_type[i]]}&lt;br /&gt;
           CalculatedPenalty.create(penalty_attr)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
 @all_penalties[participant.id] = {}&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
          @all_penalties[participant.id][:penalty_type[i]] = penalties[:penalty_type[i]]&lt;br /&gt;
      end&lt;br /&gt;
 @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== conflict_notification Method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored the '''conflict_notification''' method to '''conflict_email''' method. When instructor click the button &amp;quot;email reviewer&amp;quot; whom he thought give a unfair review, the system should be able to send an email to the reviewer automatically.The '''get_body_text''' and '''send_grading_email''' were removed from the controller. The sending email function is well simplified and delegated to a conflict_mailer.&lt;br /&gt;
&lt;br /&gt;
====Design Pattern====&lt;br /&gt;
Delegation: The conflict_email should be able to send email. The class ConflictMailer works as its delegate .The conflict_email calls the send_conflict_email function to take the job of sending an email.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
The old '''conflict_notification''' action queries an email address list of a certain kind of reviews. In its view conflict_notifiction.html.erb, A email form contains email list for instructor to choose from and email content. &lt;br /&gt;
[[File:old_email.png]]&lt;br /&gt;
&lt;br /&gt;
'''Before Refactorring''', in conflict_notification:&lt;br /&gt;
First,Get the instructor email address as sender&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
      if session[:user].role_id !=6             &lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
      @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
      @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then,Based on submission of review, the action query all the reviewers' email address  &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @questions = Hash.new&lt;br /&gt;
      questionnaires = @assignment.questionnaires&lt;br /&gt;
      questionnaires.each {&lt;br /&gt;
        |questionnaire|&lt;br /&gt;
        @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The email list is for instructor to choose from. The process_response method queries the email address.    &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @reviewers_email_hash = Hash.new            &lt;br /&gt;
      @caction = &amp;quot;view&amp;quot;&lt;br /&gt;
      @submission = params[:submission]&lt;br /&gt;
      if @submission == &amp;quot;review&amp;quot;&lt;br /&gt;
        @caction = &amp;quot;view_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;review&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.reviews, &amp;quot;ReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_of_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;metareview&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Metareview&amp;quot;, &amp;quot;Metareviewer&amp;quot;, @participant.metareviews, &amp;quot;MetareviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_feedback&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;feedback&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Feedback&amp;quot;, &amp;quot;Author&amp;quot;, @participant.feedback, &amp;quot;AuthorFeedbackQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;teammate_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;teammate&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Teammate Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.teammate_reviews, &amp;quot;TeammateReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The get_body_text method construct email content which should be removed from controller.&lt;br /&gt;
&amp;lt;pre&amp;gt;                                               &lt;br /&gt;
      @body = get_body_text(params[:submission])      &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The conflict_notification action requiring another two method &amp;quot;process_response&amp;quot; and &amp;quot;get_body_text&amp;quot; method to get the recipient email list and email content which contributes to extra complexity. The instructor only have to click the button &amp;quot;send email&amp;quot; in conflict_notifiction.html.erb and turn to send_conflict_email action, then he/she can send the email. If the instructor want to send another email, the process will repeat again,which will be terrible when reloading the &amp;quot;view&amp;quot; scores page.&lt;br /&gt;
&lt;br /&gt;
'''After Refactoring''':The querying reviews actually have done in our show_reviews action, and we can get the individual reviewers' email address.In the reviewer table,we add extra button &amp;quot;email reviewer&amp;quot;.Now the instructor could send to reviewer email directly.&lt;br /&gt;
[[File:conflict_email.png]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In _review_table.html.erb,we add the link to send email. The review_id is passed to the conflict_email action taken as the recipient.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%= link_to 'email reviewer', :action =&amp;gt; 'conflict_email',:remote=&amp;gt; true,:reviewer_id=&amp;gt; &lt;br /&gt;
&lt;br /&gt;
review.map.reviewer.user,:participant_id=&amp;gt;participant,:score=&amp;gt;sprintf(&amp;quot;%.2f&amp;quot;,score) %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In our new '''conflict_email''' action:&lt;br /&gt;
&lt;br /&gt;
We still need the instructor as the sender &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      if session[:user].role_id !=6&lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The reviewer_id is passed from the link,we can query his/her email address to send the email &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      recipient=User.find(params[:reviewer_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The responsibility of sending email has been delegated to a new mailer conflict_mailer. And the email content was constructed in the mailer.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      participant = AssignmentParticipant.find(params[:participant_id])&lt;br /&gt;
      assignment=Assignment.find(participant.parent_id)      &lt;br /&gt;
      score=params[:score]&lt;br /&gt;
      ConflictMailer.send_conflict_email(instructor,recipient,assignment,score).deliver&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Take a look at new conflict_mailer, it define a '''send_conflict_email''' method. the email was sent from sender's email and to reviewer's email.Some instance variables were used in view.&lt;br /&gt;
In conflict_mailer.erb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def send_conflict_email(sender,recipient,assignment,score)&lt;br /&gt;
      @assignment=assignment&lt;br /&gt;
      @recipient=recipient&lt;br /&gt;
      @score=score&lt;br /&gt;
      if recipient.role_id==1&lt;br /&gt;
        @role = &amp;quot;reviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;submission&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
        @role = &amp;quot;metareviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;review&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
    mail subject: &amp;quot;Confliction Email&amp;quot;,from: sender.email,to: reviewer.email&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In its view send_conflict_email.txt.haml, we edit the email content.By this way, we deleted the '''get_body_text''' and well followed the rule of MVC design&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%h1=&amp;quot;Hi ,&amp;quot; +@recipient.name&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;You submitted a score of &amp;quot;+@score+&amp;quot; for assignment &amp;quot;+@assignment.name+&amp;quot; that varied greatly from another &amp;quot;+@role+&amp;quot;'s score for the same &amp;quot;+@item+&amp;quot;.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;The Expertiza system has brought this to my attention.&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The link &amp;quot;email reviewer&amp;quot; request a ajax,so the current view page will not refresh when the action done&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      respond_to do |format|&lt;br /&gt;
        format.js&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If an email was successfully sent,The instructor should get the alert window by ajax.&lt;br /&gt;
[[File:email_sent.png]]&lt;br /&gt;
&lt;br /&gt;
=== view_my_scores method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored '''view_my_scores''' method to grades_show, deleted many unnecessary instance variables along with several review and meta reviews methods inside it. Therefore, the system will only search for scores in the database rather than search for scores and reviews, which wastes a lot of time during the grade show process. After refactoring, the complexity on this decreased from '''53''' to '''35'''.&lt;br /&gt;
We also optimize '''get_scores''' method to improve the efficiency of showing scores by students and instructors, which cost us most of the time during the project. After refactoring this method, the time cost of views in grade controller decreased by more than '''90%'''.&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Refactored '''view_my_scores''' method to '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Searched for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
&lt;br /&gt;
*Eliminated the search for reviews during the '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Deleted unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
*Deleted the unnecessary instance variables&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_score_results = Array.new&lt;br /&gt;
 @average_score_results = ScoreCache.get_class_scores(@participant.id)&lt;br /&gt;
 @statistics = Array.new&lt;br /&gt;
 @average_score_results.each { |x|&lt;br /&gt;
 @statistics &amp;lt;&amp;lt; x&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Deleted query for reviews and meta_reviews&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_reviews = ScoreCache.get_reviews_average(@participant.id)&lt;br /&gt;
 @average_metareviews = ScoreCache.get_metareviews_average(@participant.id)&lt;br /&gt;
 @my_reviews = ScoreCache.my_reviews(@participant.id)&lt;br /&gt;
 @my_metareviews = ScoreCache.my_metareviews(@participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Add a new method into grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
Add Method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 #show_reviews method gets reviews, meta reviews and author feedback information from server.&lt;br /&gt;
  def show_reviews&lt;br /&gt;
    @partial='grades/'+params[:path]&lt;br /&gt;
    @prefix=params[:prefix]&lt;br /&gt;
    @score=Hash.new&lt;br /&gt;
    @score[:assessments]=Array.new&lt;br /&gt;
    params[:score][:assessments].each do |assessment|&lt;br /&gt;
        @score[:assessments]&amp;lt;&amp;lt;Response.find(assessment)&lt;br /&gt;
    end&lt;br /&gt;
    @score[:scores]=params[:score][:scores]&lt;br /&gt;
    @participant=AssignmentParticipant.find(params[:participant])&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @questions = {}&lt;br /&gt;
    questionnaires = @assignment.questionnaires&lt;br /&gt;
    questionnaires.each do |questionnaire|&lt;br /&gt;
      @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Change view_my_score.html.erb into show_reviews.html.erb in views.&lt;br /&gt;
&lt;br /&gt;
*Add in views(show_reviews.html.erb)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;%= render :partial=&amp;gt;@partial, :locals =&amp;gt; {:prefix =&amp;gt; @prefix, :participant =&amp;gt; @participant, :rscore =&amp;gt; @score} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Result====&lt;br /&gt;
*The following test results based on the test case on Expertiza(Assignments: Program 2 style) &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89835</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1466 gjf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89835"/>
		<updated>2014-10-27T03:15:13Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Design Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1466: Refactoring GradesController==&lt;br /&gt;
&lt;br /&gt;
This wiki deals with our implementation of a controller in expertiza: [https://github.com/expertiza/expertiza/blob/rails4/app/controllers/grades_controller.rb grade_controller]  for the Expertiza Project using Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Classes involved:''' grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''What it does:'''&lt;br /&gt;
&lt;br /&gt;
This class lists the grades of all the participants for an assignments and also their reviews. Instructor can edit scores, calculate penalties and send emails for conflicts.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&lt;br /&gt;
*Modify '''calculate_all_penalties''' method which is too complex and long.&lt;br /&gt;
*Put the '''get_body_text''' method in a mailer rather than in the grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactor '''view_my_scores''' method to '''grades_show''' and delete the unnecessary variables.&lt;br /&gt;
*Try not to query for reviews and meta reviews in '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
'''What we have done:'''&lt;br /&gt;
*Modify '''calculate_all_penalties''' method.&lt;br /&gt;
*Refactor the '''conflict_notification''' method to '''conflict_email''' method. &lt;br /&gt;
*Simplify sending email function and make it delegated to the mailer.&lt;br /&gt;
*Send a conflict email to the reviewer automatically when instructor click the button &amp;quot;email reviewer&amp;quot;.&lt;br /&gt;
*Remove '''get_body_text''' and '''send_grading_email''' method from grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactor '''view_my_scores''' method to '''grades_show''' method.&lt;br /&gt;
*Search for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
*Refactor '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
*Eliminat the search for reviews and meta reviews during the '''grades_show''' method.&lt;br /&gt;
*Delete unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
==Code Modification==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== calculate_all_penalties Method===&lt;br /&gt;
====Summary====&lt;br /&gt;
&lt;br /&gt;
We have modified the calculate_penalties method and implemented all the functions it originally has. After our modification the method shrinks from 45 lines to 32 lines of Ruby code. Originally, the method includes a lot of unnecessary if and unless statements which makes the method uneasy to read and seems to have a difficult logic to calculate the penalties. &lt;br /&gt;
&lt;br /&gt;
According to the [https://codeclimate.com codeclimate] which calculate the complexity of the method, originally, it has a complexity of '''85''', however, after we modified it, the complexity goes down to '''65'''. Please check at [https://codeclimate.com/github/expertiza/expertiza/GradesController original version],[https://codeclimate.com/github/maxlpy/expertiza/GradesController modified version]&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Used for loop with selective choice to create penalty attributes and put it into the '''CalculatedPenalty''' Table, instead of duplicating the almost same code.&lt;br /&gt;
&lt;br /&gt;
*Used Object-Oriented Design patterns of Ruby: let the array respond to the method '''min''' which returns the minimum number in the array and get the logical penalty other than using if statement.(max_penalty if total_penalty is larger than max_penalty,  total_penalty if total_penalty is smaller than max_penalty)&lt;br /&gt;
&lt;br /&gt;
*Eliminated the unnecessary if statements to make the code clear to read.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
&lt;br /&gt;
*Modify if statements:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(penalties[:submission].nil?)&lt;br /&gt;
      penalties[:submission]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:review].nil?)&lt;br /&gt;
      penalties[:review]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:meta_review].nil?)&lt;br /&gt;
      penalties[:meta_review]=0&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
penalties[:submission] = 0 if penalties[:submission].nil?&lt;br /&gt;
penalties[:review] = 0 if penalties[:review].nil?&lt;br /&gt;
penalties[:meta_review] = 0 if penalties[:meta_review].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Using Objected-oriented Pattern&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(@total_penalty &amp;gt; l_policy.max_penalty)&lt;br /&gt;
      @total_penalty = l_policy.max_penalty&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @total_penality=[l_policy.max_penalty,@total_penality].min&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Using loops rather than duplicate same code&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 penalty_attr1 = {:deadline_type_id =&amp;gt; 1,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:submission]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr1)&lt;br /&gt;
 penalty_attr2 = {:deadline_type_id =&amp;gt; 2,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr2)&lt;br /&gt;
 penalty_attr3 = {:deadline_type_id =&amp;gt; 5,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:meta_review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr3)&amp;quot;&lt;br /&gt;
 @all_penalties[participant.id] = Hash.new&lt;br /&gt;
       @all_penalties[participant.id][:submission] = penalties[:submission]&lt;br /&gt;
       @all_penalties[participant.id][:review] = penalties[:review]&lt;br /&gt;
       @all_penalties[participant.id][:meta_review] = penalties[:meta_review]&lt;br /&gt;
       @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 deadline_type=[1,2,5]&lt;br /&gt;
 penalty_type=[:submission,:review,:meta_review]&lt;br /&gt;
 if calculate_for_participants&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
           penalty_attr={:deadline_type_id=&amp;gt;deadline_type[i],:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[penalty_type[i]]}&lt;br /&gt;
           CalculatedPenalty.create(penalty_attr)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
 @all_penalties[participant.id] = {}&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
          @all_penalties[participant.id][:penalty_type[i]] = penalties[:penalty_type[i]]&lt;br /&gt;
      end&lt;br /&gt;
 @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== conflict_notification Method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored the '''conflict_notification''' method to '''conflict_email''' method. When instructor click the button &amp;quot;email reviewer&amp;quot; whom he thought give a unfair review, the system should be able to send an email to the reviewer automatically.The '''get_body_text''' and '''send_grading_email''' were removed from the controller. The sending email function is well simplified and delegated to a conflict_mailer.&lt;br /&gt;
&lt;br /&gt;
====Design Pattern====&lt;br /&gt;
Delegation: The conflict_email should be able to send email. The class ConflictMailer works as its delegate .The conflict_email calls the send_conflict_email function to take the job of sending an email.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
The old '''conflict_notification''' action queries an email address list of a certain kind of reviews. In its view conflict_notification.html.erb, A email form contains email list for instructor to choose from and email content. &lt;br /&gt;
[[File:old_email.png]]&lt;br /&gt;
&lt;br /&gt;
'''Before Refactoring''', in conflict_notification:&lt;br /&gt;
First,Get the instructor email address as sender&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
      if session[:user].role_id !=6             &lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
      @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
      @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then,Based on submission of review, the action query all the reviewers' email address  &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @questions = Hash.new&lt;br /&gt;
      questionnaires = @assignment.questionnaires&lt;br /&gt;
      questionnaires.each {&lt;br /&gt;
        |questionnaire|&lt;br /&gt;
        @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The email list is for instructor to choose from. The process_response method queries the email address.    &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @reviewers_email_hash = Hash.new            &lt;br /&gt;
      @caction = &amp;quot;view&amp;quot;&lt;br /&gt;
      @submission = params[:submission]&lt;br /&gt;
      if @submission == &amp;quot;review&amp;quot;&lt;br /&gt;
        @caction = &amp;quot;view_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;review&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.reviews, &amp;quot;ReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_of_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;metareview&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Metareview&amp;quot;, &amp;quot;Metareviewer&amp;quot;, @participant.metareviews, &amp;quot;MetareviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_feedback&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;feedback&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Feedback&amp;quot;, &amp;quot;Author&amp;quot;, @participant.feedback, &amp;quot;AuthorFeedbackQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;teammate_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;teammate&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Teammate Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.teammate_reviews, &amp;quot;TeammateReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The get_body_text method construct email content which should be removed from controller.&lt;br /&gt;
&amp;lt;pre&amp;gt;                                               &lt;br /&gt;
      @body = get_body_text(params[:submission])      &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The conflict_notification action requiring another two method &amp;quot;process_response&amp;quot; and &amp;quot;get_body_text&amp;quot; method to get the recipient email list and email content which contributes to extra complexity. The instructor only have to click the button &amp;quot;send email&amp;quot; in conflict_notification.html.erb and turn to send_conflict_email action, then he/she can send the email. If the instructor want to send another email, the process will repeat again,which will be terrible when reloading the &amp;quot;view&amp;quot; scores page.&lt;br /&gt;
&lt;br /&gt;
'''After Refactoring''':The quering reiviews actually have done in our show_reviews action, and we can get the individual reviewers' email address.In the reviewer table,we add extra button &amp;quot;email reviewer&amp;quot;.Now the instructor could send to reviewer email directly.&lt;br /&gt;
[[File:conflict_email.png]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In _review_table.html.erb,we add the link to send email. The review_id is passed to the conflict_email action taken as the recipient.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%= link_to 'email reviewer', :action =&amp;gt; 'conflict_email',:remote=&amp;gt; true,:reviewer_id=&amp;gt; &lt;br /&gt;
&lt;br /&gt;
review.map.reviewer.user,:participant_id=&amp;gt;participant,:score=&amp;gt;sprintf(&amp;quot;%.2f&amp;quot;,score) %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In our new '''conflict_email''' action:&lt;br /&gt;
&lt;br /&gt;
We still need the instructor as the sender &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      if session[:user].role_id !=6&lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The reviewer_id is passed from the link,we can query his/her email address to send the email &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      recipient=User.find(params[:reviewer_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The responsibility of sending email has been delegated to a new mailer conflict_mailer. And the email content was constructed in the mailer.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      participant = AssignmentParticipant.find(params[:participant_id])&lt;br /&gt;
      assignment=Assignment.find(participant.parent_id)      &lt;br /&gt;
      score=params[:score]&lt;br /&gt;
      ConflictMailer.send_conflict_email(instructor,recipient,assignment,score).deliver&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Take a look at new conflict_mailer, it define a '''send_conflict_email''' method. the email was sent from sender's email and to reviewer's email.Some instance variables were used in view.&lt;br /&gt;
In conflict_mailer.erb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def send_conflict_email(sender,recipient,assignment,score)&lt;br /&gt;
      @assignment=assignment&lt;br /&gt;
      @recipient=recipient&lt;br /&gt;
      @score=score&lt;br /&gt;
      if recipient.role_id==1&lt;br /&gt;
        @role = &amp;quot;reviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;submission&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
        @role = &amp;quot;metareviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;review&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
    mail subject: &amp;quot;Conflication Email&amp;quot;,from: sender.email,to: reviewer.email&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In its view send_conflict_email.txt.haml, we edit the email content.By this way, we deleted the '''get_body_text''' and well followed the rule of MVC design&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%h1=&amp;quot;Hi ,&amp;quot; +@recipient.name&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;You submitted a score of &amp;quot;+@score+&amp;quot; for assignment &amp;quot;+@assignment.name+&amp;quot; that varied greatly from another &amp;quot;+@role+&amp;quot;'s score for the same &amp;quot;+@item+&amp;quot;.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;The Expertiza system has brought this to my attention.&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The link &amp;quot;email reviewer&amp;quot; request a ajax,so the current view page will not refresh when the action done&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      respond_to do |format|&lt;br /&gt;
        format.js&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If an email was successfully sent,The instructor should get the alert window by ajax.&lt;br /&gt;
[[File:email_sent.png]]&lt;br /&gt;
&lt;br /&gt;
=== view_my_scores method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored '''view_my_scores''' method to grades_show, deleted many unnecessary instance variables along with several review and meta reviews methods inside it. Therefore, the system will only search for scores in the database rather than search for scores and reviews, which wastes a lot of time during the grade show process. After refactoring, the complexity on this decreased from '''53''' to '''35'''.&lt;br /&gt;
We also optimize '''get_scores''' method to improve the efficiency of showing scores by students and instructors, which cost us most of the time during the project. After refactoring this method, the time cost of views in grade controller decreased by more than '''90%'''.&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Refactored '''view_my_scores''' method to '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Searched for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
&lt;br /&gt;
*Eliminated the search for reviews during the '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Deleted unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
*Deleted the unnecessary instance variables&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_score_results = Array.new&lt;br /&gt;
 @average_score_results = ScoreCache.get_class_scores(@participant.id)&lt;br /&gt;
 @statistics = Array.new&lt;br /&gt;
 @average_score_results.each { |x|&lt;br /&gt;
 @statistics &amp;lt;&amp;lt; x&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Deleted query for reviews and meta_reviews&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_reviews = ScoreCache.get_reviews_average(@participant.id)&lt;br /&gt;
 @average_metareviews = ScoreCache.get_metareviews_average(@participant.id)&lt;br /&gt;
 @my_reviews = ScoreCache.my_reviews(@participant.id)&lt;br /&gt;
 @my_metareviews = ScoreCache.my_metareviews(@participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Add a new method into grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
Add Method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 #show_reviews method gets reviews, meta reviews and author feedback information from server.&lt;br /&gt;
  def show_reviews&lt;br /&gt;
    @partial='grades/'+params[:path]&lt;br /&gt;
    @prefix=params[:prefix]&lt;br /&gt;
    @score=Hash.new&lt;br /&gt;
    @score[:assessments]=Array.new&lt;br /&gt;
    params[:score][:assessments].each do |assessment|&lt;br /&gt;
        @score[:assessments]&amp;lt;&amp;lt;Response.find(assessment)&lt;br /&gt;
    end&lt;br /&gt;
    @score[:scores]=params[:score][:scores]&lt;br /&gt;
    @participant=AssignmentParticipant.find(params[:participant])&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @questions = {}&lt;br /&gt;
    questionnaires = @assignment.questionnaires&lt;br /&gt;
    questionnaires.each do |questionnaire|&lt;br /&gt;
      @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Change view_my_score.html.erb into show_reviews.html.erb in views.&lt;br /&gt;
&lt;br /&gt;
*Add in views(show_reviews.html.erb)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;%= render :partial=&amp;gt;@partial, :locals =&amp;gt; {:prefix =&amp;gt; @prefix, :participant =&amp;gt; @participant, :rscore =&amp;gt; @score} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Result====&lt;br /&gt;
*The following test results based on the test case on Expertiza(Assignments: Program 2 style) &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89834</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1466 gjf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89834"/>
		<updated>2014-10-27T03:14:38Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1466: Refactoring GradesController==&lt;br /&gt;
&lt;br /&gt;
This wiki deals with our implementation of a controller in expertiza: [https://github.com/expertiza/expertiza/blob/rails4/app/controllers/grades_controller.rb grade_controller]  for the Expertiza Project using Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Classes involved:''' grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''What it does:'''&lt;br /&gt;
&lt;br /&gt;
This class lists the grades of all the participants for an assignments and also their reviews. Instructor can edit scores, calculate penalties and send emails for conflicts.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&lt;br /&gt;
*Modify '''calculate_all_penalties''' method which is too complex and long.&lt;br /&gt;
*Put the '''get_body_text''' method in a mailer rather than in the grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactor '''view_my_scores''' method to '''grades_show''' and delete the unnecessary variables.&lt;br /&gt;
*Try not to query for reviews and meta reviews in '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
'''What we have done:'''&lt;br /&gt;
*Modify '''calculate_all_penalties''' method.&lt;br /&gt;
*Refactor the '''conflict_notification''' method to '''conflict_email''' method. &lt;br /&gt;
*Simplify sending email function and make it delegated to the mailer.&lt;br /&gt;
*Send a conflict email to the reviewer automatically when instructor click the button &amp;quot;email reviewer&amp;quot;.&lt;br /&gt;
*Remove '''get_body_text''' and '''send_grading_email''' method from grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactor '''view_my_scores''' method to '''grades_show''' method.&lt;br /&gt;
*Search for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
*Refactor '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
*Eliminat the search for reviews and meta reviews during the '''grades_show''' method.&lt;br /&gt;
*Delete unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
==Code Modification==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== calculate_all_penalties Method===&lt;br /&gt;
====Summary====&lt;br /&gt;
&lt;br /&gt;
We have modified the calculate_penalties method and implemented all the functions it originally has. After our modification the method shrinks from 45 lines to 32 lines of Ruby code. Originally, the method includes a lot of unnecessary if and unless statements which makes the method uneasy to read and seems to have a difficult logic to calculate the penalties. &lt;br /&gt;
&lt;br /&gt;
According to the [https://codeclimate.com codeclimate] which calculate the complexity of the method, originally, it has a complexity of '''85''', however, after we modified it, the complexity goes down to '''65'''. Please check at [https://codeclimate.com/github/expertiza/expertiza/GradesController original version],[https://codeclimate.com/github/maxlpy/expertiza/GradesController modified version]&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Used for loop with selective choice to create penalty attributes and put it into the '''CalculatedPenalty''' Table, instead of duplicating the almost same code.&lt;br /&gt;
&lt;br /&gt;
*Used Object-Oriented Design patterns of Ruby: let the array respond to the method '''min''' which returns the minimum number in the array and get the logical penalty other than using if statement.(max_penalty if total_penalty is larger than max_penalty,  total_penalty if total_penalty is smaller than max_penalty)&lt;br /&gt;
&lt;br /&gt;
*Eliminated the unnecessary if statements to make the code clear to read.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
&lt;br /&gt;
*Modify if statements:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(penalties[:submission].nil?)&lt;br /&gt;
      penalties[:submission]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:review].nil?)&lt;br /&gt;
      penalties[:review]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:meta_review].nil?)&lt;br /&gt;
      penalties[:meta_review]=0&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
penalties[:submission] = 0 if penalties[:submission].nil?&lt;br /&gt;
penalties[:review] = 0 if penalties[:review].nil?&lt;br /&gt;
penalties[:meta_review] = 0 if penalties[:meta_review].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Using Objected-oriented Pattern&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(@total_penalty &amp;gt; l_policy.max_penalty)&lt;br /&gt;
      @total_penalty = l_policy.max_penalty&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @total_penality=[l_policy.max_penalty,@total_penality].min&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Using loops rather than duplicate same code&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 penalty_attr1 = {:deadline_type_id =&amp;gt; 1,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:submission]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr1)&lt;br /&gt;
 penalty_attr2 = {:deadline_type_id =&amp;gt; 2,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr2)&lt;br /&gt;
 penalty_attr3 = {:deadline_type_id =&amp;gt; 5,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:meta_review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr3)&amp;quot;&lt;br /&gt;
 @all_penalties[participant.id] = Hash.new&lt;br /&gt;
       @all_penalties[participant.id][:submission] = penalties[:submission]&lt;br /&gt;
       @all_penalties[participant.id][:review] = penalties[:review]&lt;br /&gt;
       @all_penalties[participant.id][:meta_review] = penalties[:meta_review]&lt;br /&gt;
       @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 deadline_type=[1,2,5]&lt;br /&gt;
 penalty_type=[:submission,:review,:meta_review]&lt;br /&gt;
 if calculate_for_participants&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
           penalty_attr={:deadline_type_id=&amp;gt;deadline_type[i],:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[penalty_type[i]]}&lt;br /&gt;
           CalculatedPenalty.create(penalty_attr)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
 @all_penalties[participant.id] = {}&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
          @all_penalties[participant.id][:penalty_type[i]] = penalties[:penalty_type[i]]&lt;br /&gt;
      end&lt;br /&gt;
 @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== conflict_notification Method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored the '''conflict_notification''' method to '''conflict_email''' method. When instructor click the button &amp;quot;email reviewer&amp;quot; whom he thought give a unfair review, the system should be able to send an email to the reviewer automatically.The '''get_body_text''' and '''send_grading_email''' were removed from the controller. The sending email function is well simplified and delegated to a conflict_mailer.&lt;br /&gt;
&lt;br /&gt;
====Design Pattern====&lt;br /&gt;
Delegation: The conflict_email should be able to send email. The class ConflictMailer works as its delegate .The conflict_email calls the send_conflict_email fuction to take the job of sending a email.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
The old '''conflict_notification''' action queries an email address list of a certain kind of reviews. In its view conflict_notification.html.erb, A email form contains email list for instructor to choose from and email content. &lt;br /&gt;
[[File:old_email.png]]&lt;br /&gt;
&lt;br /&gt;
'''Before Refactoring''', in conflict_notification:&lt;br /&gt;
First,Get the instructor email address as sender&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
      if session[:user].role_id !=6             &lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
      @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
      @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then,Based on submission of review, the action query all the reviewers' email address  &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @questions = Hash.new&lt;br /&gt;
      questionnaires = @assignment.questionnaires&lt;br /&gt;
      questionnaires.each {&lt;br /&gt;
        |questionnaire|&lt;br /&gt;
        @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The email list is for instructor to choose from. The process_response method queries the email address.    &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @reviewers_email_hash = Hash.new            &lt;br /&gt;
      @caction = &amp;quot;view&amp;quot;&lt;br /&gt;
      @submission = params[:submission]&lt;br /&gt;
      if @submission == &amp;quot;review&amp;quot;&lt;br /&gt;
        @caction = &amp;quot;view_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;review&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.reviews, &amp;quot;ReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_of_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;metareview&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Metareview&amp;quot;, &amp;quot;Metareviewer&amp;quot;, @participant.metareviews, &amp;quot;MetareviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_feedback&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;feedback&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Feedback&amp;quot;, &amp;quot;Author&amp;quot;, @participant.feedback, &amp;quot;AuthorFeedbackQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;teammate_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;teammate&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Teammate Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.teammate_reviews, &amp;quot;TeammateReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The get_body_text method construct email content which should be removed from controller.&lt;br /&gt;
&amp;lt;pre&amp;gt;                                               &lt;br /&gt;
      @body = get_body_text(params[:submission])      &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The conflict_notification action requiring another two method &amp;quot;process_response&amp;quot; and &amp;quot;get_body_text&amp;quot; method to get the recipient email list and email content which contributes to extra complexity. The instructor only have to click the button &amp;quot;send email&amp;quot; in conflict_notification.html.erb and turn to send_conflict_email action, then he/she can send the email. If the instructor want to send another email, the process will repeat again,which will be terrible when reloading the &amp;quot;view&amp;quot; scores page.&lt;br /&gt;
&lt;br /&gt;
'''After Refactoring''':The quering reiviews actually have done in our show_reviews action, and we can get the individual reviewers' email address.In the reviewer table,we add extra button &amp;quot;email reviewer&amp;quot;.Now the instructor could send to reviewer email directly.&lt;br /&gt;
[[File:conflict_email.png]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In _review_table.html.erb,we add the link to send email. The review_id is passed to the conflict_email action taken as the recipient.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%= link_to 'email reviewer', :action =&amp;gt; 'conflict_email',:remote=&amp;gt; true,:reviewer_id=&amp;gt; &lt;br /&gt;
&lt;br /&gt;
review.map.reviewer.user,:participant_id=&amp;gt;participant,:score=&amp;gt;sprintf(&amp;quot;%.2f&amp;quot;,score) %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In our new '''conflict_email''' action:&lt;br /&gt;
&lt;br /&gt;
We still need the instructor as the sender &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      if session[:user].role_id !=6&lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The reviewer_id is passed from the link,we can query his/her email address to send the email &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      recipient=User.find(params[:reviewer_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The responsibility of sending email has been delegated to a new mailer conflict_mailer. And the email content was constructed in the mailer.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      participant = AssignmentParticipant.find(params[:participant_id])&lt;br /&gt;
      assignment=Assignment.find(participant.parent_id)      &lt;br /&gt;
      score=params[:score]&lt;br /&gt;
      ConflictMailer.send_conflict_email(instructor,recipient,assignment,score).deliver&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Take a look at new conflict_mailer, it define a '''send_conflict_email''' method. the email was sent from sender's email and to reviewer's email.Some instance variables were used in view.&lt;br /&gt;
In conflict_mailer.erb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def send_conflict_email(sender,recipient,assignment,score)&lt;br /&gt;
      @assignment=assignment&lt;br /&gt;
      @recipient=recipient&lt;br /&gt;
      @score=score&lt;br /&gt;
      if recipient.role_id==1&lt;br /&gt;
        @role = &amp;quot;reviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;submission&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
        @role = &amp;quot;metareviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;review&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
    mail subject: &amp;quot;Conflication Email&amp;quot;,from: sender.email,to: reviewer.email&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In its view send_conflict_email.txt.haml, we edit the email content.By this way, we deleted the '''get_body_text''' and well followed the rule of MVC design&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%h1=&amp;quot;Hi ,&amp;quot; +@recipient.name&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;You submitted a score of &amp;quot;+@score+&amp;quot; for assignment &amp;quot;+@assignment.name+&amp;quot; that varied greatly from another &amp;quot;+@role+&amp;quot;'s score for the same &amp;quot;+@item+&amp;quot;.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;The Expertiza system has brought this to my attention.&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The link &amp;quot;email reviewer&amp;quot; request a ajax,so the current view page will not refresh when the action done&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      respond_to do |format|&lt;br /&gt;
        format.js&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If an email was successfully sent,The instructor should get the alert window by ajax.&lt;br /&gt;
[[File:email_sent.png]]&lt;br /&gt;
&lt;br /&gt;
=== view_my_scores method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored '''view_my_scores''' method to grades_show, deleted many unnecessary instance variables along with several review and meta reviews methods inside it. Therefore, the system will only search for scores in the database rather than search for scores and reviews, which wastes a lot of time during the grade show process. After refactoring, the complexity on this decreased from '''53''' to '''35'''.&lt;br /&gt;
We also optimize '''get_scores''' method to improve the efficiency of showing scores by students and instructors, which cost us most of the time during the project. After refactoring this method, the time cost of views in grade controller decreased by more than '''90%'''.&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Refactored '''view_my_scores''' method to '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Searched for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
&lt;br /&gt;
*Eliminated the search for reviews during the '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Deleted unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
*Deleted the unnecessary instance variables&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_score_results = Array.new&lt;br /&gt;
 @average_score_results = ScoreCache.get_class_scores(@participant.id)&lt;br /&gt;
 @statistics = Array.new&lt;br /&gt;
 @average_score_results.each { |x|&lt;br /&gt;
 @statistics &amp;lt;&amp;lt; x&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Deleted query for reviews and meta_reviews&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_reviews = ScoreCache.get_reviews_average(@participant.id)&lt;br /&gt;
 @average_metareviews = ScoreCache.get_metareviews_average(@participant.id)&lt;br /&gt;
 @my_reviews = ScoreCache.my_reviews(@participant.id)&lt;br /&gt;
 @my_metareviews = ScoreCache.my_metareviews(@participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Add a new method into grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
Add Method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 #show_reviews method gets reviews, meta reviews and author feedback information from server.&lt;br /&gt;
  def show_reviews&lt;br /&gt;
    @partial='grades/'+params[:path]&lt;br /&gt;
    @prefix=params[:prefix]&lt;br /&gt;
    @score=Hash.new&lt;br /&gt;
    @score[:assessments]=Array.new&lt;br /&gt;
    params[:score][:assessments].each do |assessment|&lt;br /&gt;
        @score[:assessments]&amp;lt;&amp;lt;Response.find(assessment)&lt;br /&gt;
    end&lt;br /&gt;
    @score[:scores]=params[:score][:scores]&lt;br /&gt;
    @participant=AssignmentParticipant.find(params[:participant])&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @questions = {}&lt;br /&gt;
    questionnaires = @assignment.questionnaires&lt;br /&gt;
    questionnaires.each do |questionnaire|&lt;br /&gt;
      @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Change view_my_score.html.erb into show_reviews.html.erb in views.&lt;br /&gt;
&lt;br /&gt;
*Add in views(show_reviews.html.erb)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;%= render :partial=&amp;gt;@partial, :locals =&amp;gt; {:prefix =&amp;gt; @prefix, :participant =&amp;gt; @participant, :rscore =&amp;gt; @score} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Result====&lt;br /&gt;
*The following test results based on the test case on Expertiza(Assignments: Program 2 style) &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89833</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1466 gjf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89833"/>
		<updated>2014-10-27T03:14:25Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Design Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1466: Refactoring GradesController==&lt;br /&gt;
&lt;br /&gt;
This wiki deals with our implementation of a controller in expertiza: [https://github.com/expertiza/expertiza/blob/rails4/app/controllers/grades_controller.rb grade_controller]  for the Expertiza Project using Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Classes involved:''' grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''What it does:'''&lt;br /&gt;
&lt;br /&gt;
This class lists the grades of all the participants for an assignments and also their reviews. Instructor can edit scores, calculate penalties and send emails for conflicts.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&lt;br /&gt;
*Modify '''calculate_all_penalties''' method which is too complex and long.&lt;br /&gt;
*Put the '''get_body_text''' method in a mailer rather than in the grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactor '''view_my_scores''' method to '''grades_show''' and delete the unnecessary variables.&lt;br /&gt;
*Try not to query for reviews and meta reviews in '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
'''What we have done:'''&lt;br /&gt;
*Modify '''calculate_all_penalties''' method.&lt;br /&gt;
*Refactor the '''conflict_notification''' method to '''conflict_email''' method. &lt;br /&gt;
*Simplify sending email function and make it delegated to the mailer.&lt;br /&gt;
*Send a conflict email to the reviewer automatically when instructor click the button &amp;quot;email reviewer&amp;quot;.&lt;br /&gt;
*Remove '''get_body_text''' and '''send_grading_email''' method from grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactor '''view_my_scores''' method to '''grades_show''' method.&lt;br /&gt;
*Search for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
*Refactor '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
*Eliminat the search for reviews and meta reviews during the '''grades_show''' method.&lt;br /&gt;
*Delete unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
==Code Modification==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== calculate_all_penalties Method===&lt;br /&gt;
====Summary====&lt;br /&gt;
&lt;br /&gt;
We have modified the calculate_penalties method and implemented all the functions it originally has. After our modification the method shrinks from 45 lines to 32 lines of Ruby code. Originally, the method includes a lot of unnecessary if and unless statements which makes the method uneasy to read and seems to have a difficult logic to calculate the penalties. &lt;br /&gt;
&lt;br /&gt;
According to the [https://codeclimate.com codeclimate] which calculate the complexity of the method, originally, it has a complexity of '''85''', however, after we modified it, the complexity goes down to '''65'''. Please check at [https://codeclimate.com/github/expertiza/expertiza/GradesController original version],[https://codeclimate.com/github/maxlpy/expertiza/GradesController modified version]&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Used for loop with selective choice to create penalty attributes and put it into the '''CalculatedPenalty''' Table, instead of duplicating the almost same code.&lt;br /&gt;
&lt;br /&gt;
*Used Object-Oriented Design patterns of Ruby: let the array respond to the method '''min''' which returns the minimum number in the array and get the logical penalty other than using if statement.(max_penalty if total_penalty is larger than max_penalty,  total_penalty if total_penalty is smaller than max_penalty)&lt;br /&gt;
&lt;br /&gt;
*Eliminated the unnecessary if statements to make the code clear to read.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
&lt;br /&gt;
*Modify if statements:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(penalties[:submission].nil?)&lt;br /&gt;
      penalties[:submission]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:review].nil?)&lt;br /&gt;
      penalties[:review]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:meta_review].nil?)&lt;br /&gt;
      penalties[:meta_review]=0&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
penalties[:submission] = 0 if penalties[:submission].nil?&lt;br /&gt;
penalties[:review] = 0 if penalties[:review].nil?&lt;br /&gt;
penalties[:meta_review] = 0 if penalties[:meta_review].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Using Objected-oriented Pattern&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(@total_penalty &amp;gt; l_policy.max_penalty)&lt;br /&gt;
      @total_penalty = l_policy.max_penalty&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @total_penality=[l_policy.max_penalty,@total_penality].min&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Using loops rather than duplicate same code&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 penalty_attr1 = {:deadline_type_id =&amp;gt; 1,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:submission]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr1)&lt;br /&gt;
 penalty_attr2 = {:deadline_type_id =&amp;gt; 2,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr2)&lt;br /&gt;
 penalty_attr3 = {:deadline_type_id =&amp;gt; 5,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:meta_review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr3)&amp;quot;&lt;br /&gt;
 @all_penalties[participant.id] = Hash.new&lt;br /&gt;
       @all_penalties[participant.id][:submission] = penalties[:submission]&lt;br /&gt;
       @all_penalties[participant.id][:review] = penalties[:review]&lt;br /&gt;
       @all_penalties[participant.id][:meta_review] = penalties[:meta_review]&lt;br /&gt;
       @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 deadline_type=[1,2,5]&lt;br /&gt;
 penalty_type=[:submission,:review,:meta_review]&lt;br /&gt;
 if calculate_for_participants&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
           penalty_attr={:deadline_type_id=&amp;gt;deadline_type[i],:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[penalty_type[i]]}&lt;br /&gt;
           CalculatedPenalty.create(penalty_attr)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
 @all_penalties[participant.id] = {}&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
          @all_penalties[participant.id][:penalty_type[i]] = penalties[:penalty_type[i]]&lt;br /&gt;
      end&lt;br /&gt;
 @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== conflict_notification Method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored the '''conflict_notification''' method to '''conflict_email''' method. When instructor click the button &amp;quot;email reviewer&amp;quot; whom he thought give a unfair review, the system should be able to send an email to the reviewer automatically.The '''get_body_text''' and '''send_grading_email''' were removed from the controller. The sending email function is well simplified and delegated to a conflict_mailer.&lt;br /&gt;
&lt;br /&gt;
====Design Pattern====&lt;br /&gt;
Delegation: The conflict_email should be able to send email. The class ConflictMailer works as its delegate .The conflict_email calls the send_conflict_email fuction to take the job of sending a email.&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
The old '''conflict_notification''' action queries an email address list of a certain kind of reviews. In its view conflict_notification.html.erb, A email form contains email list for instructor to choose from and email content. &lt;br /&gt;
[[File:old_email.png]]&lt;br /&gt;
&lt;br /&gt;
'''Before Refactoring''', in conflict_notification:&lt;br /&gt;
First,Get the instructor email address as sender&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
      if session[:user].role_id !=6             &lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
      @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
      @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then,Based on submission of review, the action query all the reviewers' email address  &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @questions = Hash.new&lt;br /&gt;
      questionnaires = @assignment.questionnaires&lt;br /&gt;
      questionnaires.each {&lt;br /&gt;
        |questionnaire|&lt;br /&gt;
        @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The email list is for instructor to choose from. The process_response method queries the email address.    &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @reviewers_email_hash = Hash.new            &lt;br /&gt;
      @caction = &amp;quot;view&amp;quot;&lt;br /&gt;
      @submission = params[:submission]&lt;br /&gt;
      if @submission == &amp;quot;review&amp;quot;&lt;br /&gt;
        @caction = &amp;quot;view_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;review&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.reviews, &amp;quot;ReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_of_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;metareview&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Metareview&amp;quot;, &amp;quot;Metareviewer&amp;quot;, @participant.metareviews, &amp;quot;MetareviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_feedback&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;feedback&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Feedback&amp;quot;, &amp;quot;Author&amp;quot;, @participant.feedback, &amp;quot;AuthorFeedbackQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;teammate_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;teammate&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Teammate Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.teammate_reviews, &amp;quot;TeammateReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The get_body_text method construct email content which should be removed from controller.&lt;br /&gt;
&amp;lt;pre&amp;gt;                                               &lt;br /&gt;
      @body = get_body_text(params[:submission])      &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The conflict_notification action requiring another two method &amp;quot;process_response&amp;quot; and &amp;quot;get_body_text&amp;quot; method to get the recipient email list and email content which contributes to extra complexity. The instructor only have to click the button &amp;quot;send email&amp;quot; in conflict_notification.html.erb and turn to send_conflict_email action, then he/she can send the email. If the instructor want to send another email, the process will repeat again,which will be terrible when reloading the &amp;quot;view&amp;quot; scores page.&lt;br /&gt;
&lt;br /&gt;
'''After Refactoring''':The quering reiviews actually have done in our show_reviews action, and we can get the individual reviewers' email address.In the reviewer table,we add extra button &amp;quot;email reviewer&amp;quot;.Now the instructor could send to reviewer email directly.&lt;br /&gt;
[[File:conflict_email.png]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In _review_table.html.erb,we add the link to send email. The review_id is passed to the conflict_email action taken as the recipient.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%= link_to 'email reviewer', :action =&amp;gt; 'conflict_email',:remote=&amp;gt; true,:reviewer_id=&amp;gt; &lt;br /&gt;
&lt;br /&gt;
review.map.reviewer.user,:participant_id=&amp;gt;participant,:score=&amp;gt;sprintf(&amp;quot;%.2f&amp;quot;,score) %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In our new '''conflict_email''' action:&lt;br /&gt;
&lt;br /&gt;
We still need the instructor as the sender &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      if session[:user].role_id !=6&lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The reviewer_id is passed from the link,we can query his/her email address to send the email &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      recipient=User.find(params[:reviewer_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The responsibility of sending email has been delegated to a new mailer conflict_mailer. And the email content was constructed in the mailer.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      participant = AssignmentParticipant.find(params[:participant_id])&lt;br /&gt;
      assignment=Assignment.find(participant.parent_id)      &lt;br /&gt;
      score=params[:score]&lt;br /&gt;
      ConflictMailer.send_conflict_email(instructor,recipient,assignment,score).deliver&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Take a look at new conflict_mailer, it define a '''send_conflict_email''' method. the email was sent from sender's email and to reviewer's email.Some instance variables were used in view.&lt;br /&gt;
In conflict_mailer.erb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def send_conflict_email(sender,recipient,assignment,score)&lt;br /&gt;
      @assignment=assignment&lt;br /&gt;
      @recipient=recipient&lt;br /&gt;
      @score=score&lt;br /&gt;
      if recipient.role_id==1&lt;br /&gt;
        @role = &amp;quot;reviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;submission&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
        @role = &amp;quot;metareviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;review&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
    mail subject: &amp;quot;Conflication Email&amp;quot;,from: sender.email,to: reviewer.email&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In its view send_conflict_email.txt.haml, we edit the email content.By this way, we deleted the '''get_body_text''' and well followed the rule of MVC design&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%h1=&amp;quot;Hi ,&amp;quot; +@recipient.name&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;You submitted a score of &amp;quot;+@score+&amp;quot; for assignment &amp;quot;+@assignment.name+&amp;quot; that varied greatly from another &amp;quot;+@role+&amp;quot;'s score for the same &amp;quot;+@item+&amp;quot;.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;The Expertiza system has brought this to my attention.&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The link &amp;quot;email reviewer&amp;quot; request a ajax,so the current view page will not refresh when the action done&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      respond_to do |format|&lt;br /&gt;
        format.js&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If an email was successfully sent,The instructor should get the alert window by ajax.&lt;br /&gt;
[[File:email_sent.png]]&lt;br /&gt;
&lt;br /&gt;
=== view_my_scores method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored '''view_my_scores''' method to grades_show, deleted many unnecessary instance variables along with several review and meta reviews methods inside it. Therefore, the system will only search for scores in the database rather than search for scores and reviews, which wastes a lot of time during the grade show process. After refactoring, the complexity on this decreased from '''53''' to '''35'''.&lt;br /&gt;
We also optimize '''get_scores''' method to improve the efficiency of showing scores by students and instructors, which cost us most of the time during the project. After refactoring this method, the time cost of views in grade controller decreased by more than '''90%'''.&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Refactored '''view_my_scores''' method to '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Searched for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
&lt;br /&gt;
*Eliminated the search for reviews during the '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Deleted unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
*Deleted the unnecessary instance variables&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_score_results = Array.new&lt;br /&gt;
 @average_score_results = ScoreCache.get_class_scores(@participant.id)&lt;br /&gt;
 @statistics = Array.new&lt;br /&gt;
 @average_score_results.each { |x|&lt;br /&gt;
 @statistics &amp;lt;&amp;lt; x&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Deleted query for reviews and meta_reviews&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_reviews = ScoreCache.get_reviews_average(@participant.id)&lt;br /&gt;
 @average_metareviews = ScoreCache.get_metareviews_average(@participant.id)&lt;br /&gt;
 @my_reviews = ScoreCache.my_reviews(@participant.id)&lt;br /&gt;
 @my_metareviews = ScoreCache.my_metareviews(@participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Add a new method into grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
Add Method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 #show_reviews method gets reviews, meta reviews and author feedback information from server.&lt;br /&gt;
  def show_reviews&lt;br /&gt;
    @partial='grades/'+params[:path]&lt;br /&gt;
    @prefix=params[:prefix]&lt;br /&gt;
    @score=Hash.new&lt;br /&gt;
    @score[:assessments]=Array.new&lt;br /&gt;
    params[:score][:assessments].each do |assessment|&lt;br /&gt;
        @score[:assessments]&amp;lt;&amp;lt;Response.find(assessment)&lt;br /&gt;
    end&lt;br /&gt;
    @score[:scores]=params[:score][:scores]&lt;br /&gt;
    @participant=AssignmentParticipant.find(params[:participant])&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @questions = {}&lt;br /&gt;
    questionnaires = @assignment.questionnaires&lt;br /&gt;
    questionnaires.each do |questionnaire|&lt;br /&gt;
      @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Change view_my_score.html.erb into show_reviews.html.erb in views.&lt;br /&gt;
&lt;br /&gt;
*Add in views(show_reviews.html.erb)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;%= render :partial=&amp;gt;@partial, :locals =&amp;gt; {:prefix =&amp;gt; @prefix, :participant =&amp;gt; @participant, :rscore =&amp;gt; @score} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Result====&lt;br /&gt;
*The following test results based on the test case on Expertiza(Assignments: Program 2 style) &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89832</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1466 gjf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89832"/>
		<updated>2014-10-27T03:13:55Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Design Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1466: Refactoring GradesController==&lt;br /&gt;
&lt;br /&gt;
This wiki deals with our implementation of a controller in expertiza: [https://github.com/expertiza/expertiza/blob/rails4/app/controllers/grades_controller.rb grade_controller]  for the Expertiza Project using Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Classes involved:''' grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''What it does:'''&lt;br /&gt;
&lt;br /&gt;
This class lists the grades of all the participants for an assignments and also their reviews. Instructor can edit scores, calculate penalties and send emails for conflicts.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&lt;br /&gt;
*Modify '''calculate_all_penalties''' method which is too complex and long.&lt;br /&gt;
*Put the '''get_body_text''' method in a mailer rather than in the grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactor '''view_my_scores''' method to '''grades_show''' and delete the unnecessary variables.&lt;br /&gt;
*Try not to query for reviews and meta reviews in '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
'''What we have done:'''&lt;br /&gt;
*Modify '''calculate_all_penalties''' method.&lt;br /&gt;
*Refactor the '''conflict_notification''' method to '''conflict_email''' method. &lt;br /&gt;
*Simplify sending email function and make it delegated to the mailer.&lt;br /&gt;
*Send a conflict email to the reviewer automatically when instructor click the button &amp;quot;email reviewer&amp;quot;.&lt;br /&gt;
*Remove '''get_body_text''' and '''send_grading_email''' method from grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactor '''view_my_scores''' method to '''grades_show''' method.&lt;br /&gt;
*Search for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
*Refactor '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
*Eliminat the search for reviews and meta reviews during the '''grades_show''' method.&lt;br /&gt;
*Delete unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
==Code Modification==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== calculate_all_penalties Method===&lt;br /&gt;
====Summary====&lt;br /&gt;
&lt;br /&gt;
We have modified the calculate_penalties method and implemented all the functions it originally has. After our modification the method shrinks from 45 lines to 32 lines of Ruby code. Originally, the method includes a lot of unnecessary if and unless statements which makes the method uneasy to read and seems to have a difficult logic to calculate the penalties. &lt;br /&gt;
&lt;br /&gt;
According to the [https://codeclimate.com codeclimate] which calculate the complexity of the method, originally, it has a complexity of '''85''', however, after we modified it, the complexity goes down to '''65'''. Please check at [https://codeclimate.com/github/expertiza/expertiza/GradesController original version],[https://codeclimate.com/github/maxlpy/expertiza/GradesController modified version]&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Used for loop with selective choice to create penalty attributes and put it into the '''CalculatedPenalty''' Table, instead of duplicating the almost same code.&lt;br /&gt;
&lt;br /&gt;
*Used Object-Oriented Design patterns of Ruby: let the array respond to the method '''min''' which returns the minimum number in the array and get the logical penalty other than using if statement.(max_penalty if total_penalty is larger than max_penalty,  total_penalty if total_penalty is smaller than max_penalty)&lt;br /&gt;
&lt;br /&gt;
*Eliminated the unnecessary if statements to make the code clear to read.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
&lt;br /&gt;
*Modify if statements:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(penalties[:submission].nil?)&lt;br /&gt;
      penalties[:submission]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:review].nil?)&lt;br /&gt;
      penalties[:review]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:meta_review].nil?)&lt;br /&gt;
      penalties[:meta_review]=0&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
penalties[:submission] = 0 if penalties[:submission].nil?&lt;br /&gt;
penalties[:review] = 0 if penalties[:review].nil?&lt;br /&gt;
penalties[:meta_review] = 0 if penalties[:meta_review].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Using Objected-oriented Pattern&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(@total_penalty &amp;gt; l_policy.max_penalty)&lt;br /&gt;
      @total_penalty = l_policy.max_penalty&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @total_penality=[l_policy.max_penalty,@total_penality].min&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Using loops rather than duplicate same code&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 penalty_attr1 = {:deadline_type_id =&amp;gt; 1,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:submission]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr1)&lt;br /&gt;
 penalty_attr2 = {:deadline_type_id =&amp;gt; 2,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr2)&lt;br /&gt;
 penalty_attr3 = {:deadline_type_id =&amp;gt; 5,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:meta_review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr3)&amp;quot;&lt;br /&gt;
 @all_penalties[participant.id] = Hash.new&lt;br /&gt;
       @all_penalties[participant.id][:submission] = penalties[:submission]&lt;br /&gt;
       @all_penalties[participant.id][:review] = penalties[:review]&lt;br /&gt;
       @all_penalties[participant.id][:meta_review] = penalties[:meta_review]&lt;br /&gt;
       @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 deadline_type=[1,2,5]&lt;br /&gt;
 penalty_type=[:submission,:review,:meta_review]&lt;br /&gt;
 if calculate_for_participants&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
           penalty_attr={:deadline_type_id=&amp;gt;deadline_type[i],:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[penalty_type[i]]}&lt;br /&gt;
           CalculatedPenalty.create(penalty_attr)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
 @all_penalties[participant.id] = {}&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
          @all_penalties[participant.id][:penalty_type[i]] = penalties[:penalty_type[i]]&lt;br /&gt;
      end&lt;br /&gt;
 @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== conflict_notification Method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored the '''conflict_notification''' method to '''conflict_email''' method. When instructor click the button &amp;quot;email reviewer&amp;quot; whom he thought give a unfair review, the system should be able to send an email to the reviewer automatically.The '''get_body_text''' and '''send_grading_email''' were removed from the controller. The sending email function is well simplified and delegated to a conflict_mailer.&lt;br /&gt;
&lt;br /&gt;
===Design Pattern===&lt;br /&gt;
Delegation: The conflict_email should be able to send email. The class ConflictMailer works as its delegate .The conflict_email calls the send_conflict_email fuction to take the job of sending a email. &lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
The old '''conflict_notification''' action queries an email address list of a certain kind of reviews. In its view conflict_notification.html.erb, A email form contains email list for instructor to choose from and email content. &lt;br /&gt;
[[File:old_email.png]]&lt;br /&gt;
&lt;br /&gt;
'''Before Refactoring''', in conflict_notification:&lt;br /&gt;
First,Get the instructor email address as sender&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
      if session[:user].role_id !=6             &lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
      @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
      @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then,Based on submission of review, the action query all the reviewers' email address  &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @questions = Hash.new&lt;br /&gt;
      questionnaires = @assignment.questionnaires&lt;br /&gt;
      questionnaires.each {&lt;br /&gt;
        |questionnaire|&lt;br /&gt;
        @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The email list is for instructor to choose from. The process_response method queries the email address.    &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @reviewers_email_hash = Hash.new            &lt;br /&gt;
      @caction = &amp;quot;view&amp;quot;&lt;br /&gt;
      @submission = params[:submission]&lt;br /&gt;
      if @submission == &amp;quot;review&amp;quot;&lt;br /&gt;
        @caction = &amp;quot;view_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;review&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.reviews, &amp;quot;ReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_of_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;metareview&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Metareview&amp;quot;, &amp;quot;Metareviewer&amp;quot;, @participant.metareviews, &amp;quot;MetareviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_feedback&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;feedback&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Feedback&amp;quot;, &amp;quot;Author&amp;quot;, @participant.feedback, &amp;quot;AuthorFeedbackQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;teammate_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;teammate&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Teammate Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.teammate_reviews, &amp;quot;TeammateReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The get_body_text method construct email content which should be removed from controller.&lt;br /&gt;
&amp;lt;pre&amp;gt;                                               &lt;br /&gt;
      @body = get_body_text(params[:submission])      &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The conflict_notification action requiring another two method &amp;quot;process_response&amp;quot; and &amp;quot;get_body_text&amp;quot; method to get the recipient email list and email content which contributes to extra complexity. The instructor only have to click the button &amp;quot;send email&amp;quot; in conflict_notification.html.erb and turn to send_conflict_email action, then he/she can send the email. If the instructor want to send another email, the process will repeat again,which will be terrible when reloading the &amp;quot;view&amp;quot; scores page.&lt;br /&gt;
&lt;br /&gt;
'''After Refactoring''':The quering reiviews actually have done in our show_reviews action, and we can get the individual reviewers' email address.In the reviewer table,we add extra button &amp;quot;email reviewer&amp;quot;.Now the instructor could send to reviewer email directly.&lt;br /&gt;
[[File:conflict_email.png]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In _review_table.html.erb,we add the link to send email. The review_id is passed to the conflict_email action taken as the recipient.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%= link_to 'email reviewer', :action =&amp;gt; 'conflict_email',:remote=&amp;gt; true,:reviewer_id=&amp;gt; &lt;br /&gt;
&lt;br /&gt;
review.map.reviewer.user,:participant_id=&amp;gt;participant,:score=&amp;gt;sprintf(&amp;quot;%.2f&amp;quot;,score) %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In our new '''conflict_email''' action:&lt;br /&gt;
&lt;br /&gt;
We still need the instructor as the sender &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      if session[:user].role_id !=6&lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The reviewer_id is passed from the link,we can query his/her email address to send the email &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      recipient=User.find(params[:reviewer_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The responsibility of sending email has been delegated to a new mailer conflict_mailer. And the email content was constructed in the mailer.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      participant = AssignmentParticipant.find(params[:participant_id])&lt;br /&gt;
      assignment=Assignment.find(participant.parent_id)      &lt;br /&gt;
      score=params[:score]&lt;br /&gt;
      ConflictMailer.send_conflict_email(instructor,recipient,assignment,score).deliver&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Take a look at new conflict_mailer, it define a '''send_conflict_email''' method. the email was sent from sender's email and to reviewer's email.Some instance variables were used in view.&lt;br /&gt;
In conflict_mailer.erb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def send_conflict_email(sender,recipient,assignment,score)&lt;br /&gt;
      @assignment=assignment&lt;br /&gt;
      @recipient=recipient&lt;br /&gt;
      @score=score&lt;br /&gt;
      if recipient.role_id==1&lt;br /&gt;
        @role = &amp;quot;reviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;submission&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
        @role = &amp;quot;metareviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;review&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
    mail subject: &amp;quot;Conflication Email&amp;quot;,from: sender.email,to: reviewer.email&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In its view send_conflict_email.txt.haml, we edit the email content.By this way, we deleted the '''get_body_text''' and well followed the rule of MVC design&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%h1=&amp;quot;Hi ,&amp;quot; +@recipient.name&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;You submitted a score of &amp;quot;+@score+&amp;quot; for assignment &amp;quot;+@assignment.name+&amp;quot; that varied greatly from another &amp;quot;+@role+&amp;quot;'s score for the same &amp;quot;+@item+&amp;quot;.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;The Expertiza system has brought this to my attention.&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The link &amp;quot;email reviewer&amp;quot; request a ajax,so the current view page will not refresh when the action done&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      respond_to do |format|&lt;br /&gt;
        format.js&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If an email was successfully sent,The instructor should get the alert window by ajax.&lt;br /&gt;
[[File:email_sent.png]]&lt;br /&gt;
&lt;br /&gt;
=== view_my_scores method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored '''view_my_scores''' method to grades_show, deleted many unnecessary instance variables along with several review and meta reviews methods inside it. Therefore, the system will only search for scores in the database rather than search for scores and reviews, which wastes a lot of time during the grade show process. After refactoring, the complexity on this decreased from '''53''' to '''35'''.&lt;br /&gt;
We also optimize '''get_scores''' method to improve the efficiency of showing scores by students and instructors, which cost us most of the time during the project. After refactoring this method, the time cost of views in grade controller decreased by more than '''90%'''.&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Refactored '''view_my_scores''' method to '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Searched for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
&lt;br /&gt;
*Eliminated the search for reviews during the '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Deleted unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
*Deleted the unnecessary instance variables&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_score_results = Array.new&lt;br /&gt;
 @average_score_results = ScoreCache.get_class_scores(@participant.id)&lt;br /&gt;
 @statistics = Array.new&lt;br /&gt;
 @average_score_results.each { |x|&lt;br /&gt;
 @statistics &amp;lt;&amp;lt; x&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Deleted query for reviews and meta_reviews&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_reviews = ScoreCache.get_reviews_average(@participant.id)&lt;br /&gt;
 @average_metareviews = ScoreCache.get_metareviews_average(@participant.id)&lt;br /&gt;
 @my_reviews = ScoreCache.my_reviews(@participant.id)&lt;br /&gt;
 @my_metareviews = ScoreCache.my_metareviews(@participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Add a new method into grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
Add Method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 #show_reviews method gets reviews, meta reviews and author feedback information from server.&lt;br /&gt;
  def show_reviews&lt;br /&gt;
    @partial='grades/'+params[:path]&lt;br /&gt;
    @prefix=params[:prefix]&lt;br /&gt;
    @score=Hash.new&lt;br /&gt;
    @score[:assessments]=Array.new&lt;br /&gt;
    params[:score][:assessments].each do |assessment|&lt;br /&gt;
        @score[:assessments]&amp;lt;&amp;lt;Response.find(assessment)&lt;br /&gt;
    end&lt;br /&gt;
    @score[:scores]=params[:score][:scores]&lt;br /&gt;
    @participant=AssignmentParticipant.find(params[:participant])&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @questions = {}&lt;br /&gt;
    questionnaires = @assignment.questionnaires&lt;br /&gt;
    questionnaires.each do |questionnaire|&lt;br /&gt;
      @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Change view_my_score.html.erb into show_reviews.html.erb in views.&lt;br /&gt;
&lt;br /&gt;
*Add in views(show_reviews.html.erb)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;%= render :partial=&amp;gt;@partial, :locals =&amp;gt; {:prefix =&amp;gt; @prefix, :participant =&amp;gt; @participant, :rscore =&amp;gt; @score} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Result====&lt;br /&gt;
*The following test results based on the test case on Expertiza(Assignments: Program 2 style) &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89820</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1466 gjf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89820"/>
		<updated>2014-10-27T02:47:56Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Design Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1466: Refactoring GradesController==&lt;br /&gt;
&lt;br /&gt;
This wiki deals with our implementation of a controller in expertiza: [https://github.com/expertiza/expertiza/blob/rails4/app/controllers/grades_controller.rb grade_controller]  for the Expertiza Project using Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Classes involved:''' grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''What it does:'''&lt;br /&gt;
&lt;br /&gt;
This class lists the grades of all the participants for an assignments and also their reviews. Instructor can edit scores, calculate penalties and send emails for conflicts.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&lt;br /&gt;
*Modify '''calculate_all_penalties''' method which is too complex and long.&lt;br /&gt;
*Put the '''get_body_text''' method in a mailer rather than in the grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactor '''view_my_scores''' method to '''grades_show''' and delete the unnecessary variables.&lt;br /&gt;
*Try not to query for reviews and meta reviews in '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
'''What we have done:'''&lt;br /&gt;
*Modify '''calculate_all_penalties''' method.&lt;br /&gt;
*Put the '''get_body_text''' method in a mailer rather than in the grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactored view_my_scores method to grades_show method.&lt;br /&gt;
*Searched for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
*Eliminated the search for reviews during the grades_show method.&lt;br /&gt;
*Deleted unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
==Code Modification==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== calculate_all_penalties Method===&lt;br /&gt;
====Summary====&lt;br /&gt;
&lt;br /&gt;
We have modified the calculate_penalties method and implemented all the functions it originally has. After our modification the method shrinks from 45 lines to 32 lines of Ruby code. Originally, the method includes a lot of unnecessary if and unless statements which makes the method uneasy to read and seems to have a difficult logic to calculate the penalties. &lt;br /&gt;
&lt;br /&gt;
According to the [https://codeclimate.com codeclimate] which calculate the complexity of the method, originally, it has a complexity of '''85''', however, after we modified it, the complexity goes down to '''65'''. Please check at [https://codeclimate.com/github/expertiza/expertiza/GradesController original version],[https://codeclimate.com/github/maxlpy/expertiza/GradesController modified version]&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Used for loop with selective choice to create penalty attributes and put it into the '''CalculatedPenalty''' Table, instead of duplicating the almost same code.&lt;br /&gt;
&lt;br /&gt;
*Used Object-Oriented Design patterns of Ruby: let the array respond to the method '''min''' which returns the minimum number in the array and get the logical penalty other than using if statement.(max_penalty if total_penalty is larger than max_penalty,  total_penalty if total_penalty is smaller than max_penalty)&lt;br /&gt;
&lt;br /&gt;
*Eliminated the unnecessary if statements to make the code clear to read.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
&lt;br /&gt;
*Modify if statements:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(penalties[:submission].nil?)&lt;br /&gt;
      penalties[:submission]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:review].nil?)&lt;br /&gt;
      penalties[:review]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:meta_review].nil?)&lt;br /&gt;
      penalties[:meta_review]=0&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
penalties[:submission] = 0 if penalties[:submission].nil?&lt;br /&gt;
penalties[:review] = 0 if penalties[:review].nil?&lt;br /&gt;
penalties[:meta_review] = 0 if penalties[:meta_review].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Using Objected-oriented Pattern&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(@total_penalty &amp;gt; l_policy.max_penalty)&lt;br /&gt;
      @total_penalty = l_policy.max_penalty&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @total_penality=[l_policy.max_penalty,@total_penality].min&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Using loops rather than duplicate same code&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 penalty_attr1 = {:deadline_type_id =&amp;gt; 1,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:submission]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr1)&lt;br /&gt;
 penalty_attr2 = {:deadline_type_id =&amp;gt; 2,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr2)&lt;br /&gt;
 penalty_attr3 = {:deadline_type_id =&amp;gt; 5,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:meta_review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr3)&amp;quot;&lt;br /&gt;
 @all_penalties[participant.id] = Hash.new&lt;br /&gt;
       @all_penalties[participant.id][:submission] = penalties[:submission]&lt;br /&gt;
       @all_penalties[participant.id][:review] = penalties[:review]&lt;br /&gt;
       @all_penalties[participant.id][:meta_review] = penalties[:meta_review]&lt;br /&gt;
       @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 deadline_type=[1,2,5]&lt;br /&gt;
 penalty_type=[:submission,:review,:meta_review]&lt;br /&gt;
 if calculate_for_participants&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
           penalty_attr={:deadline_type_id=&amp;gt;deadline_type[i],:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[penalty_type[i]]}&lt;br /&gt;
           CalculatedPenalty.create(penalty_attr)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
 @all_penalties[participant.id] = {}&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
          @all_penalties[participant.id][:penalty_type[i]] = penalties[:penalty_type[i]]&lt;br /&gt;
      end&lt;br /&gt;
 @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== conflict_notification Method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored the '''conflict_notification''' method to '''conflict_email''' method. When instructor click the button &amp;quot;email reviewer&amp;quot; whom he thought give a unfair review, the system should be able to send an email to the reviewer automatically.The '''get_body_text''' and '''send_grading_email''' were removed from the controller. The sending email function is well simplified and delegated to a conflict_mailer.&lt;br /&gt;
&lt;br /&gt;
===Design Pattern===&lt;br /&gt;
Delegation: The conflict_email should be able to send email. The class ConflictMailer works as its delegate .The conflict_email calls the send_conflict_email fuction to take the job of sending a email. &lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
The old '''conflict_notification''' action queries an email address list of a certain kind of reviews. In its view conflict_notification.html.erb, A email form contains email list for instructor to choose from and email content. &lt;br /&gt;
[[File:old_email.png]]&lt;br /&gt;
&lt;br /&gt;
'''Before Refactoring''', in conflict_notification:&lt;br /&gt;
First,Get the instructor email address as sender&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
      if session[:user].role_id !=6             &lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
      @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
      @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then,Based on submission of review, the action query all the reviewers' email address  &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @questions = Hash.new&lt;br /&gt;
      questionnaires = @assignment.questionnaires&lt;br /&gt;
      questionnaires.each {&lt;br /&gt;
        |questionnaire|&lt;br /&gt;
        @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The email list is for instructor to choose from. The process_response method queries the email address.    &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @reviewers_email_hash = Hash.new            &lt;br /&gt;
      @caction = &amp;quot;view&amp;quot;&lt;br /&gt;
      @submission = params[:submission]&lt;br /&gt;
      if @submission == &amp;quot;review&amp;quot;&lt;br /&gt;
        @caction = &amp;quot;view_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;review&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.reviews, &amp;quot;ReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_of_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;metareview&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Metareview&amp;quot;, &amp;quot;Metareviewer&amp;quot;, @participant.metareviews, &amp;quot;MetareviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_feedback&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;feedback&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Feedback&amp;quot;, &amp;quot;Author&amp;quot;, @participant.feedback, &amp;quot;AuthorFeedbackQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;teammate_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;teammate&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Teammate Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.teammate_reviews, &amp;quot;TeammateReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The get_body_text method construct email content which should be removed from controller.&lt;br /&gt;
&amp;lt;pre&amp;gt;                                               &lt;br /&gt;
      @body = get_body_text(params[:submission])      &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The conflict_notification action requiring another two method &amp;quot;process_response&amp;quot; and &amp;quot;get_body_text&amp;quot; method to get the recipient email list and email content which contributes to extra complexity. The instructor only have to click the button &amp;quot;send email&amp;quot; in conflict_notification.html.erb and turn to send_conflict_email action, then he/she can send the email. If the instructor want to send another email, the process will repeat again,which will be terrible when reloading the &amp;quot;view&amp;quot; scores page.&lt;br /&gt;
&lt;br /&gt;
'''After Refactoring''':The quering reiviews actually have done in our show_reviews action, and we can get the individual reviewers' email address.In the reviewer table,we add extra button &amp;quot;email reviewer&amp;quot;.Now the instructor could send to reviewer email directly.&lt;br /&gt;
[[File:conflict_email.png]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In _review_table.html.erb,we add the link to send email. The review_id is passed to the conflict_email action taken as the recipient.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%= link_to 'email reviewer', :action =&amp;gt; 'conflict_email',:remote=&amp;gt; true,:reviewer_id=&amp;gt; &lt;br /&gt;
&lt;br /&gt;
review.map.reviewer.user,:participant_id=&amp;gt;participant,:score=&amp;gt;sprintf(&amp;quot;%.2f&amp;quot;,score) %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In our new '''conflict_email''' action:&lt;br /&gt;
&lt;br /&gt;
We still need the instructor as the sender &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      if session[:user].role_id !=6&lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The reviewer_id is passed from the link,we can query his/her email address to send the email &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      recipient=User.find(params[:reviewer_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The responsibility of sending email has been delegated to a new mailer conflict_mailer. And the email content was constructed in the mailer.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      participant = AssignmentParticipant.find(params[:participant_id])&lt;br /&gt;
      assignment=Assignment.find(participant.parent_id)      &lt;br /&gt;
      score=params[:score]&lt;br /&gt;
      ConflictMailer.send_conflict_email(instructor,recipient,assignment,score).deliver&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Take a look at new conflict_mailer, it define a '''send_conflict_email''' method. the email was sent from sender's email and to reviewer's email.Some instance variables were used in view.&lt;br /&gt;
In conflict_mailer.erb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def send_conflict_email(sender,recipient,assignment,score)&lt;br /&gt;
      @assignment=assignment&lt;br /&gt;
      @recipient=recipient&lt;br /&gt;
      @score=score&lt;br /&gt;
      if recipient.role_id==1&lt;br /&gt;
        @role = &amp;quot;reviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;submission&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
        @role = &amp;quot;metareviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;review&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
    mail subject: &amp;quot;Conflication Email&amp;quot;,from: sender.email,to: reviewer.email&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In its view send_conflict_email.txt.haml, we edit the email content.By this way, we deleted the '''get_body_text''' and well followed the rule of MVC design&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%h1=&amp;quot;Hi ,&amp;quot; +@recipient.name&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;You submitted a score of &amp;quot;+@score+&amp;quot; for assignment &amp;quot;+@assignment.name+&amp;quot; that varied greatly from another &amp;quot;+@role+&amp;quot;'s score for the same &amp;quot;+@item+&amp;quot;.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;The Expertiza system has brought this to my attention.&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The link &amp;quot;email reviewer&amp;quot; request a ajax,so the current view page will not refresh when the action done&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      respond_to do |format|&lt;br /&gt;
        format.js&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If an email was successfully sent,The instructor should get the alert window by ajax.&lt;br /&gt;
[[File:email_sent.png]]&lt;br /&gt;
&lt;br /&gt;
=== view_my_scores method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored '''view_my_scores''' method to grades_show, deleted many unnecessary instance variables along with several review and meta reviews methods inside it. Therefore, the system will only search for scores in the database rather than search for scores and reviews, which wastes a lot of time during the grade show process. After refactoring, the complexity on this decreased from '''53''' to '''35'''.&lt;br /&gt;
We also optimize '''get_scores''' method to improve the efficiency of showing scores by students and instructors, which cost us most of the time during the project. After refactoring this method, the time cost of views in grade controller decreased by more than '''90%'''.&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Refactored '''view_my_scores''' method to '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Searched for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
&lt;br /&gt;
*Eliminated the search for reviews during the '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Deleted unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
*Deleted the unnecessary instance variables&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_score_results = Array.new&lt;br /&gt;
 @average_score_results = ScoreCache.get_class_scores(@participant.id)&lt;br /&gt;
 @statistics = Array.new&lt;br /&gt;
 @average_score_results.each { |x|&lt;br /&gt;
 @statistics &amp;lt;&amp;lt; x&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Deleted query for reviews and meta_reviews&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_reviews = ScoreCache.get_reviews_average(@participant.id)&lt;br /&gt;
 @average_metareviews = ScoreCache.get_metareviews_average(@participant.id)&lt;br /&gt;
 @my_reviews = ScoreCache.my_reviews(@participant.id)&lt;br /&gt;
 @my_metareviews = ScoreCache.my_metareviews(@participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Add a new method into grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
Add Method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 #show_reviews method gets reviews, meta reviews and author feedback information from server.&lt;br /&gt;
  def show_reviews&lt;br /&gt;
    @partial='grades/'+params[:path]&lt;br /&gt;
    @prefix=params[:prefix]&lt;br /&gt;
    @score=Hash.new&lt;br /&gt;
    @score[:assessments]=Array.new&lt;br /&gt;
    params[:score][:assessments].each do |assessment|&lt;br /&gt;
        @score[:assessments]&amp;lt;&amp;lt;Response.find(assessment)&lt;br /&gt;
    end&lt;br /&gt;
    @score[:scores]=params[:score][:scores]&lt;br /&gt;
    @participant=AssignmentParticipant.find(params[:participant])&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @questions = {}&lt;br /&gt;
    questionnaires = @assignment.questionnaires&lt;br /&gt;
    questionnaires.each do |questionnaire|&lt;br /&gt;
      @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Change view_my_score.html.erb into show_reviews.html.erb in views.&lt;br /&gt;
&lt;br /&gt;
*Add in views(show_reviews.html.erb)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;%= render :partial=&amp;gt;@partial, :locals =&amp;gt; {:prefix =&amp;gt; @prefix, :participant =&amp;gt; @participant, :rscore =&amp;gt; @score} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Result====&lt;br /&gt;
*The following test results based on the test case on Expertiza(Assignments: Program 2 style) &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89818</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1466 gjf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89818"/>
		<updated>2014-10-27T02:45:57Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1466: Refactoring GradesController==&lt;br /&gt;
&lt;br /&gt;
This wiki deals with our implementation of a controller in expertiza: [https://github.com/expertiza/expertiza/blob/rails4/app/controllers/grades_controller.rb grade_controller]  for the Expertiza Project using Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Classes involved:''' grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''What it does:'''&lt;br /&gt;
&lt;br /&gt;
This class lists the grades of all the participants for an assignments and also their reviews. Instructor can edit scores, calculate penalties and send emails for conflicts.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&lt;br /&gt;
*Modify '''calculate_all_penalties''' method which is too complex and long.&lt;br /&gt;
*Put the '''get_body_text''' method in a mailer rather than in the grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactor '''view_my_scores''' method to '''grades_show''' and delete the unnecessary variables.&lt;br /&gt;
*Try not to query for reviews and meta reviews in '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
'''What we have done:'''&lt;br /&gt;
*Modify '''calculate_all_penalties''' method.&lt;br /&gt;
*Put the '''get_body_text''' method in a mailer rather than in the grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactored view_my_scores method to grades_show method.&lt;br /&gt;
*Searched for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
*Eliminated the search for reviews during the grades_show method.&lt;br /&gt;
*Deleted unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
==Code Modification==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== calculate_all_penalties Method===&lt;br /&gt;
====Summary====&lt;br /&gt;
&lt;br /&gt;
We have modified the calculate_penalties method and implemented all the functions it originally has. After our modification the method shrinks from 45 lines to 32 lines of Ruby code. Originally, the method includes a lot of unnecessary if and unless statements which makes the method uneasy to read and seems to have a difficult logic to calculate the penalties. &lt;br /&gt;
&lt;br /&gt;
According to the [https://codeclimate.com codeclimate] which calculate the complexity of the method, originally, it has a complexity of '''85''', however, after we modified it, the complexity goes down to '''65'''. Please check at [https://codeclimate.com/github/expertiza/expertiza/GradesController original version],[https://codeclimate.com/github/maxlpy/expertiza/GradesController modified version]&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Used for loop with selective choice to create penalty attributes and put it into the '''CalculatedPenalty''' Table, instead of duplicating the almost same code.&lt;br /&gt;
&lt;br /&gt;
*Used Object-Oriented Design patterns of Ruby: let the array respond to the method '''min''' which returns the minimum number in the array and get the logical penalty other than using if statement.(max_penalty if total_penalty is larger than max_penalty,  total_penalty if total_penalty is smaller than max_penalty)&lt;br /&gt;
&lt;br /&gt;
*Eliminated the unnecessary if statements to make the code clear to read.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
&lt;br /&gt;
*Modify if statements:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(penalties[:submission].nil?)&lt;br /&gt;
      penalties[:submission]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:review].nil?)&lt;br /&gt;
      penalties[:review]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:meta_review].nil?)&lt;br /&gt;
      penalties[:meta_review]=0&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
penalties[:submission] = 0 if penalties[:submission].nil?&lt;br /&gt;
penalties[:review] = 0 if penalties[:review].nil?&lt;br /&gt;
penalties[:meta_review] = 0 if penalties[:meta_review].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Using Objected-oriented Pattern&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(@total_penalty &amp;gt; l_policy.max_penalty)&lt;br /&gt;
      @total_penalty = l_policy.max_penalty&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @total_penality=[l_policy.max_penalty,@total_penality].min&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Using loops rather than duplicate same code&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 penalty_attr1 = {:deadline_type_id =&amp;gt; 1,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:submission]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr1)&lt;br /&gt;
 penalty_attr2 = {:deadline_type_id =&amp;gt; 2,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr2)&lt;br /&gt;
 penalty_attr3 = {:deadline_type_id =&amp;gt; 5,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:meta_review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr3)&amp;quot;&lt;br /&gt;
 @all_penalties[participant.id] = Hash.new&lt;br /&gt;
       @all_penalties[participant.id][:submission] = penalties[:submission]&lt;br /&gt;
       @all_penalties[participant.id][:review] = penalties[:review]&lt;br /&gt;
       @all_penalties[participant.id][:meta_review] = penalties[:meta_review]&lt;br /&gt;
       @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 deadline_type=[1,2,5]&lt;br /&gt;
 penalty_type=[:submission,:review,:meta_review]&lt;br /&gt;
 if calculate_for_participants&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
           penalty_attr={:deadline_type_id=&amp;gt;deadline_type[i],:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[penalty_type[i]]}&lt;br /&gt;
           CalculatedPenalty.create(penalty_attr)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
 @all_penalties[participant.id] = {}&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
          @all_penalties[participant.id][:penalty_type[i]] = penalties[:penalty_type[i]]&lt;br /&gt;
      end&lt;br /&gt;
 @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== conflict_notification Method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored the '''conflict_notification''' method to '''conflict_email''' method. When instructor click the button &amp;quot;email reviewer&amp;quot; whom he thought give a unfair review, the system should be able to send an email to the reviewer automatically.The '''get_body_text''' and '''send_grading_email''' were removed from the controller. The sending email function is well simplified and delegated to a conflict_mailer.&lt;br /&gt;
&lt;br /&gt;
===Design Pattern===&lt;br /&gt;
Delegation: The conflict_email should be able to send email. The class ConflictMailer works as its delegate and takes the job to send a email.The conflict_email calls the&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
The old '''conflict_notification''' action queries an email address list of a certain kind of reviews. In its view conflict_notification.html.erb, A email form contains email list for instructor to choose from and email content. &lt;br /&gt;
[[File:old_email.png]]&lt;br /&gt;
&lt;br /&gt;
'''Before Refactoring''', in conflict_notification:&lt;br /&gt;
First,Get the instructor email address as sender&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
      if session[:user].role_id !=6             &lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
      @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
      @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then,Based on submission of review, the action query all the reviewers' email address  &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @questions = Hash.new&lt;br /&gt;
      questionnaires = @assignment.questionnaires&lt;br /&gt;
      questionnaires.each {&lt;br /&gt;
        |questionnaire|&lt;br /&gt;
        @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The email list is for instructor to choose from. The process_response method queries the email address.    &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @reviewers_email_hash = Hash.new            &lt;br /&gt;
      @caction = &amp;quot;view&amp;quot;&lt;br /&gt;
      @submission = params[:submission]&lt;br /&gt;
      if @submission == &amp;quot;review&amp;quot;&lt;br /&gt;
        @caction = &amp;quot;view_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;review&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.reviews, &amp;quot;ReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_of_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;metareview&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Metareview&amp;quot;, &amp;quot;Metareviewer&amp;quot;, @participant.metareviews, &amp;quot;MetareviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_feedback&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;feedback&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Feedback&amp;quot;, &amp;quot;Author&amp;quot;, @participant.feedback, &amp;quot;AuthorFeedbackQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;teammate_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;teammate&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Teammate Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.teammate_reviews, &amp;quot;TeammateReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The get_body_text method construct email content which should be removed from controller.&lt;br /&gt;
&amp;lt;pre&amp;gt;                                               &lt;br /&gt;
      @body = get_body_text(params[:submission])      &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The conflict_notification action requiring another two method &amp;quot;process_response&amp;quot; and &amp;quot;get_body_text&amp;quot; method to get the recipient email list and email content which contributes to extra complexity. The instructor only have to click the button &amp;quot;send email&amp;quot; in conflict_notification.html.erb and turn to send_conflict_email action, then he/she can send the email. If the instructor want to send another email, the process will repeat again,which will be terrible when reloading the &amp;quot;view&amp;quot; scores page.&lt;br /&gt;
&lt;br /&gt;
'''After Refactoring''':The quering reiviews actually have done in our show_reviews action, and we can get the individual reviewers' email address.In the reviewer table,we add extra button &amp;quot;email reviewer&amp;quot;.Now the instructor could send to reviewer email directly.&lt;br /&gt;
[[File:conflict_email.png]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In _review_table.html.erb,we add the link to send email. The review_id is passed to the conflict_email action taken as the recipient.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%= link_to 'email reviewer', :action =&amp;gt; 'conflict_email',:remote=&amp;gt; true,:reviewer_id=&amp;gt; &lt;br /&gt;
&lt;br /&gt;
review.map.reviewer.user,:participant_id=&amp;gt;participant,:score=&amp;gt;sprintf(&amp;quot;%.2f&amp;quot;,score) %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In our new '''conflict_email''' action:&lt;br /&gt;
&lt;br /&gt;
We still need the instructor as the sender &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      if session[:user].role_id !=6&lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The reviewer_id is passed from the link,we can query his/her email address to send the email &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      recipient=User.find(params[:reviewer_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The responsibility of sending email has been delegated to a new mailer conflict_mailer. And the email content was constructed in the mailer.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      participant = AssignmentParticipant.find(params[:participant_id])&lt;br /&gt;
      assignment=Assignment.find(participant.parent_id)      &lt;br /&gt;
      score=params[:score]&lt;br /&gt;
      ConflictMailer.send_conflict_email(instructor,recipient,assignment,score).deliver&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Take a look at new conflict_mailer, it define a '''send_conflict_email''' method. the email was sent from sender's email and to reviewer's email.Some instance variables were used in view.&lt;br /&gt;
In conflict_mailer.erb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def send_conflict_email(sender,recipient,assignment,score)&lt;br /&gt;
      @assignment=assignment&lt;br /&gt;
      @recipient=recipient&lt;br /&gt;
      @score=score&lt;br /&gt;
      if recipient.role_id==1&lt;br /&gt;
        @role = &amp;quot;reviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;submission&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
        @role = &amp;quot;metareviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;review&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
    mail subject: &amp;quot;Conflication Email&amp;quot;,from: sender.email,to: reviewer.email&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In its view send_conflict_email.txt.haml, we edit the email content.By this way, we deleted the '''get_body_text''' and well followed the rule of MVC design&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%h1=&amp;quot;Hi ,&amp;quot; +@recipient.name&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;You submitted a score of &amp;quot;+@score+&amp;quot; for assignment &amp;quot;+@assignment.name+&amp;quot; that varied greatly from another &amp;quot;+@role+&amp;quot;'s score for the same &amp;quot;+@item+&amp;quot;.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;The Expertiza system has brought this to my attention.&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The link &amp;quot;email reviewer&amp;quot; request a ajax,so the current view page will not refresh when the action done&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      respond_to do |format|&lt;br /&gt;
        format.js&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If an email was successfully sent,The instructor should get the alert window by ajax.&lt;br /&gt;
[[File:email_sent.png]]&lt;br /&gt;
&lt;br /&gt;
=== view_my_scores method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored '''view_my_scores''' method to grades_show, deleted many unnecessary instance variables along with several review and meta reviews methods inside it. Therefore, the system will only search for scores in the database rather than search for scores and reviews, which wastes a lot of time during the grade show process. After refactoring, the complexity on this decreased from '''53''' to '''35'''.&lt;br /&gt;
We also optimize '''get_scores''' method to improve the efficiency of showing scores by students and instructors, which cost us most of the time during the project. After refactoring this method, the time cost of views in grade controller decreased by more than '''90%'''.&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Refactored '''view_my_scores''' method to '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Searched for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
&lt;br /&gt;
*Eliminated the search for reviews during the '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Deleted unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
*Deleted the unnecessary instance variables&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_score_results = Array.new&lt;br /&gt;
 @average_score_results = ScoreCache.get_class_scores(@participant.id)&lt;br /&gt;
 @statistics = Array.new&lt;br /&gt;
 @average_score_results.each { |x|&lt;br /&gt;
 @statistics &amp;lt;&amp;lt; x&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Deleted query for reviews and meta_reviews&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_reviews = ScoreCache.get_reviews_average(@participant.id)&lt;br /&gt;
 @average_metareviews = ScoreCache.get_metareviews_average(@participant.id)&lt;br /&gt;
 @my_reviews = ScoreCache.my_reviews(@participant.id)&lt;br /&gt;
 @my_metareviews = ScoreCache.my_metareviews(@participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Add a new method into grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
Add Method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 #show_reviews method gets reviews, meta reviews and author feedback information from server.&lt;br /&gt;
  def show_reviews&lt;br /&gt;
    @partial='grades/'+params[:path]&lt;br /&gt;
    @prefix=params[:prefix]&lt;br /&gt;
    @score=Hash.new&lt;br /&gt;
    @score[:assessments]=Array.new&lt;br /&gt;
    params[:score][:assessments].each do |assessment|&lt;br /&gt;
        @score[:assessments]&amp;lt;&amp;lt;Response.find(assessment)&lt;br /&gt;
    end&lt;br /&gt;
    @score[:scores]=params[:score][:scores]&lt;br /&gt;
    @participant=AssignmentParticipant.find(params[:participant])&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @questions = {}&lt;br /&gt;
    questionnaires = @assignment.questionnaires&lt;br /&gt;
    questionnaires.each do |questionnaire|&lt;br /&gt;
      @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Change view_my_score.html.erb into show_reviews.html.erb in views.&lt;br /&gt;
&lt;br /&gt;
*Add in views(show_reviews.html.erb)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;%= render :partial=&amp;gt;@partial, :locals =&amp;gt; {:prefix =&amp;gt; @prefix, :participant =&amp;gt; @participant, :rscore =&amp;gt; @score} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Result====&lt;br /&gt;
*The following test results based on the test case on Expertiza(Assignments: Program 2 style) &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89817</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1466 gjf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89817"/>
		<updated>2014-10-27T02:45:14Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1466: Refactoring GradesController==&lt;br /&gt;
&lt;br /&gt;
This wiki deals with our implementation of a controller in expertiza: [https://github.com/expertiza/expertiza/blob/rails4/app/controllers/grades_controller.rb grade_controller]  for the Expertiza Project using Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Classes involved:''' grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''What it does:'''&lt;br /&gt;
&lt;br /&gt;
This class lists the grades of all the participants for an assignments and also their reviews. Instructor can edit scores, calculate penalties and send emails for conflicts.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&lt;br /&gt;
*Modify '''calculate_all_penalties''' method which is too complex and long.&lt;br /&gt;
*Put the '''get_body_text''' method in a mailer rather than in the grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactor '''view_my_scores''' method to '''grades_show''' and delete the unnecessary variables.&lt;br /&gt;
*Try not to query for reviews and meta reviews in '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
'''What we have done:'''&lt;br /&gt;
*Modify '''calculate_all_penalties''' method.&lt;br /&gt;
*Put the '''get_body_text''' method in a mailer rather than in the grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactored view_my_scores method to grades_show method.&lt;br /&gt;
*Searched for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
*Eliminated the search for reviews during the grades_show method.&lt;br /&gt;
*Deleted unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
==Code Modification==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== calculate_all_penalties Method===&lt;br /&gt;
====Summary====&lt;br /&gt;
&lt;br /&gt;
We have modified the calculate_penalties method and implemented all the functions it originally has. After our modification the method shrinks from 45 lines to 32 lines of Ruby code. Originally, the method includes a lot of unnecessary if and unless statements which makes the method uneasy to read and seems to have a difficult logic to calculate the penalties. &lt;br /&gt;
&lt;br /&gt;
According to the [https://codeclimate.com codeclimate] which calculate the complexity of the method, originally, it has a complexity of '''85''', however, after we modified it, the complexity goes down to '''65'''. Please check at [https://codeclimate.com/github/expertiza/expertiza/GradesController original version],[https://codeclimate.com/github/maxlpy/expertiza/GradesController modified version]&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Used for loop with selective choice to create penalty attributes and put it into the '''CalculatedPenalty''' Table, instead of duplicating the almost same code.&lt;br /&gt;
&lt;br /&gt;
*Used Object-Oriented Design patterns of Ruby: let the array respond to the method '''min''' which returns the minimum number in the array and get the logical penalty other than using if statement.(max_penalty if total_penalty is larger than max_penalty,  total_penalty if total_penalty is smaller than max_penalty)&lt;br /&gt;
&lt;br /&gt;
*Eliminated the unnecessary if statements to make the code clear to read.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
&lt;br /&gt;
*Modify if statements:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(penalties[:submission].nil?)&lt;br /&gt;
      penalties[:submission]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:review].nil?)&lt;br /&gt;
      penalties[:review]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:meta_review].nil?)&lt;br /&gt;
      penalties[:meta_review]=0&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
penalties[:submission] = 0 if penalties[:submission].nil?&lt;br /&gt;
penalties[:review] = 0 if penalties[:review].nil?&lt;br /&gt;
penalties[:meta_review] = 0 if penalties[:meta_review].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Using Objected-oriented Pattern&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(@total_penalty &amp;gt; l_policy.max_penalty)&lt;br /&gt;
      @total_penalty = l_policy.max_penalty&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @total_penality=[l_policy.max_penalty,@total_penality].min&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Using loops rather than duplicate same code&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 penalty_attr1 = {:deadline_type_id =&amp;gt; 1,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:submission]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr1)&lt;br /&gt;
 penalty_attr2 = {:deadline_type_id =&amp;gt; 2,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr2)&lt;br /&gt;
 penalty_attr3 = {:deadline_type_id =&amp;gt; 5,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:meta_review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr3)&amp;quot;&lt;br /&gt;
 @all_penalties[participant.id] = Hash.new&lt;br /&gt;
       @all_penalties[participant.id][:submission] = penalties[:submission]&lt;br /&gt;
       @all_penalties[participant.id][:review] = penalties[:review]&lt;br /&gt;
       @all_penalties[participant.id][:meta_review] = penalties[:meta_review]&lt;br /&gt;
       @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 deadline_type=[1,2,5]&lt;br /&gt;
 penalty_type=[:submission,:review,:meta_review]&lt;br /&gt;
 if calculate_for_participants&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
           penalty_attr={:deadline_type_id=&amp;gt;deadline_type[i],:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[penalty_type[i]]}&lt;br /&gt;
           CalculatedPenalty.create(penalty_attr)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
 @all_penalties[participant.id] = {}&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
          @all_penalties[participant.id][:penalty_type[i]] = penalties[:penalty_type[i]]&lt;br /&gt;
      end&lt;br /&gt;
 @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== conflict_notification Method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored the '''conflict_notification''' method to '''conflict_email''' method. When instructor click the button &amp;quot;email reviewer&amp;quot; whom he thought give a unfair review, the system should be able to send an email to the reviewer automatically.The '''get_body_text''' and '''send_grading_email''' were removed from the controller. The sending email function is well simplified and using delegated to a conflict_mailer.&lt;br /&gt;
===Design Pattern===&lt;br /&gt;
Delegation: The conflict_email should be able to send email. The class ConflictMailer works as its delegate and takes the job to send a email.The conflict_email calls the&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
The old '''conflict_notification''' action queries an email address list of a certain kind of reviews. In its view conflict_notification.html.erb, A email form contains email list for instructor to choose from and email content. &lt;br /&gt;
[[File:old_email.png]]&lt;br /&gt;
&lt;br /&gt;
'''Before Refactoring''', in conflict_notification:&lt;br /&gt;
First,Get the instructor email address as sender&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
      if session[:user].role_id !=6             &lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
      @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
      @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then,Based on submission of review, the action query all the reviewers' email address  &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @questions = Hash.new&lt;br /&gt;
      questionnaires = @assignment.questionnaires&lt;br /&gt;
      questionnaires.each {&lt;br /&gt;
        |questionnaire|&lt;br /&gt;
        @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The email list is for instructor to choose from. The process_response method queries the email address.    &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @reviewers_email_hash = Hash.new            &lt;br /&gt;
      @caction = &amp;quot;view&amp;quot;&lt;br /&gt;
      @submission = params[:submission]&lt;br /&gt;
      if @submission == &amp;quot;review&amp;quot;&lt;br /&gt;
        @caction = &amp;quot;view_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;review&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.reviews, &amp;quot;ReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_of_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;metareview&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Metareview&amp;quot;, &amp;quot;Metareviewer&amp;quot;, @participant.metareviews, &amp;quot;MetareviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_feedback&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;feedback&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Feedback&amp;quot;, &amp;quot;Author&amp;quot;, @participant.feedback, &amp;quot;AuthorFeedbackQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;teammate_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;teammate&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Teammate Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.teammate_reviews, &amp;quot;TeammateReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The get_body_text method construct email content which should be removed from controller.&lt;br /&gt;
&amp;lt;pre&amp;gt;                                               &lt;br /&gt;
      @body = get_body_text(params[:submission])      &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The conflict_notification action requiring another two method &amp;quot;process_response&amp;quot; and &amp;quot;get_body_text&amp;quot; method to get the recipient email list and email content which contributes to extra complexity. The instructor only have to click the button &amp;quot;send email&amp;quot; in conflict_notification.html.erb and turn to send_conflict_email action, then he/she can send the email. If the instructor want to send another email, the process will repeat again,which will be terrible when reloading the &amp;quot;view&amp;quot; scores page.&lt;br /&gt;
&lt;br /&gt;
'''After Refactoring''':The quering reiviews actually have done in our show_reviews action, and we can get the individual reviewers' email address.In the reviewer table,we add extra button &amp;quot;email reviewer&amp;quot;.Now the instructor could send to reviewer email directly.&lt;br /&gt;
[[File:conflict_email.png]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In _review_table.html.erb,we add the link to send email. The review_id is passed to the conflict_email action taken as the recipient.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%= link_to 'email reviewer', :action =&amp;gt; 'conflict_email',:remote=&amp;gt; true,:reviewer_id=&amp;gt; &lt;br /&gt;
&lt;br /&gt;
review.map.reviewer.user,:participant_id=&amp;gt;participant,:score=&amp;gt;sprintf(&amp;quot;%.2f&amp;quot;,score) %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In our new '''conflict_email''' action:&lt;br /&gt;
&lt;br /&gt;
We still need the instructor as the sender &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      if session[:user].role_id !=6&lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The reviewer_id is passed from the link,we can query his/her email address to send the email &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      recipient=User.find(params[:reviewer_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The responsibility of sending email has been delegated to a new mailer conflict_mailer. And the email content was constructed in the mailer.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      participant = AssignmentParticipant.find(params[:participant_id])&lt;br /&gt;
      assignment=Assignment.find(participant.parent_id)      &lt;br /&gt;
      score=params[:score]&lt;br /&gt;
      ConflictMailer.send_conflict_email(instructor,recipient,assignment,score).deliver&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Take a look at new conflict_mailer, it define a '''send_conflict_email''' method. the email was sent from sender's email and to reviewer's email.Some instance variables were used in view.&lt;br /&gt;
In conflict_mailer.erb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def send_conflict_email(sender,recipient,assignment,score)&lt;br /&gt;
      @assignment=assignment&lt;br /&gt;
      @recipient=recipient&lt;br /&gt;
      @score=score&lt;br /&gt;
      if recipient.role_id==1&lt;br /&gt;
        @role = &amp;quot;reviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;submission&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
        @role = &amp;quot;metareviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;review&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
    mail subject: &amp;quot;Conflication Email&amp;quot;,from: sender.email,to: reviewer.email&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In its view send_conflict_email.txt.haml, we edit the email content.By this way, we deleted the '''get_body_text''' and well followed the rule of MVC design&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%h1=&amp;quot;Hi ,&amp;quot; +@recipient.name&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;You submitted a score of &amp;quot;+@score+&amp;quot; for assignment &amp;quot;+@assignment.name+&amp;quot; that varied greatly from another &amp;quot;+@role+&amp;quot;'s score for the same &amp;quot;+@item+&amp;quot;.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;The Expertiza system has brought this to my attention.&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The link &amp;quot;email reviewer&amp;quot; request a ajax,so the current view page will not refresh when the action done&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      respond_to do |format|&lt;br /&gt;
        format.js&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If an email was successfully sent,The instructor should get the alert window by ajax.&lt;br /&gt;
[[File:email_sent.png]]&lt;br /&gt;
&lt;br /&gt;
=== view_my_scores method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored '''view_my_scores''' method to grades_show, deleted many unnecessary instance variables along with several review and meta reviews methods inside it. Therefore, the system will only search for scores in the database rather than search for scores and reviews, which wastes a lot of time during the grade show process. After refactoring, the complexity on this decreased from '''53''' to '''35'''.&lt;br /&gt;
We also optimize '''get_scores''' method to improve the efficiency of showing scores by students and instructors, which cost us most of the time during the project. After refactoring this method, the time cost of views in grade controller decreased by more than '''90%'''.&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Refactored '''view_my_scores''' method to '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Searched for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
&lt;br /&gt;
*Eliminated the search for reviews during the '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Deleted unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
*Deleted the unnecessary instance variables&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_score_results = Array.new&lt;br /&gt;
 @average_score_results = ScoreCache.get_class_scores(@participant.id)&lt;br /&gt;
 @statistics = Array.new&lt;br /&gt;
 @average_score_results.each { |x|&lt;br /&gt;
 @statistics &amp;lt;&amp;lt; x&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Deleted query for reviews and meta_reviews&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_reviews = ScoreCache.get_reviews_average(@participant.id)&lt;br /&gt;
 @average_metareviews = ScoreCache.get_metareviews_average(@participant.id)&lt;br /&gt;
 @my_reviews = ScoreCache.my_reviews(@participant.id)&lt;br /&gt;
 @my_metareviews = ScoreCache.my_metareviews(@participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Add a new method into grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
Add Method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 #show_reviews method gets reviews, meta reviews and author feedback information from server.&lt;br /&gt;
  def show_reviews&lt;br /&gt;
    @partial='grades/'+params[:path]&lt;br /&gt;
    @prefix=params[:prefix]&lt;br /&gt;
    @score=Hash.new&lt;br /&gt;
    @score[:assessments]=Array.new&lt;br /&gt;
    params[:score][:assessments].each do |assessment|&lt;br /&gt;
        @score[:assessments]&amp;lt;&amp;lt;Response.find(assessment)&lt;br /&gt;
    end&lt;br /&gt;
    @score[:scores]=params[:score][:scores]&lt;br /&gt;
    @participant=AssignmentParticipant.find(params[:participant])&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @questions = {}&lt;br /&gt;
    questionnaires = @assignment.questionnaires&lt;br /&gt;
    questionnaires.each do |questionnaire|&lt;br /&gt;
      @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Change view_my_score.html.erb into show_reviews.html.erb in views.&lt;br /&gt;
&lt;br /&gt;
*Add in views(show_reviews.html.erb)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;%= render :partial=&amp;gt;@partial, :locals =&amp;gt; {:prefix =&amp;gt; @prefix, :participant =&amp;gt; @participant, :rscore =&amp;gt; @score} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Result====&lt;br /&gt;
*The following test results based on the test case on Expertiza(Assignments: Program 2 style) &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89810</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1466 gjf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89810"/>
		<updated>2014-10-27T02:36:47Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1466: Refactoring GradesController==&lt;br /&gt;
&lt;br /&gt;
This wiki deals with our implementation of a controller in expertiza: [https://github.com/expertiza/expertiza/blob/rails4/app/controllers/grades_controller.rb grade_controller]  for the Expertiza Project using Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Classes involved:''' grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''What it does:'''&lt;br /&gt;
&lt;br /&gt;
This class lists the grades of all the participants for an assignments and also their reviews. Instructor can edit scores, calculate penalties and send emails for conflicts.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&lt;br /&gt;
*Modify '''calculate_all_penalties''' method which is too complex and long.&lt;br /&gt;
*Put the '''get_body_text''' method in a mailer rather than in the grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactor '''view_my_scores''' method to '''grades_show''' and delete the unnecessary variables.&lt;br /&gt;
*Try not to query for reviews and meta reviews in '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
==Code Modification==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== calculate_all_penalties Method===&lt;br /&gt;
====Summary====&lt;br /&gt;
&lt;br /&gt;
We have modified the calculate_penalties method and implemented all the functions it originally has. After our modification the method shrinks from 45 lines to 32 lines of Ruby code. Originally, the method includes a lot of unnecessary if and unless statements which makes the method uneasy to read and seems to have a difficult logic to calculate the penalties. &lt;br /&gt;
&lt;br /&gt;
According to the [https://codeclimate.com codeclimate] which calculate the complexity of the method, originally, it has a complexity of '''85''', however, after we modified it, the complexity goes down to '''65'''. Please check at [https://codeclimate.com/github/expertiza/expertiza/GradesController original version],[https://codeclimate.com/github/maxlpy/expertiza/GradesController modified version]&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Used for loop with selective choice to create penalty attributes and put it into the '''CalculatedPenalty''' Table, instead of duplicating the almost same code.&lt;br /&gt;
&lt;br /&gt;
*Used Object-Oriented Design patterns of Ruby: let the array respond to the method '''min''' which returns the minimum number in the array and get the logical penalty other than using if statement.(max_penalty if total_penalty is larger than max_penalty,  total_penalty if total_penalty is smaller than max_penalty)&lt;br /&gt;
&lt;br /&gt;
*Eliminated the unnecessary if statements to make the code clear to read.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
&lt;br /&gt;
*Modify if statements:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(penalties[:submission].nil?)&lt;br /&gt;
      penalties[:submission]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:review].nil?)&lt;br /&gt;
      penalties[:review]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:meta_review].nil?)&lt;br /&gt;
      penalties[:meta_review]=0&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
penalties[:submission] = 0 if penalties[:submission].nil?&lt;br /&gt;
penalties[:review] = 0 if penalties[:review].nil?&lt;br /&gt;
penalties[:meta_review] = 0 if penalties[:meta_review].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Using Objected-oriented Pattern&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(@total_penalty &amp;gt; l_policy.max_penalty)&lt;br /&gt;
      @total_penalty = l_policy.max_penalty&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @total_penality=[l_policy.max_penalty,@total_penality].min&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Using loops rather than duplicate same code&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 penalty_attr1 = {:deadline_type_id =&amp;gt; 1,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:submission]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr1)&lt;br /&gt;
 penalty_attr2 = {:deadline_type_id =&amp;gt; 2,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr2)&lt;br /&gt;
 penalty_attr3 = {:deadline_type_id =&amp;gt; 5,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:meta_review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr3)&amp;quot;&lt;br /&gt;
 @all_penalties[participant.id] = Hash.new&lt;br /&gt;
       @all_penalties[participant.id][:submission] = penalties[:submission]&lt;br /&gt;
       @all_penalties[participant.id][:review] = penalties[:review]&lt;br /&gt;
       @all_penalties[participant.id][:meta_review] = penalties[:meta_review]&lt;br /&gt;
       @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 deadline_type=[1,2,5]&lt;br /&gt;
 penalty_type=[:submission,:review,:meta_review]&lt;br /&gt;
 if calculate_for_participants&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
           penalty_attr={:deadline_type_id=&amp;gt;deadline_type[i],:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[penalty_type[i]]}&lt;br /&gt;
           CalculatedPenalty.create(penalty_attr)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
 @all_penalties[participant.id] = {}&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
          @all_penalties[participant.id][:penalty_type[i]] = penalties[:penalty_type[i]]&lt;br /&gt;
      end&lt;br /&gt;
 @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== conflict_notification Method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored the '''conflict_notification''' method to '''conflict_email''' method. When instructor click the button &amp;quot;email reviewer&amp;quot; whom he thought give a unfair review, the system should be able to send an email to the reviewer automatically.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
The old '''conflict_notification''' action queries an email address list of a certain kind of reviews. In its view conflict_notification.html.erb, A email form contains email list for instructor to choose from and email content. &lt;br /&gt;
[[File:old_email.png]]&lt;br /&gt;
&lt;br /&gt;
'''Before Refactoring''', in conflict_notification:&lt;br /&gt;
First,Get the instructor email address as sender&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
      if session[:user].role_id !=6             &lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
      @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
      @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then,Based on submission of review, the action query all the reviewers' email address  &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @questions = Hash.new&lt;br /&gt;
      questionnaires = @assignment.questionnaires&lt;br /&gt;
      questionnaires.each {&lt;br /&gt;
        |questionnaire|&lt;br /&gt;
        @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The email list is for instructor to choose from. The process_response method queries the email address.    &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @reviewers_email_hash = Hash.new            &lt;br /&gt;
      @caction = &amp;quot;view&amp;quot;&lt;br /&gt;
      @submission = params[:submission]&lt;br /&gt;
      if @submission == &amp;quot;review&amp;quot;&lt;br /&gt;
        @caction = &amp;quot;view_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;review&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.reviews, &amp;quot;ReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_of_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;metareview&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Metareview&amp;quot;, &amp;quot;Metareviewer&amp;quot;, @participant.metareviews, &amp;quot;MetareviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_feedback&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;feedback&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Feedback&amp;quot;, &amp;quot;Author&amp;quot;, @participant.feedback, &amp;quot;AuthorFeedbackQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;teammate_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;teammate&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Teammate Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.teammate_reviews, &amp;quot;TeammateReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The get_body_text method construct email content which should be removed from controller.&lt;br /&gt;
&amp;lt;pre&amp;gt;                                               &lt;br /&gt;
      @body = get_body_text(params[:submission])      &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The conflict_notification action requiring another two method &amp;quot;process_response&amp;quot; and &amp;quot;get_body_text&amp;quot; method to get the recipient email list and email content which contributes to extra complexity. The instructor only have to click the button &amp;quot;send email&amp;quot; in conflict_notification.html.erb and turn to send_conflict_email action, then he/she can send the email. If the instructor want to send another email, the process will repeat again,which will be terrible when reloading the &amp;quot;view&amp;quot; scores page.&lt;br /&gt;
&lt;br /&gt;
'''After Refactoring''':The quering reiviews actually have done in our show_reviews action, and we can get the individual reviewers' email address.In the reviewer table,we add extra button &amp;quot;email reviewer&amp;quot;.Now the instructor could send to reviewer email directly.&lt;br /&gt;
[[File:conflict_email.png]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In _review_table.html.erb,we add the link to send email. The review_id is passed to the conflict_email action taken as the recipient.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%= link_to 'email reviewer', :action =&amp;gt; 'conflict_email',:remote=&amp;gt; true,:reviewer_id=&amp;gt; &lt;br /&gt;
&lt;br /&gt;
review.map.reviewer.user,:participant_id=&amp;gt;participant,:score=&amp;gt;sprintf(&amp;quot;%.2f&amp;quot;,score) %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In our new '''conflict_email''' action:&lt;br /&gt;
&lt;br /&gt;
We still need the instructor as the sender &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      if session[:user].role_id !=6&lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The reviewer_id is passed from the link,we can query his/her email address to send the email &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      recipient=User.find(params[:reviewer_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The responsibility of sending email has been delegated to a new mailer conflict_mailer. And the email content was constructed in the mailer.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      participant = AssignmentParticipant.find(params[:participant_id])&lt;br /&gt;
      assignment=Assignment.find(participant.parent_id)      &lt;br /&gt;
      score=params[:score]&lt;br /&gt;
      ConflictMailer.send_conflict_email(instructor,recipient,assignment,score).deliver&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Take a look at new conflict_mailer, it define a '''send_conflict_email''' method. the email was sent from sender's email and to reviewer's email.Some instance variables were used in view.&lt;br /&gt;
In conflict_mailer.erb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def send_conflict_email(sender,recipient,assignment,score)&lt;br /&gt;
      @assignment=assignment&lt;br /&gt;
      @recipient=recipient&lt;br /&gt;
      @score=score&lt;br /&gt;
      if recipient.role_id==1&lt;br /&gt;
        @role = &amp;quot;reviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;submission&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
        @role = &amp;quot;metareviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;review&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
    mail subject: &amp;quot;Conflication Email&amp;quot;,from: sender.email,to: reviewer.email&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In its view send_conflict_email.txt.haml, we edit the email content.By this way, we deleted the '''get_body_text''' and well followed the rule of MVC design&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%h1=&amp;quot;Hi ,&amp;quot; +@recipient.name&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;You submitted a score of &amp;quot;+@score+&amp;quot; for assignment &amp;quot;+@assignment.name+&amp;quot; that varied greatly from another &amp;quot;+@role+&amp;quot;'s score for the same &amp;quot;+@item+&amp;quot;.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;The Expertiza system has brought this to my attention.&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The link &amp;quot;email reviewer&amp;quot; request a ajax,so the current view page will not refresh when the action done&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      respond_to do |format|&lt;br /&gt;
        format.js&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If an email was successfully sent,The instructor should get the alert window by ajax.&lt;br /&gt;
[[File:email_sent.png]]&lt;br /&gt;
&lt;br /&gt;
=== view_my_scores method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored '''view_my_scores''' method to grades_show, deleted many unnecessary instance variables along with several review and meta reviews methods inside it. Therefore, the system will only search for scores in the database rather than search for scores and reviews, which wastes a lot of time during the grade show process. After refactoring, the complexity on this decreased from '''53''' to '''35'''.&lt;br /&gt;
We also optimize '''get_scores''' method to improve the efficiency of showing scores by students and instructors, which cost us most of the time during the project. After refactoring this method, the time cost of views in grade controller decreased by more than '''90%'''.&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Refactored '''view_my_scores''' method to '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Searched for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
&lt;br /&gt;
*Eliminated the search for reviews during the '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Deleted unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
*Deleted the unnecessary instance variables&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_score_results = Array.new&lt;br /&gt;
 @average_score_results = ScoreCache.get_class_scores(@participant.id)&lt;br /&gt;
 @statistics = Array.new&lt;br /&gt;
 @average_score_results.each { |x|&lt;br /&gt;
 @statistics &amp;lt;&amp;lt; x&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Deleted query for reviews and meta_reviews&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_reviews = ScoreCache.get_reviews_average(@participant.id)&lt;br /&gt;
 @average_metareviews = ScoreCache.get_metareviews_average(@participant.id)&lt;br /&gt;
 @my_reviews = ScoreCache.my_reviews(@participant.id)&lt;br /&gt;
 @my_metareviews = ScoreCache.my_metareviews(@participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Add a new method into grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
Add Method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 #show_reviews method gets reviews, meta reviews and author feedback information from server.&lt;br /&gt;
  def show_reviews&lt;br /&gt;
    @partial='grades/'+params[:path]&lt;br /&gt;
    @prefix=params[:prefix]&lt;br /&gt;
    @score=Hash.new&lt;br /&gt;
    @score[:assessments]=Array.new&lt;br /&gt;
    params[:score][:assessments].each do |assessment|&lt;br /&gt;
        @score[:assessments]&amp;lt;&amp;lt;Response.find(assessment)&lt;br /&gt;
    end&lt;br /&gt;
    @score[:scores]=params[:score][:scores]&lt;br /&gt;
    @participant=AssignmentParticipant.find(params[:participant])&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @questions = {}&lt;br /&gt;
    questionnaires = @assignment.questionnaires&lt;br /&gt;
    questionnaires.each do |questionnaire|&lt;br /&gt;
      @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Change view_my_score.html.erb into show_reviews.html.erb in views.&lt;br /&gt;
&lt;br /&gt;
*Add in views(show_reviews.html.erb)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;%= render :partial=&amp;gt;@partial, :locals =&amp;gt; {:prefix =&amp;gt; @prefix, :participant =&amp;gt; @participant, :rscore =&amp;gt; @score} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Result====&lt;br /&gt;
*The following test results based on the test case on Expertiza(Assignments: Program 2 style) &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89808</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1466 gjf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89808"/>
		<updated>2014-10-27T02:34:28Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1466: Refactoring GradesController==&lt;br /&gt;
&lt;br /&gt;
This wiki deals with our implementation of a controller in expertiza: [https://github.com/expertiza/expertiza/blob/rails4/app/controllers/grades_controller.rb grade_controller]  for the Expertiza Project using Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Classes involved:''' grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''What it does:'''&lt;br /&gt;
&lt;br /&gt;
This class lists the grades of all the participants for an assignments and also their reviews. Instructor can edit scores, calculate penalties and send emails for conflicts.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&lt;br /&gt;
*Modify '''calculate_all_penalties''' method which is too complex and long.&lt;br /&gt;
*Put the '''get_body_text''' method in a mailer rather than in the grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactor '''view_my_scores''' method to '''grades_show''' and delete the unnecessary variables.&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
*Try not to query for reviews and meta reviews in '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
==Code Modification==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== calculate_all_penalties Method===&lt;br /&gt;
====Summary====&lt;br /&gt;
&lt;br /&gt;
We have modified the calculate_penalties method and implemented all the functions it originally has. After our modification the method shrinks from 45 lines to 32 lines of Ruby code. Originally, the method includes a lot of unnecessary if and unless statements which makes the method uneasy to read and seems to have a difficult logic to calculate the penalties. &lt;br /&gt;
&lt;br /&gt;
According to the [https://codeclimate.com codeclimate] which calculate the complexity of the method, originally, it has a complexity of '''85''', however, after we modified it, the complexity goes down to '''65'''. Please check at [https://codeclimate.com/github/expertiza/expertiza/GradesController original version],[https://codeclimate.com/github/maxlpy/expertiza/GradesController modified version]&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Used for loop with selective choice to create penalty attributes and put it into the '''CalculatedPenalty''' Table, instead of duplicating the almost same code.&lt;br /&gt;
&lt;br /&gt;
*Used Object-Oriented Design patterns of Ruby: let the array respond to the method '''min''' which returns the minimum number in the array and get the logical penalty other than using if statement.(max_penalty if total_penalty is larger than max_penalty,  total_penalty if total_penalty is smaller than max_penalty)&lt;br /&gt;
&lt;br /&gt;
*Eliminated the unnecessary if statements to make the code clear to read.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
&lt;br /&gt;
*Modify if statements:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(penalties[:submission].nil?)&lt;br /&gt;
      penalties[:submission]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:review].nil?)&lt;br /&gt;
      penalties[:review]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:meta_review].nil?)&lt;br /&gt;
      penalties[:meta_review]=0&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
penalties[:submission] = 0 if penalties[:submission].nil?&lt;br /&gt;
penalties[:review] = 0 if penalties[:review].nil?&lt;br /&gt;
penalties[:meta_review] = 0 if penalties[:meta_review].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Using Objected-oriented Pattern&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(@total_penalty &amp;gt; l_policy.max_penalty)&lt;br /&gt;
      @total_penalty = l_policy.max_penalty&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @total_penality=[l_policy.max_penalty,@total_penality].min&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Using loops rather than duplicate same code&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 penalty_attr1 = {:deadline_type_id =&amp;gt; 1,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:submission]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr1)&lt;br /&gt;
 penalty_attr2 = {:deadline_type_id =&amp;gt; 2,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr2)&lt;br /&gt;
 penalty_attr3 = {:deadline_type_id =&amp;gt; 5,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:meta_review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr3)&amp;quot;&lt;br /&gt;
 @all_penalties[participant.id] = Hash.new&lt;br /&gt;
       @all_penalties[participant.id][:submission] = penalties[:submission]&lt;br /&gt;
       @all_penalties[participant.id][:review] = penalties[:review]&lt;br /&gt;
       @all_penalties[participant.id][:meta_review] = penalties[:meta_review]&lt;br /&gt;
       @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 deadline_type=[1,2,5]&lt;br /&gt;
 penalty_type=[:submission,:review,:meta_review]&lt;br /&gt;
 if calculate_for_participants&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
           penalty_attr={:deadline_type_id=&amp;gt;deadline_type[i],:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[penalty_type[i]]}&lt;br /&gt;
           CalculatedPenalty.create(penalty_attr)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
 @all_penalties[participant.id] = {}&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
          @all_penalties[participant.id][:penalty_type[i]] = penalties[:penalty_type[i]]&lt;br /&gt;
      end&lt;br /&gt;
 @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== conflict_notification Method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored the '''conflict_notification''' method to '''conflict_email''' method. When instructor click the button &amp;quot;email reviewer&amp;quot; whom he thought give a unfair review, the system should be able to send an email to the reviewer automatically.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
The old '''conflict_notification''' action queries an email address list of a certain kind of reviews. In its view conflict_notification.html.erb, A email form contains email list for instructor to choose from and email content. &lt;br /&gt;
[[File:old_email.png]]&lt;br /&gt;
&lt;br /&gt;
'''Before Refactoring''', in conflict_notification:&lt;br /&gt;
First,Get the instructor email address as sender&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
      if session[:user].role_id !=6             &lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
      @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
      @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then,Based on submission of review, the action query all the reviewers' email address  &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @questions = Hash.new&lt;br /&gt;
      questionnaires = @assignment.questionnaires&lt;br /&gt;
      questionnaires.each {&lt;br /&gt;
        |questionnaire|&lt;br /&gt;
        @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The email list is for instructor to choose from. The process_response method queries the email address.    &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @reviewers_email_hash = Hash.new            &lt;br /&gt;
      @caction = &amp;quot;view&amp;quot;&lt;br /&gt;
      @submission = params[:submission]&lt;br /&gt;
      if @submission == &amp;quot;review&amp;quot;&lt;br /&gt;
        @caction = &amp;quot;view_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;review&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.reviews, &amp;quot;ReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_of_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;metareview&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Metareview&amp;quot;, &amp;quot;Metareviewer&amp;quot;, @participant.metareviews, &amp;quot;MetareviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_feedback&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;feedback&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Feedback&amp;quot;, &amp;quot;Author&amp;quot;, @participant.feedback, &amp;quot;AuthorFeedbackQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;teammate_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;teammate&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Teammate Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.teammate_reviews, &amp;quot;TeammateReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The get_body_text method construct email content also in controller&lt;br /&gt;
&amp;lt;pre&amp;gt;                                               &lt;br /&gt;
      @body = get_body_text(params[:submission])      &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The conflict_notification action requiring another two method &amp;quot;process_response&amp;quot; and &amp;quot;get_body_text&amp;quot; method to get the recipient email list and email content which contributes to extra complexity. The instructor only have to click the button &amp;quot;send email&amp;quot; in conflict_notification.html.erb and turn to send_conflict_email action, then he/she can send the email. If the instructor want to send another email, the process will repeat again,which will be terrible when reloading the &amp;quot;view&amp;quot; scores page.&lt;br /&gt;
&lt;br /&gt;
'''After Refactoring''':The quering reiviews actually have done in our show_reviews action, and we can get the individual reviewers' email address.In the reviewer table,we add extra button &amp;quot;email reviewer&amp;quot;.Now the instructor could send to reviewer email directly.&lt;br /&gt;
[[File:conflict_email.png]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In _review_table.html.erb,we add the link to send email. The review_id is passed to the conflict_email action taken as the recipient.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%= link_to 'email reviewer', :action =&amp;gt; 'conflict_email',:remote=&amp;gt; true,:reviewer_id=&amp;gt; &lt;br /&gt;
&lt;br /&gt;
review.map.reviewer.user,:participant_id=&amp;gt;participant,:score=&amp;gt;sprintf(&amp;quot;%.2f&amp;quot;,score) %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In our new '''conflict_email''' action:&lt;br /&gt;
&lt;br /&gt;
We still need the instructor as the sender &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      if session[:user].role_id !=6&lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The reviewer_id is passed from the link,we can query his/her email address to send the email &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      recipient=User.find(params[:reviewer_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The responsibility of sending email has been delegated to a new mailer conflict_mailer. And the email content was constructed in the mailer.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      participant = AssignmentParticipant.find(params[:participant_id])&lt;br /&gt;
      assignment=Assignment.find(participant.parent_id)      &lt;br /&gt;
      score=params[:score]&lt;br /&gt;
      ConflictMailer.send_conflict_email(instructor,recipient,assignment,score).deliver&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Take a look at new conflict_mailer, it define a '''send_conflict_email''' method. the email was sent from sender's email and to reviewer's email.Some instance variables were used in view.&lt;br /&gt;
In conflict_mailer.erb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def send_conflict_email(sender,recipient,assignment,score)&lt;br /&gt;
      @assignment=assignment&lt;br /&gt;
      @recipient=recipient&lt;br /&gt;
      @score=score&lt;br /&gt;
      if recipient.role_id==1&lt;br /&gt;
        @role = &amp;quot;reviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;submission&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
        @role = &amp;quot;metareviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;review&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
    mail subject: &amp;quot;Conflication Email&amp;quot;,from: sender.email,to: reviewer.email&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In its view send_conflict_email.txt.haml, we edit the email content.By this way, we deleted the '''get_body_text''' and well followed the rule of MVC design&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%h1=&amp;quot;Hi ,&amp;quot; +@recipient.name&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;You submitted a score of &amp;quot;+@score+&amp;quot; for assignment &amp;quot;+@assignment.name+&amp;quot; that varied greatly from another &amp;quot;+@role+&amp;quot;'s score for the same &amp;quot;+@item+&amp;quot;.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;The Expertiza system has brought this to my attention.&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The link &amp;quot;email reviewer&amp;quot; request a ajax,so the current view page will not refresh when the action done&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      respond_to do |format|&lt;br /&gt;
        format.js&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If an email was successfully sent,The instructor should get the alert window by ajax.&lt;br /&gt;
[[File:email_sent.png]]&lt;br /&gt;
&lt;br /&gt;
=== view_my_scores method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored '''view_my_scores''' method to grades_show, deleted many unnecessary instance variables along with several review and meta reviews methods inside it. Therefore, the system will only search for scores in the database rather than search for scores and reviews, which wastes a lot of time during the grade show process. After refactoring, the complexity on this decreased from '''53''' to '''35'''.&lt;br /&gt;
We also optimize '''get_scores''' method to improve the efficiency of showing scores by students and instructors, which cost us most of the time during the project. After refactoring this method, the time cost of views in grade controller decreased by more than '''90%'''.&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Refactored '''view_my_scores''' method to '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Searched for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
&lt;br /&gt;
*Eliminated the search for reviews during the '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Deleted unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
*Deleted the unnecessary instance variables&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_score_results = Array.new&lt;br /&gt;
 @average_score_results = ScoreCache.get_class_scores(@participant.id)&lt;br /&gt;
 @statistics = Array.new&lt;br /&gt;
 @average_score_results.each { |x|&lt;br /&gt;
 @statistics &amp;lt;&amp;lt; x&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Deleted query for reviews and meta_reviews&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_reviews = ScoreCache.get_reviews_average(@participant.id)&lt;br /&gt;
 @average_metareviews = ScoreCache.get_metareviews_average(@participant.id)&lt;br /&gt;
 @my_reviews = ScoreCache.my_reviews(@participant.id)&lt;br /&gt;
 @my_metareviews = ScoreCache.my_metareviews(@participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Add a new method into grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
Add Method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 #show_reviews method gets reviews, meta reviews and author feedback information from server.&lt;br /&gt;
  def show_reviews&lt;br /&gt;
    @partial='grades/'+params[:path]&lt;br /&gt;
    @prefix=params[:prefix]&lt;br /&gt;
    @score=Hash.new&lt;br /&gt;
    @score[:assessments]=Array.new&lt;br /&gt;
    params[:score][:assessments].each do |assessment|&lt;br /&gt;
        @score[:assessments]&amp;lt;&amp;lt;Response.find(assessment)&lt;br /&gt;
    end&lt;br /&gt;
    @score[:scores]=params[:score][:scores]&lt;br /&gt;
    @participant=AssignmentParticipant.find(params[:participant])&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @questions = {}&lt;br /&gt;
    questionnaires = @assignment.questionnaires&lt;br /&gt;
    questionnaires.each do |questionnaire|&lt;br /&gt;
      @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Change view_my_score.html.erb into show_reviews.html.erb in views.&lt;br /&gt;
&lt;br /&gt;
*Add in views(show_reviews.html.erb)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;%= render :partial=&amp;gt;@partial, :locals =&amp;gt; {:prefix =&amp;gt; @prefix, :participant =&amp;gt; @participant, :rscore =&amp;gt; @score} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Result====&lt;br /&gt;
*The following test results based on the test case on Expertiza(Assignments: Program 2 style) &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89807</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1466 gjf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89807"/>
		<updated>2014-10-27T02:32:26Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1466: Refactoring GradesController==&lt;br /&gt;
&lt;br /&gt;
This wiki deals with our implementation of a controller in expertiza: [https://github.com/expertiza/expertiza/blob/rails4/app/controllers/grades_controller.rb grade_controller]  for the Expertiza Project using Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Classes involved:''' grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''What it does:'''&lt;br /&gt;
&lt;br /&gt;
This class lists the grades of all the participants for an assignments and also their reviews. Instructor can edit scores, calculate penalties and send emails for conflicts.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&lt;br /&gt;
*Modify '''calculate_all_penalties''' method which is too complex and long.&lt;br /&gt;
*Put the '''get_body_text''' method in a mailer rather than in the grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactor '''view_my_scores''' method to '''grades_show''' and delete the unnecessary variables.&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
*Try not to query for reviews and meta reviews in '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
==Code Modification==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== calculate_all_penalties Method===&lt;br /&gt;
====Summary====&lt;br /&gt;
&lt;br /&gt;
We have modified the calculate_penalties method and implemented all the functions it originally has. After our modification the method shrinks from 45 lines to 32 lines of Ruby code. Originally, the method includes a lot of unnecessary if and unless statements which makes the method uneasy to read and seems to have a difficult logic to calculate the penalties. &lt;br /&gt;
&lt;br /&gt;
According to the [https://codeclimate.com codeclimate] which calculate the complexity of the method, originally, it has a complexity of '''85''', however, after we modified it, the complexity goes down to '''65'''. Please check at [https://codeclimate.com/github/expertiza/expertiza/GradesController original version],[https://codeclimate.com/github/maxlpy/expertiza/GradesController modified version]&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Used for loop with selective choice to create penalty attributes and put it into the '''CalculatedPenalty''' Table, instead of duplicating the almost same code.&lt;br /&gt;
&lt;br /&gt;
*Used Object-Oriented Design patterns of Ruby: let the array respond to the method '''min''' which returns the minimum number in the array and get the logical penalty other than using if statement.(max_penalty if total_penalty is larger than max_penalty,  total_penalty if total_penalty is smaller than max_penalty)&lt;br /&gt;
&lt;br /&gt;
*Eliminated the unnecessary if statements to make the code clear to read.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
&lt;br /&gt;
*Modify if statements:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(penalties[:submission].nil?)&lt;br /&gt;
      penalties[:submission]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:review].nil?)&lt;br /&gt;
      penalties[:review]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:meta_review].nil?)&lt;br /&gt;
      penalties[:meta_review]=0&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
penalties[:submission] = 0 if penalties[:submission].nil?&lt;br /&gt;
penalties[:review] = 0 if penalties[:review].nil?&lt;br /&gt;
penalties[:meta_review] = 0 if penalties[:meta_review].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Using Objected-oriented Pattern&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(@total_penalty &amp;gt; l_policy.max_penalty)&lt;br /&gt;
      @total_penalty = l_policy.max_penalty&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @total_penality=[l_policy.max_penalty,@total_penality].min&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Using loops rather than duplicate same code&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 penalty_attr1 = {:deadline_type_id =&amp;gt; 1,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:submission]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr1)&lt;br /&gt;
 penalty_attr2 = {:deadline_type_id =&amp;gt; 2,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr2)&lt;br /&gt;
 penalty_attr3 = {:deadline_type_id =&amp;gt; 5,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:meta_review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr3)&amp;quot;&lt;br /&gt;
 @all_penalties[participant.id] = Hash.new&lt;br /&gt;
       @all_penalties[participant.id][:submission] = penalties[:submission]&lt;br /&gt;
       @all_penalties[participant.id][:review] = penalties[:review]&lt;br /&gt;
       @all_penalties[participant.id][:meta_review] = penalties[:meta_review]&lt;br /&gt;
       @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 deadline_type=[1,2,5]&lt;br /&gt;
 penalty_type=[:submission,:review,:meta_review]&lt;br /&gt;
 if calculate_for_participants&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
           penalty_attr={:deadline_type_id=&amp;gt;deadline_type[i],:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[penalty_type[i]]}&lt;br /&gt;
           CalculatedPenalty.create(penalty_attr)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
 @all_penalties[participant.id] = {}&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
          @all_penalties[participant.id][:penalty_type[i]] = penalties[:penalty_type[i]]&lt;br /&gt;
      end&lt;br /&gt;
 @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== conflict_notification Method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored the '''conflict_notification''' method to '''conflict_email''' method. When instructor click the button &amp;quot;email reviewer&amp;quot; whom he thought give a unfair review, the system should be able to send an email to the reviewer automatically.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
The old '''conflict_notification''' action queries an email address list of a certain kind of reviews. In its view conflict_notification.html.erb, A email form contains email list for instructor to choose from and email content. &lt;br /&gt;
[[File:old_email.png]]&lt;br /&gt;
&lt;br /&gt;
'''Before Refactoring''', in conflict_notification:&lt;br /&gt;
First,Get the instructor email address as sender&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
      if session[:user].role_id !=6             &lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
      @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
      @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then,Based on submission of review, the action query all the reviewers' email address  &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @questions = Hash.new&lt;br /&gt;
      questionnaires = @assignment.questionnaires&lt;br /&gt;
      questionnaires.each {&lt;br /&gt;
        |questionnaire|&lt;br /&gt;
        @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The email list is for instructor to choose from. The process_response method queries the email address.    &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @reviewers_email_hash = Hash.new            &lt;br /&gt;
      @caction = &amp;quot;view&amp;quot;&lt;br /&gt;
      @submission = params[:submission]&lt;br /&gt;
      if @submission == &amp;quot;review&amp;quot;&lt;br /&gt;
        @caction = &amp;quot;view_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;review&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.reviews, &amp;quot;ReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_of_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;metareview&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Metareview&amp;quot;, &amp;quot;Metareviewer&amp;quot;, @participant.metareviews, &amp;quot;MetareviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_feedback&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;feedback&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Feedback&amp;quot;, &amp;quot;Author&amp;quot;, @participant.feedback, &amp;quot;AuthorFeedbackQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;teammate_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;teammate&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Teammate Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.teammate_reviews, &amp;quot;TeammateReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The get_body_text method construct email content also in controller&lt;br /&gt;
&amp;lt;pre&amp;gt;                                               &lt;br /&gt;
      @body = get_body_text(params[:submission])      &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The conflict_notification action requiring another two method &amp;quot;process_response&amp;quot; and &amp;quot;get_body_text&amp;quot; method to get the recipient email list and email content which contributes to extra complexity. The instructor only have to click the button &amp;quot;send email&amp;quot; in conflict_notification.html.erb and turn to send_conflict_email action, then he/she can send the email. If the instructor want to send another email, the process will repeat again,which will be terrible when reloading the &amp;quot;view&amp;quot; scores page.&lt;br /&gt;
&lt;br /&gt;
'''After Refactoring''':The quering reiviews actually have done in our show_reviews action, and we can get the individual reviewers' email address.In the reviewer table,we add extra button &amp;quot;email reviewer&amp;quot;.Now the instructor could send to reviewer email directly.&lt;br /&gt;
[[File:conflict_email.png]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In _review_table.html.erb,we add the link to send email. The review_id is passed to the conflict_email action taken as the recipient.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%= link_to 'email reviewer', :action =&amp;gt; 'conflict_email',:remote=&amp;gt; true,:reviewer_id=&amp;gt; &lt;br /&gt;
&lt;br /&gt;
review.map.reviewer.user,:participant_id=&amp;gt;participant,:score=&amp;gt;sprintf(&amp;quot;%.2f&amp;quot;,score) %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In our new '''conflict_email''' action:&lt;br /&gt;
&lt;br /&gt;
We still need the instructor as the sender &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      if session[:user].role_id !=6&lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The reviewer_id is passed from the link,we can query his/her email address to send the email &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      recipient=User.find(params[:reviewer_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The responsibility of sending email has been delegated to a new mailer conflict_mailer. And the email content was constructed in the mailer.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      participant = AssignmentParticipant.find(params[:participant_id])&lt;br /&gt;
      assignment=Assignment.find(participant.parent_id)      &lt;br /&gt;
      score=params[:score]&lt;br /&gt;
      ConflictMailer.send_conflict_email(instructor,recipient,assignment,score).deliver&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Take a look at new conflict_mailer, it define a '''send_conflict_email''' method. the email was sent from sender's email and to reviewer's email.Some instance variables were used in view.&lt;br /&gt;
In conflict_mailer.erb&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def send_conflict_email(sender,recipient,assignment,score)&lt;br /&gt;
      @assignment=assignment&lt;br /&gt;
      @recipient=recipient&lt;br /&gt;
      @score=score&lt;br /&gt;
      if recipient.role_id==1&lt;br /&gt;
        @role = &amp;quot;reviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;submission&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
        @role = &amp;quot;metareviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;review&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
    mail subject: &amp;quot;Conflication Email&amp;quot;,from: sender.email,to: reviewer.email&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In its view send_conflict_email.txt.haml, we construct the email content.By this way, we follow the rule of MVC design&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%h1=&amp;quot;Hi ,&amp;quot; +@recipient.name&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;You submitted a score of &amp;quot;+@score+&amp;quot; for assignment &amp;quot;+@assignment.name+&amp;quot; that varied greatly from another &amp;quot;+@role+&amp;quot;'s score for the same &amp;quot;+@item+&amp;quot;.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
%p=&amp;quot;The Expertiza system has brought this to my attention.&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The link &amp;quot;email reviewer&amp;quot; request a ajax,so the current view page will not refresh when the action done&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      respond_to do |format|&lt;br /&gt;
        format.js&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If an email was successfully sent,The instructor should get the alert window by ajax.&lt;br /&gt;
[[File:email_sent.png]]&lt;br /&gt;
&lt;br /&gt;
=== view_my_scores method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored '''view_my_scores''' method to grades_show, deleted many unnecessary instance variables along with several review and meta reviews methods inside it. Therefore, the system will only search for scores in the database rather than search for scores and reviews, which wastes a lot of time during the grade show process. After refactoring, the complexity on this decreased from '''53''' to '''35'''.&lt;br /&gt;
We also optimize '''get_scores''' method to improve the efficiency of showing scores by students and instructors, which cost us most of the time during the project. After refactoring this method, the time cost of views in grade controller decreased by more than '''90%'''.&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Refactored '''view_my_scores''' method to '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Searched for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
&lt;br /&gt;
*Eliminated the search for reviews during the '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Deleted unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
*Deleted the unnecessary instance variables&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_score_results = Array.new&lt;br /&gt;
 @average_score_results = ScoreCache.get_class_scores(@participant.id)&lt;br /&gt;
 @statistics = Array.new&lt;br /&gt;
 @average_score_results.each { |x|&lt;br /&gt;
 @statistics &amp;lt;&amp;lt; x&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Deleted query for reviews and meta_reviews&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_reviews = ScoreCache.get_reviews_average(@participant.id)&lt;br /&gt;
 @average_metareviews = ScoreCache.get_metareviews_average(@participant.id)&lt;br /&gt;
 @my_reviews = ScoreCache.my_reviews(@participant.id)&lt;br /&gt;
 @my_metareviews = ScoreCache.my_metareviews(@participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Add a new method into grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
Add Method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 #show_reviews method gets reviews, meta reviews and author feedback information from server.&lt;br /&gt;
  def show_reviews&lt;br /&gt;
    @partial='grades/'+params[:path]&lt;br /&gt;
    @prefix=params[:prefix]&lt;br /&gt;
    @score=Hash.new&lt;br /&gt;
    @score[:assessments]=Array.new&lt;br /&gt;
    params[:score][:assessments].each do |assessment|&lt;br /&gt;
        @score[:assessments]&amp;lt;&amp;lt;Response.find(assessment)&lt;br /&gt;
    end&lt;br /&gt;
    @score[:scores]=params[:score][:scores]&lt;br /&gt;
    @participant=AssignmentParticipant.find(params[:participant])&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @questions = {}&lt;br /&gt;
    questionnaires = @assignment.questionnaires&lt;br /&gt;
    questionnaires.each do |questionnaire|&lt;br /&gt;
      @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Change view_my_score.html.erb into show_reviews.html.erb in views.&lt;br /&gt;
&lt;br /&gt;
*Add in views(show_reviews.html.erb)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;%= render :partial=&amp;gt;@partial, :locals =&amp;gt; {:prefix =&amp;gt; @prefix, :participant =&amp;gt; @participant, :rscore =&amp;gt; @score} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Result====&lt;br /&gt;
*The following test results based on the test case on Expertiza(Assignments: Program 2 style) &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89806</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1466 gjf</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1466_gjf&amp;diff=89806"/>
		<updated>2014-10-27T02:29:03Z</updated>

		<summary type="html">&lt;p&gt;Jgu7: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1466: Refactoring GradesController==&lt;br /&gt;
&lt;br /&gt;
This wiki deals with our implementation of a controller in expertiza: [https://github.com/expertiza/expertiza/blob/rails4/app/controllers/grades_controller.rb grade_controller]  for the Expertiza Project using Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Classes involved:''' grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
'''What it does:'''&lt;br /&gt;
&lt;br /&gt;
This class lists the grades of all the participants for an assignments and also their reviews. Instructor can edit scores, calculate penalties and send emails for conflicts.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&lt;br /&gt;
*Modify '''calculate_all_penalties''' method which is too complex and long.&lt;br /&gt;
*Put the '''get_body_text''' method in a mailer rather than in the grades_controller.&lt;br /&gt;
*Refactor '''conflict_nofication''' method to '''conflict_email''' and make it delegated to the mailer. &lt;br /&gt;
*Refactor '''view_my_scores''' method to '''grades_show''' and delete the unnecessary variables.&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
*Try not to query for reviews and meta reviews in '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
==Code Modification==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== calculate_all_penalties Method===&lt;br /&gt;
====Summary====&lt;br /&gt;
&lt;br /&gt;
We have modified the calculate_penalties method and implemented all the functions it originally has. After our modification the method shrinks from 45 lines to 32 lines of Ruby code. Originally, the method includes a lot of unnecessary if and unless statements which makes the method uneasy to read and seems to have a difficult logic to calculate the penalties. &lt;br /&gt;
&lt;br /&gt;
According to the [https://codeclimate.com codeclimate] which calculate the complexity of the method, originally, it has a complexity of '''85''', however, after we modified it, the complexity goes down to '''65'''. Please check at [https://codeclimate.com/github/expertiza/expertiza/GradesController original version],[https://codeclimate.com/github/maxlpy/expertiza/GradesController modified version]&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Used for loop with selective choice to create penalty attributes and put it into the '''CalculatedPenalty''' Table, instead of duplicating the almost same code.&lt;br /&gt;
&lt;br /&gt;
*Used Object-Oriented Design patterns of Ruby: let the array respond to the method '''min''' which returns the minimum number in the array and get the logical penalty other than using if statement.(max_penalty if total_penalty is larger than max_penalty,  total_penalty if total_penalty is smaller than max_penalty)&lt;br /&gt;
&lt;br /&gt;
*Eliminated the unnecessary if statements to make the code clear to read.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
&lt;br /&gt;
*Modify if statements:&lt;br /&gt;
&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(penalties[:submission].nil?)&lt;br /&gt;
      penalties[:submission]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:review].nil?)&lt;br /&gt;
      penalties[:review]=0&lt;br /&gt;
 end&lt;br /&gt;
 if(penalties[:meta_review].nil?)&lt;br /&gt;
      penalties[:meta_review]=0&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
penalties[:submission] = 0 if penalties[:submission].nil?&lt;br /&gt;
penalties[:review] = 0 if penalties[:review].nil?&lt;br /&gt;
penalties[:meta_review] = 0 if penalties[:meta_review].nil?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Using Objected-oriented Pattern&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 if(@total_penalty &amp;gt; l_policy.max_penalty)&lt;br /&gt;
      @total_penalty = l_policy.max_penalty&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @total_penality=[l_policy.max_penalty,@total_penality].min&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Using loops rather than duplicate same code&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 penalty_attr1 = {:deadline_type_id =&amp;gt; 1,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:submission]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr1)&lt;br /&gt;
 penalty_attr2 = {:deadline_type_id =&amp;gt; 2,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr2)&lt;br /&gt;
 penalty_attr3 = {:deadline_type_id =&amp;gt; 5,:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[:meta_review]}&lt;br /&gt;
       CalculatedPenalty.create(penalty_attr3)&amp;quot;&lt;br /&gt;
 @all_penalties[participant.id] = Hash.new&lt;br /&gt;
       @all_penalties[participant.id][:submission] = penalties[:submission]&lt;br /&gt;
       @all_penalties[participant.id][:review] = penalties[:review]&lt;br /&gt;
       @all_penalties[participant.id][:meta_review] = penalties[:meta_review]&lt;br /&gt;
       @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 deadline_type=[1,2,5]&lt;br /&gt;
 penalty_type=[:submission,:review,:meta_review]&lt;br /&gt;
 if calculate_for_participants&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
           penalty_attr={:deadline_type_id=&amp;gt;deadline_type[i],:participant_id =&amp;gt; @participant.id, :penalty_points =&amp;gt; penalties[penalty_type[i]]}&lt;br /&gt;
           CalculatedPenalty.create(penalty_attr)&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
 @all_penalties[participant.id] = {}&lt;br /&gt;
      for i in 0..2&lt;br /&gt;
          @all_penalties[participant.id][:penalty_type[i]] = penalties[:penalty_type[i]]&lt;br /&gt;
      end&lt;br /&gt;
 @all_penalties[participant.id][:total_penalty] = @total_penalty&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== conflict_notification Method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored the '''conflict_notification''' method to '''conflict_email''' method. When instructor click the button &amp;quot;email reviewer&amp;quot; whom he thought give a unfair review, the system should be able to send an email to the reviewer automatically.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
The old '''conflict_notification''' action queries an email address list of a certain kind of reviews. In its view conflict_notification.html.erb, A email form contains email list for instructor to choose from and email content. &lt;br /&gt;
[[File:old_email.png]]&lt;br /&gt;
&lt;br /&gt;
'''Before Refactoring''', in conflict_notification:&lt;br /&gt;
First,Get the instructor email address as sender&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
      if session[:user].role_id !=6             &lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
      @participant = AssignmentParticipant.find(params[:id])&lt;br /&gt;
      @assignment = Assignment.find(@participant.parent_id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then,Based on submission of review, the action query all the reviewers' email address  &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @questions = Hash.new&lt;br /&gt;
      questionnaires = @assignment.questionnaires&lt;br /&gt;
      questionnaires.each {&lt;br /&gt;
        |questionnaire|&lt;br /&gt;
        @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
      }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The email list is for instructor to choose from. The process_response method queries the email address.    &lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
      @reviewers_email_hash = Hash.new            &lt;br /&gt;
      @caction = &amp;quot;view&amp;quot;&lt;br /&gt;
      @submission = params[:submission]&lt;br /&gt;
      if @submission == &amp;quot;review&amp;quot;&lt;br /&gt;
        @caction = &amp;quot;view_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;review&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.reviews, &amp;quot;ReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_of_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;metareview&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Metareview&amp;quot;, &amp;quot;Metareviewer&amp;quot;, @participant.metareviews, &amp;quot;MetareviewQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;review_feedback&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;feedback&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Feedback&amp;quot;, &amp;quot;Author&amp;quot;, @participant.feedback, &amp;quot;AuthorFeedbackQuestionnaire&amp;quot;)&lt;br /&gt;
      elsif @submission == &amp;quot;teammate_review&amp;quot;&lt;br /&gt;
        @symbol = &amp;quot;teammate&amp;quot;&lt;br /&gt;
        process_response(&amp;quot;Teammate Review&amp;quot;, &amp;quot;Reviewer&amp;quot;, @participant.teammate_reviews, &amp;quot;TeammateReviewQuestionnaire&amp;quot;)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The get_body_text method construct email content also in controller&lt;br /&gt;
&amp;lt;pre&amp;gt;                                               &lt;br /&gt;
      @body = get_body_text(params[:submission])      &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The conflict_notification action requiring another two method &amp;quot;process_response&amp;quot; and &amp;quot;get_body_text&amp;quot; method to get the recipient email list and email content which contributes to extra complexity. The instructor only have to click the button &amp;quot;send email&amp;quot; in conflict_notification.html.erb and turn to send_conflict_email action, then he/she can send the email. If the instructor want to send another email, the process will repeat again,which will be terrible when reloading the &amp;quot;view&amp;quot; scores page.&lt;br /&gt;
&lt;br /&gt;
'''After Refactoring''':The quering reiviews actually have done in our show_reviews action, and we can get the individual reviewers' email address.In the reviewer table,we add extra button &amp;quot;email reviewer&amp;quot;.Now the instructor could send to reviewer email directly.&lt;br /&gt;
[[File:conflict_email.png]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In _review_table.html.erb,we add the link to send email. The review_id is passed to the conflict_email action taken as the recipient.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;%= link_to 'email reviewer', :action =&amp;gt; 'conflict_email',:remote=&amp;gt; true,:reviewer_id=&amp;gt; &lt;br /&gt;
&lt;br /&gt;
review.map.reviewer.user,:participant_id=&amp;gt;participant,:score=&amp;gt;sprintf(&amp;quot;%.2f&amp;quot;,score) %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In our new '''conflict_email''' action:&lt;br /&gt;
&lt;br /&gt;
We still need the instructor as the sender &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      if session[:user].role_id !=6&lt;br /&gt;
        @instructor = session[:user]&lt;br /&gt;
      else&lt;br /&gt;
        @instructor = Ta.get_my_instructor(session[:user].id)&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The reviewer_id is passed from the link,we can query his/her email address to send the email &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      recipient=User.find(params[:reviewer_id])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The responsibility of sending email has been delegated to a new mailer conflict_mailer. And the email content was constructed in the mailer.  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      participant = AssignmentParticipant.find(params[:participant_id])&lt;br /&gt;
      assignment=Assignment.find(participant.parent_id)      &lt;br /&gt;
      score=params[:score]&lt;br /&gt;
      ConflictMailer.send_conflict_email(instructor,recipient,assignment,score).deliver&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Take a look at new conflict_mailer, it define a '''send_conflict_email''' method. the email was sent from sender's email and to reviewer's email.Some instance variables were used in view.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 def send_conflict_email(sender,recipient,assignment,score)&lt;br /&gt;
      @assignment=assignment&lt;br /&gt;
      @recipient=recipient&lt;br /&gt;
      @score=score&lt;br /&gt;
      if recipient.role_id==1&lt;br /&gt;
        @role = &amp;quot;reviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;submission&amp;quot;&lt;br /&gt;
      else&lt;br /&gt;
        @role = &amp;quot;metareviewer&amp;quot;&lt;br /&gt;
        @item = &amp;quot;review&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
    mail subject: &amp;quot;Conflication Email&amp;quot;,from: sender.email,to: reviewer.email&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The link &amp;quot;email reviewer&amp;quot; request a ajax,so the current view page will not refresh when the action done&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
      respond_to do |format|&lt;br /&gt;
        format.js&lt;br /&gt;
      end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If an email was successfully sent,The instructor should get the alert window by ajax.&lt;br /&gt;
[[File:email_sent.png]]&lt;br /&gt;
&lt;br /&gt;
=== view_my_scores method===&lt;br /&gt;
&lt;br /&gt;
====Summary====&lt;br /&gt;
We refactored '''view_my_scores''' method to grades_show, deleted many unnecessary instance variables along with several review and meta reviews methods inside it. Therefore, the system will only search for scores in the database rather than search for scores and reviews, which wastes a lot of time during the grade show process. After refactoring, the complexity on this decreased from '''53''' to '''35'''.&lt;br /&gt;
We also optimize '''get_scores''' method to improve the efficiency of showing scores by students and instructors, which cost us most of the time during the project. After refactoring this method, the time cost of views in grade controller decreased by more than '''90%'''.&lt;br /&gt;
&lt;br /&gt;
We have done the following to the original methods:&lt;br /&gt;
&lt;br /&gt;
*Refactored '''view_my_scores''' method to '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Searched for the key reasons which lead to huge waiting time for getting score.&lt;br /&gt;
&lt;br /&gt;
*Refactored '''get_assessments_for''' method in response_map.rb and lead to more than 90% off the current waiting time.&lt;br /&gt;
&lt;br /&gt;
*Eliminated the search for reviews during the '''grades_show''' method.&lt;br /&gt;
&lt;br /&gt;
*Deleted unnecessary instance Variables.&lt;br /&gt;
&lt;br /&gt;
====Implementation====&lt;br /&gt;
*Deleted the unnecessary instance variables&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_score_results = Array.new&lt;br /&gt;
 @average_score_results = ScoreCache.get_class_scores(@participant.id)&lt;br /&gt;
 @statistics = Array.new&lt;br /&gt;
 @average_score_results.each { |x|&lt;br /&gt;
 @statistics &amp;lt;&amp;lt; x&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Deleted query for reviews and meta_reviews&lt;br /&gt;
&lt;br /&gt;
Deleted Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @average_reviews = ScoreCache.get_reviews_average(@participant.id)&lt;br /&gt;
 @average_metareviews = ScoreCache.get_metareviews_average(@participant.id)&lt;br /&gt;
 @my_reviews = ScoreCache.my_reviews(@participant.id)&lt;br /&gt;
 @my_metareviews = ScoreCache.my_metareviews(@participant.id)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Modify '''get_assessments_for''' method in response_map.rb&lt;br /&gt;
After doing this, the time cost of view function decreased by more than 90%&lt;br /&gt;
Before Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 # the original method to find all response &lt;br /&gt;
 @all_resp=Response.all&lt;br /&gt;
 for element in @all_resp&lt;br /&gt;
     if (element.map_id == map.map_id)&lt;br /&gt;
         @array_sort &amp;lt;&amp;lt; element&lt;br /&gt;
         @test &amp;lt;&amp;lt; map&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Refactoring:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 @all_resp=Response.find_by_map_id(map.map_id)&lt;br /&gt;
 @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
 @test &amp;lt;&amp;lt; map&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Add a new method into grades_controller.rb&lt;br /&gt;
&lt;br /&gt;
Add Method:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 #show_reviews method gets reviews, meta reviews and author feedback information from server.&lt;br /&gt;
  def show_reviews&lt;br /&gt;
    @partial='grades/'+params[:path]&lt;br /&gt;
    @prefix=params[:prefix]&lt;br /&gt;
    @score=Hash.new&lt;br /&gt;
    @score[:assessments]=Array.new&lt;br /&gt;
    params[:score][:assessments].each do |assessment|&lt;br /&gt;
        @score[:assessments]&amp;lt;&amp;lt;Response.find(assessment)&lt;br /&gt;
    end&lt;br /&gt;
    @score[:scores]=params[:score][:scores]&lt;br /&gt;
    @participant=AssignmentParticipant.find(params[:participant])&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @questions = {}&lt;br /&gt;
    questionnaires = @assignment.questionnaires&lt;br /&gt;
    questionnaires.each do |questionnaire|&lt;br /&gt;
      @questions[questionnaire.symbol] = questionnaire.questions&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Change view_my_score.html.erb into show_reviews.html.erb in views.&lt;br /&gt;
&lt;br /&gt;
*Add in views(show_reviews.html.erb)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;%= render :partial=&amp;gt;@partial, :locals =&amp;gt; {:prefix =&amp;gt; @prefix, :participant =&amp;gt; @participant, :rscore =&amp;gt; @score} %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Result====&lt;br /&gt;
*The following test results based on the test case on Expertiza(Assignments: Program 2 style) &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;font-size: 90%;&amp;quot;&lt;br /&gt;
|+ style=&amp;quot;font-size: 1.25em;&amp;quot; |&lt;br /&gt;
|-&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Name&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Before Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| After Refactoring&lt;br /&gt;
!style=&amp;quot;background:#eFeFeF;&amp;quot;| Reduced By&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| View all team's score(instructor)&lt;br /&gt;
| 484988ms&lt;br /&gt;
| 8642ms&lt;br /&gt;
| 98.21%&lt;br /&gt;
|-&lt;br /&gt;
| View own score(student)&lt;br /&gt;
| 8941ms&lt;br /&gt;
| 651ms&lt;br /&gt;
| 92.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
*Original Time for Instructor to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_old.png‎|frame|center|Original Time for Instructor to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Instructor to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Instructor_new.png‎|frame|center|Time for Instructor to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
*Original Time for Student to View all scores&lt;br /&gt;
&lt;br /&gt;
[[File:Student_old.png‎|frame|center|Original Time for Student to View all scores]]&lt;br /&gt;
&lt;br /&gt;
*Time for Student to View all scores after Refactoring&lt;br /&gt;
&lt;br /&gt;
[[File:Student_new.png‎|frame|center|Time for Student to View all scores after Refactoring]]&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Jgu7</name></author>
	</entry>
</feed>