CSC/ECE 517 Spring 2015/oss E1503 RSA: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 129: Line 129:
= Re-factored Code Cases =
= Re-factored Code Cases =


== Case 1 : Refactoring add_this_bookmark and add_topic_bookmark ==
== Case 1 : Refactoring ... ==  


The consistency of these two methods shows plenty of repetitive code. In order to effectively refactor these methods and reuse the code they both need, our team merged the two methods together by enabling add_this_bookmark method to handle creation of a bookmark when a topic id is provided (main functionality of add_topic_bookmark method). Once we implemented this change on add_this_bookmark method, we deleted add_topic_bookmark method as it became obsolete. Therefore, we retained the same functionality while reducing the method by 7 repetitive lines of code.
===Functions added===
 
===Before Changes===


<pre>
<pre>
   def self.add_topic_bookmark(b_url, b_title, b_tags_text, b_description,session_user, topicid)
  # This method returns the unique participants for assignment list.
     # Check if the bookmark exists and add / edit based on that
   def self.getAssignmentUniqueParticipantList(assignmentList)
    bookmark_exists = check_bookmark_exists(b_url)
     AssignmentParticipant.where(:parent_id => assignmentList.pluck(:id)).uniq
    bmapping_exists = check_bmapping_exists(b_url,session_user)
    if (!bookmark_exists || !bmapping_exists)
      Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topicid)
    elsif (bmapping_exists)
      Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)
    end
   end
   end


   def self.add_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)
  # This method returns the unique participant teams for assignment list.
     bookmark_exists = check_bookmark_exists(b_url)
   def self.getAssignmentUniqueParticipantTeamList(assignmentList)
    bmapping_exists = check_bmapping_exists(b_url,session_user)
     Team.where("parent_id IN (?) AND type = ?", assignmentList.pluck(:id), 'AssignmentTeam').uniq
    if (!bookmark_exists || !bmapping_exists)
      Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user)
    elsif (bmapping_exists)
      Bookmark.edit_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user)
    end
   end
   end
</pre>
</pre>


===After Changes===
===Before Refactoring===
<pre>
<pre>
  def self.add_this_bookmark(b_url, b_title, b_tags_text, b_description,session_user, topic_id)
assignmentMap = getAssignmentMapping(assignmentList, participantList, teamList)
    bookmark_exists = check_bookmark_exists(b_url)
</pre>
    bmapping_exists = check_bmapping_exists(b_url,session_user)
 
    if (!bookmark_exists || !bmapping_exists)
===After Refactoring===
      if(topic_id) # something has been passed for topic_id
<pre>
        Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user,topic_id)
assignmentMap = getAssignmentMapping(assignmentList, getAssignmentUniqueParticipantList(assignmentList), getAssignmentUniqueParticipantTeamList(assignmentList))
      else
        Bookmark.add_bookmark(b_url, b_title, b_tags_text, b_description,session_user, nil)
      end
    elsif (bmapping_exists)
      Bookmark.edit(b_url, b_title, b_tags_text, b_description,session_user)
    end
  end
</pre>
</pre>



Revision as of 21:12, 22 March 2015

E1503. Refactor Leaderboard model, Leaderboard_helper and LeaderboardController classes

This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the Leaderboard model, LeaderboardController, and Leaderboard_helper classes as per standard coding methodology for Ruby on Rails.

Introduction to Expertiza

Expertiza is a peer review based system used to provide improved learning experience. Project is developed as a combined effort of students and faculty using the Ruby on Rails framework. Expertiza allows the instructor to create and customize assignments, create a list of topics the students can sign up for, have students work on teams and then review each other's assignments at the end. Expertiza supports submission of almost any document type, including the URLs and wiki pages.

Leaderboard is a module that can be used to find top three leaders in any class based on the score they have received on their submissions and reviews.


Project Description

Classes involved:

leaderboard.rb
leaderboard_controller.rb

Modules involved:

leaderboard_helper.rb

What they do:

This class is responsible for calculating top 3 individuals which is to be displayed as the leaderboard for the class and generates a metric which aggregates peer review scores for all course assignments and then sorts individuals.

What needs to be done:

Methods like getParticipantsScore and extractPersonalAchievements needs to be refactored as these single functions have multiple responsibilities. They can be modularized delegating single resposibility to one function. sortHash method is not an explicit leaderboard model and can be moved to helper functions. Some snippets of code are redundant and have no effect on functionality. They can be removed.

Changes Made

Leaderboard Model

Method Name Changes Made Reason For Change
model/Leaderboard#getParticipantsScore Refactored original method functionality into
getAssignmentUniqueParticipantList,
getAssignmentUniqueParticipantTeamList,
getAggregatedAssignmentRevieweeList,
getRevieweeListScore, and
getUserScoreHashForCourse methods
Many different features were originally written in one method. We refactored this method into many methods to achieve singularity.
model/Leaderboard#sortHash
helpers/leaderboard_helper#sortHash
Migrated method from Leaderboard model to leaderboard_helper class. sortHash is a helper method and is not explicit part of model class, hence it was moved to achieve code reusability and remove redundancy.
model/Leaderboard scoreEntryScore parameter Parameter name is changed to entryScore The name was confusing. It was used to represent each entry's score, hence we changed the name to maintain readability of code.
model/Leaderboard#extractPersonalAchievements Removed unwanted code snippets Redundant code snippet was found which has no affect on program.
model/Leaderboard#extractPersonalAchievements Refactored method functionality and created private method, getCourseAccomplishmentHash More than one feature was implemented into one method. we split the functionality and remove code redundancy.

Bookmark Controller

Method Name Changes Made Reason For Change
create ---------------- -----------
update ----------------- --------
edit -------------- ---------

destroy

----------------- ---------
--------------- ----------
---------- ----------

Views

Method Name Changes Made Reason For Change
bookmarks/_result.html.erb ---------------- -----------
bookmarks/search_bookmarks.html.erb ----------------- --------
bookmarks/view_bookmarks.html.erb -------------- ---------
bookmarks/_searchmine.html.erb ----------------- ---------
bookmarks/add_bookmark_form.html.erb ----------------- ---------
bookmarks/edit_bookmark_form.html.erb ----------------- ---------
bookmarks/managing_bookmarks.html.erb ----------------- ---------
layouts/application.html.erb ----------------- ---------

Re-factored Code Cases

Case 1 : Refactoring ...

Functions added

  # This method returns the unique participants for assignment list.
  def self.getAssignmentUniqueParticipantList(assignmentList)
    AssignmentParticipant.where(:parent_id => assignmentList.pluck(:id)).uniq
  end

  # This method returns the unique participant teams for assignment list.
  def self.getAssignmentUniqueParticipantTeamList(assignmentList)
    Team.where("parent_id IN (?) AND type = ?", assignmentList.pluck(:id), 'AssignmentTeam').uniq
  end

Before Refactoring

assignmentMap = getAssignmentMapping(assignmentList, participantList, teamList)

After Refactoring

assignmentMap = getAssignmentMapping(assignmentList, getAssignmentUniqueParticipantList(assignmentList), getAssignmentUniqueParticipantTeamList(assignmentList))

Case 2 :

Steps to verify changes manually

User2 Role

Automated Tests

Unit test

Integration (Cucumber) tests

See Also

References