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

From Expertiza_Wiki
Jump to navigation Jump to search

About Expertiza

Expertiza is the software benefits for both instructors and students by supporting various types of submissions and providing reusable objects for peer review. It is an open-source project based on Ruby on Rails framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.

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)

Description about project

This page is a description of Expertiza OSS project E2225 is refactoring review_mapping_helper.rb. The work that we have done aims to reduce the size of individual helper methods and attempt to write cleaner code. We have tried our best to write code that is easily readable, concise and not too involved.

Files Involved

  • review_mapping_helper.rb

Code modifications

1. Refactored get_team_color method The functions retrieves the color reflecting the state of the team's review and assignment submission status. Current code:

  def get_team_color(response_map)
    # Storing redundantly computed value in a variable
    assignment_created = @assignment.created_at
    # Storing redundantly computed value in a variable
    assignment_due_dates = DueDate.where(parent_id: response_map.reviewed_object_id)
    # Returning colour based on conditions
    if Response.exists?(map_id: response_map.id)
      if !response_map.try(:reviewer).try(:review_grade).nil?
        'brown'
      elsif response_for_each_round?(response_map)
        'blue'
      else
        obtain_team_color(response_map, assignment_created, assignment_due_dates)
      end
    else
      'red'
    end
  end

Modifications:

  def get_team_color(response_map)
    # Storing redundantly computed value in a variable
    assignment_created = @assignment.created_at
    # Storing redundantly computed value in a variable
    assignment_due_dates = DueDate.where(parent_id: response_map.reviewed_object_id)
    # Returning colour based on conditions
    return 'red' unless Response.exists?(map_id: response_map.id)

    if !response_map.try(:reviewer).try(:review_grade).nil?
      'brown'
    elsif response_for_each_round?(response_map)
      'blue'
    else
      obtain_team_color(response_map, assignment_created, assignment_due_dates)
    end
  end


2. Refactor check_submission_state method Checks the status of the submission of an assignment or deliverable within each round and assigns the color for the team

Current code:

  def check_submission_state(response_map, assignment_created, assignment_due_dates, round, color)
    if submitted_within_round?(round, response_map, assignment_created, assignment_due_dates)
      color.push 'purple'
    else
      link = submitted_hyperlink(round, response_map, assignment_created, assignment_due_dates)
      if link.nil? || (link !~ %r{https*:\/\/wiki(.*)}) # can be extended for github links in future
        color.push 'green'
      else
        link_updated_at = get_link_updated_at(link)
        color.push link_updated_since_last?(round, assignment_due_dates, link_updated_at) ? 'purple' : 'green'
      end
    end
  end

Modifications:

def check_submission_state(response_map, assignment_created, assignment_due_dates, round, color
  return color.push 'purple' if submitted_within_round?(round, response_map, assignment_created, assignment_due_dates)

  link = submitted_hyperlink(round, response_map, assignment_created, assignment_due_dates)
  return color.push 'green' if link.nil? || (link !~ %r{https*:\/\/wiki(.*)})

  link_updated_at = get_link_updated_at(link)
  color.push link_updated_since_last?(round, assignment_due_dates, link_updated_at) ? 'purple' : 'green'
 end



GitHub links

Link to Expertiza repository: here

Link to the forked repository: here