CSC/ECE 517 Fall 2014/OSS E1467 rsv: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 62: Line 62:


==Changes==
==Changes==
1. Leaderboard.rb
{| class="wikitable"
○ Methods like getIndependantAssignments and getParticipantEntriesInCourses are
|-
refactored to reduce the database calls within loop. Database calls have huge impact on
! style="width:5%;"|Sr. No.
overall complexity of the code and performance of the software.
! style="width:13%;"|Method Name
sortHash : This method modified the input hash. We refactored it to not alter the input
! style="width:33%;"|Changes Made
hash object, but rather return a new deep copy of the updated hash object.
! style="width:43%;"|Reason For Change
extractPersonalAchievements : This method is refactored to use only 1 database call
|- style="vertical-align:top;"
|''''' 1 '''''
| getIndependantAssignments
| Reduced the number of database calls within loop.
| Less complexity and runs faster.
|-
|''''' 2 '''''
| getParticipantEntriesInCourses
| Reduced the number of database calls within loop.
| Less complexity and runs faster.
|-
|''''' 3 '''''
| sortHash
| in place changes.
| Returns a new deep copy of the updated hash.
|-
|''''' 4 '''''
| extractPersonalAchievements
| Confusing code with extra data base calls.
| This method is refactored to use only 1 database call
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this
method is reduced from 72 to 35 *.
method is reduced from 72 to 35 *.
addEntryToCSHash : This method is refactored to reduce the redundant code. The new
|-
method name is addScoreToResultantHash. As mentioned earlier, this is called internally
|''''' 5 '''''
| addEntryToCSHash
| Confusing code with extra data base calls.
| The new method name is addScoreToResultantHash. As mentioned earlier, this is called internally
by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from
by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from
67 to 39 *.
67 to 39 *.
 
|-
getParticipantEntriesInAssignmentList : This method was the most complex method in
|''''' 6 '''''
the class. The new refactored method name is getParticipantsScore. The method was
| getParticipantEntriesInAssignmentList
| This method was the most complex method in the class.  
| The new refactored method name is getParticipantsScore. The method was
refactored on various aspects like reducing database calls drastically, removing redundant
refactored on various aspects like reducing database calls drastically, removing redundant
code computation, redundant data storage in complex group of hashes and series of
code computation, redundant data storage in complex group of hashes and series of
Line 84: Line 108:
database call within loop and 3 outside loops. Also, the overall code complexity is reduced
database call within loop and 3 outside loops. Also, the overall code complexity is reduced
from 142 to 64 *.
from 142 to 64 *.
|-
|}
○ There was a requirement in the project, that we should come up with an efficient way to
○ 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
search for participants based on assignment ids. However, upon investigation, we found
Line 90: Line 119:
participant and team with corresponding assignment. This is very useful while computing
participant and team with corresponding assignment. This is very useful while computing
leaderboard.
leaderboard.
2. Leaderboard_helper.rb
2. Leaderboard_helper.rb
○ userIsInstructor : This method was refactored to reduce multiple database calls. 4
○ userIsInstructor : This method was refactored to reduce multiple database calls. 4
Line 98: Line 128:
○ getTop3Leaderboards : This method is a dead code, not called from anywhere, therefore,
○ getTop3Leaderboards : This method is a dead code, not called from anywhere, therefore,
we have commented this for the moment.
we have commented this for the moment.
There are several other changes in the views and controller which deal with renaming of the methods
There are several other changes in the views and controller which deal with renaming of the methods
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked
github repository to view those changes.
github repository to view those changes.
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who
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
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. e.g. user480/password
are other existing users who have participated in the same assignment. e.g. user480/password
* Code complexity measurement is according to Code Climate


==Testing==
==Testing==

Revision as of 17:18, 29 October 2014

Writeup Page

Expertiza - Refactoring LeaderBoard model

Our project is to refactor the code in the "Leaderboard" functionality of the web application Expertiza<ref name="expertiza>Expertiza http://wikis.lib.ncsu.edu/index.php/Expertiza</ref>. The Expertiza project is a system to create reusable learning objects through peer review. The classes involved gets all the assignments in the course and all the participants in a course or in an assignment. The responsibility of the leaderboard module is to generate the top 3 individuals which is to be displayed as the leaderboard for the class and a personal leaderboard view to see a personal aggregated score.



Project Description

Classes involved: leaderboard.rb and associated other model and controllers classes.

1. Come up with an efficient way to search for participants based on assignment ids.

2. Refactor score hash for personal achievements. (Method: extractPersonalAchievements). Seperate out method which will rank individual personal achievements.

3. Refactor addEntryToCSHash according to your new metric method.

4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant.

5. Refactor getParticipantEntriesInAssignmentList method. Its very complex (Complexity=142).

6. Refactor addEntryToCSHash according to your new metric method.

Existing Functionality

Leaderboard 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.

Leaderboard model has following 3 important methods:

Sr. No. Method Name Comment
1 getParticipantEntriesInAssignmentList(assignmentList) This method is responsible for calculating the leaderboard of all the participants associated

with assignments in given assignment list.

2 extractPersonalAchievements(csHash, courseIdList, userId) 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.

3 addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) This method is called internally from Leaderboard.getParticipantEntriesInAssignmentList. This method aggregates score of a user grouped by course id, further grouped by

questionnaire type.

In the OSS project, we have refactored these methods along with other smaller methods in Leaderboard.rb, Leaderboard_helper.rb. We have also refactored ambiguous variable and method names.

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 enhancement of overall complexity of the feature.

Changes

Sr. No. Method Name Changes Made Reason For Change
1 getIndependantAssignments Reduced the number of database calls within loop. Less complexity and runs faster.
2 getParticipantEntriesInCourses Reduced the number of database calls within loop. Less complexity and runs faster.
3 sortHash in place changes. Returns a new deep copy of the updated hash.
4 extractPersonalAchievements Confusing code with extra data base calls. This method is refactored to use only 1 database call

unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35 *.

5 addEntryToCSHash Confusing code with extra data base calls. The new method name is addScoreToResultantHash. As mentioned earlier, this is called internally

by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from 67 to 39 *.

6 getParticipantEntriesInAssignmentList This method was the most complex method in the class. The new refactored method name is getParticipantsScore. 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 *.


○ 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 getAssignmentMapping, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.

2. Leaderboard_helper.rb ○ userIsInstructor : This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call. ○ studentInWhichCourses : 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. ○ getTop3Leaderboards : This method is a dead code, not called from anywhere, therefore, we have commented this for the moment.

There are several other changes in the views and controller which deal with renaming of the methods and variables, adding proper comments etc and minor code refactoring. Please refer to our forked github repository to view those changes.

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 are other existing users who have participated in the same assignment. e.g. user480/password

Testing

Build Status Page in CruiseControl <ref name="cc"></ref>. View of Refactored Leaderboard

Optimization