CSC/ECE 517 Fall 2014/OSS E1466 gjf

From Expertiza_Wiki
Jump to navigation Jump to search

E1466: Refactoring GradesController

This wiki deals with our implementation of a controller in expertiza: grade_controller for the Expertiza Project using Ruby on Rails.

Introduction

Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities.

Project Description


Classes involved: grades_controller.rb

What it does:

This class lists the grades of all the participants for an assignments and also their reviews. Instructor can edit scores, calculate penalties and send emails for conflicts.

What needs to be done:

  • Modify calculate_all_penalties method which is too complex and long.
  • Put the get_body_text method in a mailer rather than in the grades_controller.
  • Refactor conflict_nofication method to conflict_email and make it delegated to the mailer.
  • Refactor view_my_scores method to grades_show and delete the unnecessary variables.
  • Try not to query for reviews and meta reviews in grades_show method.

Code Modification

calculate_all_penalties

Summary:

We have modified the calculate_penalties method and implemented all the functions it originally has. After our modification the method shrinks from 45 lines to 32 lines of Ruby code. Originally, the method includes a lot of unnecessary if and unless statements which makes the method uneasy to read and seems to have a difficult logic to calculate the penalties.

According to the codeclimate which calculate the complexity of the method, originally, it has a complexity of 85, however, after we modified it, the complexity goes down to 65. Please check at original version,modified version

We have done the following to the original methods:

  • Used the for loop with selective choice to create penalty attributes and put it into the CalculatedPenalty Table, instead of duplicating the code which are almost the same,
  • Made full use of the characteristics of Ruby, let the array respond the method min which returns the minimum number in the array. What I get from this is the logical penalty (max_penalty if total_penalty is larger than max_penalty, total_penalty if total_penalty is smaller than max_penalty),when comparing the total_penalty with max_penalty, other than using if statement,
  • Eliminated the unnecessary if statement to make the code clear to read.

Appendix

References