CSC/ECE 517 Spring 2024 - E2406 Refactor review mapping helper.rb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
 
(23 intermediate revisions by 2 users not shown)
Line 9: Line 9:


=== Relevant Links ===
=== Relevant Links ===
* == Link to Expertiza Repository: == https://github.com/expertiza/expertiza <br>
* '''Link to Expertiza Repository:''' https://github.com/expertiza/expertiza <br>
* == Link to Forked Repository: == https://github.com/kanishkharde/expertiza <br>
 
* == Link to Pull Request: == https://github.com/expertiza/expertiza/pull/?<br>
* '''Link to Forked Repository: ''' https://github.com/kanishkharde/expertiza <br>
 
* ''' Link to Pull Request: '''https://github.com/expertiza/expertiza/pull/2802<br>


== Expertiza Background==
== Expertiza Background==
Line 86: Line 88:
* Review methods related to feedback_response_maps and add comments or refactor small classes to enhance clarity and documentation.<br/>
* Review methods related to feedback_response_maps and add comments or refactor small classes to enhance clarity and documentation.<br/>
* Ensure consistent naming conventions and adherence to coding standards throughout the codebase.<br/><br/>
* Ensure consistent naming conventions and adherence to coding standards throughout the codebase.<br/><br/>
* We're going to make confusing variables easier to understand by rearranging them.<br/>
* Even though we tried hard in project 3, we couldn't cover all the code. In project 4, we're going to write more tests and use the test skeleton better.


'''This section contains changes and contributions to Project 4'''
'''This section contains changes and contributions to Project 4'''
----
----


* '''Issue #6:''' make a separate file for for chart related elements in <code>review_mapping_helper.rb</code><br>
'''Issue #4:''' Method <code>get_awarded_review_score</code> needs to be refactored
'''Methods involved:''' <code>initialize_chart_elements()</code>, <code>display_volume_metric_chart()</code>, <code>display_tagging_interval_chart()</code>, <code>calculate_key_chart_information()</code><br><br>
*'''Methods involved:''' <code>get_awarded_review_score</code><br>
'''Previous Code:''' All these methods were previously a part of the <code>review_mapping_helper.rb</code> when it should have its separate helper file<br>
*'''Solution:'''After addressing Issue 2, the method was renamed to <code>determine_awarded_review_score</code> to align with Ruby conventions. Additionally, redundant instance variable settings were moved inside the loop to streamline the code. The explicit nil or -1.0 checks were eliminated and integrated into the <code>instance_variable_set</code> line. <br>
'''Problem:''' These methods perform similar tasks of generating graphs and can have there separate module or a mixin and also each of the methods more than 30 lines inside them making them too large<br>
*'''Changes'''
'''Solution:''' distributed this code among 2 newly created files named <code>review_mapping_charts_helper.rb</code> and <code>data_mapping_helper.rb</code> within helper folder. This way the chart helper methods are separated from review_mapping_helper where they are out of place and difficult for any developer to find. <code>review_mapping_charts_helper.rb</code> contains the original methods and <code>data_mapping_helper.rb</code> manages the data need by these chart methods<br>
[[File:Issue4.jpg]]
<br><br>


'''review_mapping_charts_helper.rb'''
<pre>
module  ReviewMappingChartsHelper
...
    def initialize_chart_elements()
    def display_volume_metric_chart()
    def display_tagging_interval_chart()
    def calculate_key_chart_information()
</pre>
<br>
'''all link related to these changes:'''<br>
[https://github.com/expertiza/expertiza/pull/2663/files#diff-e2d994d01ebf485444d434603035df8e07eb9db7e625cfc42e7ad83f5b5c333e review_mapping_charts_helper.rb] <br>[https://github.com/expertiza/expertiza/pull/2663/files#diff-c41058c9caa3baa134bad689e28b7903d372d6a64388daccbb2e0ced964da568 review_mapping_helper.rb] <br>
[https://github.com/expertiza/expertiza/pull/2663/files#diff-ab7a32a37c43b8681f146d9e7e420aee006c8a435e11c45944ac8a13f941c969 data_mapping_helper.rb]<br>
<br><br>
----
----


----
'''Issue #5:''' The method <code>sort_reviewer_by_review_volume_desc</code> should be generalized so that it can sort by any metric, not just review volume. Other metrics might include number of suggestions, or number of suggestions + number of problems detected. This method should not be counting the number of review rounds! Since other places in the code will need to know the number of review rounds, it should be calculated somewhere else in the system.<br/>
*'''Issue #7:''' Several methods for feedback_response_maps, check docs to manage this confusion<br/>
*'''Methods involved:''' <code>sort_reviewer_by_review_volume_desc</code><br/>
'''Methods involved:''' <code> feedback_response_for_author()</code><br/>
*'''Problem:''' The current function, sort_reviewer_by_review_volume_desc, arranges reviewers in descending order based solely on review volume. This limited approach means it can't be applied to sorting by other metrics.<br/>
'''Previous Code:''' previous code had an ambiguous variable name<br/>
*'''Solution:'''The idea is to create a more versatile approach by changing the name of <code>sort_reviewer_by_review_volume_desc</code> to <code>sort_reviewer_desc</code> and allowing a metric argument for sorting reviewers, as demonstrated below. This modification was also applied to the <code>review_report</code> section where it was originally used.<br>
'''Problem:''' It wasn't clear what the variable was used for. <br/>
*'''Changes'''
'''Solution:''' refactor the variable name to be more easily understood and add comments to give a clear explanation for why it exists<br/>
[[File:5_1.jpg]]
<br><br>
[[File:Issue_Metrics5.jpg]]
<br><br>
<br><br>
----
----


*'''Issue #5:''' The method <code>sort_reviewer_by_review_volume_desc</code> should be generalized so that it can sort by any metric, not just review volume. Other metrics might include number of suggestions, or number of suggestions + number of problems detected. This method should not be counting the number of review rounds! Since other places in the code will need to know the number of review rounds, it should be calculated somewhere else in the system.<br/>
'''Issue #6:''' make a separate file for for chart related elements in <code>review_mapping_helper.rb</code><br>
'''Methods involved:''' <code>sort_reviewer_by_review_volume_desc</code><br/>
*'''Methods involved:''' <code>display_volume_metric_chart()</code>, <code>display_tagging_interval_chart()</code><br>
'''Problem:''' Currently the method sort_reviewer_by_review_volume_desc sorts the reviewers in descending order but only considers one metric which is review volume which makes it very specific and it cannot be used if we want to sort by other metrics<br/>
*'''Previous Code:''' The methods mentioned used to be included in the review_mapping_helper.rb file, but they should have been in their own helper file.<br>
'''Solution:'''The solution here is make this a generalized method by renaming <code>sort_reviewer_by_review_volume_desc</code> to <code>sort_reviewer_desc</code> and accepting a metric as argument on which we can sort the the reviewers as shown below. Since it was used in <code>review_report</code> partial the implementation was changed there as well<br><br>
*'''Problem:''' These techniques carry out comparable functions in creating graphs and can be implemented as either distinct modules or mixins. Additionally, each method contains more than 30 lines, making them excessively lengthy.<br>
'''review_mapping_helper.rb'''<br><br>
*'''Solution:''' Created new module named 'Charts' withinthe same file. This way the chart helper methods are separated from review_mapping_helper where they are out of place and difficult for any developer to find. <br>
[[File: E2353-Issue-4-1.png|900px]] <br>
*'''Changes'''
'''app/views/reports/_review_report.html.erb'''<br><br>
[[File:Issue6.jpg]]<br><br>
[[File:E2353issue-4-2.png|900px]] <br><br>
[[File:Issue6.2.jpg]]
'''review_mapping_helper_spec.rb'''<br><br>
[[File:E2353-issue4-3.png|900px]] <br><br>
'''All link related to these changes:'''<br><br>
[https://github.com/expertiza/expertiza/pull/2663/files#diff-c41058c9caa3baa134bad689e28b7903d372d6a64388daccbb2e0ced964da568 review_mapping_helper.rb] <br>
[https://github.com/expertiza/expertiza/pull/2663/files#diff-10395a909ed1f2034b4a4c8f57c0e30382d9492e0b16bb6fe6fb91a424f6f034 _review_report.html.erb] <br>
[https://github.com/expertiza/expertiza/pull/2663/files#diff-1f05f505eaa5edaf0790cdeb6e774cc499685cce4edf12b253ecd358ce710582 review_mapping_helper_spec.rb]<br><br>
<br><br>
<br><br>
----
----


*'''Issue #9:''' Method <code>get_awarded_review_score</code> needs to be refactored
'''Issue #7:''' Several methods for feedback_response_maps, check docs to manage this confusion<br/>
'''Methods involved:''' <code>get_awarded_review_score</code><br>
*'''Methods involved:''' <code> feedback_response_for_author()</code><br/>
'''Solution:''' Post tackling of Issue 2, the name of the method was changed to <code>compute_awarded_review_score</code> to make it more ruby like. Further on, the code which involved redundant setting of instance variables was placed inside the loop to make it more concise. The explicit check for nil or -1.0 was removed and added to the <code>instance_variable_set</code> line.
*'''Previous Code:''' previous code had an ambiguous variable name<br/>
 
*'''Problem:''' The purpose of the variable was unclear.<br/>
Before
*'''Solution:''' Rename the variable to enhance its clarity and provide comments to explain its purpose clearly.<br/>
<pre>
*'''Changes'''
def compute_awarded_review_score(reviewer_id, team_id)
[[File:Issue7.jpg]]
    # Storing redundantly computed value in num_rounds variable
<br><br>
    num_rounds = @assignment.num_review_rounds
    # Setting values of instance variables
    (1..num_rounds).each { |round| instance_variable_set('@score_awarded_round_' + round.to_s, '-----') }
    # Iterating through list
    (1..num_rounds).each do |round|
      # Changing values of instance variable based on below condition
      if @review_scores[reviewer_id] && @review_scores[reviewer_id][round] && @review_scores[reviewer_id][round][team_id] && @review_scores[reviewer_id][round][team_id] != -1.0
        instance_variable_set('@score_awarded_round_' + round.to_s, @review_scores[reviewer_id][round][team_id].to_s + '%')
      end
    end
  end
</pre>
 
 
After
<pre>
def compute_awarded_review_score(reviewer_id, team_id)
    num_rounds = @assignment.num_review_rounds
 
    (1..num_rounds).each do |round|
      score = @review_scores && @review_scores[reviewer_id] && @review_scores[reviewer_id][round] && @review_scores[reviewer_id][round][team_id]
      instance_variable_set("@score_awarded_round_#{round}", "#{score}%") unless score.nil? || score == -1.0
    end
end
</pre>
 
'''All links related to these changes:'''<br><br>
[https://github.com/expertiza/expertiza/pull/2663/commits/7549f7eb407f01fa7afb84ac6a2581bf36b13396 review_mapping_helper.rb] <br> <br>
----
----


==Test Plan==
==Test Plan==

Latest revision as of 18:13, 24 April 2024

Team

Mentor

  • Ananya Mantravadi (amantra)

Team Members

  • Ravi Ghevariya (rghevar)
  • Manan Patel (mrpatel8)
  • Kanishk Harde (knharde)

Relevant Links

Expertiza Background

Expertiza is a Ruby on Rails framework-based open-source web application. It is kept up by NC State University employees and students. With the help of this program, instructors can fully manage the assignments and responsibilities assigned in their classes. Expertiza provides many strong features, such as subject addition, group creation, and peer review administration. It is a flexible platform that can manage many kinds of tasks. Users can consult the Expertiza wiki to get more in-depth details about the many capabilities that Expertiza offers.

About Helper

The Ruby on Rails review_mapping_helper module offers a number of helper methods to make the peer review process easier in assignments. It has the capacity to calculate review scores, manage submission statuses, generate review reports, and visualize review metrics; however, it needs to be refactored in order to make the code more readable and maintainable.

Problem Statement

The existing codebase derived from E2301 suffers from lack of clarity, violating the Expert pattern, and inefficient methods, hindering code understandability and maintainability. Key issues include convoluted data handling in views, unclear color-coding methods, and inefficient sorting functions. Additionally, redundant methods and unclear feedback_response_maps further obscure the code's purpose.

Tasks

1. Refactor get_data_for_review_report to use partials for clearer code in views/reports.
2. Refactor color-related methods for clarity and consistency, using American spelling.
3. Rename methods starting with "get" to adhere to Ruby conventions.
4. Update get_awarded_review_score to utilize standardized score-calculation code.
5. Generalize sort_reviewer_by_review_volume_desc for sorting by various metrics.
6. Extracting chart-generating methods into their own module or evaluating the necessity of list_review_submissions
7. Review and clarify the purpose of feedback_response_maps methods.
8. Add comments or refactor small classes for clarity and documentation.

Phase 1

We have concentrated our efforts on addressing the following difficulties throughout the project's first phase:
1. Refactor get_data_for_review_report to use partials for clearer code in views/reports.
2. Refactor color-related methods for clarity and consistency, using American spelling.
3. Rename methods starting with "get" to adhere to Ruby conventions.
8. Add comments or refactor small classes for clarity and documentation.

Phase 2

We have planned our efforts on addressing the following difficulties throughout the project's second phase:
4. Update get_awarded_review_score to utilize standardized score-calculation code.
5. Generalize sort_reviewer_by_review_volume_desc for sorting by various metrics.
6. Extracting chart-generating methods into their own module or evaluating the necessity of list_review_submissions
7. Review and clarify the purpose of feedback_response_maps methods.


Implementation

Phase 1

Refactor the `get_data_for_review_report` method

Refactor the `color-related` methods

Rename methods starting with `get` to adhere to Ruby conventions methods

Design Pattern

The Refactoring pattern is essential to enhance code readability, maintainability, and adherence to best practices. By systematically restructuring code components, eliminating redundancies, and applying standard conventions, the Refactoring pattern ensures improved code quality and easier future modifications.

Plan of work

We began our work by examining the review_mapping_helper.rb file to understand its connection to the rest of the codebase. We then had detailed discussions with our mentor about the project's flow and structure. We organized our project requirements by difficulty levels, assigned tasks among the team, and began refactoring existing methods and creating new files as needed. We made sure to preserve the integrity of existing test cases while adding new ones where needed.

Project 4 - DESIGN DOC

We have been assigned below-cited changes to do after project 3

4. Refactoring get_awarded_review_score Method:

  • Standardize the score-calculation logic to ensure consistency and readability.
  • Break down complex calculations into smaller, more understandable components.
  • Improve method documentation and clarity to enhance understanding.

5. Generalizing sort_reviewer_by_review_volume_desc:

  • Modify the method to accept flexible sorting metrics, enabling customization based on various criteria.
  • Update method documentation to reflect the changes and provide usage guidelines.

6. Code Organization Enhancements:

  • Extract chart-generating methods into separate modules or classes for better organization and reusability.
  • Evaluate the necessity of list_review_submissions method based on insights from the Expertiza wiki and refactor accordingly.

7. Documentation and Clarity Improvements:

  • Review methods related to feedback_response_maps and add comments or refactor small classes to enhance clarity and documentation.
  • Ensure consistent naming conventions and adherence to coding standards throughout the codebase.

This section contains changes and contributions to Project 4


Issue #4: Method get_awarded_review_score needs to be refactored

  • Methods involved: get_awarded_review_score
  • Solution:After addressing Issue 2, the method was renamed to determine_awarded_review_score to align with Ruby conventions. Additionally, redundant instance variable settings were moved inside the loop to streamline the code. The explicit nil or -1.0 checks were eliminated and integrated into the instance_variable_set line.
  • Changes




Issue #5: The method sort_reviewer_by_review_volume_desc should be generalized so that it can sort by any metric, not just review volume. Other metrics might include number of suggestions, or number of suggestions + number of problems detected. This method should not be counting the number of review rounds! Since other places in the code will need to know the number of review rounds, it should be calculated somewhere else in the system.

  • Methods involved: sort_reviewer_by_review_volume_desc
  • Problem: The current function, sort_reviewer_by_review_volume_desc, arranges reviewers in descending order based solely on review volume. This limited approach means it can't be applied to sorting by other metrics.
  • Solution:The idea is to create a more versatile approach by changing the name of sort_reviewer_by_review_volume_desc to sort_reviewer_desc and allowing a metric argument for sorting reviewers, as demonstrated below. This modification was also applied to the review_report section where it was originally used.
  • Changes






Issue #6: make a separate file for for chart related elements in review_mapping_helper.rb

  • Methods involved: display_volume_metric_chart(), display_tagging_interval_chart()
  • Previous Code: The methods mentioned used to be included in the review_mapping_helper.rb file, but they should have been in their own helper file.
  • Problem: These techniques carry out comparable functions in creating graphs and can be implemented as either distinct modules or mixins. Additionally, each method contains more than 30 lines, making them excessively lengthy.
  • Solution: Created new module named 'Charts' withinthe same file. This way the chart helper methods are separated from review_mapping_helper where they are out of place and difficult for any developer to find.
  • Changes






Issue #7: Several methods for feedback_response_maps, check docs to manage this confusion

  • Methods involved: feedback_response_for_author()
  • Previous Code: previous code had an ambiguous variable name
  • Problem: The purpose of the variable was unclear.
  • Solution: Rename the variable to enhance its clarity and provide comments to explain its purpose clearly.
  • Changes




Test Plan

This project involves refactoring, meaning that the original functionality should remain unchanged. Tasks included adding comments to existing code, altering variable names, and similar adjustments that didn't affect the test cases. When method names were modified or moved to different files, corresponding changes were made in the relevant RSpec files. All test cases passed successfully, indicating that the refactoring didn't break the existing functionality.


The image below shows the test cases are passing as well as most of the code climate issues were resolved.