CSC/ECE 517 Fall 2013/oss E818 mra: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
(Created page with "<mainpage-leftcolumn-start /> =E818 Refactoring and testing -- analytics= ==Problem statement:== ===Classes:=== * analytic_controller.rb (163 lines) * assignment_analytic.rb (20...")
 
No edit summary
Line 1: Line 1:
<mainpage-leftcolumn-start />
=E818 Refactoring and testing -- analytics=
=E818 Refactoring and testing -- analytics=


Line 18: Line 17:
===What needs to be done:===
===What needs to be done:===
At least analytic_controller.rb and course_analytic.rb have much duplicated code, which should be factored out. Additionally, analytic_controller.rb has methods that are too complicated, and should be separated into shorter, well-named methods, to make the operation of the class more transparent. Also, there are absolutely no tests for any of these methods.
At least analytic_controller.rb and course_analytic.rb have much duplicated code, which should be factored out. Additionally, analytic_controller.rb has methods that are too complicated, and should be separated into shorter, well-named methods, to make the operation of the class more transparent. Also, there are absolutely no tests for any of these methods.
==Code changes==
# At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:
##self.questionnaire_unique? in assignment_analytic.rb
##questionnaire_of_type(type_name_in_string) in assignment_analytic.rb
#The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.
#The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.
Following was one of the pattern that existed:
<pre>
# Expertiza code before refactoring in assignment_analytic.rb
def team_review_counts   
  list = Array.new   
  self.teams.each do |team|     
        list << team.num_reviews   
  end     
  if (list.empty?)     
          [0]   
  else     
          list
  end
end
</pre>
The refactored code for the above logic:
<pre>
# Helper function moved to common_analytic.rb
def extract_from_list(list, property)
      list.map { |item| item.send(property) }
end
# Method in assignment_analytic.rb
def team_review_counts   
      extract_from_list self.teams, :num_reviews
      (list.empty?) ? [0] : list   
end
</pre>
The following is a list of methods and classes changed for refactoring:
#assignment_analytic.rb
##self.questionnaire_unique?
##questionnaire_of_type
##team_review_counts
##team_scores
#course_analytic.rb
##average_num_assignment_teams
##average_assignment_score
##assignment_review_counts
##assignment_team_counts
##assignment_average_scores
##assignment_max_scores
##assignment_min_scores
#assignment_team_analytic.rb
##average_review_word_count
##average_review_score
##average_review_character_count
##review_character_counts
##review_scores
##review_word_counts
#questionnaire_analytic.rb
##questions_text_list
##word_count_list
##character_count_list
#response_analytic.rb
##word_count_list
##character_count_list
##question_score_list
##comments_text_list

Revision as of 01:18, 30 October 2013

E818 Refactoring and testing -- analytics

Problem statement:

Classes:

  • analytic_controller.rb (163 lines)
  • assignment_analytic.rb (206 lines)
  • assignment_team_analytic.rb (126 lines)
  • course_analytic.rb (142 lines)
  • question_analytic.rb (12 lines)
  • questionnaire_analytic.rb (55 lines)
  • response_analytic.rb (101 lines)
  • score_analytic.rb (12 lines)

What they do:

Display information about various system components in summary form, to aid in analysis.

What needs to be done:

At least analytic_controller.rb and course_analytic.rb have much duplicated code, which should be factored out. Additionally, analytic_controller.rb has methods that are too complicated, and should be separated into shorter, well-named methods, to make the operation of the class more transparent. Also, there are absolutely no tests for any of these methods.

Code changes

  1. At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:
    1. self.questionnaire_unique? in assignment_analytic.rb
    2. questionnaire_of_type(type_name_in_string) in assignment_analytic.rb
  2. The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.
  3. The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.

Following was one of the pattern that existed:

# Expertiza code before refactoring in assignment_analytic.rb
def team_review_counts     
  list = Array.new     
  self.teams.each do |team|       
         list << team.num_reviews     
  end      
  if (list.empty?)       
          [0]     
  else      
          list
  end
end


The refactored code for the above logic:

 
# Helper function moved to common_analytic.rb
def extract_from_list(list, property)
      list.map { |item| item.send(property) }
end
 
# Method in assignment_analytic.rb
def team_review_counts     
      extract_from_list self.teams, :num_reviews
      (list.empty?) ? [0] : list    
end

The following is a list of methods and classes changed for refactoring:

  1. assignment_analytic.rb
    1. self.questionnaire_unique?
    2. questionnaire_of_type
    3. team_review_counts
    4. team_scores
  2. course_analytic.rb
    1. average_num_assignment_teams
    2. average_assignment_score
    3. assignment_review_counts
    4. assignment_team_counts
    5. assignment_average_scores
    6. assignment_max_scores
    7. assignment_min_scores
  3. assignment_team_analytic.rb
    1. average_review_word_count
    2. average_review_score
    3. average_review_character_count
    4. review_character_counts
    5. review_scores
    6. review_word_counts
  4. questionnaire_analytic.rb
    1. questions_text_list
    2. word_count_list
    3. character_count_list
  5. response_analytic.rb
    1. word_count_list
    2. character_count_list
    3. question_score_list
    4. comments_text_list