CSC/ECE 517 Spring 2022 - E2225: Refactor review mapping helper.rb

From Expertiza_Wiki
Jump to navigation Jump to search

This wiki page is for the description of changes made under E2225 OSS assignment for Fall 2022, CSC 517.

Expertiza Background

Expertiza is an educational web application created and maintained by the joint efforts of the students and the faculty at NCSU. It’s an open source project developed on Ruby on Rails platform and it’s code is available on Github. It allows students to review each other’s work and improve their work upon this feedback.

Background

A helper method in Ruby performs certain repetitive tasks across multiple classes or a singular class, so that code is not reused and redundancy is reduced. The review_mapping_helper.rb file is primarily used to perform routine tasks with reviews. Tasks such as returning the user's name instead of the team name when there is a single person in the team, checking whether the work has been submitted within the given round and sorting the reviewers by average number of reviews in each round. Each of these functions' visibility is dependent on the type of user.

Team Members

  • Ankur Mundra (amundra@ncsu.edu)
  • Shruti Magai (smagai@ncsu.edu)
  • Sudharsan Janardhanan (sjanard@ncsu.edu)


Files modified in current project

A helper file has been modified for this project namely:

1. review_mapping_helper.rb

List of changes

We worked on the following work items(WIs)
WI1 : Refactor get_team_color method to reduce cognitive complexity
WI2 : Refactor check_submission_state to reduce cognitive complexity
WI3 : Improved assignment branch condition of method get_awarded_review_score
WI4 : Refactored review_metrics method to reduce cognitive complexity
WI5 : Refactored calculate_key_chart_information to reduce complexity
WI6 : Added top level class documentation and corrected indentation
WI7 : Updated method names for method name too long issue


Solutions Implemented and Delivered

  • Refactoring get_team_color method

1. This method retrieves the team's color according to the state of the review and assignment status

The initial method consisted of an if clause with multiple if-else statements nested inside.
We refactored the code and utilized the unless statement to make the code ruby friendly.

Initial code:

Refactored code:


2. Refactoring check_submission_state method

The initial method consisted of an if clause with multiple if-else statements nested inside.
We refactored the code and used inline if conditions to make the code more concise.

Initial code:

Refactored code:

3. Refactoring get_awarded_review_score to reduce the Assignment Branch Condition size

Assignment Branch Condition size for get_awarded_review_score was too high. Reduced the ABC size to make the method more readily understood, more reusable and more testable.

4. Refactoring review_metrics method

We utilize the unless statement to return an empty value if there is no review associated with a given team, eliminating the use of if statements in favor of ruby styled code.

Refactored code:

5. Refactored calculate_key_chart_information to reduce complexity

Used a guard clause instead of wrapping the code inside a conditional expression. In coding we are always looking for simplicity and atomic definitions and eager return statements are a really nice way to tight up the code.


6. Top level documentation and corrected indentation

We've added top level documentation to describe the functionality of classes such as the ReviewStrategy class, StudentReviewStrategy class and TeamReviewStratregy class.
Ruby style guidelines dictate that 2 spaces be used instead of tabs. We've performed these changes throughout the document.

Scope for future improvement

1.