<?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=Rroshan</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=Rroshan"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Rroshan"/>
	<updated>2026-09-30T21:04:50Z</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/OSS_E1467_rsv&amp;diff=92109</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=92109"/>
		<updated>2014-11-14T09:35:17Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type (''ReviewQuestionnaire'', ''AuthorFeedbackQuestionnaire'', ''MetareviewQuestionnaire'' and ''TeammateReviewQuestionnaire''), in each course of the logged-in user. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.46.18.78:3000/&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.46.18.78:3001/&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/sanjeevs/expertiza &amp;lt;ref&amp;gt;[https://github.com/sanjeevs/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/444 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/444 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
Also, there was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Design Pattern=&lt;br /&gt;
Leaderboard is a separate implementation which includes reading existing scores for the sole purpose of creating the leaders in different categories. As the task is more related to calculate and manipulate data, it was not feasible to implement any design pattern. We reduced the complexity and redundancy of database calls by reducing database calls from 625 to 111 to do the same task.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup. Login by any user and navigate to ''Home &amp;gt; Leaderboard'' to test the functionality.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#projectLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Lleaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
&lt;br /&gt;
We computed the number of data base ''&amp;quot;SELECT&amp;quot;'' call generated by the database driver by filtering the messages from the rails server's log. In the original code there were '''625''' database select access generated for the leaderboard view. In the new refactored code the number of select calls dropped to '''111'''.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| '''roles'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|13&lt;br /&gt;
| Optimized the SQL query in ''leaderboard_helper.rb'' to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| '''users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| '''participants'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|111&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|3&lt;br /&gt;
| All the participants associated with computed assignment list are calculated in a single database call and cached in memory rather than calling repetitively within loop.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignments'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|16&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Database calls to ''Assignments'' table was reduced as result of removing it from multiple loops. Supporting data structure and caching enabled to achieve this reduction.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignment_questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Upon careful code investigation, we felt there is no need of any database calls to ''assignment_questionnaires'' table. This contains mapping of ''assignment id'' and ''questionnaire id''.&lt;br /&gt;
|-&lt;br /&gt;
| '''questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|311&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Leaderboard reads the scores from ''ScoreCache'' table, which has ''revieweeId'' and a response object_type (''ReviewResponseMap'', ''AuthorFeedbackResponseMap'', etc.). Refactored code reuses the association of ''response object_type'' to the ''questionnaire_type'' and reduces the usage to 0. this is the most significant reduction in database calls. &lt;br /&gt;
|-&lt;br /&gt;
| '''score_caches'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|22&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|1&lt;br /&gt;
| ''ScoreCache'' table has a field - ''revieweeId'' which can be either ''participantId'' or ''teamId''. All repetitive database calls was reduced to a single call by combining target ''participantId'' and ''teamId'' as a list of ''revieweeId''.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|2&lt;br /&gt;
| Teams table was repetitively called within a loop to retrieve participation in a set of assignments. It was pulled out of the loop and modified to get the same result for all the teams for a larger set of assignments.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams_users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| '''leaderboards'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|9&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Leaderboards table was called multiple times to retrieve the Label for scores of corresponding questionnaire type.&amp;lt;br /&amp;gt;(e.g. ''&amp;quot;ReviewQuestionnaire&amp;quot; - &amp;quot;Submitted Work&amp;quot;''). It was reduced to fetch all such mapping and cached.&lt;br /&gt;
|-&lt;br /&gt;
| '''courses'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost '''15%'''.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|'''1'''&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''2'''&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|'''3'''&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''4'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''5'''&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|'''6'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|'''7'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|'''8'''&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|'''9'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|'''10'''&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E1475.Sequence_Diagram.png&amp;diff=91980</id>
		<title>File:E1475.Sequence Diagram.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E1475.Sequence_Diagram.png&amp;diff=91980"/>
		<updated>2014-11-12T02:50:34Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: uploaded a new version of &amp;amp;quot;File:E1475.Sequence Diagram.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:UseCase.png&amp;diff=91975</id>
		<title>File:UseCase.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:UseCase.png&amp;diff=91975"/>
		<updated>2014-11-12T02:45:32Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: uploaded a new version of &amp;amp;quot;File:UseCase.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:DatabaseDesign.png&amp;diff=91972</id>
		<title>File:DatabaseDesign.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:DatabaseDesign.png&amp;diff=91972"/>
		<updated>2014-11-12T02:42:35Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: uploaded a new version of &amp;amp;quot;File:DatabaseDesign.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:UML_Design.png&amp;diff=91969</id>
		<title>File:UML Design.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:UML_Design.png&amp;diff=91969"/>
		<updated>2014-11-12T02:37:51Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: uploaded a new version of &amp;amp;quot;File:UML Design.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:UML_Design.png&amp;diff=91961</id>
		<title>File:UML Design.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:UML_Design.png&amp;diff=91961"/>
		<updated>2014-11-12T02:33:27Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: uploaded a new version of &amp;amp;quot;File:UML Design.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91900</id>
		<title>CSC/ECE 517 Fall 2014/final E1475 nrnn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91900"/>
		<updated>2014-11-12T01:06:42Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Previous work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt; E1475. Intelligent assignment of teams&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Problem Statement&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
According to the existing code workflow, the assignment of topics to teams are based on FCFS (first come first serve) basis, where a team which first signs up for a topic gets the topic while other teams are waitlisted on the same topic. Since ‘sign up time’ is the only factor considered for topic assignment this method causes problems such as:&lt;br /&gt;
&lt;br /&gt;
#The assignment of topics are FCFS, hence not completely fair.&lt;br /&gt;
#Non-uniform distribution of topics among the teams in a class.&lt;br /&gt;
#The current system fails to resolve the problem when many teams bid for handful of topics(among many topics) causing unnecessary additions to the waitlist.&lt;br /&gt;
#The assignment of topics is more focused on individual selection and ‘sign up time’. Factors such as team size are not considered which are important while assigning a topic to the team and potentially can reduce many issues faced by the current system. &lt;br /&gt;
&lt;br /&gt;
To address the above mentioned issues, we have designed an ‘intelligent assignment of topics’ system which tries to address the issues faced by the current system.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Introduction &amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Expertiza ==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt; is a project developed using [http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails ]&amp;lt;/ref&amp;gt; platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment (LITRE)]&amp;lt;ref&amp;gt;[http://litre.ncsu.edu/ Learning in a Technology-Rich Environment (LITRE)]&amp;lt;/ref&amp;gt; program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
==Existing signup process==&lt;br /&gt;
The signup process for group projects is observed by most students to be a troublesome task  in expertiza. The current sign up process for topics is based on FCFS basis, where a student who signs up for a topic of his/her choice first, gets it. We have discovered some pitfalls with the current ‘topic assignment’ system in Expertiza which arises due to the below mentioned factors.  Due to these reasons, we now try to propose an intelligent system which can addresses many issues faced with the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Pitfalls with the current system ==&lt;br /&gt;
#One student can sign up only for a single topic. In cases where many topics are available, a student is forced to choose a single topic among many available topics which can be a difficult task. To select a single topic which best fits his/her choice among many available topics requires a pre-study of all topics prior to the signup process. Such a pre-requirement is not fulfilled by most  students, which results in a student signing up for a topic which he/she has randomly selected OR because it was among the only available topics.&lt;br /&gt;
#If a student is not able to sign up for a topic of his choice, he can waitlist himself for all the remaining topics, which causes unnecessary traffic in the waitlist queue of a topic. &lt;br /&gt;
#If all the teams choose a handful of topics among many topics, it would also result in unnecessary additions in the waitlist queue for those few topics resulting in a situation where all the topics are not uniformly distributed among all the teams&lt;br /&gt;
#Before, signing up, if more than one student forms a team and if each student belonging to the same team tries to signup for different topics, than those topics are allotted to individual students resulting in a situation where a team can hold more than one topic. Thus other teams are forced to choose from remaining topics which eventually results in longer waitlists.&lt;br /&gt;
&lt;br /&gt;
After observing the above problems with the existing method of ‘topic assignment’ in expertiza, we have proposed and implemented an ‘intelligent assignment of topics’ method to overcome all the shortcomings of the existing system in expertiza.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Previous work ==&lt;br /&gt;
Previously in 2012, to address this issue of expertiza, a team proposed a possible solution of [https://docs.google.com/document/d/1tyWX8njxDLvYpN7wJf5hjA6lnWbzQRP9vUKGxxRjRzo/edit#heading=h.5cgh9aixuut7/ ‘lottery based topic assignment’]&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1tyWX8njxDLvYpN7wJf5hjA6lnWbzQRP9vUKGxxRjRzo/edit#heading=h.5cgh9aixuut7/ Lottery based topic assignment]&amp;lt;/ref&amp;gt; algorithm. The algorithm works by considering every team as strength of 1, representing the student in the team. After sign up the topic would be allotted to the team based on a lottery system where a team is randomly selected for every topic. However this method failed to address the following issues:&lt;br /&gt;
#It did not consider the case where a team could be of more than one member, hence it allowed every team member to bid for different topics resulting in the same problem as mentioned in point (4) of Pitfalls with the current system.&lt;br /&gt;
#The topics were awarded based on a Lottery system and not based on any other criteria which resulted in topic assignment to be a game of luck factor rather than on individual’s choice.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Design Workflow &amp;lt;/b&amp;gt;=&lt;br /&gt;
To address the issues faced by both, the current system and lottery based system, we propose a solution based on ‘intelligent team assignment’ algorithm. The algorithm is based on two important factors:&lt;br /&gt;
&lt;br /&gt;
#Team strength&lt;br /&gt;
#Priority order of the topics submitted by the team.&lt;br /&gt;
&lt;br /&gt;
The algorithm works on bidding process which can be explained as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Before the bidding process ==&lt;br /&gt;
#Initially, every student is a team of 1 member. Before the bidding process takes place, students can merge their teams to form a larger team. The person to whom they have merged becomes the team owner/captain.&lt;br /&gt;
#Every team is given x bids(x is calculated based on the total class strength and total topics proposed), that they can place on each topic of their choice in a priority order where 1 being the highest priority.&lt;br /&gt;
#Every topic is allowed ‘p’ number of maximum bids after which the topic is waitlisted in the system.&lt;br /&gt;
#Teams can also place their bids on waitlisted topics. However, every topic has a threshold ‘q’ which signifies the maximum waitlisted bids allowed for each topic.&lt;br /&gt;
#Thus, if the combined threshold of ‘p+q’ bids for a topic is reached then the topic is no longer available for bidding unless the topic is dropped by a team which reduces the ‘p+q’ threshold value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== During Bidding Process ==&lt;br /&gt;
#Every team can place their bids on the available topics. Since every team is given ‘x’ bids, each team can bid for ‘x’ topics and list their bids in a priority order.&lt;br /&gt;
#A team can also place their bids on  waitlisted topics. The maximum allowed bids for waitlisted topics is ‘y’ where y is some portion of bids taken from total bids(x) allowed for each team.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== After the Bidding Process ==&lt;br /&gt;
#After the bidding process is complete, the teams can continue to merge to form larger teams.&lt;br /&gt;
#If team A merges with team B, the bids of team A would be lost.&lt;br /&gt;
#The merging of the teams is allowed till the topic assignment date when the teams would finally be assigned the topics by running an algorithm.&lt;br /&gt;
#The teams can also change their submitted topic priority order any number of times before running the ‘topic assignment’ algorithm. &lt;br /&gt;
&lt;br /&gt;
 The algorithm assigns the topic to each teams based on the following factors:&lt;br /&gt;
&lt;br /&gt;
# The team which is close to or has maximum possible team strength has a higher probability of winning the topic they had placed their bid on.&lt;br /&gt;
# For a team which satisfies condition(1), a topic would be assigned to the team based on the priority order of the bids that the team specified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
#As each team can place their bids on the available topics based on their topic priority. Hence every team gets to choose more than one topic of their choice.&lt;br /&gt;
&lt;br /&gt;
#As every topic has a maximum number of allowed bids, after which the topic is no longer available for bidding, this method addresses the issue where many teams choose only a handful topics among all topics. &lt;br /&gt;
&lt;br /&gt;
#As the maximum allowed bids for waitlisting a topic is also limited for every team, hence the issue of unnecessary additions to waitlist is resolved by this method.&lt;br /&gt;
&lt;br /&gt;
#The teams are assigned topics based on modified [http://en.wikipedia.org/wiki/Stable_marriage_problem/ Stable marriage problem] algorithm which considers factors such as team size and priority ensuring that the topics are no longer assigned based on FCFS basis. Thus this method addresses the most important issue where a topic is not assigned to the team just because the team was late to sign up for the topic as compared to the other teams.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Requirements&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
1) The instructor should be able to create assignments which can utilize intelligent assignment of teams. (It is an optional feature)&lt;br /&gt;
&lt;br /&gt;
2) The instructor should be able to set the maximum number of bids a team can make. Defaulted to 3.&lt;br /&gt;
&lt;br /&gt;
3) The teams should be able place bids on different topics limited to the number set by the instructor for these assignments&lt;br /&gt;
&lt;br /&gt;
4) The teams should be able to prioritize their bids.&lt;br /&gt;
&lt;br /&gt;
5) The instructor should be able to kick off the intelligent assignment of teams.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Sequence Diagram&amp;lt;/b&amp;gt;=&lt;br /&gt;
[[File:E1475.Sequence Diagram.png|frame|center|Fig 1. Sequence Diagram]]&lt;br /&gt;
Fig 1. shows the sequence diagram for this feature. The diagram shows the sequences exclusive to this feature. Therefore, this assumes that the assignment/exercise has already been created. &lt;br /&gt;
Once the assignment is created, the instructor can enable the 'intelligent assignment of teams' feature for the particular assignment. Enabling this feature would give the students(or teams) a view to place bids on the topics they like. They can associate each bid with a priority. Once the deadline has passed, the instructor can kickoff the process which performs the automatic assignment. This would in turn start assigning teams with topics based on their bid preferences.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;UML Design&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
The intelligent assignment controller is dependent on the ''AssignmentTopicController'' and other models like - ''Assignment'', ''AssignmentTopic'' and ''Team''. When the instructor starts the intelligent assignment of topics to teams, ''IntelligentAssignmentController'' triggers the assignment algorithm.&lt;br /&gt;
&lt;br /&gt;
The students interact with ''AssignmentTopicView'' which lists down all the topics for the assignment and allows students to bid for topics with priority. ''AssignmentTopicController'' is responsible for recording all the bids and priorities correctly.&lt;br /&gt;
&lt;br /&gt;
Following is the UML diagram of the O-O design focusing only on the component related to intelligent assignment of topics to teams.&lt;br /&gt;
&lt;br /&gt;
[[File: UML_Design.png|UML Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Database Design&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
In order to meet other solution requirement, new tables are added. The following diagram represents the new tables in [http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation Crow Foot's Notation]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation Crow Foot's Notation]&amp;lt;/ref&amp;gt;. The ''user'' table mentioned is not new and is present only to explain the field - ''ownerId''.&lt;br /&gt;
&lt;br /&gt;
Earlier, all the information in ''AssignmentTopic'' and ''AssignmentTopicMetadata'' tables were in a single table called ''signup_topics''. However, there was lot of data redundancy observed and we also required to add an extra field in the table ''signup_topics''. Therefore, we decided to store the topics related to an assignment according to the diagram. One caveat to this design is that all the topics for an assignment are considered equal in terms of category, maximum bids allowed and maximum bids in waiting list.&lt;br /&gt;
&lt;br /&gt;
The table ''bid'' is supposed to store all the bids on the topics with their priority. The owner of the bid will be recorded too. Current requirement is to have only one bid per topic by an owner. Therefore, we could have ''(ownerId, topicId)'' pair as the primary key. However, in order to support multiple bids in a future sceario, we have used a field ''id'' as the primary key.&lt;br /&gt;
&lt;br /&gt;
Apart from the mentioned new tables, we will be using pre-existing tables to meet our requirements and design.&lt;br /&gt;
&lt;br /&gt;
[[File: DatabaseDesign.png|Database Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91898</id>
		<title>CSC/ECE 517 Fall 2014/final E1475 nrnn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91898"/>
		<updated>2014-11-12T01:03:56Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Database Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt; E1475. Intelligent assignment of teams&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Problem Statement&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
According to the existing code workflow, the assignment of topics to teams are based on FCFS (first come first serve) basis, where a team which first signs up for a topic gets the topic while other teams are waitlisted on the same topic. Since ‘sign up time’ is the only factor considered for topic assignment this method causes problems such as:&lt;br /&gt;
&lt;br /&gt;
#The assignment of topics are FCFS, hence not completely fair.&lt;br /&gt;
#Non-uniform distribution of topics among the teams in a class.&lt;br /&gt;
#The current system fails to resolve the problem when many teams bid for handful of topics(among many topics) causing unnecessary additions to the waitlist.&lt;br /&gt;
#The assignment of topics is more focused on individual selection and ‘sign up time’. Factors such as team size are not considered which are important while assigning a topic to the team and potentially can reduce many issues faced by the current system. &lt;br /&gt;
&lt;br /&gt;
To address the above mentioned issues, we have designed an ‘intelligent assignment of topics’ system which tries to address the issues faced by the current system.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Introduction &amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Expertiza ==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt; is a project developed using [http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails ]&amp;lt;/ref&amp;gt; platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment (LITRE)]&amp;lt;ref&amp;gt;[http://litre.ncsu.edu/ Learning in a Technology-Rich Environment (LITRE)]&amp;lt;/ref&amp;gt; program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
==Existing signup process==&lt;br /&gt;
The signup process for group projects is observed by most students to be a troublesome task  in expertiza. The current sign up process for topics is based on FCFS basis, where a student who signs up for a topic of his/her choice first, gets it. We have discovered some pitfalls with the current ‘topic assignment’ system in Expertiza which arises due to the below mentioned factors.  Due to these reasons, we now try to propose an intelligent system which can addresses many issues faced with the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Pitfalls with the current system ==&lt;br /&gt;
#One student can sign up only for a single topic. In cases where many topics are available, a student is forced to choose a single topic among many available topics which can be a difficult task. To select a single topic which best fits his/her choice among many available topics requires a pre-study of all topics prior to the signup process. Such a pre-requirement is not fulfilled by most  students, which results in a student signing up for a topic which he/she has randomly selected OR because it was among the only available topics.&lt;br /&gt;
#If a student is not able to sign up for a topic of his choice, he can waitlist himself for all the remaining topics, which causes unnecessary traffic in the waitlist queue of a topic. &lt;br /&gt;
#If all the teams choose a handful of topics among many topics, it would also result in unnecessary additions in the waitlist queue for those few topics resulting in a situation where all the topics are not uniformly distributed among all the teams&lt;br /&gt;
#Before, signing up, if more than one student forms a team and if each student belonging to the same team tries to signup for different topics, than those topics are allotted to individual students resulting in a situation where a team can hold more than one topic. Thus other teams are forced to choose from remaining topics which eventually results in longer waitlists.&lt;br /&gt;
&lt;br /&gt;
After observing the above problems with the existing method of ‘topic assignment’ in expertiza, we have proposed and implemented an ‘intelligent assignment of topics’ method to overcome all the shortcomings of the existing system in expertiza.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Previous work ==&lt;br /&gt;
Previously in 2012, to address this issue of expertiza, a team proposed a possible solution of ‘lottery based topic assignment’ algorithm. The algorithm works by considering every team as strength of 1, representing the student in the team. After sign up the topic would be allotted to the team based on a lottery system where a team is randomly selected for every topic. However this method failed to address the following issues:&lt;br /&gt;
#It did not consider the case where a team could be of more than one member, hence it allowed every team member to bid for different topics resulting in the same problem as mentioned in point (4) of Pitfalls with the current system.&lt;br /&gt;
#The topics were awarded based on a Lottery system and not based on any other criteria which resulted in topic assignment to be a game of luck factor rather than on individual’s choice.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Design Workflow &amp;lt;/b&amp;gt;=&lt;br /&gt;
To address the issues faced by both, the current system and lottery based system, we propose a solution based on ‘intelligent team assignment’ algorithm. The algorithm is based on two important factors:&lt;br /&gt;
&lt;br /&gt;
#Team strength&lt;br /&gt;
#Priority order of the topics submitted by the team.&lt;br /&gt;
&lt;br /&gt;
The algorithm works on bidding process which can be explained as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Before the bidding process ==&lt;br /&gt;
#Initially, every student is a team of 1 member. Before the bidding process takes place, students can merge their teams to form a larger team. The person to whom they have merged becomes the team owner/captain.&lt;br /&gt;
#Every team is given x bids(x is calculated based on the total class strength and total topics proposed), that they can place on each topic of their choice in a priority order where 1 being the highest priority.&lt;br /&gt;
#Every topic is allowed ‘p’ number of maximum bids after which the topic is waitlisted in the system.&lt;br /&gt;
#Teams can also place their bids on waitlisted topics. However, every topic has a threshold ‘q’ which signifies the maximum waitlisted bids allowed for each topic.&lt;br /&gt;
#Thus, if the combined threshold of ‘p+q’ bids for a topic is reached then the topic is no longer available for bidding unless the topic is dropped by a team which reduces the ‘p+q’ threshold value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== During Bidding Process ==&lt;br /&gt;
#Every team can place their bids on the available topics. Since every team is given ‘x’ bids, each team can bid for ‘x’ topics and list their bids in a priority order.&lt;br /&gt;
#A team can also place their bids on  waitlisted topics. The maximum allowed bids for waitlisted topics is ‘y’ where y is some portion of bids taken from total bids(x) allowed for each team.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== After the Bidding Process ==&lt;br /&gt;
#After the bidding process is complete, the teams can continue to merge to form larger teams.&lt;br /&gt;
#If team A merges with team B, the bids of team A would be lost.&lt;br /&gt;
#The merging of the teams is allowed till the topic assignment date when the teams would finally be assigned the topics by running an algorithm.&lt;br /&gt;
#The teams can also change their submitted topic priority order any number of times before running the ‘topic assignment’ algorithm. &lt;br /&gt;
&lt;br /&gt;
 The algorithm assigns the topic to each teams based on the following factors:&lt;br /&gt;
&lt;br /&gt;
# The team which is close to or has maximum possible team strength has a higher probability of winning the topic they had placed their bid on.&lt;br /&gt;
# For a team which satisfies condition(1), a topic would be assigned to the team based on the priority order of the bids that the team specified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
#As each team can place their bids on the available topics based on their topic priority. Hence every team gets to choose more than one topic of their choice.&lt;br /&gt;
&lt;br /&gt;
#As every topic has a maximum number of allowed bids, after which the topic is no longer available for bidding, this method addresses the issue where many teams choose only a handful topics among all topics. &lt;br /&gt;
&lt;br /&gt;
#As the maximum allowed bids for waitlisting a topic is also limited for every team, hence the issue of unnecessary additions to waitlist is resolved by this method.&lt;br /&gt;
&lt;br /&gt;
#The teams are assigned topics based on modified [http://en.wikipedia.org/wiki/Stable_marriage_problem/ Stable marriage problem] algorithm which considers factors such as team size and priority ensuring that the topics are no longer assigned based on FCFS basis. Thus this method addresses the most important issue where a topic is not assigned to the team just because the team was late to sign up for the topic as compared to the other teams.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Requirements&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
1) The instructor should be able to create assignments which can utilize intelligent assignment of teams. (It is an optional feature)&lt;br /&gt;
&lt;br /&gt;
2) The instructor should be able to set the maximum number of bids a team can make. Defaulted to 3.&lt;br /&gt;
&lt;br /&gt;
3) The teams should be able place bids on different topics limited to the number set by the instructor for these assignments&lt;br /&gt;
&lt;br /&gt;
4) The teams should be able to prioritize their bids.&lt;br /&gt;
&lt;br /&gt;
5) The instructor should be able to kick off the intelligent assignment of teams.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Sequence Diagram&amp;lt;/b&amp;gt;=&lt;br /&gt;
[[File:E1475.Sequence Diagram.png|frame|center|Fig 1. Sequence Diagram]]&lt;br /&gt;
Fig 1. shows the sequence diagram for this feature. The diagram shows the sequences exclusive to this feature. Therefore, this assumes that the assignment/exercise has already been created. &lt;br /&gt;
Once the assignment is created, the instructor can enable the 'intelligent assignment of teams' feature for the particular assignment. Enabling this feature would give the students(or teams) a view to place bids on the topics they like. They can associate each bid with a priority. Once the deadline has passed, the instructor can kickoff the process which performs the automatic assignment. This would in turn start assigning teams with topics based on their bid preferences.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;UML Design&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
The intelligent assignment controller is dependent on the ''AssignmentTopicController'' and other models like - ''Assignment'', ''AssignmentTopic'' and ''Team''. When the instructor starts the intelligent assignment of topics to teams, ''IntelligentAssignmentController'' triggers the assignment algorithm.&lt;br /&gt;
&lt;br /&gt;
The students interact with ''AssignmentTopicView'' which lists down all the topics for the assignment and allows students to bid for topics with priority. ''AssignmentTopicController'' is responsible for recording all the bids and priorities correctly.&lt;br /&gt;
&lt;br /&gt;
Following is the UML diagram of the O-O design focusing only on the component related to intelligent assignment of topics to teams.&lt;br /&gt;
&lt;br /&gt;
[[File: UML_Design.png|UML Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Database Design&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
In order to meet other solution requirement, new tables are added. The following diagram represents the new tables in [http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation Crow Foot's Notation]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation Crow Foot's Notation]&amp;lt;/ref&amp;gt;. The ''user'' table mentioned is not new and is present only to explain the field - ''ownerId''.&lt;br /&gt;
&lt;br /&gt;
Earlier, all the information in ''AssignmentTopic'' and ''AssignmentTopicMetadata'' tables were in a single table called ''signup_topics''. However, there was lot of data redundancy observed and we also required to add an extra field in the table ''signup_topics''. Therefore, we decided to store the topics related to an assignment according to the diagram. One caveat to this design is that all the topics for an assignment are considered equal in terms of category, maximum bids allowed and maximum bids in waiting list.&lt;br /&gt;
&lt;br /&gt;
The table ''bid'' is supposed to store all the bids on the topics with their priority. The owner of the bid will be recorded too. Current requirement is to have only one bid per topic by an owner. Therefore, we could have ''(ownerId, topicId)'' pair as the primary key. However, in order to support multiple bids in a future sceario, we have used a field ''id'' as the primary key.&lt;br /&gt;
&lt;br /&gt;
Apart from the mentioned new tables, we will be using pre-existing tables to meet our requirements and design.&lt;br /&gt;
&lt;br /&gt;
[[File: DatabaseDesign.png|Database Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91896</id>
		<title>CSC/ECE 517 Fall 2014/final E1475 nrnn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91896"/>
		<updated>2014-11-12T01:02:27Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt; E1475. Intelligent assignment of teams&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Problem Statement&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
According to the existing code workflow, the assignment of topics to teams are based on FCFS (first come first serve) basis, where a team which first signs up for a topic gets the topic while other teams are waitlisted on the same topic. Since ‘sign up time’ is the only factor considered for topic assignment this method causes problems such as:&lt;br /&gt;
&lt;br /&gt;
#The assignment of topics are FCFS, hence not completely fair.&lt;br /&gt;
#Non-uniform distribution of topics among the teams in a class.&lt;br /&gt;
#The current system fails to resolve the problem when many teams bid for handful of topics(among many topics) causing unnecessary additions to the waitlist.&lt;br /&gt;
#The assignment of topics is more focused on individual selection and ‘sign up time’. Factors such as team size are not considered which are important while assigning a topic to the team and potentially can reduce many issues faced by the current system. &lt;br /&gt;
&lt;br /&gt;
To address the above mentioned issues, we have designed an ‘intelligent assignment of topics’ system which tries to address the issues faced by the current system.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Introduction &amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Expertiza ==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt; is a project developed using [http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails ]&amp;lt;/ref&amp;gt; platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment (LITRE)]&amp;lt;ref&amp;gt;[http://litre.ncsu.edu/ Learning in a Technology-Rich Environment (LITRE)]&amp;lt;/ref&amp;gt; program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
==Existing signup process==&lt;br /&gt;
The signup process for group projects is observed by most students to be a troublesome task  in expertiza. The current sign up process for topics is based on FCFS basis, where a student who signs up for a topic of his/her choice first, gets it. We have discovered some pitfalls with the current ‘topic assignment’ system in Expertiza which arises due to the below mentioned factors.  Due to these reasons, we now try to propose an intelligent system which can addresses many issues faced with the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Pitfalls with the current system ==&lt;br /&gt;
#One student can sign up only for a single topic. In cases where many topics are available, a student is forced to choose a single topic among many available topics which can be a difficult task. To select a single topic which best fits his/her choice among many available topics requires a pre-study of all topics prior to the signup process. Such a pre-requirement is not fulfilled by most  students, which results in a student signing up for a topic which he/she has randomly selected OR because it was among the only available topics.&lt;br /&gt;
#If a student is not able to sign up for a topic of his choice, he can waitlist himself for all the remaining topics, which causes unnecessary traffic in the waitlist queue of a topic. &lt;br /&gt;
#If all the teams choose a handful of topics among many topics, it would also result in unnecessary additions in the waitlist queue for those few topics resulting in a situation where all the topics are not uniformly distributed among all the teams&lt;br /&gt;
#Before, signing up, if more than one student forms a team and if each student belonging to the same team tries to signup for different topics, than those topics are allotted to individual students resulting in a situation where a team can hold more than one topic. Thus other teams are forced to choose from remaining topics which eventually results in longer waitlists.&lt;br /&gt;
&lt;br /&gt;
After observing the above problems with the existing method of ‘topic assignment’ in expertiza, we have proposed and implemented an ‘intelligent assignment of topics’ method to overcome all the shortcomings of the existing system in expertiza.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Previous work ==&lt;br /&gt;
Previously in 2012, to address this issue of expertiza, a team proposed a possible solution of ‘lottery based topic assignment’ algorithm. The algorithm works by considering every team as strength of 1, representing the student in the team. After sign up the topic would be allotted to the team based on a lottery system where a team is randomly selected for every topic. However this method failed to address the following issues:&lt;br /&gt;
#It did not consider the case where a team could be of more than one member, hence it allowed every team member to bid for different topics resulting in the same problem as mentioned in point (4) of Pitfalls with the current system.&lt;br /&gt;
#The topics were awarded based on a Lottery system and not based on any other criteria which resulted in topic assignment to be a game of luck factor rather than on individual’s choice.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Design Workflow &amp;lt;/b&amp;gt;=&lt;br /&gt;
To address the issues faced by both, the current system and lottery based system, we propose a solution based on ‘intelligent team assignment’ algorithm. The algorithm is based on two important factors:&lt;br /&gt;
&lt;br /&gt;
#Team strength&lt;br /&gt;
#Priority order of the topics submitted by the team.&lt;br /&gt;
&lt;br /&gt;
The algorithm works on bidding process which can be explained as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Before the bidding process ==&lt;br /&gt;
#Initially, every student is a team of 1 member. Before the bidding process takes place, students can merge their teams to form a larger team. The person to whom they have merged becomes the team owner/captain.&lt;br /&gt;
#Every team is given x bids(x is calculated based on the total class strength and total topics proposed), that they can place on each topic of their choice in a priority order where 1 being the highest priority.&lt;br /&gt;
#Every topic is allowed ‘p’ number of maximum bids after which the topic is waitlisted in the system.&lt;br /&gt;
#Teams can also place their bids on waitlisted topics. However, every topic has a threshold ‘q’ which signifies the maximum waitlisted bids allowed for each topic.&lt;br /&gt;
#Thus, if the combined threshold of ‘p+q’ bids for a topic is reached then the topic is no longer available for bidding unless the topic is dropped by a team which reduces the ‘p+q’ threshold value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== During Bidding Process ==&lt;br /&gt;
#Every team can place their bids on the available topics. Since every team is given ‘x’ bids, each team can bid for ‘x’ topics and list their bids in a priority order.&lt;br /&gt;
#A team can also place their bids on  waitlisted topics. The maximum allowed bids for waitlisted topics is ‘y’ where y is some portion of bids taken from total bids(x) allowed for each team.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== After the Bidding Process ==&lt;br /&gt;
#After the bidding process is complete, the teams can continue to merge to form larger teams.&lt;br /&gt;
#If team A merges with team B, the bids of team A would be lost.&lt;br /&gt;
#The merging of the teams is allowed till the topic assignment date when the teams would finally be assigned the topics by running an algorithm.&lt;br /&gt;
#The teams can also change their submitted topic priority order any number of times before running the ‘topic assignment’ algorithm. &lt;br /&gt;
&lt;br /&gt;
 The algorithm assigns the topic to each teams based on the following factors:&lt;br /&gt;
&lt;br /&gt;
# The team which is close to or has maximum possible team strength has a higher probability of winning the topic they had placed their bid on.&lt;br /&gt;
# For a team which satisfies condition(1), a topic would be assigned to the team based on the priority order of the bids that the team specified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
#As each team can place their bids on the available topics based on their topic priority. Hence every team gets to choose more than one topic of their choice.&lt;br /&gt;
&lt;br /&gt;
#As every topic has a maximum number of allowed bids, after which the topic is no longer available for bidding, this method addresses the issue where many teams choose only a handful topics among all topics. &lt;br /&gt;
&lt;br /&gt;
#As the maximum allowed bids for waitlisting a topic is also limited for every team, hence the issue of unnecessary additions to waitlist is resolved by this method.&lt;br /&gt;
&lt;br /&gt;
#The teams are assigned topics based on modified [http://en.wikipedia.org/wiki/Stable_marriage_problem/ Stable marriage problem] algorithm which considers factors such as team size and priority ensuring that the topics are no longer assigned based on FCFS basis. Thus this method addresses the most important issue where a topic is not assigned to the team just because the team was late to sign up for the topic as compared to the other teams.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Requirements&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
1) The instructor should be able to create assignments which can utilize intelligent assignment of teams. (It is an optional feature)&lt;br /&gt;
&lt;br /&gt;
2) The instructor should be able to set the maximum number of bids a team can make. Defaulted to 3.&lt;br /&gt;
&lt;br /&gt;
3) The teams should be able place bids on different topics limited to the number set by the instructor for these assignments&lt;br /&gt;
&lt;br /&gt;
4) The teams should be able to prioritize their bids.&lt;br /&gt;
&lt;br /&gt;
5) The instructor should be able to kick off the intelligent assignment of teams.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Sequence Diagram&amp;lt;/b&amp;gt;=&lt;br /&gt;
[[File:E1475.Sequence Diagram.png|frame|center|Fig 1. Sequence Diagram]]&lt;br /&gt;
Fig 1. shows the sequence diagram for this feature. The diagram shows the sequences exclusive to this feature. Therefore, this assumes that the assignment/exercise has already been created. &lt;br /&gt;
Once the assignment is created, the instructor can enable the 'intelligent assignment of teams' feature for the particular assignment. Enabling this feature would give the students(or teams) a view to place bids on the topics they like. They can associate each bid with a priority. Once the deadline has passed, the instructor can kickoff the process which performs the automatic assignment. This would in turn start assigning teams with topics based on their bid preferences.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;UML Design&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
The intelligent assignment controller is dependent on the ''AssignmentTopicController'' and other models like - ''Assignment'', ''AssignmentTopic'' and ''Team''. When the instructor starts the intelligent assignment of topics to teams, ''IntelligentAssignmentController'' triggers the assignment algorithm.&lt;br /&gt;
&lt;br /&gt;
The students interact with ''AssignmentTopicView'' which lists down all the topics for the assignment and allows students to bid for topics with priority. ''AssignmentTopicController'' is responsible for recording all the bids and priorities correctly.&lt;br /&gt;
&lt;br /&gt;
Following is the UML diagram of the O-O design focusing only on the component related to intelligent assignment of topics to teams.&lt;br /&gt;
&lt;br /&gt;
[[File: UML_Design.png|UML Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Database Design&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
In order to meet other solution requirement, new tables are added. The following diagram represents the new tables in [http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation Crow Foot's Notation]. The ''user'' table mentioned is not new and is present only to explain the field - ''ownerId''.&lt;br /&gt;
&lt;br /&gt;
Earlier, all the information in ''AssignmentTopic'' and ''AssignmentTopicMetadata'' tables were in a single table called ''signup_topics''. However, there was lot of data redundancy observed and we also required to add an extra field in the table ''signup_topics''. Therefore, we decided to store the topics related to an assignment according to the diagram. One caveat to this design is that all the topics for an assignment are considered equal in terms of category, maximum bids allowed and maximum bids in waiting list.&lt;br /&gt;
&lt;br /&gt;
The table ''bid'' is supposed to store all the bids on the topics with their priority. The owner of the bid will be recorded too. Current requirement is to have only one bid per topic by an owner. Therefore, we could have ''(ownerId, topicId)'' pair as the primary key. However, in order to support multiple bids in a future sceario, we have used a field ''id'' as the primary key.&lt;br /&gt;
&lt;br /&gt;
Apart from the mentioned new tables, we will be using pre-existing tables to meet our requirements and design.&lt;br /&gt;
&lt;br /&gt;
[[File: DatabaseDesign.png|Database Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91895</id>
		<title>CSC/ECE 517 Fall 2014/final E1475 nrnn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91895"/>
		<updated>2014-11-12T01:01:44Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt; E1475. Intelligent assignment of teams&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Problem Statement&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
According to the existing code workflow, the assignment of topics to teams are based on FCFS (first come first serve) basis, where a team which first signs up for a topic gets the topic while other teams are waitlisted on the same topic. Since ‘sign up time’ is the only factor considered for topic assignment this method causes problems such as:&lt;br /&gt;
&lt;br /&gt;
#The assignment of topics are FCFS, hence not completely fair.&lt;br /&gt;
#Non-uniform distribution of topics among the teams in a class.&lt;br /&gt;
#The current system fails to resolve the problem when many teams bid for handful of topics(among many topics) causing unnecessary additions to the waitlist.&lt;br /&gt;
#The assignment of topics is more focused on individual selection and ‘sign up time’. Factors such as team size are not considered which are important while assigning a topic to the team and potentially can reduce many issues faced by the current system. &lt;br /&gt;
&lt;br /&gt;
To address the above mentioned issues, we have designed an ‘intelligent assignment of topics’ system which tries to address the issues faced by the current system.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Introduction &amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Expertiza ==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;ref&amp;gt;[Expertiza http://expertiza.ncsu.edu/]&amp;lt;/ref&amp;gt; is a project developed using [http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails]&amp;lt;ref&amp;gt;[Ruby on Rails http://en.wikipedia.org/wiki/Ruby_on_Rails]&amp;lt;/ref&amp;gt; platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment (LITRE)]&amp;lt;ref&amp;gt;[http://litre.ncsu.edu/ Learning in a Technology-Rich Environment (LITRE)]&amp;lt;/ref&amp;gt; program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
==Existing signup process==&lt;br /&gt;
The signup process for group projects is observed by most students to be a troublesome task  in expertiza. The current sign up process for topics is based on FCFS basis, where a student who signs up for a topic of his/her choice first, gets it. We have discovered some pitfalls with the current ‘topic assignment’ system in Expertiza which arises due to the below mentioned factors.  Due to these reasons, we now try to propose an intelligent system which can addresses many issues faced with the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Pitfalls with the current system ==&lt;br /&gt;
#One student can sign up only for a single topic. In cases where many topics are available, a student is forced to choose a single topic among many available topics which can be a difficult task. To select a single topic which best fits his/her choice among many available topics requires a pre-study of all topics prior to the signup process. Such a pre-requirement is not fulfilled by most  students, which results in a student signing up for a topic which he/she has randomly selected OR because it was among the only available topics.&lt;br /&gt;
#If a student is not able to sign up for a topic of his choice, he can waitlist himself for all the remaining topics, which causes unnecessary traffic in the waitlist queue of a topic. &lt;br /&gt;
#If all the teams choose a handful of topics among many topics, it would also result in unnecessary additions in the waitlist queue for those few topics resulting in a situation where all the topics are not uniformly distributed among all the teams&lt;br /&gt;
#Before, signing up, if more than one student forms a team and if each student belonging to the same team tries to signup for different topics, than those topics are allotted to individual students resulting in a situation where a team can hold more than one topic. Thus other teams are forced to choose from remaining topics which eventually results in longer waitlists.&lt;br /&gt;
&lt;br /&gt;
After observing the above problems with the existing method of ‘topic assignment’ in expertiza, we have proposed and implemented an ‘intelligent assignment of topics’ method to overcome all the shortcomings of the existing system in expertiza.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Previous work ==&lt;br /&gt;
Previously in 2012, to address this issue of expertiza, a team proposed a possible solution of ‘lottery based topic assignment’ algorithm. The algorithm works by considering every team as strength of 1, representing the student in the team. After sign up the topic would be allotted to the team based on a lottery system where a team is randomly selected for every topic. However this method failed to address the following issues:&lt;br /&gt;
#It did not consider the case where a team could be of more than one member, hence it allowed every team member to bid for different topics resulting in the same problem as mentioned in point (4) of Pitfalls with the current system.&lt;br /&gt;
#The topics were awarded based on a Lottery system and not based on any other criteria which resulted in topic assignment to be a game of luck factor rather than on individual’s choice.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Design Workflow &amp;lt;/b&amp;gt;=&lt;br /&gt;
To address the issues faced by both, the current system and lottery based system, we propose a solution based on ‘intelligent team assignment’ algorithm. The algorithm is based on two important factors:&lt;br /&gt;
&lt;br /&gt;
#Team strength&lt;br /&gt;
#Priority order of the topics submitted by the team.&lt;br /&gt;
&lt;br /&gt;
The algorithm works on bidding process which can be explained as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Before the bidding process ==&lt;br /&gt;
#Initially, every student is a team of 1 member. Before the bidding process takes place, students can merge their teams to form a larger team. The person to whom they have merged becomes the team owner/captain.&lt;br /&gt;
#Every team is given x bids(x is calculated based on the total class strength and total topics proposed), that they can place on each topic of their choice in a priority order where 1 being the highest priority.&lt;br /&gt;
#Every topic is allowed ‘p’ number of maximum bids after which the topic is waitlisted in the system.&lt;br /&gt;
#Teams can also place their bids on waitlisted topics. However, every topic has a threshold ‘q’ which signifies the maximum waitlisted bids allowed for each topic.&lt;br /&gt;
#Thus, if the combined threshold of ‘p+q’ bids for a topic is reached then the topic is no longer available for bidding unless the topic is dropped by a team which reduces the ‘p+q’ threshold value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== During Bidding Process ==&lt;br /&gt;
#Every team can place their bids on the available topics. Since every team is given ‘x’ bids, each team can bid for ‘x’ topics and list their bids in a priority order.&lt;br /&gt;
#A team can also place their bids on  waitlisted topics. The maximum allowed bids for waitlisted topics is ‘y’ where y is some portion of bids taken from total bids(x) allowed for each team.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== After the Bidding Process ==&lt;br /&gt;
#After the bidding process is complete, the teams can continue to merge to form larger teams.&lt;br /&gt;
#If team A merges with team B, the bids of team A would be lost.&lt;br /&gt;
#The merging of the teams is allowed till the topic assignment date when the teams would finally be assigned the topics by running an algorithm.&lt;br /&gt;
#The teams can also change their submitted topic priority order any number of times before running the ‘topic assignment’ algorithm. &lt;br /&gt;
&lt;br /&gt;
 The algorithm assigns the topic to each teams based on the following factors:&lt;br /&gt;
&lt;br /&gt;
# The team which is close to or has maximum possible team strength has a higher probability of winning the topic they had placed their bid on.&lt;br /&gt;
# For a team which satisfies condition(1), a topic would be assigned to the team based on the priority order of the bids that the team specified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
#As each team can place their bids on the available topics based on their topic priority. Hence every team gets to choose more than one topic of their choice.&lt;br /&gt;
&lt;br /&gt;
#As every topic has a maximum number of allowed bids, after which the topic is no longer available for bidding, this method addresses the issue where many teams choose only a handful topics among all topics. &lt;br /&gt;
&lt;br /&gt;
#As the maximum allowed bids for waitlisting a topic is also limited for every team, hence the issue of unnecessary additions to waitlist is resolved by this method.&lt;br /&gt;
&lt;br /&gt;
#The teams are assigned topics based on modified [http://en.wikipedia.org/wiki/Stable_marriage_problem/ Stable marriage problem] algorithm which considers factors such as team size and priority ensuring that the topics are no longer assigned based on FCFS basis. Thus this method addresses the most important issue where a topic is not assigned to the team just because the team was late to sign up for the topic as compared to the other teams.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Requirements&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
1) The instructor should be able to create assignments which can utilize intelligent assignment of teams. (It is an optional feature)&lt;br /&gt;
&lt;br /&gt;
2) The instructor should be able to set the maximum number of bids a team can make. Defaulted to 3.&lt;br /&gt;
&lt;br /&gt;
3) The teams should be able place bids on different topics limited to the number set by the instructor for these assignments&lt;br /&gt;
&lt;br /&gt;
4) The teams should be able to prioritize their bids.&lt;br /&gt;
&lt;br /&gt;
5) The instructor should be able to kick off the intelligent assignment of teams.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Sequence Diagram&amp;lt;/b&amp;gt;=&lt;br /&gt;
[[File:E1475.Sequence Diagram.png|frame|center|Fig 1. Sequence Diagram]]&lt;br /&gt;
Fig 1. shows the sequence diagram for this feature. The diagram shows the sequences exclusive to this feature. Therefore, this assumes that the assignment/exercise has already been created. &lt;br /&gt;
Once the assignment is created, the instructor can enable the 'intelligent assignment of teams' feature for the particular assignment. Enabling this feature would give the students(or teams) a view to place bids on the topics they like. They can associate each bid with a priority. Once the deadline has passed, the instructor can kickoff the process which performs the automatic assignment. This would in turn start assigning teams with topics based on their bid preferences.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;UML Design&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
The intelligent assignment controller is dependent on the ''AssignmentTopicController'' and other models like - ''Assignment'', ''AssignmentTopic'' and ''Team''. When the instructor starts the intelligent assignment of topics to teams, ''IntelligentAssignmentController'' triggers the assignment algorithm.&lt;br /&gt;
&lt;br /&gt;
The students interact with ''AssignmentTopicView'' which lists down all the topics for the assignment and allows students to bid for topics with priority. ''AssignmentTopicController'' is responsible for recording all the bids and priorities correctly.&lt;br /&gt;
&lt;br /&gt;
Following is the UML diagram of the O-O design focusing only on the component related to intelligent assignment of topics to teams.&lt;br /&gt;
&lt;br /&gt;
[[File: UML_Design.png|UML Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Database Design&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
In order to meet other solution requirement, new tables are added. The following diagram represents the new tables in [http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation Crow Foot's Notation]. The ''user'' table mentioned is not new and is present only to explain the field - ''ownerId''.&lt;br /&gt;
&lt;br /&gt;
Earlier, all the information in ''AssignmentTopic'' and ''AssignmentTopicMetadata'' tables were in a single table called ''signup_topics''. However, there was lot of data redundancy observed and we also required to add an extra field in the table ''signup_topics''. Therefore, we decided to store the topics related to an assignment according to the diagram. One caveat to this design is that all the topics for an assignment are considered equal in terms of category, maximum bids allowed and maximum bids in waiting list.&lt;br /&gt;
&lt;br /&gt;
The table ''bid'' is supposed to store all the bids on the topics with their priority. The owner of the bid will be recorded too. Current requirement is to have only one bid per topic by an owner. Therefore, we could have ''(ownerId, topicId)'' pair as the primary key. However, in order to support multiple bids in a future sceario, we have used a field ''id'' as the primary key.&lt;br /&gt;
&lt;br /&gt;
Apart from the mentioned new tables, we will be using pre-existing tables to meet our requirements and design.&lt;br /&gt;
&lt;br /&gt;
[[File: DatabaseDesign.png|Database Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91894</id>
		<title>CSC/ECE 517 Fall 2014/final E1475 nrnn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91894"/>
		<updated>2014-11-12T01:00:10Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Database Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt; E1475. Intelligent assignment of teams&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Problem Statement&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
According to the existing code workflow, the assignment of topics to teams are based on FCFS (first come first serve) basis, where a team which first signs up for a topic gets the topic while other teams are waitlisted on the same topic. Since ‘sign up time’ is the only factor considered for topic assignment this method causes problems such as:&lt;br /&gt;
&lt;br /&gt;
#The assignment of topics are FCFS, hence not completely fair.&lt;br /&gt;
#Non-uniform distribution of topics among the teams in a class.&lt;br /&gt;
#The current system fails to resolve the problem when many teams bid for handful of topics(among many topics) causing unnecessary additions to the waitlist.&lt;br /&gt;
#The assignment of topics is more focused on individual selection and ‘sign up time’. Factors such as team size are not considered which are important while assigning a topic to the team and potentially can reduce many issues faced by the current system. &lt;br /&gt;
&lt;br /&gt;
To address the above mentioned issues, we have designed an ‘intelligent assignment of topics’ system which tries to address the issues faced by the current system.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Introduction &amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Expertiza ==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using [http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment (LITRE)]&amp;lt;ref&amp;gt;[http://litre.ncsu.edu/ Learning in a Technology-Rich Environment (LITRE)]&amp;lt;/ref&amp;gt; program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
==Existing signup process==&lt;br /&gt;
The signup process for group projects is observed by most students to be a troublesome task  in expertiza. The current sign up process for topics is based on FCFS basis, where a student who signs up for a topic of his/her choice first, gets it. We have discovered some pitfalls with the current ‘topic assignment’ system in Expertiza which arises due to the below mentioned factors.  Due to these reasons, we now try to propose an intelligent system which can addresses many issues faced with the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Pitfalls with the current system ==&lt;br /&gt;
#One student can sign up only for a single topic. In cases where many topics are available, a student is forced to choose a single topic among many available topics which can be a difficult task. To select a single topic which best fits his/her choice among many available topics requires a pre-study of all topics prior to the signup process. Such a pre-requirement is not fulfilled by most  students, which results in a student signing up for a topic which he/she has randomly selected OR because it was among the only available topics.&lt;br /&gt;
#If a student is not able to sign up for a topic of his choice, he can waitlist himself for all the remaining topics, which causes unnecessary traffic in the waitlist queue of a topic. &lt;br /&gt;
#If all the teams choose a handful of topics among many topics, it would also result in unnecessary additions in the waitlist queue for those few topics resulting in a situation where all the topics are not uniformly distributed among all the teams&lt;br /&gt;
#Before, signing up, if more than one student forms a team and if each student belonging to the same team tries to signup for different topics, than those topics are allotted to individual students resulting in a situation where a team can hold more than one topic. Thus other teams are forced to choose from remaining topics which eventually results in longer waitlists.&lt;br /&gt;
&lt;br /&gt;
After observing the above problems with the existing method of ‘topic assignment’ in expertiza, we have proposed and implemented an ‘intelligent assignment of topics’ method to overcome all the shortcomings of the existing system in expertiza.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Previous work ==&lt;br /&gt;
Previously in 2012, to address this issue of expertiza, a team proposed a possible solution of ‘lottery based topic assignment’ algorithm. The algorithm works by considering every team as strength of 1, representing the student in the team. After sign up the topic would be allotted to the team based on a lottery system where a team is randomly selected for every topic. However this method failed to address the following issues:&lt;br /&gt;
#It did not consider the case where a team could be of more than one member, hence it allowed every team member to bid for different topics resulting in the same problem as mentioned in point (4) of Pitfalls with the current system.&lt;br /&gt;
#The topics were awarded based on a Lottery system and not based on any other criteria which resulted in topic assignment to be a game of luck factor rather than on individual’s choice.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Design Workflow &amp;lt;/b&amp;gt;=&lt;br /&gt;
To address the issues faced by both, the current system and lottery based system, we propose a solution based on ‘intelligent team assignment’ algorithm. The algorithm is based on two important factors:&lt;br /&gt;
&lt;br /&gt;
#Team strength&lt;br /&gt;
#Priority order of the topics submitted by the team.&lt;br /&gt;
&lt;br /&gt;
The algorithm works on bidding process which can be explained as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Before the bidding process ==&lt;br /&gt;
#Initially, every student is a team of 1 member. Before the bidding process takes place, students can merge their teams to form a larger team. The person to whom they have merged becomes the team owner/captain.&lt;br /&gt;
#Every team is given x bids(x is calculated based on the total class strength and total topics proposed), that they can place on each topic of their choice in a priority order where 1 being the highest priority.&lt;br /&gt;
#Every topic is allowed ‘p’ number of maximum bids after which the topic is waitlisted in the system.&lt;br /&gt;
#Teams can also place their bids on waitlisted topics. However, every topic has a threshold ‘q’ which signifies the maximum waitlisted bids allowed for each topic.&lt;br /&gt;
#Thus, if the combined threshold of ‘p+q’ bids for a topic is reached then the topic is no longer available for bidding unless the topic is dropped by a team which reduces the ‘p+q’ threshold value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== During Bidding Process ==&lt;br /&gt;
#Every team can place their bids on the available topics. Since every team is given ‘x’ bids, each team can bid for ‘x’ topics and list their bids in a priority order.&lt;br /&gt;
#A team can also place their bids on  waitlisted topics. The maximum allowed bids for waitlisted topics is ‘y’ where y is some portion of bids taken from total bids(x) allowed for each team.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== After the Bidding Process ==&lt;br /&gt;
#After the bidding process is complete, the teams can continue to merge to form larger teams.&lt;br /&gt;
#If team A merges with team B, the bids of team A would be lost.&lt;br /&gt;
#The merging of the teams is allowed till the topic assignment date when the teams would finally be assigned the topics by running an algorithm.&lt;br /&gt;
#The teams can also change their submitted topic priority order any number of times before running the ‘topic assignment’ algorithm. &lt;br /&gt;
&lt;br /&gt;
 The algorithm assigns the topic to each teams based on the following factors:&lt;br /&gt;
&lt;br /&gt;
# The team which is close to or has maximum possible team strength has a higher probability of winning the topic they had placed their bid on.&lt;br /&gt;
# For a team which satisfies condition(1), a topic would be assigned to the team based on the priority order of the bids that the team specified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
#As each team can place their bids on the available topics based on their topic priority. Hence every team gets to choose more than one topic of their choice.&lt;br /&gt;
&lt;br /&gt;
#As every topic has a maximum number of allowed bids, after which the topic is no longer available for bidding, this method addresses the issue where many teams choose only a handful topics among all topics. &lt;br /&gt;
&lt;br /&gt;
#As the maximum allowed bids for waitlisting a topic is also limited for every team, hence the issue of unnecessary additions to waitlist is resolved by this method.&lt;br /&gt;
&lt;br /&gt;
#The teams are assigned topics based on modified [http://en.wikipedia.org/wiki/Stable_marriage_problem/ Stable marriage problem] algorithm which considers factors such as team size and priority ensuring that the topics are no longer assigned based on FCFS basis. Thus this method addresses the most important issue where a topic is not assigned to the team just because the team was late to sign up for the topic as compared to the other teams.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Requirements&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
1) The instructor should be able to create assignments which can utilize intelligent assignment of teams. (It is an optional feature)&lt;br /&gt;
&lt;br /&gt;
2) The instructor should be able to set the maximum number of bids a team can make. Defaulted to 3.&lt;br /&gt;
&lt;br /&gt;
3) The teams should be able place bids on different topics limited to the number set by the instructor for these assignments&lt;br /&gt;
&lt;br /&gt;
4) The teams should be able to prioritize their bids.&lt;br /&gt;
&lt;br /&gt;
5) The instructor should be able to kick off the intelligent assignment of teams.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Sequence Diagram&amp;lt;/b&amp;gt;=&lt;br /&gt;
[[File:E1475.Sequence Diagram.png|frame|center|Fig 1. Sequence Diagram]]&lt;br /&gt;
Fig 1. shows the sequence diagram for this feature. The diagram shows the sequences exclusive to this feature. Therefore, this assumes that the assignment/exercise has already been created. &lt;br /&gt;
Once the assignment is created, the instructor can enable the 'intelligent assignment of teams' feature for the particular assignment. Enabling this feature would give the students(or teams) a view to place bids on the topics they like. They can associate each bid with a priority. Once the deadline has passed, the instructor can kickoff the process which performs the automatic assignment. This would in turn start assigning teams with topics based on their bid preferences.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;UML Design&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
The intelligent assignment controller is dependent on the ''AssignmentTopicController'' and other models like - ''Assignment'', ''AssignmentTopic'' and ''Team''. When the instructor starts the intelligent assignment of topics to teams, ''IntelligentAssignmentController'' triggers the assignment algorithm.&lt;br /&gt;
&lt;br /&gt;
The students interact with ''AssignmentTopicView'' which lists down all the topics for the assignment and allows students to bid for topics with priority. ''AssignmentTopicController'' is responsible for recording all the bids and priorities correctly.&lt;br /&gt;
&lt;br /&gt;
Following is the UML diagram of the O-O design focusing only on the component related to intelligent assignment of topics to teams.&lt;br /&gt;
&lt;br /&gt;
[[File: UML_Design.png|UML Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Database Design&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
In order to meet other solution requirement, new tables are added. The following diagram represents the new tables in [http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation Crow Foot's Notation]. The ''user'' table mentioned is not new and is present only to explain the field - ''ownerId''.&lt;br /&gt;
&lt;br /&gt;
Earlier, all the information in ''AssignmentTopic'' and ''AssignmentTopicMetadata'' tables were in a single table called ''signup_topics''. However, there was lot of data redundancy observed and we also required to add an extra field in the table ''signup_topics''. Therefore, we decided to store the topics related to an assignment according to the diagram. One caveat to this design is that all the topics for an assignment are considered equal in terms of category, maximum bids allowed and maximum bids in waiting list.&lt;br /&gt;
&lt;br /&gt;
The table ''bid'' is supposed to store all the bids on the topics with their priority. The owner of the bid will be recorded too. Current requirement is to have only one bid per topic by an owner. Therefore, we could have ''(ownerId, topicId)'' pair as the primary key. However, in order to support multiple bids in a future sceario, we have used a field ''id'' as the primary key.&lt;br /&gt;
&lt;br /&gt;
Apart from the mentioned new tables, we will be using pre-existing tables to meet our requirements and design.&lt;br /&gt;
&lt;br /&gt;
[[File: DatabaseDesign.png|Database Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91893</id>
		<title>CSC/ECE 517 Fall 2014/final E1475 nrnn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91893"/>
		<updated>2014-11-12T00:59:43Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt; E1475. Intelligent assignment of teams&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Problem Statement&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
According to the existing code workflow, the assignment of topics to teams are based on FCFS (first come first serve) basis, where a team which first signs up for a topic gets the topic while other teams are waitlisted on the same topic. Since ‘sign up time’ is the only factor considered for topic assignment this method causes problems such as:&lt;br /&gt;
&lt;br /&gt;
#The assignment of topics are FCFS, hence not completely fair.&lt;br /&gt;
#Non-uniform distribution of topics among the teams in a class.&lt;br /&gt;
#The current system fails to resolve the problem when many teams bid for handful of topics(among many topics) causing unnecessary additions to the waitlist.&lt;br /&gt;
#The assignment of topics is more focused on individual selection and ‘sign up time’. Factors such as team size are not considered which are important while assigning a topic to the team and potentially can reduce many issues faced by the current system. &lt;br /&gt;
&lt;br /&gt;
To address the above mentioned issues, we have designed an ‘intelligent assignment of topics’ system which tries to address the issues faced by the current system.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Introduction &amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Expertiza ==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using [http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment (LITRE)]&amp;lt;ref&amp;gt;[http://litre.ncsu.edu/ Learning in a Technology-Rich Environment (LITRE)]&amp;lt;/ref&amp;gt; program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
==Existing signup process==&lt;br /&gt;
The signup process for group projects is observed by most students to be a troublesome task  in expertiza. The current sign up process for topics is based on FCFS basis, where a student who signs up for a topic of his/her choice first, gets it. We have discovered some pitfalls with the current ‘topic assignment’ system in Expertiza which arises due to the below mentioned factors.  Due to these reasons, we now try to propose an intelligent system which can addresses many issues faced with the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Pitfalls with the current system ==&lt;br /&gt;
#One student can sign up only for a single topic. In cases where many topics are available, a student is forced to choose a single topic among many available topics which can be a difficult task. To select a single topic which best fits his/her choice among many available topics requires a pre-study of all topics prior to the signup process. Such a pre-requirement is not fulfilled by most  students, which results in a student signing up for a topic which he/she has randomly selected OR because it was among the only available topics.&lt;br /&gt;
#If a student is not able to sign up for a topic of his choice, he can waitlist himself for all the remaining topics, which causes unnecessary traffic in the waitlist queue of a topic. &lt;br /&gt;
#If all the teams choose a handful of topics among many topics, it would also result in unnecessary additions in the waitlist queue for those few topics resulting in a situation where all the topics are not uniformly distributed among all the teams&lt;br /&gt;
#Before, signing up, if more than one student forms a team and if each student belonging to the same team tries to signup for different topics, than those topics are allotted to individual students resulting in a situation where a team can hold more than one topic. Thus other teams are forced to choose from remaining topics which eventually results in longer waitlists.&lt;br /&gt;
&lt;br /&gt;
After observing the above problems with the existing method of ‘topic assignment’ in expertiza, we have proposed and implemented an ‘intelligent assignment of topics’ method to overcome all the shortcomings of the existing system in expertiza.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Previous work ==&lt;br /&gt;
Previously in 2012, to address this issue of expertiza, a team proposed a possible solution of ‘lottery based topic assignment’ algorithm. The algorithm works by considering every team as strength of 1, representing the student in the team. After sign up the topic would be allotted to the team based on a lottery system where a team is randomly selected for every topic. However this method failed to address the following issues:&lt;br /&gt;
#It did not consider the case where a team could be of more than one member, hence it allowed every team member to bid for different topics resulting in the same problem as mentioned in point (4) of Pitfalls with the current system.&lt;br /&gt;
#The topics were awarded based on a Lottery system and not based on any other criteria which resulted in topic assignment to be a game of luck factor rather than on individual’s choice.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Design Workflow &amp;lt;/b&amp;gt;=&lt;br /&gt;
To address the issues faced by both, the current system and lottery based system, we propose a solution based on ‘intelligent team assignment’ algorithm. The algorithm is based on two important factors:&lt;br /&gt;
&lt;br /&gt;
#Team strength&lt;br /&gt;
#Priority order of the topics submitted by the team.&lt;br /&gt;
&lt;br /&gt;
The algorithm works on bidding process which can be explained as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Before the bidding process ==&lt;br /&gt;
#Initially, every student is a team of 1 member. Before the bidding process takes place, students can merge their teams to form a larger team. The person to whom they have merged becomes the team owner/captain.&lt;br /&gt;
#Every team is given x bids(x is calculated based on the total class strength and total topics proposed), that they can place on each topic of their choice in a priority order where 1 being the highest priority.&lt;br /&gt;
#Every topic is allowed ‘p’ number of maximum bids after which the topic is waitlisted in the system.&lt;br /&gt;
#Teams can also place their bids on waitlisted topics. However, every topic has a threshold ‘q’ which signifies the maximum waitlisted bids allowed for each topic.&lt;br /&gt;
#Thus, if the combined threshold of ‘p+q’ bids for a topic is reached then the topic is no longer available for bidding unless the topic is dropped by a team which reduces the ‘p+q’ threshold value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== During Bidding Process ==&lt;br /&gt;
#Every team can place their bids on the available topics. Since every team is given ‘x’ bids, each team can bid for ‘x’ topics and list their bids in a priority order.&lt;br /&gt;
#A team can also place their bids on  waitlisted topics. The maximum allowed bids for waitlisted topics is ‘y’ where y is some portion of bids taken from total bids(x) allowed for each team.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== After the Bidding Process ==&lt;br /&gt;
#After the bidding process is complete, the teams can continue to merge to form larger teams.&lt;br /&gt;
#If team A merges with team B, the bids of team A would be lost.&lt;br /&gt;
#The merging of the teams is allowed till the topic assignment date when the teams would finally be assigned the topics by running an algorithm.&lt;br /&gt;
#The teams can also change their submitted topic priority order any number of times before running the ‘topic assignment’ algorithm. &lt;br /&gt;
&lt;br /&gt;
 The algorithm assigns the topic to each teams based on the following factors:&lt;br /&gt;
&lt;br /&gt;
# The team which is close to or has maximum possible team strength has a higher probability of winning the topic they had placed their bid on.&lt;br /&gt;
# For a team which satisfies condition(1), a topic would be assigned to the team based on the priority order of the bids that the team specified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
#As each team can place their bids on the available topics based on their topic priority. Hence every team gets to choose more than one topic of their choice.&lt;br /&gt;
&lt;br /&gt;
#As every topic has a maximum number of allowed bids, after which the topic is no longer available for bidding, this method addresses the issue where many teams choose only a handful topics among all topics. &lt;br /&gt;
&lt;br /&gt;
#As the maximum allowed bids for waitlisting a topic is also limited for every team, hence the issue of unnecessary additions to waitlist is resolved by this method.&lt;br /&gt;
&lt;br /&gt;
#The teams are assigned topics based on modified [http://en.wikipedia.org/wiki/Stable_marriage_problem/ Stable marriage problem] algorithm which considers factors such as team size and priority ensuring that the topics are no longer assigned based on FCFS basis. Thus this method addresses the most important issue where a topic is not assigned to the team just because the team was late to sign up for the topic as compared to the other teams.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Requirements&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
1) The instructor should be able to create assignments which can utilize intelligent assignment of teams. (It is an optional feature)&lt;br /&gt;
&lt;br /&gt;
2) The instructor should be able to set the maximum number of bids a team can make. Defaulted to 3.&lt;br /&gt;
&lt;br /&gt;
3) The teams should be able place bids on different topics limited to the number set by the instructor for these assignments&lt;br /&gt;
&lt;br /&gt;
4) The teams should be able to prioritize their bids.&lt;br /&gt;
&lt;br /&gt;
5) The instructor should be able to kick off the intelligent assignment of teams.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Sequence Diagram&amp;lt;/b&amp;gt;=&lt;br /&gt;
[[File:E1475.Sequence Diagram.png|frame|center|Fig 1. Sequence Diagram]]&lt;br /&gt;
Fig 1. shows the sequence diagram for this feature. The diagram shows the sequences exclusive to this feature. Therefore, this assumes that the assignment/exercise has already been created. &lt;br /&gt;
Once the assignment is created, the instructor can enable the 'intelligent assignment of teams' feature for the particular assignment. Enabling this feature would give the students(or teams) a view to place bids on the topics they like. They can associate each bid with a priority. Once the deadline has passed, the instructor can kickoff the process which performs the automatic assignment. This would in turn start assigning teams with topics based on their bid preferences.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;UML Design&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
The intelligent assignment controller is dependent on the ''AssignmentTopicController'' and other models like - ''Assignment'', ''AssignmentTopic'' and ''Team''. When the instructor starts the intelligent assignment of topics to teams, ''IntelligentAssignmentController'' triggers the assignment algorithm.&lt;br /&gt;
&lt;br /&gt;
The students interact with ''AssignmentTopicView'' which lists down all the topics for the assignment and allows students to bid for topics with priority. ''AssignmentTopicController'' is responsible for recording all the bids and priorities correctly.&lt;br /&gt;
&lt;br /&gt;
Following is the UML diagram of the O-O design focusing only on the component related to intelligent assignment of topics to teams.&lt;br /&gt;
&lt;br /&gt;
[[File: UML_Design.png|UML Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Database Design&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
In order to meet other solution requirement, new tables are added. The following diagram represents the new tables in [http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation Crow Foot's Notation]. The ''user'' table mentioned is not new and is present only to explain the field - ''ownerId''.&lt;br /&gt;
&lt;br /&gt;
Earlier, all the information in ''AssignmentTopic'' and ''AssignmentTopicMetadata'' tables were in a single table called ''signup_topics''. However, there was lot of data redundancy observed and we also required to add an extra field in the table ''signup_topics''. Therefore, we decided to store the topics related to an assignment according to the diagram. One caveat to this design is that all the topics for an assignment are considered equal in terms of category, maximum bids allowed and maximum bids in waiting list.&lt;br /&gt;
&lt;br /&gt;
The table ''bid'' is supposed to store all the bids on the topics with their priority. The owner of the bid will be recorded too. Current requirement is to have only one bid per topic by an owner. Therefore, we could have ''(ownerId, topicId)'' pair as the primary key. However, in order to support multiple bids in a future sceario, we have used a field ''id'' as the primary key.&lt;br /&gt;
&lt;br /&gt;
Apart from the mentioned new tables, we will be using pre-existing tables to meet our requirements and design.&lt;br /&gt;
&lt;br /&gt;
[[File: DatabaseDesign.png|Database Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://docs.google.com/document/d/1tyWX8njxDLvYpN7wJf5hjA6lnWbzQRP9vUKGxxRjRzo/edit#heading=h.5cgh9aixuut7/ Lottery based topic assignment doc]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://github.com/csuich2/expertiza/tree/lottery_topic_selection/ Lottery based topic assignment code]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Stable_marriage_problem/ Stable Marriage Problem]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation Crow Foot's Notation]&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91888</id>
		<title>CSC/ECE 517 Fall 2014/final E1475 nrnn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91888"/>
		<updated>2014-11-12T00:55:55Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt; E1475. Intelligent assignment of teams&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Problem Statement&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
According to the existing code workflow, the assignment of topics to teams are based on FCFS (first come first serve) basis, where a team which first signs up for a topic gets the topic while other teams are waitlisted on the same topic. Since ‘sign up time’ is the only factor considered for topic assignment this method causes problems such as:&lt;br /&gt;
&lt;br /&gt;
#The assignment of topics are FCFS, hence not completely fair.&lt;br /&gt;
#Non-uniform distribution of topics among the teams in a class.&lt;br /&gt;
#The current system fails to resolve the problem when many teams bid for handful of topics(among many topics) causing unnecessary additions to the waitlist.&lt;br /&gt;
#The assignment of topics is more focused on individual selection and ‘sign up time’. Factors such as team size are not considered which are important while assigning a topic to the team and potentially can reduce many issues faced by the current system. &lt;br /&gt;
&lt;br /&gt;
To address the above mentioned issues, we have designed an ‘intelligent assignment of topics’ system which tries to address the issues faced by the current system.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Introduction &amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Expertiza ==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using [http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU [http://litre.ncsu.edu/ Learning in a Technology-Rich Environment (LITRE)]&amp;lt;ref&amp;gt;[http://litre.ncsu.edu/ Learning in a Technology-Rich Environment (LITRE)]&amp;lt;/ref&amp;gt; program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
==Existing signup process==&lt;br /&gt;
The signup process for group projects is observed by most students to be a troublesome task  in expertiza. The current sign up process for topics is based on FCFS basis, where a student who signs up for a topic of his/her choice first, gets it. We have discovered some pitfalls with the current ‘topic assignment’ system in Expertiza which arises due to the below mentioned factors.  Due to these reasons, we now try to propose an intelligent system which can addresses many issues faced with the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Pitfalls with the current system ==&lt;br /&gt;
#One student can sign up only for a single topic. In cases where many topics are available, a student is forced to choose a single topic among many available topics which can be a difficult task. To select a single topic which best fits his/her choice among many available topics requires a pre-study of all topics prior to the signup process. Such a pre-requirement is not fulfilled by most  students, which results in a student signing up for a topic which he/she has randomly selected OR because it was among the only available topics.&lt;br /&gt;
#If a student is not able to sign up for a topic of his choice, he can waitlist himself for all the remaining topics, which causes unnecessary traffic in the waitlist queue of a topic. &lt;br /&gt;
#If all the teams choose a handful of topics among many topics, it would also result in unnecessary additions in the waitlist queue for those few topics resulting in a situation where all the topics are not uniformly distributed among all the teams&lt;br /&gt;
#Before, signing up, if more than one student forms a team and if each student belonging to the same team tries to signup for different topics, than those topics are allotted to individual students resulting in a situation where a team can hold more than one topic. Thus other teams are forced to choose from remaining topics which eventually results in longer waitlists.&lt;br /&gt;
&lt;br /&gt;
After observing the above problems with the existing method of ‘topic assignment’ in expertiza, we have proposed and implemented an ‘intelligent assignment of topics’ method to overcome all the shortcomings of the existing system in expertiza.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Previous work ==&lt;br /&gt;
Previously in 2012, to address this issue of expertiza, a team proposed a possible solution of ‘lottery based topic assignment’ algorithm. The algorithm works by considering every team as strength of 1, representing the student in the team. After sign up the topic would be allotted to the team based on a lottery system where a team is randomly selected for every topic. However this method failed to address the following issues:&lt;br /&gt;
#It did not consider the case where a team could be of more than one member, hence it allowed every team member to bid for different topics resulting in the same problem as mentioned in point (4) of Pitfalls with the current system.&lt;br /&gt;
#The topics were awarded based on a Lottery system and not based on any other criteria which resulted in topic assignment to be a game of luck factor rather than on individual’s choice.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Design Workflow &amp;lt;/b&amp;gt;=&lt;br /&gt;
To address the issues faced by both, the current system and lottery based system, we propose a solution based on ‘intelligent team assignment’ algorithm. The algorithm is based on two important factors:&lt;br /&gt;
&lt;br /&gt;
#Team strength&lt;br /&gt;
#Priority order of the topics submitted by the team.&lt;br /&gt;
&lt;br /&gt;
The algorithm works on bidding process which can be explained as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Before the bidding process ==&lt;br /&gt;
#Initially, every student is a team of 1 member. Before the bidding process takes place, students can merge their teams to form a larger team. The person to whom they have merged becomes the team owner/captain.&lt;br /&gt;
#Every team is given x bids(x is calculated based on the total class strength and total topics proposed), that they can place on each topic of their choice in a priority order where 1 being the highest priority.&lt;br /&gt;
#Every topic is allowed ‘p’ number of maximum bids after which the topic is waitlisted in the system.&lt;br /&gt;
#Teams can also place their bids on waitlisted topics. However, every topic has a threshold ‘q’ which signifies the maximum waitlisted bids allowed for each topic.&lt;br /&gt;
#Thus, if the combined threshold of ‘p+q’ bids for a topic is reached then the topic is no longer available for bidding unless the topic is dropped by a team which reduces the ‘p+q’ threshold value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== During Bidding Process ==&lt;br /&gt;
#Every team can place their bids on the available topics. Since every team is given ‘x’ bids, each team can bid for ‘x’ topics and list their bids in a priority order.&lt;br /&gt;
#A team can also place their bids on  waitlisted topics. The maximum allowed bids for waitlisted topics is ‘y’ where y is some portion of bids taken from total bids(x) allowed for each team.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== After the Bidding Process ==&lt;br /&gt;
#After the bidding process is complete, the teams can continue to merge to form larger teams.&lt;br /&gt;
#If team A merges with team B, the bids of team A would be lost.&lt;br /&gt;
#The merging of the teams is allowed till the topic assignment date when the teams would finally be assigned the topics by running an algorithm.&lt;br /&gt;
#The teams can also change their submitted topic priority order any number of times before running the ‘topic assignment’ algorithm. &lt;br /&gt;
&lt;br /&gt;
 The algorithm assigns the topic to each teams based on the following factors:&lt;br /&gt;
&lt;br /&gt;
# The team which is close to or has maximum possible team strength has a higher probability of winning the topic they had placed their bid on.&lt;br /&gt;
# For a team which satisfies condition(1), a topic would be assigned to the team based on the priority order of the bids that the team specified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
#As each team can place their bids on the available topics based on their topic priority. Hence every team gets to choose more than one topic of their choice.&lt;br /&gt;
&lt;br /&gt;
#As every topic has a maximum number of allowed bids, after which the topic is no longer available for bidding, this method addresses the issue where many teams choose only a handful topics among all topics. &lt;br /&gt;
&lt;br /&gt;
#As the maximum allowed bids for waitlisting a topic is also limited for every team, hence the issue of unnecessary additions to waitlist is resolved by this method.&lt;br /&gt;
&lt;br /&gt;
#The teams are assigned topics based on modified [http://en.wikipedia.org/wiki/Stable_marriage_problem/ Stable marriage problem] algorithm which considers factors such as team size and priority ensuring that the topics are no longer assigned based on FCFS basis. Thus this method addresses the most important issue where a topic is not assigned to the team just because the team was late to sign up for the topic as compared to the other teams.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Requirements&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
1) The instructor should be able to create assignments which can utilize intelligent assignment of teams. (It is an optional feature)&lt;br /&gt;
&lt;br /&gt;
2) The instructor should be able to set the maximum number of bids a team can make. Defaulted to 3.&lt;br /&gt;
&lt;br /&gt;
3) The teams should be able place bids on different topics limited to the number set by the instructor for these assignments&lt;br /&gt;
&lt;br /&gt;
4) The teams should be able to prioritize their bids.&lt;br /&gt;
&lt;br /&gt;
5) The instructor should be able to kick off the intelligent assignment of teams.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Sequence Diagram&amp;lt;/b&amp;gt;=&lt;br /&gt;
[[File:E1475.Sequence Diagram.png|frame|center|Fig 1. Sequence Diagram]]&lt;br /&gt;
Fig 1. shows the sequence diagram for this feature. The diagram shows the sequences exclusive to this feature. Therefore, this assumes that the assignment/exercise has already been created. &lt;br /&gt;
Once the assignment is created, the instructor can enable the 'intelligent assignment of teams' feature for the particular assignment. Enabling this feature would give the students(or teams) a view to place bids on the topics they like. They can associate each bid with a priority. Once the deadline has passed, the instructor can kickoff the process which performs the automatic assignment. This would in turn start assigning teams with topics based on their bid preferences.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;UML Design&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
The intelligent assignment controller is dependent on the ''AssignmentTopicController'' and other models like - ''Assignment'', ''AssignmentTopic'' and ''Team''. When the instructor starts the intelligent assignment of topics to teams, ''IntelligentAssignmentController'' triggers the assignment algorithm.&lt;br /&gt;
&lt;br /&gt;
The students interact with ''AssignmentTopicView'' which lists down all the topics for the assignment and allows students to bid for topics with priority. ''AssignmentTopicController'' is responsible for recording all the bids and priorities correctly.&lt;br /&gt;
&lt;br /&gt;
Following is the UML diagram of the O-O design focusing only on the component related to intelligent assignment of topics to teams.&lt;br /&gt;
&lt;br /&gt;
[[File: UML_Design.png|UML Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Database Design&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
In order to meet other solution requirement, new tables are added. The following diagram represents the new tables in [http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation crow foot's notation]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation Crow Foot's Notation]&amp;lt;/ref&amp;gt;. The ''user'' table mentioned is not new and is present only to explain the field - ''ownerId''.&lt;br /&gt;
&lt;br /&gt;
Earlier, all the information in ''AssignmentTopic'' and ''AssignmentTopicMetadata'' tables were in a single table called ''signup_topics''. However, there was lot of data redundancy observed and we also required to add an extra field in the table ''signup_topics''. Therefore, we decided to store the topics related to an assignment according to the diagram. One caveat to this design is that all the topics for an assignment are considered equal in terms of category, maximum bids allowed and maximum bids in waiting list.&lt;br /&gt;
&lt;br /&gt;
The table ''bid'' is supposed to store all the bids on the topics with their priority. The owner of the bid will be recorded too. Current requirement is to have only one bid per topic by an owner. Therefore, we could have ''(ownerId, topicId)'' pair as the primary key. However, in order to support multiple bids in a future sceario, we have used a field ''id'' as the primary key.&lt;br /&gt;
&lt;br /&gt;
Apart from the mentioned new tables, we will be using pre-existing tables to meet our requirements and design.&lt;br /&gt;
&lt;br /&gt;
[[File: DatabaseDesign.png|Database Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://docs.google.com/document/d/1tyWX8njxDLvYpN7wJf5hjA6lnWbzQRP9vUKGxxRjRzo/edit#heading=h.5cgh9aixuut7/ Lottery based topic assignment doc]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://github.com/csuich2/expertiza/tree/lottery_topic_selection/ Lottery based topic assignment code]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://en.wikipedia.org/wiki/Stable_marriage_problem/ Stable Marriage Problem]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91877</id>
		<title>CSC/ECE 517 Fall 2014/final E1475 nrnn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91877"/>
		<updated>2014-11-12T00:45:41Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /*  Problem Statement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=&amp;lt;b&amp;gt; E1475. Intelligent assignment of teams&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Problem Statement&amp;lt;/b&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
According to the existing code workflow, the assignment of topics to teams are based on FCFS (first come first serve) basis, where a team which first signs up for a topic gets the topic while other teams are waitlisted on the same topic. Since ‘sign up time’ is the only factor considered for topic assignment this method causes problems such as:&lt;br /&gt;
&lt;br /&gt;
#The assignment of topics are FCFS, hence not completely fair.&lt;br /&gt;
#Non-uniform distribution of topics among the teams in a class.&lt;br /&gt;
#The current system fails to resolve the problem when many teams bid for handful of topics(among many topics) causing unnecessary additions to the waitlist.&lt;br /&gt;
#The assignment of topics is more focused on individual selection and ‘sign up time’. Factors such as team size are not considered which are important while assigning a topic to the team and potentially can reduce many issues faced by the current system. &lt;br /&gt;
&lt;br /&gt;
To address the above mentioned issues, we have designed an ‘intelligent assignment of topics’ system which tries to address the issues faced by the current system.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Introduction &amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Expertiza&amp;lt;ref name=&amp;quot;Expertiza&amp;quot;&amp;gt;http://expertiza.ncsu.edu/&amp;lt;/ref&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a project developed using [http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] platform. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from [https://github.com/expertiza/expertiza github]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large.&lt;br /&gt;
&lt;br /&gt;
Expertiza is supported by National Science Foundation under Grant No. 0536558. Additional funding from the NCSU Learning in a Technology-Rich Environment (LITRE) program, the NCSU Faculty Center for Teaching and Learning, the NCSU STEM Initiative, and the Center for Advanced Computing and Communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Existing signup process==&lt;br /&gt;
The signup process for group projects is observed by most students to be a troublesome task  in expertiza. The current sign up process for topics is based on FCFS basis, where a student who signs up for a topic of his/her choice first, gets it. We have discovered some pitfalls with the current ‘topic assignment’ system in Expertiza which arises due to the below mentioned factors.  Due to these reasons, we now try to propose an intelligent system which can addresses many issues faced with the current Expertiza system.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Pitfalls with the current system ==&lt;br /&gt;
#One student can sign up only for a single topic. In cases where many topics are available, a student is forced to choose a single topic among many available topics which can be a difficult task. To select a single topic which best fits his/her choice among many available topics requires a pre-study of all topics prior to the signup process. Such a pre-requirement is not fulfilled by most  students, which results in a student signing up for a topic which he/she has randomly selected OR because it was among the only available topics.&lt;br /&gt;
#If a student is not able to sign up for a topic of his choice, he can waitlist himself for all the remaining topics, which causes unnecessary traffic in the waitlist queue of a topic. &lt;br /&gt;
#If all the teams choose a handful of topics among many topics, it would also result in unnecessary additions in the waitlist queue for those few topics resulting in a situation where all the topics are not uniformly distributed among all the teams&lt;br /&gt;
#Before, signing up, if more than one student forms a team and if each student belonging to the same team tries to signup for different topics, than those topics are allotted to individual students resulting in a situation where a team can hold more than one topic. Thus other teams are forced to choose from remaining topics which eventually results in longer waitlists.&lt;br /&gt;
&lt;br /&gt;
After observing the above problems with the existing method of ‘topic assignment’ in expertiza, we have proposed and implemented an ‘intelligent assignment of topics’ method to overcome all the shortcomings of the existing system in expertiza.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Previous work &amp;lt;ref name=&amp;quot;Previous 2012 Work&amp;quot;&amp;gt;https://docs.google.com/document/d/1tyWX8njxDLvYpN7wJf5hjA6lnWbzQRP9vUKGxxRjRzo/edit#heading=h.5cgh9aixuut7&amp;lt;/ref&amp;gt;==&lt;br /&gt;
Previously in 2012, to address this issue of expertiza, a team proposed a possible solution of ‘lottery based topic assignment’ algorithm. The algorithm works by considering every team as strength of 1, representing the student in the team. After sign up the topic would be allotted to the team based on a lottery system where a team is randomly selected for every topic. However this method failed to address the following issues:&lt;br /&gt;
#It did not consider the case where a team could be of more than one member, hence it allowed every team member to bid for different topics resulting in the same problem as mentioned in point (4) of Pitfalls with the current system.&lt;br /&gt;
#The topics were awarded based on a Lottery system and not based on any other criteria which resulted in topic assignment to be a game of luck factor rather than on individual’s choice.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt; Design Workflow &amp;lt;/b&amp;gt;=&lt;br /&gt;
To address the issues faced by both, the current system and lottery based system, we propose a solution based on ‘intelligent team assignment’ algorithm. The algorithm is based on two important factors:&lt;br /&gt;
&lt;br /&gt;
#Team strength&lt;br /&gt;
#Priority order of the topics submitted by the team.&lt;br /&gt;
&lt;br /&gt;
The algorithm works on bidding process which can be explained as follows:&lt;br /&gt;
== Before the bidding process ==&lt;br /&gt;
#Initially, every student is a team of 1 member. Before the bidding process takes place, students can merge their teams to form a larger team. The person to whom they have merged becomes the team owner/captain.&lt;br /&gt;
#Every team is given x bids(x is calculated based on the total class strength and total topics proposed), that they can place on each topic of their choice in a priority order where 1 being the highest priority.&lt;br /&gt;
#Every topic is allowed ‘p’ number of maximum bids after which the topic is waitlisted in the system.&lt;br /&gt;
#Teams can also place their bids on waitlisted topics. However, every topic has a threshold ‘q’ which signifies the maximum waitlisted bids allowed for each topic.&lt;br /&gt;
#Thus, if the combined threshold of ‘p+q’ bids for a topic is reached then the topic is no longer available for bidding unless the topic is dropped by a team which reduces the ‘p+q’ threshold value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== During Bidding Process ==&lt;br /&gt;
#Every team can place their bids on the available topics. Since every team is given ‘x’ bids, each team can bid for ‘x’ topics and list their bids in a priority order.&lt;br /&gt;
#A team can also place their bids on  waitlisted topics. The maximum allowed bids for waitlisted topics is ‘y’ where y is some portion of bids taken from total bids(x) allowed for each team.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== After the Bidding Process ==&lt;br /&gt;
#After the bidding process is complete, the teams can continue to merge to form larger teams.&lt;br /&gt;
#If team A merges with team B, the bids of team A would be lost.&lt;br /&gt;
#The merging of the teams is allowed till the topic assignment date when the teams would finally be assigned the topics by running an algorithm.&lt;br /&gt;
#The teams can also change their submitted topic priority order any number of times before running the ‘topic assignment’ algorithm. &lt;br /&gt;
&lt;br /&gt;
 The algorithm assigns the topic to each teams based on the following factors:&lt;br /&gt;
&lt;br /&gt;
# The team which is close to or has maximum possible team strength has a higher probability of winning the topic they had placed their bid on.&lt;br /&gt;
# For a team which satisfies condition(1), a topic would be assigned to the team based on the priority order of the bids that the team specified.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
#As each team can place their bids on the available topics based on their topic priority. Hence every team gets to choose more than one topic of their choice.&lt;br /&gt;
&lt;br /&gt;
#As every topic has a maximum number of allowed bids, after which the topic is no longer available for bidding, this method addresses the issue where many teams choose only a handful topics among all topics. &lt;br /&gt;
&lt;br /&gt;
#As the maximum allowed bids for waitlisting a topic is also limited for every team, hence the issue of unnecessary additions to waitlist is resolved by this method.&lt;br /&gt;
&lt;br /&gt;
#The teams are assigned topics based on modified ‘stable matching’ algorithm which considers factors such as team size and priority ensuring that the topics are no longer assigned based on FCFS basis. Thus this method addresses the most important issue where a topic is not assigned to the team just because the team was late to sign up for the topic as compared to the other teams.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Requirements&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
1) The instructor should be able to create assignments which can utilize intelligent assignment of teams. (It is an optional feature)&lt;br /&gt;
&lt;br /&gt;
2) The instructor should be able to set the maximum number of bids a team can make. Defaulted to 3.&lt;br /&gt;
&lt;br /&gt;
3) The teams should be able place bids on different topics limited to the number set by the instructor for these assignments&lt;br /&gt;
&lt;br /&gt;
4) The teams should be able to prioritize their bids.&lt;br /&gt;
&lt;br /&gt;
5) The instructor should be able to kick off the intelligent assignment of teams.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Sequence Diagram&amp;lt;/b&amp;gt;=&lt;br /&gt;
[[File:E1475.Sequence Diagram.png|frame|center|Fig 1. Sequence Diagram]]&lt;br /&gt;
Fig 1. shows the sequence diagram for this feature. The diagram shows the sequences exclusive to this feature. Therefore, this assumes that the assignment/exercise has already been created. &lt;br /&gt;
Once the assignment is created, the instructor can enable the 'intelligent assignment of teams' feature for the particular assignment. Enabling this feature would give the students(or teams) a view to place bids on the topics they like. They can associate each bid with a priority. Once the deadline has passed, the instructor can kickoff the process which performs the automatic assignment. This would in turn start assigning teams with topics based on their bid preferences.&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;UML Design&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
The intelligent assignment controller is dependent on the ''AssignmentTopicController'' and other models like - ''Assignment'', ''AssignmentTopic'' and ''Team''. When the instructor starts the intelligent assignment of topics to teams, ''IntelligentAssignmentController'' triggers the assignment algorithm.&lt;br /&gt;
&lt;br /&gt;
The students interact with ''AssignmentTopicView'' which lists down all the topics for the assignment and allows students to bid for topics with priority. ''AssignmentTopicController'' is responsible for recording all the bids and priorities correctly.&lt;br /&gt;
&lt;br /&gt;
Following is the UML diagram of the O-O design focusing only on the component related to intelligent assignment of topics to teams.&lt;br /&gt;
&lt;br /&gt;
[[File: UML_Design.png|UML Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;Database Design&amp;lt;/b&amp;gt;=&lt;br /&gt;
&lt;br /&gt;
In order to meet other solution requirement, new tables are added. The following diagram represents the new tables in [http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation crow foot's notation]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation Crow Foot's Notation]&amp;lt;/ref&amp;gt;. The ''user'' table mentioned is not new and is present only to explain the field - ''ownerId''.&lt;br /&gt;
&lt;br /&gt;
Earlier, all the information in ''AssignmentTopic'' and ''AssignmentTopicMetadata'' tables were in a single table called ''signup_topics''. However, there was lot of data redundancy observed and we also required to add an extra field in the table ''signup_topics''. Therefore, we decided to store the topics related to an assignment according to the diagram. One caveat to this design is that all the topics for an assignment are considered equal in terms of category, maximum bids allowed and maximum bids in waiting list.&lt;br /&gt;
&lt;br /&gt;
The table ''bid'' is supposed to store all the bids on the topics with their priority. The owner of the bid will be recorded too. Current requirement is to have only one bid per topic by an owner. Therefore, we could have ''(ownerId, topicId)'' pair as the primary key. However, in order to support multiple bids in a future sceario, we have used a field ''id'' as the primary key.&lt;br /&gt;
&lt;br /&gt;
Apart from the mentioned new tables, we will be using pre-existing tables to meet our requirements and design.&lt;br /&gt;
&lt;br /&gt;
[[File: DatabaseDesign.png|Database Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;b&amp;gt;References&amp;lt;/b&amp;gt;=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91855</id>
		<title>CSC/ECE 517 Fall 2014/final E1475 nrnn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91855"/>
		<updated>2014-11-12T00:23:56Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Database Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= E1475. Intelligent assignment of teams =&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
According to the existing code workflow, the assignment of topics to teams are based on first come first serve basis, where a team which first signs up for a topic gets the topic while  the other teams which choose the same topic are waitlisted. Since ‘sign up time’ is the only factor considered for topic assignment this method causes problems such as:&lt;br /&gt;
&lt;br /&gt;
#Non-uniform distribution of topic between teams in a class&lt;br /&gt;
#The current system fails to resolve the problem when many teams bid for handful of topics(among many topics) causing unnecessary additions to the waitlist&lt;br /&gt;
#The assignment of topics is more focussed on individual selection and ‘sign up time’. Factors such as team size are not considered which are important while assigning a topic to the team and potentially can reduce many issues faced by the current system. &lt;br /&gt;
&lt;br /&gt;
To address the above mentioned issues, we have designed an ‘intelligent assignment of topics’ system which tries to address the issues faced by the current system.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
The signup process for group projects is observed by most students to be a troublesome task  in expertiza. The current sign up process for topics is based on FCFS basis, where a student who signs up for a topic of his/her choice first, gets it. We have discovered some pitfalls with the current ‘topic assignment’ system in Expertiza which arises due to the below mentioned factors.  Due to these reasons, we now try to propose an intelligent system which can addresses many issues faced with the current Expertiza system.&lt;br /&gt;
== Pitfalls with the current system ==&lt;br /&gt;
#One student can sign up only for a single topic. In cases where many topics are available, a student is forced to choose a single topic among many available topics which can be a difficult task. To select a single topic which best fits his/her choice among many available topics requires a pre-study of all topics prior to the signup process. Such a pre-requirement is not fulfilled by most  students, which results in a student signing up for a topic which he/she has randomly selected OR because it was among the only available topics.&lt;br /&gt;
#If a student is not able to sign up for a topic of his choice, he can waitlist himself for all the remaining topics, which causes unnecessary traffic in the waitlist queue of a topic. &lt;br /&gt;
#If all the teams choose a handful of topics among many topics, it would also result in unnecessary additions in the waitlist queue for those few topics resulting in a situation where all the topics are not uniformly distributed among all the teams&lt;br /&gt;
#Before, signing up, if more than one student forms a team and if each student belonging to the same team tries to signup for different topics, than those topics are allotted to individual students resulting in a situation where a team can hold more than one topic. Thus other teams are forced to choose from remaining topics which eventually results in longer waitlists.&lt;br /&gt;
&lt;br /&gt;
After observing the above problems with the existing method of ‘topic assignment’ in expertiza, we have proposed and implemented an ‘intelligent assignment of topics’ method to overcome all the shortcomings of the existing system in expertiza.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Previous work ==&lt;br /&gt;
Previously in 2012, to address this issue of expertiza, a team proposed a possible solution of ‘lottery based topic assignment’ algorithm. The algorithm works by considering every team as strength of 1, representing the student in the team. After sign up the topic would be allotted to the team based on a lottery system where a team is randomly selected for every topic. However this method failed to address the following issues:&lt;br /&gt;
#It did not consider the case where a team could be of more than one member, hence it allowed every team member to bid for different topics resulting in the same problem as mentioned in point (4) of Pitfalls with the current system.&lt;br /&gt;
#The topics were awarded based on a Lottery system and not based on any other criteria which resulted in topic assignment to be a game of luck factor rather than on individual’s choice.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Design Workflow =&lt;br /&gt;
To address the issues faced by both, the current system and lottery based system, we propose a solution based on ‘intelligent team assignment’ algorithm. The algorithm is based on two important factors:&lt;br /&gt;
&lt;br /&gt;
#Team strength&lt;br /&gt;
#Priority order of the topics submitted by the team.&lt;br /&gt;
&lt;br /&gt;
The algorithm works on bidding process which can be explained as follows:&lt;br /&gt;
== Before the bidding process ==&lt;br /&gt;
#Initially, every student is a team of 1 member. Before the bidding process takes place, students can merge their teams to form a larger team. The person to whom they have merged becomes the team owner/captain.&lt;br /&gt;
#Every team is given x bids(x is calculated based on the total class strength and total topics proposed), that they can place on each topic of their choice in a priority order where 1 being the highest priority.&lt;br /&gt;
#Every topic is allowed ‘p’ number of maximum bids after which the topic is waitlisted in the system.&lt;br /&gt;
#Teams can also place their bids on waitlisted topics. However, every topic has a threshold ‘q’ which signifies the maximum waitlisted bids allowed for each topic.&lt;br /&gt;
#Thus, if the combined threshold of ‘p+q’ bids for a topic is reached then the topic is no longer available for bidding unless the topic is dropped by a team which reduces the ‘p+q’ threshold value.&lt;br /&gt;
&lt;br /&gt;
== During Bidding Process ==&lt;br /&gt;
#Every team can place their bids on the available topics. Since every team is given ‘x’ bids, each team can bid for ‘x’ topics and list their bids in a priority order.&lt;br /&gt;
#A team can also place their bids on  waitlisted topics. The maximum allowed bids for waitlisted topics is ‘y’ where y is some portion of bids taken from total bids(x) allowed for each team.&lt;br /&gt;
&lt;br /&gt;
== After the Bidding Process ==&lt;br /&gt;
#After the bidding process is complete, the teams can continue to merge to form larger teams.&lt;br /&gt;
#If team A merges with team B, the bids of team A would be lost.&lt;br /&gt;
#The merging of the teams is allowed till the topic assignment date when the teams would finally be assigned the topics by running an algorithm.&lt;br /&gt;
#The teams can also change their submitted topic priority order any number of times before running the ‘topic assignment’ algorithm. &lt;br /&gt;
&lt;br /&gt;
 The algorithm assigns the topic to each teams based on the following factors:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a) The team which is close to or has maximum possible team strength has a higher probability of winning the topic they had placed their bid on.    &amp;lt;br&amp;gt;&lt;br /&gt;
b) For a team which satisfies condition(1) mentioned above, a topic would be assigned to the team based on the priority order of the bids that the team specified.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== Features ==&lt;br /&gt;
#As each team can place their bids on the available topics based on their topic priority. Hence every team gets to choose more than one topic of their choice.&lt;br /&gt;
&lt;br /&gt;
#As every topic has a maximum number of allowed bids, after which the topic is no longer available for bidding, this method addresses the issue where many teams choose only a handful topics among all topics. &lt;br /&gt;
&lt;br /&gt;
#As the maximum allowed bids for waitlisting a topic is also limited for every team, hence the issue of unnecessary additions to waitlist is resolved by this method.&lt;br /&gt;
&lt;br /&gt;
#The teams are assigned topics based on modified ‘stable matching’ algorithm which considers factors such as team size and priority ensuring that the topics are no longer assigned based on FCFS basis. Thus this method addresses the most important issue where a topic is not assigned to the team just because the team was late to sign up for the topic as compared to the other teams.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Requirements=&lt;br /&gt;
&lt;br /&gt;
1) The instructor should be able to create assignments which can utilize intelligent assignment of teams. (It is an optional feature)&lt;br /&gt;
&lt;br /&gt;
2) The instructor should be able to set the maximum number of bids a team can make. Defaulted to 3.&lt;br /&gt;
&lt;br /&gt;
3) The teams should be able place bids on different topics limited to the number set by the instructor for these assignments&lt;br /&gt;
&lt;br /&gt;
4) The teams should be able to prioritize their bids.&lt;br /&gt;
&lt;br /&gt;
5) The instructor should be able to kick off the intelligent assignment of teams.&lt;br /&gt;
&lt;br /&gt;
=Sequence Diagram=&lt;br /&gt;
[[File:E1475.Sequence Diagram.png|frame|center|Fig 1. Sequence Diagram]]&lt;br /&gt;
Fig 1. shows the sequence diagram for this feature. The diagram shows the sequences exclusive to this feature. Therefore, this assumes that the assignment/exercise has already been created. &lt;br /&gt;
Once the assignment is created, the instructor can enable the 'intelligent assignment of teams' feature for the particular assignment. Enabling this feature would give the students(or teams) a view to place bids on the topics they like. They can associate each bid with a priority. Once the deadline has passed, the instructor can kickoff the process which performs the automatic assignment. This would in turn start assigning teams with topics based on their bid preferences. &lt;br /&gt;
&lt;br /&gt;
=UML Design=&lt;br /&gt;
&lt;br /&gt;
The intelligent assignment controller is dependent on the ''AssignmentTopicController'' and other models like - ''Assignment'', ''AssignmentTopic'' and ''Team''. When the instructor starts the intelligent assignment of topics to teams, ''IntelligentAssignmentController'' triggers the assignment algorithm.&lt;br /&gt;
&lt;br /&gt;
The students interact with ''AssignmentTopicView'' which lists down all the topics for the assignment and allows students to bid for topics with priority. ''AssignmentTopicController'' is responsible for recording all the bids and priorities correctly.&lt;br /&gt;
&lt;br /&gt;
Following is the UML diagram of the O-O design focusing only on the component related to intelligent assignment of topics to teams.&lt;br /&gt;
&lt;br /&gt;
[[File: UML_Design.png|UML Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=Database Design=&lt;br /&gt;
&lt;br /&gt;
In order to meet other solution requirement, new tables are added. The following diagram represents the new tables in [http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation crow foot's notation]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation Crow Foot's Notation]&amp;lt;/ref&amp;gt;. The ''user'' table mentioned is not new and is present only to explain the field - ''ownerId''.&lt;br /&gt;
&lt;br /&gt;
Earlier, all the information in ''AssignmentTopic'' and ''AssignmentTopicMetadata'' tables were in a single table called ''signup_topics''. However, there was lot of data redundancy observed and we also required to add an extra field in the table ''signup_topics''. Therefore, we decided to store the topics related to an assignment according to the diagram. One caveat to this design is that all the topics for an assignment are considered equal in terms of category, maximum bids allowed and maximum bids in waiting list.&lt;br /&gt;
&lt;br /&gt;
The table ''bid'' is supposed to store all the bids on the topics with their priority. The owner of the bid will be recorded too. Current requirement is to have only one bid per topic by an owner. Therefore, we could have ''(ownerId, topicId)'' pair as the primary key. However, in order to support multiple bids in a future sceario, we have used a field ''id'' as the primary key.&lt;br /&gt;
&lt;br /&gt;
Apart from the mentioned new tables, we will be using pre-existing tables to meet our requirements and design.&lt;br /&gt;
&lt;br /&gt;
[[File: DatabaseDesign.png|Database Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91853</id>
		<title>CSC/ECE 517 Fall 2014/final E1475 nrnn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91853"/>
		<updated>2014-11-12T00:23:09Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Database Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= E1475. Intelligent assignment of teams =&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
According to the existing code workflow, the assignment of topics to teams are based on first come first serve basis, where a team which first signs up for a topic gets the topic while  the other teams which choose the same topic are waitlisted. Since ‘sign up time’ is the only factor considered for topic assignment this method causes problems such as:&lt;br /&gt;
&lt;br /&gt;
#Non-uniform distribution of topic between teams in a class&lt;br /&gt;
#The current system fails to resolve the problem when many teams bid for handful of topics(among many topics) causing unnecessary additions to the waitlist&lt;br /&gt;
#The assignment of topics is more focussed on individual selection and ‘sign up time’. Factors such as team size are not considered which are important while assigning a topic to the team and potentially can reduce many issues faced by the current system. &lt;br /&gt;
&lt;br /&gt;
To address the above mentioned issues, we have designed an ‘intelligent assignment of topics’ system which tries to address the issues faced by the current system.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
The signup process for group projects is observed by most students to be a troublesome task  in expertiza. The current sign up process for topics is based on FCFS basis, where a student who signs up for a topic of his/her choice first, gets it. We have discovered some pitfalls with the current ‘topic assignment’ system in Expertiza which arises due to the below mentioned factors.  Due to these reasons, we now try to propose an intelligent system which can addresses many issues faced with the current Expertiza system.&lt;br /&gt;
== Pitfalls with the current system ==&lt;br /&gt;
#One student can sign up only for a single topic. In cases where many topics are available, a student is forced to choose a single topic among many available topics which can be a difficult task. To select a single topic which best fits his/her choice among many available topics requires a pre-study of all topics prior to the signup process. Such a pre-requirement is not fulfilled by most  students, which results in a student signing up for a topic which he/she has randomly selected OR because it was among the only available topics.&lt;br /&gt;
#If a student is not able to sign up for a topic of his choice, he can waitlist himself for all the remaining topics, which causes unnecessary traffic in the waitlist queue of a topic. &lt;br /&gt;
#If all the teams choose a handful of topics among many topics, it would also result in unnecessary additions in the waitlist queue for those few topics resulting in a situation where all the topics are not uniformly distributed among all the teams&lt;br /&gt;
#Before, signing up, if more than one student forms a team and if each student belonging to the same team tries to signup for different topics, than those topics are allotted to individual students resulting in a situation where a team can hold more than one topic. Thus other teams are forced to choose from remaining topics which eventually results in longer waitlists.&lt;br /&gt;
&lt;br /&gt;
After observing the above problems with the existing method of ‘topic assignment’ in expertiza, we have proposed and implemented an ‘intelligent assignment of topics’ method to overcome all the shortcomings of the existing system in expertiza.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Previous work ==&lt;br /&gt;
Previously in 2012, to address this issue of expertiza, a team proposed a possible solution of ‘lottery based topic assignment’ algorithm. The algorithm works by considering every team as strength of 1, representing the student in the team. After sign up the topic would be allotted to the team based on a lottery system where a team is randomly selected for every topic. However this method failed to address the following issues:&lt;br /&gt;
#It did not consider the case where a team could be of more than one member, hence it allowed every team member to bid for different topics resulting in the same problem as mentioned in point (4) of Pitfalls with the current system.&lt;br /&gt;
#The topics were awarded based on a Lottery system and not based on any other criteria which resulted in topic assignment to be a game of luck factor rather than on individual’s choice.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Design Workflow =&lt;br /&gt;
To address the issues faced by both, the current system and lottery based system, we propose a solution based on ‘intelligent team assignment’ algorithm. The algorithm is based on two important factors:&lt;br /&gt;
&lt;br /&gt;
#Team strength&lt;br /&gt;
#Priority order of the topics submitted by the team.&lt;br /&gt;
&lt;br /&gt;
The algorithm works on bidding process which can be explained as follows:&lt;br /&gt;
== Before the bidding process ==&lt;br /&gt;
#Initially, every student is a team of 1 member. Before the bidding process takes place, students can merge their teams to form a larger team. The person to whom they have merged becomes the team owner/captain.&lt;br /&gt;
#Every team is given x bids(x is calculated based on the total class strength and total topics proposed), that they can place on each topic of their choice in a priority order where 1 being the highest priority.&lt;br /&gt;
#Every topic is allowed ‘p’ number of maximum bids after which the topic is waitlisted in the system.&lt;br /&gt;
#Teams can also place their bids on waitlisted topics. However, every topic has a threshold ‘q’ which signifies the maximum waitlisted bids allowed for each topic.&lt;br /&gt;
#Thus, if the combined threshold of ‘p+q’ bids for a topic is reached then the topic is no longer available for bidding unless the topic is dropped by a team which reduces the ‘p+q’ threshold value.&lt;br /&gt;
&lt;br /&gt;
== During Bidding Process ==&lt;br /&gt;
#Every team can place their bids on the available topics. Since every team is given ‘x’ bids, each team can bid for ‘x’ topics and list their bids in a priority order.&lt;br /&gt;
#A team can also place their bids on  waitlisted topics. The maximum allowed bids for waitlisted topics is ‘y’ where y is some portion of bids taken from total bids(x) allowed for each team.&lt;br /&gt;
&lt;br /&gt;
== After the Bidding Process ==&lt;br /&gt;
#After the bidding process is complete, the teams can continue to merge to form larger teams.&lt;br /&gt;
#If team A merges with team B, the bids of team A would be lost.&lt;br /&gt;
#The merging of the teams is allowed till the topic assignment date when the teams would finally be assigned the topics by running an algorithm.&lt;br /&gt;
#The teams can also change their submitted topic priority order any number of times before running the ‘topic assignment’ algorithm. &lt;br /&gt;
&lt;br /&gt;
 The algorithm assigns the topic to each teams based on the following factors:&lt;br /&gt;
&lt;br /&gt;
# The team which is close to or has maximum possible team strength has a higher probability of winning the topic they had placed their bid on.    &lt;br /&gt;
# For a team which satisfies condition(1) mentioned above, a topic would be assigned to the team based on the priority order of the bids that the team specified.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
#As each team can place their bids on the available topics based on their topic priority. Hence every team gets to choose more than one topic of their choice.&lt;br /&gt;
&lt;br /&gt;
#As every topic has a maximum number of allowed bids, after which the topic is no longer available for bidding, this method addresses the issue where many teams choose only a handful topics among all topics. &lt;br /&gt;
&lt;br /&gt;
#As the maximum allowed bids for waitlisting a topic is also limited for every team, hence the issue of unnecessary additions to waitlist is resolved by this method.&lt;br /&gt;
&lt;br /&gt;
#The teams are assigned topics based on modified ‘stable matching’ algorithm which considers factors such as team size and priority ensuring that the topics are no longer assigned based on FCFS basis. Thus this method addresses the most important issue where a topic is not assigned to the team just because the team was late to sign up for the topic as compared to the other teams.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Requirements=&lt;br /&gt;
&lt;br /&gt;
1) The instructor should be able to create assignments which can utilize intelligent assignment of teams. (It is an optional feature)&lt;br /&gt;
&lt;br /&gt;
2) The instructor should be able to set the maximum number of bids a team can make. Defaulted to 3.&lt;br /&gt;
&lt;br /&gt;
3) The teams should be able place bids on different topics limited to the number set by the instructor for these assignments&lt;br /&gt;
&lt;br /&gt;
4) The teams should be able to prioritize their bids.&lt;br /&gt;
&lt;br /&gt;
5) The instructor should be able to kick off the intelligent assignment of teams.&lt;br /&gt;
&lt;br /&gt;
=Sequence Diagram=&lt;br /&gt;
[[File:E1475.Sequence Diagram.png|frame|center|Fig 1. Sequence Diagram]]&lt;br /&gt;
Fig 1. shows the sequence diagram for this feature. The diagram shows the sequences exclusive to this feature. Therefore, this assumes that the assignment/exercise has already been created. &lt;br /&gt;
Once the assignment is created, the instructor can enable the 'intelligent assignment of teams' feature for the particular assignment. Enabling this feature would give the students(or teams) a view to place bids on the topics they like. They can associate each bid with a priority. Once the deadline has passed, the instructor can kickoff the process which performs the automatic assignment. This would in turn start assigning teams with topics based on their bid preferences. &lt;br /&gt;
&lt;br /&gt;
=UML Design=&lt;br /&gt;
&lt;br /&gt;
The intelligent assignment controller is dependent on the ''AssignmentTopicController'' and other models like - ''Assignment'', ''AssignmentTopic'' and ''Team''. When the instructor starts the intelligent assignment of topics to teams, ''IntelligentAssignmentController'' triggers the assignment algorithm.&lt;br /&gt;
&lt;br /&gt;
The students interact with ''AssignmentTopicView'' which lists down all the topics for the assignment and allows students to bid for topics with priority. ''AssignmentTopicController'' is responsible for recording all the bids and priorities correctly.&lt;br /&gt;
&lt;br /&gt;
Following is the UML diagram of the O-O design focusing only on the component related to intelligent assignment of topics to teams.&lt;br /&gt;
&lt;br /&gt;
[[File: UML_Design.png|UML Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=Database Design=&lt;br /&gt;
&lt;br /&gt;
In order to meet other solution requirement, new tables are added. The following diagram represents the new tables in [http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation crow foot's notation]&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation]&amp;lt;/ref&amp;gt;. The ''user'' table mentioned is not new and is present only to explain the field - ''ownerId''.&lt;br /&gt;
&lt;br /&gt;
Earlier, all the information in ''AssignmentTopic'' and ''AssignmentTopicMetadata'' tables were in a single table called ''signup_topics''. However, there was lot of data redundancy observed and we also required to add an extra field in the table ''signup_topics''. Therefore, we decided to store the topics related to an assignment according to the diagram. One caveat to this design is that all the topics for an assignment are considered equal in terms of category, maximum bids allowed and maximum bids in waiting list.&lt;br /&gt;
&lt;br /&gt;
The table ''bid'' is supposed to store all the bids on the topics with their priority. The owner of the bid will be recorded too. Current requirement is to have only one bid per topic by an owner. Therefore, we could have ''(ownerId, topicId)'' pair as the primary key. However, in order to support multiple bids in a future sceario, we have used a field ''id'' as the primary key.&lt;br /&gt;
&lt;br /&gt;
Apart from the mentioned new tables, we will be using pre-existing tables to meet our requirements and design.&lt;br /&gt;
&lt;br /&gt;
[[File: DatabaseDesign.png|Database Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91843</id>
		<title>CSC/ECE 517 Fall 2014/final E1475 nrnn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91843"/>
		<updated>2014-11-12T00:12:48Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* UML Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= E1475. Intelligent assignment of teams =&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
According to the existing code workflow, the assignment of topics to teams are based on first come first serve basis, where a team which first signs up for a topic gets the topic while  the other teams which choose the same topic are waitlisted. Since ‘sign up time’ is the only factor considered for topic assignment this method causes problems such as:&lt;br /&gt;
&lt;br /&gt;
#Non-uniform distribution of topic between teams in a class&lt;br /&gt;
#The current system fails to resolve the problem when many teams bid for handful of topics(among many topics) causing unnecessary additions to the waitlist&lt;br /&gt;
#The assignment of topics is more focussed on individual selection and ‘sign up time’. Factors such as team size are not considered which are important while assigning a topic to the team and potentially can reduce many issues faced by the current system. &lt;br /&gt;
&lt;br /&gt;
To address the above mentioned issues, we have designed an ‘intelligent assignment of topics’ system which tries to address the issues faced by the current system.&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
The signup process for group projects is observed by most students to be a troublesome task  in expertiza. The current sign up process for topics is based on FCFS basis, where a student who signs up for a topic of his/her choice first, gets it. We have discovered some pitfalls with the current ‘topic assignment’ system in Expertiza which arises due to the below mentioned factors.  Due to these reasons, we now try to propose an intelligent system which can addresses many issues faced with the current Expertiza system.&lt;br /&gt;
== Pitfalls with the current system ==&lt;br /&gt;
#One student can sign up only for a single topic. In cases where many topics are available, a student is forced to choose a single topic among many available topics which can be a difficult task. To select a single topic which best fits his/her choice among many available topics requires a pre-study of all topics prior to the signup process. Such a pre-requirement is not fulfilled by most  students, which results in a student signing up for a topic which he/she has randomly selected OR because it was among the only available topics.&lt;br /&gt;
#If a student is not able to sign up for a topic of his choice, he can waitlist himself for all the remaining topics, which causes unnecessary traffic in the waitlist queue of a topic. &lt;br /&gt;
#If all the teams choose a handful of topics among many topics, it would also result in unnecessary additions in the waitlist queue for those few topics resulting in a situation where all the topics are not uniformly distributed among all the teams&lt;br /&gt;
#Before, signing up, if more than one student forms a team and if each student belonging to the same team tries to signup for different topics, than those topics are allotted to individual students resulting in a situation where a team can hold more than one topic. Thus other teams are forced to choose from remaining topics which eventually results in longer waitlists.&lt;br /&gt;
&lt;br /&gt;
After observing the above problems with the existing method of ‘topic assignment’ in expertiza, we have proposed and implemented an ‘intelligent assignment of topics’ method to overcome all the shortcomings of the existing system in expertiza.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Previous work ==&lt;br /&gt;
Previously in 2012, to address this issue of expertiza, a team proposed a possible solution of ‘lottery based topic assignment’ algorithm. The algorithm works by considering every team as strength of 1, representing the student in the team. After sign up the topic would be allotted to the team based on a lottery system where a team is randomly selected for every topic. However this method failed to address the following issues:&lt;br /&gt;
#It did not consider the case where a team could be of more than one member, hence it allowed every team member to bid for different topics resulting in the same problem as mentioned in point (4) of Pitfalls with the current system.&lt;br /&gt;
#The topics were awarded based on a Lottery system and not based on any other criteria which resulted in topic assignment to be a game of luck factor rather than on individual’s choice.&lt;br /&gt;
&lt;br /&gt;
=Requirements=&lt;br /&gt;
&lt;br /&gt;
1) The instructor should be able to create assignments which can utilize intelligent assignment of teams. (It is an optional feature)&lt;br /&gt;
&lt;br /&gt;
2) The instructor should be able to set the maximum number of bids a team can make. Defaulted to 3.&lt;br /&gt;
&lt;br /&gt;
3) The teams should be able place bids on different topics limited to the number set by the instructor for these assignments&lt;br /&gt;
&lt;br /&gt;
4) The teams should be able to prioritize their bids.&lt;br /&gt;
&lt;br /&gt;
5) The instructor should be able to kick off the intelligent assignment of teams.&lt;br /&gt;
&lt;br /&gt;
=Sequence Diagram=&lt;br /&gt;
[[File:E1475.Sequence Diagram.png|frame|center|Fig 1. Sequence Diagram]]&lt;br /&gt;
Fig 1. shows the sequence diagram for this feature. The diagram shows the sequences exclusive to this feature. Therefore, this assumes that the assignment/exercise has already been created. &lt;br /&gt;
Once the assignment is created, the instructor can enable the 'intelligent assignment of teams' feature for the particular assignment. Enabling this feature would give the students(or teams) a view to place bids on the topics they like. They can associate each bid with a priority. Once the deadline has passed, the instructor can kickoff the process which performs the automatic assignment. This would in turn start assigning teams with topics based on their bid preferences. &lt;br /&gt;
&lt;br /&gt;
=UML Design=&lt;br /&gt;
&lt;br /&gt;
The intelligent assignment controller is dependent on the ''AssignmentTopicController'' and other models like - ''Assignment'', ''AssignmentTopic'' and ''Team''. When the instructor starts the intelligent assignment of topics to teams, ''IntelligentAssignmentController'' triggers the assignment algorithm.&lt;br /&gt;
&lt;br /&gt;
The students interact with ''AssignmentTopicView'' which lists down all the topics for the assignment and allows students to bid for topics with priority. ''AssignmentTopicController'' is responsible for recording all the bids and priorities correctly.&lt;br /&gt;
&lt;br /&gt;
Following is the UML diagram of the O-O design focusing only on the component related to intelligent assignment of topics to teams.&lt;br /&gt;
&lt;br /&gt;
[[File: UML_Design.png|UML Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=Database Design=&lt;br /&gt;
&lt;br /&gt;
In order to meet other solution requirement, new tables are added. The following diagram represents the new tables in crow foot's notation. The ''user'' table mentioned is not new and is present only to explain the field - ''ownerId''.&lt;br /&gt;
&lt;br /&gt;
Earlier, all the information in ''AssignmentTopic'' and ''AssignmentTopicMetadata'' tables were in a single table called ''signup_topics''. However, there was lot of data redundancy observed and we also required to add an extra field in the table ''signup_topics''. Therefore, we decided to store the topics related to an assignment according to the diagram. One caveat to this design is that all the topics for an assignment are considered equal in terms of category, maximum bids allowed and maximum bids in waiting list.&lt;br /&gt;
&lt;br /&gt;
The table ''bid'' is supposed to store all the bids on the topics with their priority. The owner of the bid will be recorded too. Current requirement is to have only one bid per topic by an owner. Therefore, we could have ''(ownerId, topicId)'' pair as the primary key. However, in order to support multiple bids in a future sceario, we have used a field ''id'' as the primary key.&lt;br /&gt;
&lt;br /&gt;
Apart from the mentioned new tables, we will be using pre-existing tables to meet our requirements and design.&lt;br /&gt;
&lt;br /&gt;
[[File: DatabaseDesign.png|Database Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91837</id>
		<title>CSC/ECE 517 Fall 2014/final E1475 nrnn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91837"/>
		<updated>2014-11-12T00:04:11Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Database Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Requirements=&lt;br /&gt;
&lt;br /&gt;
1) The instructor should be able to create assignments which can utilize intelligent assignment of teams. (It is an optional feature)&lt;br /&gt;
&lt;br /&gt;
2) The instructor should be able to set the maximum number of bids a team can make. Defaulted to 3.&lt;br /&gt;
&lt;br /&gt;
3) The teams should be able place bids on different topics limited to the number set by the instructor for these assignments&lt;br /&gt;
&lt;br /&gt;
4) The teams should be able to prioritize their bids.&lt;br /&gt;
&lt;br /&gt;
5) The instructor should be able to kick off the intelligent assignment of teams.&lt;br /&gt;
&lt;br /&gt;
=Sequence Diagram=&lt;br /&gt;
[[File:E1475.Sequence Diagram.png|frame|center|Fig 1. Sequence Diagram]]&lt;br /&gt;
Fig 1. shows the sequence diagram for this feature. The diagram shows the sequences exclusive to this feature. Therefore, this assumes that the assignment/exercise has already been created. &lt;br /&gt;
Once the assignment is created, the instructor can enable the 'intelligent assignment of teams' feature for the particular assignment. Enabling this feature would give the students(or teams) a view to place bids on the topics they like. They can associate each bid with a priority. Once the deadline has passed, the instructor can kickoff the process which performs the automatic assignment. This would in turn start assigning teams with topics based on their bid preferences. &lt;br /&gt;
&lt;br /&gt;
=UML Design=&lt;br /&gt;
[[File: UML_Design.png|UML Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=Database Design=&lt;br /&gt;
&lt;br /&gt;
In order to meet other solution requirement, new tables are added. The following diagram represents the new tables in crow foot's notation. The ''user'' table mentioned is not new and is present only to explain the field - ''ownerId''.&lt;br /&gt;
&lt;br /&gt;
Earlier, all the information in ''AssignmentTopic'' and ''AssignmentTopicMetadata'' tables were in a single table called ''signup_topics''. However, there was lot of data redundancy observed and we also required to add an extra field in the table ''signup_topics''. Therefore, we decided to store the topics related to an assignment according to the diagram. One caveat to this design is that all the topics for an assignment are considered equal in terms of category, maximum bids allowed and maximum bids in waiting list.&lt;br /&gt;
&lt;br /&gt;
The table ''bid'' is supposed to store all the bids on the topics with their priority. The owner of the bid will be recorded too. Current requirement is to have only one bid per topic by an owner. Therefore, we could have ''(ownerId, topicId)'' pair as the primary key. However, in order to support multiple bids in a future sceario, we have used a field ''id'' as the primary key.&lt;br /&gt;
&lt;br /&gt;
Apart from the mentioned new tables, we will be using pre-existing tables to meet our requirements and design.&lt;br /&gt;
&lt;br /&gt;
[[File: DatabaseDesign.png|Database Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:DatabaseDesign.png&amp;diff=91822</id>
		<title>File:DatabaseDesign.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:DatabaseDesign.png&amp;diff=91822"/>
		<updated>2014-11-11T23:46:10Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91759</id>
		<title>CSC/ECE 517 Fall 2014/final E1475 nrnn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91759"/>
		<updated>2014-11-11T22:25:53Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* UML Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Requirements=&lt;br /&gt;
&lt;br /&gt;
1) The instructor should be able to create assignments which can utilize intelligent assignment of teams. (It is an optional feature)&lt;br /&gt;
&lt;br /&gt;
2) The instructor should be able to set the maximum number of bids a team can make. Defaulted to 3.&lt;br /&gt;
&lt;br /&gt;
3) The teams should be able place bids on different topics limited to the number set by the instructor for these assignments&lt;br /&gt;
&lt;br /&gt;
4) The teams should be able to prioritize their bids.&lt;br /&gt;
&lt;br /&gt;
5) The instructor should be able to kick off the intelligent assignment of teams.&lt;br /&gt;
&lt;br /&gt;
=Sequence Diagram=&lt;br /&gt;
[[File:E1475.Sequence Diagram.png|frame|center|Fig 1. Sequence Diagram]]&lt;br /&gt;
Fig 1. shows the sequence diagram for this feature. The diagram shows the sequences exclusive to this feature. Therefore, this assumes that the assignment/exercise has already been created. &lt;br /&gt;
Once the assignment is created, the instructor can enable the 'intelligent assignment of teams' feature for the particular assignment. Enabling this feature would give the students(or teams) a view to place bids on the topics they like. They can associate each bid with a priority. Once the deadline has passed, the instructor can kickoff the process which performs the automatic assignment. This would in turn start assigning teams with topics based on their bid preferences. &lt;br /&gt;
&lt;br /&gt;
=UML Design=&lt;br /&gt;
[[File: UML_Design.png|UML Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=Database Design=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:UML_Design.png&amp;diff=91723</id>
		<title>File:UML Design.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:UML_Design.png&amp;diff=91723"/>
		<updated>2014-11-11T19:24:33Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: uploaded a new version of &amp;amp;quot;File:UML Design.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91721</id>
		<title>CSC/ECE 517 Fall 2014/final E1475 nrnn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91721"/>
		<updated>2014-11-11T19:16:33Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* UML Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Requirements=&lt;br /&gt;
&lt;br /&gt;
1) The instructor should be able to create assignments which can utilize intelligent assignment of teams. (It is an optional feature)&lt;br /&gt;
&lt;br /&gt;
2) The instructor should be able to set the maximum number of bids a team can make. Defaulted to 3.&lt;br /&gt;
&lt;br /&gt;
3) The teams should be able place bids on different topics limited to the number set by the instructor for these assignments&lt;br /&gt;
&lt;br /&gt;
4) The teams should be able to prioritize their bids.&lt;br /&gt;
&lt;br /&gt;
5) The instructor should be able to kick off the intelligent assignment of teams.&lt;br /&gt;
&lt;br /&gt;
=Sequence Diagram=&lt;br /&gt;
[[File:E1475.Sequence Diagram.png|frame|center|Fig 1. Sequence Diagram]]&lt;br /&gt;
Fig 1. shows the sequence diagram for this feature. The diagram shows the sequences exclusive to this feature. Therefore, this assumes that the assignment/exercise has already been created. &lt;br /&gt;
Once the assignment is created, the instructor can enable the 'intelligent assignment of teams' feature for the particular assignment. Enabling this feature would give the students(or teams) a view to place bids on the topics they like. They can associate each bid with a priority. Once the deadline has passed, the instructor can kickoff the process which performs the automatic assignment. This would in turn start assigning teams with topics based on their bid preferences. &lt;br /&gt;
&lt;br /&gt;
=UML Design=&lt;br /&gt;
[[File: UML_Design.png|UML Design|frame|center]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:UML_Design.png&amp;diff=91720</id>
		<title>File:UML Design.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:UML_Design.png&amp;diff=91720"/>
		<updated>2014-11-11T19:15:55Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91701</id>
		<title>CSC/ECE 517 Fall 2014/final E1475 nrnn</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/final_E1475_nrnn&amp;diff=91701"/>
		<updated>2014-11-11T17:56:19Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Requirements=&lt;br /&gt;
&lt;br /&gt;
1) The instructor should be able to create assignments which can utilize intelligent assignment of teams. (It is an optional feature)&lt;br /&gt;
&lt;br /&gt;
2) The instructor should be able to set the maximum number of bids a team can make. Defaulted to 3.&lt;br /&gt;
&lt;br /&gt;
3) The teams should be able place bids on different topics limited to the number set by the instructor for these assignments&lt;br /&gt;
&lt;br /&gt;
4) The teams should be able to prioritize their bids.&lt;br /&gt;
&lt;br /&gt;
5) The instructor should be able to kick off the intelligent assignment of teams.&lt;br /&gt;
&lt;br /&gt;
=Sequence Diagram=&lt;br /&gt;
[[File:E1475.Sequence Diagram.png|frame|center|Fig 1. Sequence Diagram]]&lt;br /&gt;
Fig 1. shows the sequence diagram for this feature. The diagram shows the sequences exclusive to this feature. Therefore, this assumes that the assignment/exercise has already been created. &lt;br /&gt;
Once the assignment is created, the instructor can enable the 'intelligent assignment of teams' feature for the particular assignment. Enabling this feature would give the students(or teams) a view to place bids on the topics they like. They can associate each bid with a priority. Once the deadline has passed, the instructor can kickoff the process which performs the automatic assignment. This would in turn start assigning teams with topics based on their bid preferences. &lt;br /&gt;
&lt;br /&gt;
=UML Design=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=91475</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=91475"/>
		<updated>2014-11-06T03:07:19Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type (''ReviewQuestionnaire'', ''AuthorFeedbackQuestionnaire'', ''MetareviewQuestionnaire'' and ''TeammateReviewQuestionnaire''), in each course of the logged-in user. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/sanjeevs/expertiza &amp;lt;ref&amp;gt;[https://github.com/sanjeevs/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/444 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/444 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
Also, there was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Design Pattern=&lt;br /&gt;
Leaderboard is a separate implementation which includes reading existing scores for the sole purpose of creating the leaders in different categories. As the task is more related to calculate and manipulate data, it was not feasible to implement any design pattern. We reduced the complexity and redundancy of database calls by reducing database calls from 625 to 111 to do the same task.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup. Login by any user and navigate to ''Home &amp;gt; Leaderboard'' to test the functionality.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#projectLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Lleaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
&lt;br /&gt;
We computed the number of data base ''&amp;quot;SELECT&amp;quot;'' call generated by the database driver by filtering the messages from the rails server's log. In the original code there were '''625''' database select access generated for the leaderboard view. In the new refactored code the number of select calls dropped to '''111'''.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| '''roles'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|13&lt;br /&gt;
| Optimized the SQL query in ''leaderboard_helper.rb'' to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| '''users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| '''participants'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|111&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|3&lt;br /&gt;
| All the participants associated with computed assignment list are calculated in a single database call and cached in memory rather than calling repetitively within loop.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignments'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|16&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Database calls to ''Assignments'' table was reduced as result of removing it from multiple loops. Supporting data structure and caching enabled to achieve this reduction.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignment_questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Upon careful code investigation, we felt there is no need of any database calls to ''assignment_questionnaires'' table. This contains mapping of ''assignment id'' and ''questionnaire id''.&lt;br /&gt;
|-&lt;br /&gt;
| '''questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|311&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Leaderboard reads the scores from ''ScoreCache'' table, which has ''revieweeId'' and a response object_type (''ReviewResponseMap'', ''AuthorFeedbackResponseMap'', etc.). Refactored code reuses the association of ''response object_type'' to the ''questionnaire_type'' and reduces the usage to 0. this is the most significant reduction in database calls. &lt;br /&gt;
|-&lt;br /&gt;
| '''score_caches'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|22&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|1&lt;br /&gt;
| ''ScoreCache'' table has a field - ''revieweeId'' which can be either ''participantId'' or ''teamId''. All repetitive database calls was reduced to a single call by combining target ''participantId'' and ''teamId'' as a list of ''revieweeId''.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|2&lt;br /&gt;
| Teams table was repetitively called within a loop to retrieve participation in a set of assignments. It was pulled out of the loop and modified to get the same result for all the teams for a larger set of assignments.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams_users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| '''leaderboards'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|9&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Leaderboards table was called multiple times to retrieve the Label for scores of corresponding questionnaire type.&amp;lt;br /&amp;gt;(e.g. ''&amp;quot;ReviewQuestionnaire&amp;quot; - &amp;quot;Submitted Work&amp;quot;''). It was reduced to fetch all such mapping and cached.&lt;br /&gt;
|-&lt;br /&gt;
| '''courses'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost '''15%'''.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|'''1'''&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''2'''&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|'''3'''&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''4'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''5'''&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|'''6'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|'''7'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|'''8'''&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|'''9'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|'''10'''&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90973</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90973"/>
		<updated>2014-10-29T23:26:32Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type (''ReviewQuestionnaire'', ''AuthorFeedbackQuestionnaire'', ''MetareviewQuestionnaire'' and ''TeammateReviewQuestionnaire''), in each course of the logged-in user. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|-&lt;br /&gt;
| '''Repository link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/sanjeevs/expertiza &amp;lt;ref&amp;gt;[https://github.com/sanjeevs/expertiza Forked repository]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/444 &amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza/pull/444 Pull request]&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
Also, there was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#TestingLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Lleaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
&lt;br /&gt;
We computed the number of data base ''&amp;quot;SELECT&amp;quot;'' call generated by the database driver by filtering the messages from the rails server's log. In the original code there were '''625''' database select access generated for the leaderboard view. In the new refactored code the number of select calls dropped to '''111'''.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| '''roles'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|13&lt;br /&gt;
| Optimized the SQL query in ''leaderboard_helper.rb'' to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| '''users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| '''participants'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|111&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|3&lt;br /&gt;
| All the participants associated with computed assignment list are calculated in a single database call and cached in memory rather than calling repetitively within loop.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignments'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|16&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Database calls to ''Assignments'' table was reduced as result of removing it from multiple loops. Supporting data structure and caching enabled to achieve this reduction.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignment_questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Upon careful code investigation, we felt there is no need of any database calls to ''assignment_questionnaires'' table. This contains mapping of ''assignment id'' and ''questionnaire id''.&lt;br /&gt;
|-&lt;br /&gt;
| '''questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|311&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Leaderboard reads the scores from ''ScoreCache'' table, which has ''revieweeId'' and a response object_type (''ReviewResponseMap'', ''AuthorFeedbackResponseMap'', etc.). Refactored code reuses the association of ''response object_type'' to the ''questionnaire_type'' and reduces the usage to 0. this is the most significant reduction in database calls. &lt;br /&gt;
|-&lt;br /&gt;
| '''score_caches'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|22&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|1&lt;br /&gt;
| ''ScoreCache'' table has a field - ''revieweeId'' which can be either ''participantId'' or ''teamId''. All repetitive database calls was reduced to a single call by combining target ''participantId'' and ''teamId'' as a list of ''revieweeId''.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|2&lt;br /&gt;
| Teams table was repetitively called within a loop to retrieve participation in a set of assignments. It was pulled out of the loop and modified to get the same result for all the teams for a larger set of assignments.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams_users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| '''leaderboards'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|9&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Leaderboards table was called multiple times to retrieve the Label for scores of corresponding questionnaire type.&amp;lt;br /&amp;gt;(e.g. ''&amp;quot;ReviewQuestionnaire&amp;quot; - &amp;quot;Submitted Work&amp;quot;''). It was reduced to fetch all such mapping and cached.&lt;br /&gt;
|-&lt;br /&gt;
| '''courses'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost '''15%'''.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|'''1'''&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''2'''&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|'''3'''&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''4'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''5'''&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|'''6'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|'''7'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|'''8'''&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|'''9'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|'''10'''&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90969</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90969"/>
		<updated>2014-10-29T23:24:21Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type (''ReviewQuestionnaire'', ''AuthorFeedbackQuestionnaire'', ''MetareviewQuestionnaire'' and ''TeammateReviewQuestionnaire''), in each course of the logged-in user. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;projectLinks&amp;quot; style=&amp;quot;float: right;&amp;quot;&amp;gt;&lt;br /&gt;
[[File:expertiza_logo.jpg|center]]&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|-&lt;br /&gt;
| '''Project link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/sanjeevs/expertiza&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/444&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
Also, there was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#TestingLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Lleaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
&lt;br /&gt;
We computed the number of data base ''&amp;quot;SELECT&amp;quot;'' call generated by the database driver by filtering the messages from the rails server's log. In the original code there were '''625''' database select access generated for the leaderboard view. In the new refactored code the number of select calls dropped to '''111'''.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| '''roles'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|13&lt;br /&gt;
| Optimized the SQL query in ''leaderboard_helper.rb'' to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| '''users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| '''participants'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|111&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|3&lt;br /&gt;
| All the participants associated with computed assignment list are calculated in a single database call and cached in memory rather than calling repetitively within loop.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignments'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|16&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Database calls to ''Assignments'' table was reduced as result of removing it from multiple loops. Supporting data structure and caching enabled to achieve this reduction.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignment_questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Upon careful code investigation, we felt there is no need of any database calls to ''assignment_questionnaires'' table. This contains mapping of ''assignment id'' and ''questionnaire id''.&lt;br /&gt;
|-&lt;br /&gt;
| '''questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|311&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Leaderboard reads the scores from ''ScoreCache'' table, which has ''revieweeId'' and a response object_type (''ReviewResponseMap'', ''AuthorFeedbackResponseMap'', etc.). Refactored code reuses the association of ''response object_type'' to the ''questionnaire_type'' and reduces the usage to 0. this is the most significant reduction in database calls. &lt;br /&gt;
|-&lt;br /&gt;
| '''score_caches'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|22&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|1&lt;br /&gt;
| ''ScoreCache'' table has a field - ''revieweeId'' which can be either ''participantId'' or ''teamId''. All repetitive database calls was reduced to a single call by combining target ''participantId'' and ''teamId'' as a list of ''revieweeId''.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|2&lt;br /&gt;
| Teams table was repetitively called within a loop to retrieve participation in a set of assignments. It was pulled out of the loop and modified to get the same result for all the teams for a larger set of assignments.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams_users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| '''leaderboards'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|9&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Leaderboards table was called multiple times to retrieve the Label for scores of corresponding questionnaire type.&amp;lt;br /&amp;gt;(e.g. ''&amp;quot;ReviewQuestionnaire&amp;quot; - &amp;quot;Submitted Work&amp;quot;''). It was reduced to fetch all such mapping and cached.&lt;br /&gt;
|-&lt;br /&gt;
| '''courses'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost '''15%'''.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|'''1'''&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''2'''&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|'''3'''&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''4'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''5'''&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|'''6'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|'''7'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|'''8'''&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|'''9'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|'''10'''&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Expertiza_logo.jpg&amp;diff=90968</id>
		<title>File:Expertiza logo.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Expertiza_logo.jpg&amp;diff=90968"/>
		<updated>2014-10-29T23:23:59Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90961</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90961"/>
		<updated>2014-10-29T23:15:37Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type (''ReviewQuestionnaire'', ''AuthorFeedbackQuestionnaire'', ''MetareviewQuestionnaire'' and ''TeammateReviewQuestionnaire''), in each course of the logged-in user. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;TestingLinks&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | '''Expertiza project links'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Refactored Instance'''&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| '''Original Instance'''&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|-&lt;br /&gt;
| '''Project link'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/sanjeevs/expertiza&lt;br /&gt;
|-&lt;br /&gt;
| '''Pull request'''&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | https://github.com/expertiza/expertiza/pull/444&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
Also, there was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#TestingLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Lleaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
&lt;br /&gt;
We computed the number of data base ''&amp;quot;SELECT&amp;quot;'' call generated by the database driver by filtering the messages from the rails server's log. In the original code there were '''625''' database select access generated for the leaderboard view. In the new refactored code the number of select calls dropped to '''111'''.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| '''roles'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|13&lt;br /&gt;
| Optimized the SQL query in ''leaderboard_helper.rb'' to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| '''users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| '''participants'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|111&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|3&lt;br /&gt;
| All the participants associated with computed assignment list are calculated in a single database call and cached in memory rather than calling repetitively within loop.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignments'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|16&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Database calls to ''Assignments'' table was reduced as result of removing it from multiple loops. Supporting data structure and caching enabled to achieve this reduction.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignment_questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Upon careful code investigation, we felt there is no need of any database calls to ''assignment_questionnaires'' table. This contains mapping of ''assignment id'' and ''questionnaire id''.&lt;br /&gt;
|-&lt;br /&gt;
| '''questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|311&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Leaderboard reads the scores from ''ScoreCache'' table, which has ''revieweeId'' and a response object_type (''ReviewResponseMap'', ''AuthorFeedbackResponseMap'', etc.). Refactored code reuses the association of ''response object_type'' to the ''questionnaire_type'' and reduces the usage to 0. this is the most significant reduction in database calls. &lt;br /&gt;
|-&lt;br /&gt;
| '''score_caches'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|22&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|1&lt;br /&gt;
| ''ScoreCache'' table has a field - ''revieweeId'' which can be either ''participantId'' or ''teamId''. All repetitive database calls was reduced to a single call by combining target ''participantId'' and ''teamId'' as a list of ''revieweeId''.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|2&lt;br /&gt;
| Teams table was repetitively called within a loop to retrieve participation in a set of assignments. It was pulled out of the loop and modified to get the same result for all the teams for a larger set of assignments.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams_users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| '''leaderboards'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|9&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Leaderboards table was called multiple times to retrieve the Label for scores of corresponding questionnaire type.&amp;lt;br /&amp;gt;(e.g. ''&amp;quot;ReviewQuestionnaire&amp;quot; - &amp;quot;Submitted Work&amp;quot;''). It was reduced to fetch all such mapping and cached.&lt;br /&gt;
|-&lt;br /&gt;
| '''courses'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost '''15%'''.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|'''1'''&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''2'''&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|'''3'''&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''4'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''5'''&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|'''6'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|'''7'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|'''8'''&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|'''9'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|'''10'''&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90949</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90949"/>
		<updated>2014-10-29T23:05:34Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Optimization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type (''ReviewQuestionnaire'', ''AuthorFeedbackQuestionnaire'', ''MetareviewQuestionnaire'' and ''TeammateReviewQuestionnaire''), in each course of the logged-in user. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;TestingLinks&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza instance links&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
Also, there was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#TestingLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Lleaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
&lt;br /&gt;
We computed the number of data base ''&amp;quot;SELECT&amp;quot;'' call generated by the database driver by filtering the messages from the rails server's log. In the original code there were '''625''' database select access generated for the leaderboard view. In the new refactored code the number of select calls dropped to '''111'''.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| '''roles'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|13&lt;br /&gt;
| Optimized the SQL query in ''leaderboard_helper.rb'' to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| '''users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| '''participants'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|111&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|3&lt;br /&gt;
| All the participants associated with computed assignment list are calculated in a single database call and cached in memory rather than calling repetitively within loop.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignments'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|16&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Database calls to ''Assignments'' table was reduced as result of removing it from multiple loops. Supporting data structure and caching enabled to achieve this reduction.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignment_questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Upon careful code investigation, we felt there is no need of any database calls to ''assignment_questionnaires'' table. This contains mapping of ''assignment id'' and ''questionnaire id''.&lt;br /&gt;
|-&lt;br /&gt;
| '''questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|311&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Leaderboard reads the scores from ''ScoreCache'' table, which has ''revieweeId'' and a response object_type (''ReviewResponseMap'', ''AuthorFeedbackResponseMap'', etc.). Refactored code reuses the association of ''response object_type'' to the ''questionnaire_type'' and reduces the usage to 0. this is the most significant reduction in database calls. &lt;br /&gt;
|-&lt;br /&gt;
| '''score_caches'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|22&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|1&lt;br /&gt;
| ''ScoreCache'' table has a field - ''revieweeId'' which can be either ''participantId'' or ''teamId''. All repetitive database calls was reduced to a single call by combining target ''participantId'' and ''teamId'' as a list of ''revieweeId''.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|2&lt;br /&gt;
| Teams table was repetitively called within a loop to retrieve participation in a set of assignments. It was pulled out of the loop and modified to get the same result for all the teams for a larger set of assignments.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams_users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| '''leaderboards'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|9&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Leaderboards table was called multiple times to retrieve the Label for scores of corresponding questionnaire type.&amp;lt;br /&amp;gt;(e.g. ''&amp;quot;ReviewQuestionnaire&amp;quot; - &amp;quot;Submitted Work&amp;quot;''). It was reduced to fetch all such mapping and cached.&lt;br /&gt;
|-&lt;br /&gt;
| '''courses'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost '''15%'''.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|'''1'''&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''2'''&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|'''3'''&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''4'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''5'''&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|'''6'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|'''7'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|'''8'''&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|'''9'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|'''10'''&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90941</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90941"/>
		<updated>2014-10-29T22:56:33Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Changes in Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type (''ReviewQuestionnaire'', ''AuthorFeedbackQuestionnaire'', ''MetareviewQuestionnaire'' and ''TeammateReviewQuestionnaire''), in each course of the logged-in user. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;TestingLinks&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza instance links&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
Also, there was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#TestingLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
&lt;br /&gt;
We computed the number of data base ''&amp;quot;SELECT&amp;quot;'' call generated the database driver by filtering the messages from the rails server. In the original code there were '''625''' database select access generated for the leaderboard view. In the new code the number of select calls dropped to '''111'''.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| '''roles'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|13&lt;br /&gt;
| Optimized the SQL query in leaderboard_helper.rb to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| '''users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| '''participants'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|111&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|3&lt;br /&gt;
| All the participants associated with computed assignment list are calculated in a single database call and cached in memory rather than calling repetitively within loop.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignments'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|16&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Database calls to ''Assignments'' table was reduced as result of removing it from multiple loops. Supporting data structure and caching enabled to achieve this reduction.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignment_questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Upon careful code investigation, we felt there is no need of any database calls to assignment_questionnaires table. This contains mapping of assignment id and questionnaire id.&lt;br /&gt;
|-&lt;br /&gt;
| '''questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|311&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Leaderboard reads the scores from ''ScoreCache'' table, which has ''revieweeId'' and a response object_type (''ReviewResponseMap'', ''AuthorFeedbackResponseMap'', etc.). Refactored code reuses the association of ''response object_type'' to the ''questionnaire_type'' and reduces the usage to 0. this is the most significant reduction in database calls. &lt;br /&gt;
|-&lt;br /&gt;
| '''score_caches'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|22&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|1&lt;br /&gt;
| ScoreCache table has a field - ''revieweeId'' which can be either ''participantId'' or ''teamId''. All repetitive database calls was reduced to a single call by combining target participantId and teamId as a list of ''revieweeId''.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|2&lt;br /&gt;
| Teams table was repetitively called within a loop to retrieve participation in a set of assignments. It was pulled out of the loop and modified to get the same result for all the teams for a larger set of assignments.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams_users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| '''leaderboards'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|9&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Leaderboards table was called multiple times to retrieve the Label for scores of corresponding questionnaire type.&amp;lt;br /&amp;gt;(e.g. ''&amp;quot;ReviewQuestionnaire&amp;quot; - &amp;quot;Submitted Work&amp;quot;''). It was reduced to fetch all such mapping and cached.&lt;br /&gt;
|-&lt;br /&gt;
| '''courses'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost '''15%'''.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|'''1'''&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''2'''&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|'''3'''&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''4'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''5'''&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|'''6'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|'''7'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|'''8'''&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|'''9'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|'''10'''&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90939</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90939"/>
		<updated>2014-10-29T22:55:44Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Existing Functionality */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type (''ReviewQuestionnaire'', ''AuthorFeedbackQuestionnaire'', ''MetareviewQuestionnaire'' and ''TeammateReviewQuestionnaire''), in each course of the logged-in user. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;TestingLinks&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza instance links&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#TestingLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
&lt;br /&gt;
We computed the number of data base ''&amp;quot;SELECT&amp;quot;'' call generated the database driver by filtering the messages from the rails server. In the original code there were '''625''' database select access generated for the leaderboard view. In the new code the number of select calls dropped to '''111'''.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| '''roles'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|13&lt;br /&gt;
| Optimized the SQL query in leaderboard_helper.rb to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| '''users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| '''participants'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|111&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|3&lt;br /&gt;
| All the participants associated with computed assignment list are calculated in a single database call and cached in memory rather than calling repetitively within loop.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignments'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|16&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Database calls to ''Assignments'' table was reduced as result of removing it from multiple loops. Supporting data structure and caching enabled to achieve this reduction.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignment_questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Upon careful code investigation, we felt there is no need of any database calls to assignment_questionnaires table. This contains mapping of assignment id and questionnaire id.&lt;br /&gt;
|-&lt;br /&gt;
| '''questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|311&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Leaderboard reads the scores from ''ScoreCache'' table, which has ''revieweeId'' and a response object_type (''ReviewResponseMap'', ''AuthorFeedbackResponseMap'', etc.). Refactored code reuses the association of ''response object_type'' to the ''questionnaire_type'' and reduces the usage to 0. this is the most significant reduction in database calls. &lt;br /&gt;
|-&lt;br /&gt;
| '''score_caches'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|22&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|1&lt;br /&gt;
| ScoreCache table has a field - ''revieweeId'' which can be either ''participantId'' or ''teamId''. All repetitive database calls was reduced to a single call by combining target participantId and teamId as a list of ''revieweeId''.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|2&lt;br /&gt;
| Teams table was repetitively called within a loop to retrieve participation in a set of assignments. It was pulled out of the loop and modified to get the same result for all the teams for a larger set of assignments.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams_users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| '''leaderboards'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|9&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Leaderboards table was called multiple times to retrieve the Label for scores of corresponding questionnaire type.&amp;lt;br /&amp;gt;(e.g. ''&amp;quot;ReviewQuestionnaire&amp;quot; - &amp;quot;Submitted Work&amp;quot;''). It was reduced to fetch all such mapping and cached.&lt;br /&gt;
|-&lt;br /&gt;
| '''courses'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost '''15%'''.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|'''1'''&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''2'''&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|'''3'''&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''4'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''5'''&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|'''6'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|'''7'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|'''8'''&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|'''9'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|'''10'''&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90937</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90937"/>
		<updated>2014-10-29T22:54:58Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Changes in Helper */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type (''ReviewQuestionnaire'', ''AuthorFeedbackQuestionnaire'', ''MetareviewQuestionnaire'' and ''TeammateReviewQuestionnaire''), in each course of the logged-in user. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;TestingLinks&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza instance links&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#TestingLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
&lt;br /&gt;
We computed the number of data base ''&amp;quot;SELECT&amp;quot;'' call generated the database driver by filtering the messages from the rails server. In the original code there were '''625''' database select access generated for the leaderboard view. In the new code the number of select calls dropped to '''111'''.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| '''roles'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|13&lt;br /&gt;
| Optimized the SQL query in leaderboard_helper.rb to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| '''users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| '''participants'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|111&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|3&lt;br /&gt;
| All the participants associated with computed assignment list are calculated in a single database call and cached in memory rather than calling repetitively within loop.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignments'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|16&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Database calls to ''Assignments'' table was reduced as result of removing it from multiple loops. Supporting data structure and caching enabled to achieve this reduction.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignment_questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Upon careful code investigation, we felt there is no need of any database calls to assignment_questionnaires table. This contains mapping of assignment id and questionnaire id.&lt;br /&gt;
|-&lt;br /&gt;
| '''questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|311&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Leaderboard reads the scores from ''ScoreCache'' table, which has ''revieweeId'' and a response object_type (''ReviewResponseMap'', ''AuthorFeedbackResponseMap'', etc.). Refactored code reuses the association of ''response object_type'' to the ''questionnaire_type'' and reduces the usage to 0. this is the most significant reduction in database calls. &lt;br /&gt;
|-&lt;br /&gt;
| '''score_caches'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|22&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|1&lt;br /&gt;
| ScoreCache table has a field - ''revieweeId'' which can be either ''participantId'' or ''teamId''. All repetitive database calls was reduced to a single call by combining target participantId and teamId as a list of ''revieweeId''.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|2&lt;br /&gt;
| Teams table was repetitively called within a loop to retrieve participation in a set of assignments. It was pulled out of the loop and modified to get the same result for all the teams for a larger set of assignments.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams_users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| '''leaderboards'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|9&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Leaderboards table was called multiple times to retrieve the Label for scores of corresponding questionnaire type.&amp;lt;br /&amp;gt;(e.g. ''&amp;quot;ReviewQuestionnaire&amp;quot; - &amp;quot;Submitted Work&amp;quot;''). It was reduced to fetch all such mapping and cached.&lt;br /&gt;
|-&lt;br /&gt;
| '''courses'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost '''15%'''.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|'''1'''&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''2'''&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|'''3'''&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''4'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''5'''&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|'''6'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|'''7'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|'''8'''&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|'''9'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|'''10'''&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90936</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90936"/>
		<updated>2014-10-29T22:54:40Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Changes in Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type (''ReviewQuestionnaire'', ''AuthorFeedbackQuestionnaire'', ''MetareviewQuestionnaire'' and ''TeammateReviewQuestionnaire''), in each course of the logged-in user. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;TestingLinks&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza instance links&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#TestingLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
&lt;br /&gt;
We computed the number of data base ''&amp;quot;SELECT&amp;quot;'' call generated the database driver by filtering the messages from the rails server. In the original code there were '''625''' database select access generated for the leaderboard view. In the new code the number of select calls dropped to '''111'''.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| '''roles'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|13&lt;br /&gt;
| Optimized the SQL query in leaderboard_helper.rb to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| '''users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| '''participants'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|111&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|3&lt;br /&gt;
| All the participants associated with computed assignment list are calculated in a single database call and cached in memory rather than calling repetitively within loop.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignments'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|16&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Database calls to ''Assignments'' table was reduced as result of removing it from multiple loops. Supporting data structure and caching enabled to achieve this reduction.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignment_questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Upon careful code investigation, we felt there is no need of any database calls to assignment_questionnaires table. This contains mapping of assignment id and questionnaire id.&lt;br /&gt;
|-&lt;br /&gt;
| '''questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|311&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Leaderboard reads the scores from ''ScoreCache'' table, which has ''revieweeId'' and a response object_type (''ReviewResponseMap'', ''AuthorFeedbackResponseMap'', etc.). Refactored code reuses the association of ''response object_type'' to the ''questionnaire_type'' and reduces the usage to 0. this is the most significant reduction in database calls. &lt;br /&gt;
|-&lt;br /&gt;
| '''score_caches'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|22&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|1&lt;br /&gt;
| ScoreCache table has a field - ''revieweeId'' which can be either ''participantId'' or ''teamId''. All repetitive database calls was reduced to a single call by combining target participantId and teamId as a list of ''revieweeId''.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|2&lt;br /&gt;
| Teams table was repetitively called within a loop to retrieve participation in a set of assignments. It was pulled out of the loop and modified to get the same result for all the teams for a larger set of assignments.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams_users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| '''leaderboards'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|9&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Leaderboards table was called multiple times to retrieve the Label for scores of corresponding questionnaire type.&amp;lt;br /&amp;gt;(e.g. ''&amp;quot;ReviewQuestionnaire&amp;quot; - &amp;quot;Submitted Work&amp;quot;''). It was reduced to fetch all such mapping and cached.&lt;br /&gt;
|-&lt;br /&gt;
| '''courses'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost '''15%'''.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|'''1'''&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''2'''&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|'''3'''&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''4'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''5'''&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|'''6'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|'''7'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|'''8'''&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|'''9'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|'''10'''&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90935</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90935"/>
		<updated>2014-10-29T22:54:09Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Existing Functionality */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type (''ReviewQuestionnaire'', ''AuthorFeedbackQuestionnaire'', ''MetareviewQuestionnaire'' and ''TeammateReviewQuestionnaire''), in each course of the logged-in user. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;TestingLinks&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza instance links&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;text-align:center;&amp;quot;|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#TestingLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
&lt;br /&gt;
We computed the number of data base ''&amp;quot;SELECT&amp;quot;'' call generated the database driver by filtering the messages from the rails server. In the original code there were '''625''' database select access generated for the leaderboard view. In the new code the number of select calls dropped to '''111'''.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| '''roles'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|13&lt;br /&gt;
| Optimized the SQL query in leaderboard_helper.rb to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| '''users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| '''participants'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|111&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|3&lt;br /&gt;
| All the participants associated with computed assignment list are calculated in a single database call and cached in memory rather than calling repetitively within loop.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignments'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|16&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Database calls to ''Assignments'' table was reduced as result of removing it from multiple loops. Supporting data structure and caching enabled to achieve this reduction.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignment_questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Upon careful code investigation, we felt there is no need of any database calls to assignment_questionnaires table. This contains mapping of assignment id and questionnaire id.&lt;br /&gt;
|-&lt;br /&gt;
| '''questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|311&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Leaderboard reads the scores from ''ScoreCache'' table, which has ''revieweeId'' and a response object_type (''ReviewResponseMap'', ''AuthorFeedbackResponseMap'', etc.). Refactored code reuses the association of ''response object_type'' to the ''questionnaire_type'' and reduces the usage to 0. this is the most significant reduction in database calls. &lt;br /&gt;
|-&lt;br /&gt;
| '''score_caches'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|22&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|1&lt;br /&gt;
| ScoreCache table has a field - ''revieweeId'' which can be either ''participantId'' or ''teamId''. All repetitive database calls was reduced to a single call by combining target participantId and teamId as a list of ''revieweeId''.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|2&lt;br /&gt;
| Teams table was repetitively called within a loop to retrieve participation in a set of assignments. It was pulled out of the loop and modified to get the same result for all the teams for a larger set of assignments.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams_users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| '''leaderboards'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|9&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Leaderboards table was called multiple times to retrieve the Label for scores of corresponding questionnaire type.&amp;lt;br /&amp;gt;(e.g. ''&amp;quot;ReviewQuestionnaire&amp;quot; - &amp;quot;Submitted Work&amp;quot;''). It was reduced to fetch all such mapping and cached.&lt;br /&gt;
|-&lt;br /&gt;
| '''courses'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost '''15%'''.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|'''1'''&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''2'''&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|'''3'''&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''4'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''5'''&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|'''6'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|'''7'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|'''8'''&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|'''9'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|'''10'''&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90928</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90928"/>
		<updated>2014-10-29T22:50:05Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type (''ReviewQuestionnaire'', ''AuthorFeedbackQuestionnaire'', ''MetareviewQuestionnaire'' and ''TeammateReviewQuestionnaire''), in each course of the logged-in user. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;TestingLinks&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza instance links&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#TestingLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
&lt;br /&gt;
We computed the number of data base ''&amp;quot;SELECT&amp;quot;'' call generated the database driver by filtering the messages from the rails server. In the original code there were '''625''' database select access generated for the leaderboard view. In the new code the number of select calls dropped to '''111'''.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| '''roles'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|13&lt;br /&gt;
| Optimized the SQL query in leaderboard_helper.rb to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| '''users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| '''participants'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|111&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|3&lt;br /&gt;
| All the participants associated with computed assignment list are calculated in a single database call and cached in memory rather than calling repetitively within loop.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignments'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|16&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Database calls to ''Assignments'' table was reduced as result of removing it from multiple loops. Supporting data structure and caching enabled to achieve this reduction.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignment_questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Upon careful code investigation, we felt there is no need of any database calls to assignment_questionnaires table. This contains mapping of assignment id and questionnaire id.&lt;br /&gt;
|-&lt;br /&gt;
| '''questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|311&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Leaderboard reads the scores from ''ScoreCache'' table, which has ''revieweeId'' and a response object_type (''ReviewResponseMap'', ''AuthorFeedbackResponseMap'', etc.). Refactored code reuses the association of ''response object_type'' to the ''questionnaire_type'' and reduces the usage to 0. this is the most significant reduction in database calls. &lt;br /&gt;
|-&lt;br /&gt;
| '''score_caches'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|22&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|1&lt;br /&gt;
| ScoreCache table has a field - ''revieweeId'' which can be either ''participantId'' or ''teamId''. All repetitive database calls was reduced to a single call by combining target participantId and teamId as a list of ''revieweeId''.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|2&lt;br /&gt;
| Teams table was repetitively called within a loop to retrieve participation in a set of assignments. It was pulled out of the loop and modified to get the same result for all the teams for a larger set of assignments.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams_users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| '''leaderboards'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|9&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Leaderboards table was called multiple times to retrieve the Label for scores of corresponding questionnaire type.&amp;lt;br /&amp;gt;(e.g. ''&amp;quot;ReviewQuestionnaire&amp;quot; - &amp;quot;Submitted Work&amp;quot;''). It was reduced to fetch all such mapping and cached.&lt;br /&gt;
|-&lt;br /&gt;
| '''courses'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost '''15%'''.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|'''1'''&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''2'''&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|'''3'''&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''4'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''5'''&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|'''6'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|'''7'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|'''8'''&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|'''9'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|'''10'''&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90924</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90924"/>
		<updated>2014-10-29T22:46:25Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Performance Optimization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;TestingLinks&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza instance links&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#TestingLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
&lt;br /&gt;
We computed the number of data base ''&amp;quot;SELECT&amp;quot;'' call generated the database driver by filtering the messages from the rails server. In the original code there were '''625''' database select access generated for the leaderboard view. In the new code the number of select calls dropped to '''111'''.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| '''roles'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|13&lt;br /&gt;
| Optimized the SQL query in leaderboard_helper.rb to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| '''users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| '''participants'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|111&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|3&lt;br /&gt;
| All the participants associated with computed assignment list are calculated in a single database call and cached in memory rather than calling repetitively within loop.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignments'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|16&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Database calls to ''Assignments'' table was reduced as result of removing it from multiple loops. Supporting data structure and caching enabled to achieve this reduction.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignment_questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Upon careful code investigation, we felt there is no need of any database calls to assignment_questionnaires table. This contains mapping of assignment id and questionnaire id.&lt;br /&gt;
|-&lt;br /&gt;
| '''questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|311&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Leaderboard reads the scores from ''ScoreCache'' table, which has ''revieweeId'' and a response object_type (''ReviewResponseMap'', ''AuthorFeedbackResponseMap'', etc.). Refactored code reuses the association of ''response object_type'' to the ''questionnaire_type'' and reduces the usage to 0. this is the most significant reduction in database calls. &lt;br /&gt;
|-&lt;br /&gt;
| '''score_caches'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|22&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|1&lt;br /&gt;
| ScoreCache table has a field - ''revieweeId'' which can be either ''participantId'' or ''teamId''. All repetitive database calls was reduced to a single call by combining target participantId and teamId as a list of ''revieweeId''.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|2&lt;br /&gt;
| Teams table was repetitively called within a loop to retrieve participation in a set of assignments. It was pulled out of the loop and modified to get the same result for all the teams for a larger set of assignments.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams_users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| '''leaderboards'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|9&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Leaderboards table was called multiple times to retrieve the Label for scores of corresponding questionnaire type.&amp;lt;br /&amp;gt;(e.g. ''&amp;quot;ReviewQuestionnaire&amp;quot; - &amp;quot;Submitted Work&amp;quot;''). It was reduced to fetch all such mapping and cached.&lt;br /&gt;
|-&lt;br /&gt;
| '''courses'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost '''15%'''.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|'''1'''&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''2'''&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|'''3'''&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''4'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''5'''&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|'''6'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|'''7'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|'''8'''&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|'''9'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|'''10'''&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90923</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90923"/>
		<updated>2014-10-29T22:46:01Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Performance Optimization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;TestingLinks&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza instance links&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#TestingLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
&lt;br /&gt;
We computed the number of data base ''&amp;quot;SELECT&amp;quot;'' call generated the database driver by filtering the messages from the rails server. In the original code there were '''625''' database select access generated for the leaderboard view. In the new code the number of select calls dropped to '''111'''.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| '''roles'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|13&lt;br /&gt;
| Optimized the SQL query in leaderboard_helper.rb to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| '''users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| '''participants'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|111&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|3&lt;br /&gt;
| All the participants associated with computed assignment list are calculated in a single database call and cached in memory rather than calling repetitively within loop.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignments'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|16&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Database calls to ''Assignments'' table was reduced as result of removing it from multiple loops. Supporting data structure and caching enabled to achieve this reduction.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignment_questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Upon careful code investigation, we felt there is no need of any database calls to assignment_questionnaires table. This contains mapping of assignment id and questionnaire id.&lt;br /&gt;
|-&lt;br /&gt;
| '''questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|311&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Leaderboard reads the scores from ''ScoreCache'' table, which has ''revieweeId'' and a response object_type (''ReviewResponseMap'', ''AuthorFeedbackResponseMap'', etc.). Refactored code reuses the association of ''response object_type'' to the ''questionnaire_type'' and reduces the usage to 0. this is the most significant reduction in database calls. &lt;br /&gt;
|-&lt;br /&gt;
| '''score_caches'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|22&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|1&lt;br /&gt;
| ScoreCache table has a field - ''revieweeId'' which can be either ''participantId'' or ''teamId''. All repetitive database calls was reduced to a single call by combining target participantId and teamId as a list of ''revieweeId''.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|2&lt;br /&gt;
| Teams table was repetitively called within a loop to retrieve participation in a set of assignments. It was pulled out of the loop and modified to get the same result for all the teams for a larger set of assignments.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams_users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| '''leaderboards'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|9&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Leaderboards table was called multiple times to retrieve the Label for scores of corresponding questionnaire type.&amp;lt;br /&amp;gt;(e.g. ''&amp;quot;ReviewQuestionnaire&amp;quot; - &amp;quot;Submitted Work&amp;quot;''). It was reduced to fetch all such mapping and cached.&lt;br /&gt;
|-&lt;br /&gt;
| '''courses'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost 15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|'''1'''&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''2'''&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|'''3'''&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''4'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|'''5'''&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|'''6'''&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|'''7'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|'''8'''&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|'''9'''&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|'''10'''&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90922</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90922"/>
		<updated>2014-10-29T22:43:56Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Database Optimization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;TestingLinks&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza instance links&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#TestingLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code style=&amp;quot;background:#F0F0FF&amp;quot;&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
&lt;br /&gt;
We computed the number of data base ''&amp;quot;SELECT&amp;quot;'' call generated the database driver by filtering the messages from the rails server. In the original code there were '''625''' database select access generated for the leaderboard view. In the new code the number of select calls dropped to '''111'''.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| '''roles'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|13&lt;br /&gt;
| Optimized the SQL query in leaderboard_helper.rb to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| '''users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| '''participants'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|111&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|3&lt;br /&gt;
| All the participants associated with computed assignment list are calculated in a single database call and cached in memory rather than calling repetitively within loop.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignments'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|16&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Database calls to ''Assignments'' table was reduced as result of removing it from multiple loops. Supporting data structure and caching enabled to achieve this reduction.&lt;br /&gt;
|-&lt;br /&gt;
| '''assignment_questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Upon careful code investigation, we felt there is no need of any database calls to assignment_questionnaires table. This contains mapping of assignment id and questionnaire id.&lt;br /&gt;
|-&lt;br /&gt;
| '''questionnaires'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|311&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|0&lt;br /&gt;
| Leaderboard reads the scores from ''ScoreCache'' table, which has ''revieweeId'' and a response object_type (''ReviewResponseMap'', ''AuthorFeedbackResponseMap'', etc.). Refactored code reuses the association of ''response object_type'' to the ''questionnaire_type'' and reduces the usage to 0. this is the most significant reduction in database calls. &lt;br /&gt;
|-&lt;br /&gt;
| '''score_caches'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|22&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|1&lt;br /&gt;
| ScoreCache table has a field - ''revieweeId'' which can be either ''participantId'' or ''teamId''. All repetitive database calls was reduced to a single call by combining target participantId and teamId as a list of ''revieweeId''.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|11&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|2&lt;br /&gt;
| Teams table was repetitively called within a loop to retrieve participation in a set of assignments. It was pulled out of the loop and modified to get the same result for all the teams for a larger set of assignments.&lt;br /&gt;
|-&lt;br /&gt;
| '''teams_users'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| '''leaderboards'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|9&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| Leaderboards table was called multiple times to retrieve the Label for scores of corresponding questionnaire type.&amp;lt;br /&amp;gt;(e.g. ''&amp;quot;ReviewQuestionnaire&amp;quot; - &amp;quot;Submitted Work&amp;quot;''). It was reduced to fetch all such mapping and cached.&lt;br /&gt;
|-&lt;br /&gt;
| '''courses'''&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| style=&amp;quot;text-align: center;&amp;quot;|5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost 15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90883</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90883"/>
		<updated>2014-10-29T22:05:03Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Database Optimization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;TestingLinks&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza instance links&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:2%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#TestingLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
We computed the number of data base &amp;quot;SELECT&amp;quot; call generated the database driver by filtering the messages from the rails server. In the original code there were 625 data base select access generated for the leaderboard view. In the new code the number of select calls dropped to 111.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| roles&lt;br /&gt;
| 52&lt;br /&gt;
| 13&lt;br /&gt;
| Optimized the SQL query in leaderboard_helper.rb to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| users&lt;br /&gt;
| 25&lt;br /&gt;
| 25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| participants&lt;br /&gt;
| 111&lt;br /&gt;
| 3&lt;br /&gt;
| All the participants associated with computed assignment list are calculated in a single database call and cached in memory rather than calling repetitively within loop.&lt;br /&gt;
|-&lt;br /&gt;
| assignments&lt;br /&gt;
| 16&lt;br /&gt;
| 5&lt;br /&gt;
| Database calls to ''Assignments'' table was reduced as result of removing it from multiple loops. Supporting data structure and caching enabled to achieve this reduction.&lt;br /&gt;
|-&lt;br /&gt;
| assignment_questionnaires&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| Upon careful code investigation, we felt there is no need of any database calls to assignment_questionnaires table. This contains mapping of assignment id and questionnaire id.&lt;br /&gt;
|-&lt;br /&gt;
| questionnaires&lt;br /&gt;
| 311&lt;br /&gt;
| 0&lt;br /&gt;
| Leaderboard reads the scores from ''ScoreCache'' table, which has ''revieweeId'' and a response object_type (''ReviewResponseMap'', ''AuthorFeedbackResponseMap'', etc.). Refactored code reuses the association of ''response object_type'' to the ''questionnaire_type'' and reduces the usage to 0. this is the most significant reduction in database calls. &lt;br /&gt;
|-&lt;br /&gt;
| score_caches&lt;br /&gt;
| 22&lt;br /&gt;
| 1&lt;br /&gt;
| ScoreCache table has a field - ''revieweeId'' which can be either ''participantId'' or ''teamId''. All repetitive database calls was reduced to a single call by combining target participantId and teamId as a list of ''revieweeId''.&lt;br /&gt;
|-&lt;br /&gt;
| teams&lt;br /&gt;
| 11&lt;br /&gt;
| 2&lt;br /&gt;
| Teams table was repetitively called within a loop to retrieve participation in a set of assignments. It was pulled out of the loop and modified to get the same result for all the teams for a larger set of assignments.&lt;br /&gt;
|-&lt;br /&gt;
| teams_users&lt;br /&gt;
| 52&lt;br /&gt;
| 52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| leaderboards&lt;br /&gt;
| 9&lt;br /&gt;
| 5&lt;br /&gt;
| Leaderboards table was called multiple times to retrieve the Label for scores of corresponding questionnaire type. e.g. ''&amp;quot;ReviewQuestionnaire&amp;quot; - &amp;quot;Submitted Work&amp;quot;''. It was reduced to fetch all such mapping and cached.&lt;br /&gt;
|-&lt;br /&gt;
| courses&lt;br /&gt;
| 5&lt;br /&gt;
| 5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost 15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90862</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90862"/>
		<updated>2014-10-29T21:30:35Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Database Optimization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;TestingLinks&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza instance links&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#TestingLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
We computed the number of data base &amp;quot;SELECT&amp;quot; call generated the database driver by filtering the messages from the rails server. In the original code there were 625 data base select access generated for the leaderboard view. In the new code the number of select calls dropped to 111.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| roles&lt;br /&gt;
| 52&lt;br /&gt;
| 13&lt;br /&gt;
| Optimized the SQL query in leaderboard_helper.rb to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| users&lt;br /&gt;
| 25&lt;br /&gt;
| 25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| participants&lt;br /&gt;
| 111&lt;br /&gt;
| 3&lt;br /&gt;
| All the participants associated with computed Assignment list are calculated in a single database call and cached in memory rather than calling repetitively.&lt;br /&gt;
|-&lt;br /&gt;
| assignments&lt;br /&gt;
| 16&lt;br /&gt;
| 5&lt;br /&gt;
| Database calls to Assignments table was reduced as result of removing it from multiple loops. Supporting data structure and caching enabled to achieve this.&lt;br /&gt;
|-&lt;br /&gt;
| assignment_questionnaires&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| Upon careful code investigation, we felt there is no need of any database calls to assignment_questionnaires table. This contains mapping of assignment id and questionnaire id.&lt;br /&gt;
|-&lt;br /&gt;
| questionnaires&lt;br /&gt;
| 311&lt;br /&gt;
| 0&lt;br /&gt;
| Leaderboard reads the scores from ScoreCache, which has revieweeId and a response object_type (''ReviewResponseMap'', ''AuthorFeedbackResponseMap'', etc.). Refactored code reuses the association of response object_type to the questionnaire_type and reduces the usage to 0.&lt;br /&gt;
|-&lt;br /&gt;
| score_caches&lt;br /&gt;
| 22&lt;br /&gt;
| 1&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| teams&lt;br /&gt;
| 11&lt;br /&gt;
| 2&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| teams_users&lt;br /&gt;
| 52&lt;br /&gt;
| 52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| leaderboards&lt;br /&gt;
| 9&lt;br /&gt;
| 5&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| courses&lt;br /&gt;
| 5&lt;br /&gt;
| 5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost 15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90858</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90858"/>
		<updated>2014-10-29T21:22:42Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;TestingLinks&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza instance links&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | '''username= &amp;quot;user480&amp;quot;&amp;lt;br /&amp;gt;password= &amp;quot;password&amp;quot;'''&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#TestingLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
We computed the number of data base &amp;quot;SELECT&amp;quot; call generated the database driver by filtering the messages from the rails server. In the original code there were 625 data base select access generated for the leaderboard view. In the new code the number of select calls dropped to 111.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| roles&lt;br /&gt;
| 52&lt;br /&gt;
| 13&lt;br /&gt;
| Optimized the SQL query in leaderboard_helper.rb to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| users&lt;br /&gt;
| 25&lt;br /&gt;
| 25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| participants&lt;br /&gt;
| 111&lt;br /&gt;
| 3&lt;br /&gt;
| All the participants associated with computed Assignment list are calculated in a single database call and cached in memory rather than calling repetitively.&lt;br /&gt;
|-&lt;br /&gt;
| assignments&lt;br /&gt;
| 16&lt;br /&gt;
| 5&lt;br /&gt;
| Assignem&lt;br /&gt;
|-&lt;br /&gt;
| assignment_questionnaires&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| questionnaires&lt;br /&gt;
| 311&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| score_caches&lt;br /&gt;
| 22&lt;br /&gt;
| 1&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| teams&lt;br /&gt;
| 11&lt;br /&gt;
| 2&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| teams_users&lt;br /&gt;
| 52&lt;br /&gt;
| 52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| leaderboards&lt;br /&gt;
| 9&lt;br /&gt;
| 5&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| courses&lt;br /&gt;
| 5&lt;br /&gt;
| 5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost 15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90857</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90857"/>
		<updated>2014-10-29T21:20:12Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;TestingLinks&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza Links&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | username= &amp;quot;user480&amp;quot; password= &amp;quot;password&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;&lt;br /&gt;
[[#TestingLinks|'''Expertiza Test instances links''']]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
We computed the number of data base &amp;quot;SELECT&amp;quot; call generated the database driver by filtering the messages from the rails server. In the original code there were 625 data base select access generated for the leaderboard view. In the new code the number of select calls dropped to 111.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| roles&lt;br /&gt;
| 52&lt;br /&gt;
| 13&lt;br /&gt;
| Optimized the SQL query in leaderboard_helper.rb to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| users&lt;br /&gt;
| 25&lt;br /&gt;
| 25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| participants&lt;br /&gt;
| 111&lt;br /&gt;
| 3&lt;br /&gt;
| All the participants associated with computed Assignment list are calculated in a single database call and cached in memory rather than calling repetitively.&lt;br /&gt;
|-&lt;br /&gt;
| assignments&lt;br /&gt;
| 16&lt;br /&gt;
| 5&lt;br /&gt;
| Assignem&lt;br /&gt;
|-&lt;br /&gt;
| assignment_questionnaires&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| questionnaires&lt;br /&gt;
| 311&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| score_caches&lt;br /&gt;
| 22&lt;br /&gt;
| 1&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| teams&lt;br /&gt;
| 11&lt;br /&gt;
| 2&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| teams_users&lt;br /&gt;
| 52&lt;br /&gt;
| 52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| leaderboards&lt;br /&gt;
| 9&lt;br /&gt;
| 5&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| courses&lt;br /&gt;
| 5&lt;br /&gt;
| 5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost 15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90842</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90842"/>
		<updated>2014-10-29T21:11:39Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Database Optimization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;TestingLinks&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza Link&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | username= &amp;quot;user480&amp;quot; password= &amp;quot;password&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
[[#TestingLinks|Testing Links]]&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;'''e.g. Username/Password: user480/password'''&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
We computed the number of data base &amp;quot;SELECT&amp;quot; call generated the database driver by filtering the messages from the rails server. In the original code there were 625 data base select access generated for the leaderboard view. In the new code the number of select calls dropped to 111.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| roles&lt;br /&gt;
| 52&lt;br /&gt;
| 13&lt;br /&gt;
| Optimized the SQL query in leaderboard_helper.rb to replace multiple database calls.&lt;br /&gt;
|-&lt;br /&gt;
| users&lt;br /&gt;
| 25&lt;br /&gt;
| 25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| participants&lt;br /&gt;
| 111&lt;br /&gt;
| 3&lt;br /&gt;
| All the participants associated with computed Assignment list are calculated in a single database call and cached in memory rather than calling repetitively.&lt;br /&gt;
|-&lt;br /&gt;
| assignments&lt;br /&gt;
| 16&lt;br /&gt;
| 5&lt;br /&gt;
| Assignem&lt;br /&gt;
|-&lt;br /&gt;
| assignment_questionnaires&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| questionnaires&lt;br /&gt;
| 311&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| score_caches&lt;br /&gt;
| 22&lt;br /&gt;
| 1&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| teams&lt;br /&gt;
| 11&lt;br /&gt;
| 2&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| teams_users&lt;br /&gt;
| 52&lt;br /&gt;
| 52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| leaderboards&lt;br /&gt;
| 9&lt;br /&gt;
| 5&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| courses&lt;br /&gt;
| 5&lt;br /&gt;
| 5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost 15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90839</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90839"/>
		<updated>2014-10-29T21:06:13Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;TestingLinks&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza Link&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | username= &amp;quot;user480&amp;quot; password= &amp;quot;password&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note for testing :''' It is recommended that in order to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there are other existing users who have participated in the same assignment.&amp;lt;br /&amp;gt;'''e.g. Username/Password: user480/password'''&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
We computed the number of data base &amp;quot;SELECT&amp;quot; call generated the database driver by filtering the messages from the rails server. In the original code there were 625 data base select access generated for the leaderboard view. In the new code the number of select calls dropped to 111.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| roles&lt;br /&gt;
| 52&lt;br /&gt;
| 13&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| users&lt;br /&gt;
| 25&lt;br /&gt;
| 25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| participants&lt;br /&gt;
| 111&lt;br /&gt;
| 3&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignments&lt;br /&gt;
| 16&lt;br /&gt;
| 5&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignment_questionnaires&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| questionnaires&lt;br /&gt;
| 311&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| score_caches&lt;br /&gt;
| 22&lt;br /&gt;
| 1&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| teams&lt;br /&gt;
| 11&lt;br /&gt;
| 2&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| teams_users&lt;br /&gt;
| 52&lt;br /&gt;
| 52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| leaderboards&lt;br /&gt;
| 9&lt;br /&gt;
| 5&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| courses&lt;br /&gt;
| 5&lt;br /&gt;
| 5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost 15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90836</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90836"/>
		<updated>2014-10-29T21:03:27Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Future Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza Link&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | username= &amp;quot;user480&amp;quot; password= &amp;quot;password&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
We computed the number of data base &amp;quot;SELECT&amp;quot; call generated the database driver by filtering the messages from the rails server. In the original code there were 625 data base select access generated for the leaderboard view. In the new code the number of select calls dropped to 111.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| roles&lt;br /&gt;
| 52&lt;br /&gt;
| 13&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| users&lt;br /&gt;
| 25&lt;br /&gt;
| 25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| participants&lt;br /&gt;
| 111&lt;br /&gt;
| 3&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignments&lt;br /&gt;
| 16&lt;br /&gt;
| 5&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignment_questionnaires&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| questionnaires&lt;br /&gt;
| 311&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| score_caches&lt;br /&gt;
| 22&lt;br /&gt;
| 1&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| teams&lt;br /&gt;
| 11&lt;br /&gt;
| 2&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| teams_users&lt;br /&gt;
| 52&lt;br /&gt;
| 52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| leaderboards&lt;br /&gt;
| 9&lt;br /&gt;
| 5&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| courses&lt;br /&gt;
| 5&lt;br /&gt;
| 5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost 15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
Based on use case and requirement, we can implement a metric to calculate final scores based on weights of an assignment or a questionnaire type. However, it solely depends on the the requirement whether such logic should be implemented in the Leaderboard model or the Score computation model. The team recommends that such manipulation and calculation of scores should not be part of Leaderboard model. Leaderboard model should focus on determining the eligible participants and compute the final leaderboard list.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90819</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90819"/>
		<updated>2014-10-29T20:53:05Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Code Optimization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza Link&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | username= &amp;quot;user480&amp;quot;, password= &amp;quot;password&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
We computed the number of data base &amp;quot;SELECT&amp;quot; call generated the database driver by filtering the messages from the rails server. In the original code there were 625 data base select access generated for the leaderboard view. In the new code the number of select calls dropped to 111.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| roles&lt;br /&gt;
| 52&lt;br /&gt;
| 13&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| users&lt;br /&gt;
| 25&lt;br /&gt;
| 25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| participants&lt;br /&gt;
| 111&lt;br /&gt;
| 3&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignments&lt;br /&gt;
| 16&lt;br /&gt;
| 5&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignment_questionnaires&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| questionnaires&lt;br /&gt;
| 311&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| score_caches&lt;br /&gt;
| 22&lt;br /&gt;
| 1&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| teams&lt;br /&gt;
| 11&lt;br /&gt;
| 2&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| teams_users&lt;br /&gt;
| 52&lt;br /&gt;
| 52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| leaderboards&lt;br /&gt;
| 9&lt;br /&gt;
| 5&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| courses&lt;br /&gt;
| 5&lt;br /&gt;
| 5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost 15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
There was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90818</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90818"/>
		<updated>2014-10-29T20:52:46Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Code Optimization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza Link&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | username= &amp;quot;user480&amp;quot;, password= &amp;quot;password&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|left|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
We computed the number of data base &amp;quot;SELECT&amp;quot; call generated the database driver by filtering the messages from the rails server. In the original code there were 625 data base select access generated for the leaderboard view. In the new code the number of select calls dropped to 111.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| roles&lt;br /&gt;
| 52&lt;br /&gt;
| 13&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| users&lt;br /&gt;
| 25&lt;br /&gt;
| 25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| participants&lt;br /&gt;
| 111&lt;br /&gt;
| 3&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignments&lt;br /&gt;
| 16&lt;br /&gt;
| 5&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignment_questionnaires&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| questionnaires&lt;br /&gt;
| 311&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| score_caches&lt;br /&gt;
| 22&lt;br /&gt;
| 1&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| teams&lt;br /&gt;
| 11&lt;br /&gt;
| 2&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| teams_users&lt;br /&gt;
| 52&lt;br /&gt;
| 52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| leaderboards&lt;br /&gt;
| 9&lt;br /&gt;
| 5&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| courses&lt;br /&gt;
| 5&lt;br /&gt;
| 5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost 15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
There was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90817</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90817"/>
		<updated>2014-10-29T20:52:26Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Code Optimization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza Link&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | username= &amp;quot;user480&amp;quot;, password= &amp;quot;password&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
We computed the number of data base &amp;quot;SELECT&amp;quot; call generated the database driver by filtering the messages from the rails server. In the original code there were 625 data base select access generated for the leaderboard view. In the new code the number of select calls dropped to 111.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| roles&lt;br /&gt;
| 52&lt;br /&gt;
| 13&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| users&lt;br /&gt;
| 25&lt;br /&gt;
| 25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| participants&lt;br /&gt;
| 111&lt;br /&gt;
| 3&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignments&lt;br /&gt;
| 16&lt;br /&gt;
| 5&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignment_questionnaires&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| questionnaires&lt;br /&gt;
| 311&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| score_caches&lt;br /&gt;
| 22&lt;br /&gt;
| 1&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| teams&lt;br /&gt;
| 11&lt;br /&gt;
| 2&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| teams_users&lt;br /&gt;
| 52&lt;br /&gt;
| 52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| leaderboards&lt;br /&gt;
| 9&lt;br /&gt;
| 5&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| courses&lt;br /&gt;
| 5&lt;br /&gt;
| 5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost 15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
There was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90815</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90815"/>
		<updated>2014-10-29T20:51:55Z</updated>

		<summary type="html">&lt;p&gt;Rroshan: /* Code Optimization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza Link&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | username= &amp;quot;user480&amp;quot;, password= &amp;quot;password&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%. Following is the overall improvement report by Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center]]&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
We computed the number of data base &amp;quot;SELECT&amp;quot; call generated the database driver by filtering the messages from the rails server. In the original code there were 625 data base select access generated for the leaderboard view. In the new code the number of select calls dropped to 111.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| roles&lt;br /&gt;
| 52&lt;br /&gt;
| 13&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| users&lt;br /&gt;
| 25&lt;br /&gt;
| 25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| participants&lt;br /&gt;
| 111&lt;br /&gt;
| 3&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignments&lt;br /&gt;
| 16&lt;br /&gt;
| 5&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignment_questionnaires&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| questionnaires&lt;br /&gt;
| 311&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| score_caches&lt;br /&gt;
| 22&lt;br /&gt;
| 1&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| teams&lt;br /&gt;
| 11&lt;br /&gt;
| 2&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| teams_users&lt;br /&gt;
| 52&lt;br /&gt;
| 52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| leaderboards&lt;br /&gt;
| 9&lt;br /&gt;
| 5&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| courses&lt;br /&gt;
| 5&lt;br /&gt;
| 5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost 15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
There was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rroshan</name></author>
	</entry>
</feed>