CSC/ECE 517 Spring 2019 - Project E1906. Refactor stage deadlines in Assignment.rb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 22: Line 22:
* stage_deadline(topic_id = nil)
* stage_deadline(topic_id = nil)


The goal of the project focuses on refactoring some of the above more complex methods,modifying some of the language to make it more Ruby friendly,removing some redundant code. This project is basically an attempt to make this part of the application easier to read and maintain.
The goal of the project focuses on refactoring some of the above more complex methods, modifying some of the language to make it more Ruby friendly, removing some redundant code. This project is basically an attempt to make this part of the application easier to read and maintain.


=='''Solutions Implemented'''==
=='''Solutions Implemented'''==
==='''Problem 1'''===
==='''Problem 1'''===


The above methods were being used at various places to check if the assignment is 'Finished' which made the code very redundant.Assignment is said to be finished if the next_due_date is nil.
The above methods were being used at various places to check if the assignment is 'Finished' which made the code very redundant. Assignment is said to be finished if the next_due_date is nil.


===='''Solution'''====
===='''Solution'''====


We have created a new method "finished?" that checks if the next_due_date is nil.
We have created a new method "finished?" that checks if the next_due_date is nil (which means that the assignment is "finished").


<pre>
<pre>

Revision as of 21:50, 24 March 2019

This wiki page is for the description of changes made under E1906 OSS assignment for Spring 2019, CSC/ECE 517.

Expertiza Background

Expertiza is a web application developed using Ruby on Rails Framework whose creation and maintenance is taken care of by students as well as the faculty of NCSU.It's code is available on Github Expertiza on GitHub.Expertiza allows the instructor to create and edit new as well as existing assignments.This also includes creating a wide range of topics under each assignment which students can sign up for.They can also publish surveys and reviews,view statistical results, set deadlines for assignments and make announcements.It provides a platform for students to signup for topics,form teams,view and submit assignments and give peer reviews and feedback.

Stage Deadline Background

An assignment in Expertiza has many deadlines possible: deadlines for submission and review in each round,deadlines for signing up and dropping topics,submitting meta-reviews,etc.Depending on what the next deadline is,an Expertiza assignment is said to be in a particular kind of what is called "stage".For example,if the next deadline(after the current time) is a submission deadline which is a DueDate object,then the assignment is said to be in a "submission" phase.

Depending on which stage an assignment is in, certain activities may be permissible or impermissible.For example, the default for a submission stage is to allow submission but not review,and in a review stage,the default is to allow review but not submission.These defaults may be changed by checking the relevant boxes on the Due Dates tab of assignment creation or editing.In the figure below it can be seen the "Other's work" link is grayed out as review is not permissible during submission phase.

Problem Statement

E1906 is an Expertiza based OSS project which deals basically with refactoring stage deadlines in assignment.rb file.Class assignment.rb has several methods for checking what kind of stage an assignment is in at the current time.These are:

  • current_stage_name(topic_id = nil)
  • find_current_stage(topic_id = nil)
  • get_current_stage(topic_id = nil)
  • link_for_current_stage(topic_id = nil)
  • stage_deadline(topic_id = nil)

The goal of the project focuses on refactoring some of the above more complex methods, modifying some of the language to make it more Ruby friendly, removing some redundant code. This project is basically an attempt to make this part of the application easier to read and maintain.

Solutions Implemented

Problem 1

The above methods were being used at various places to check if the assignment is 'Finished' which made the code very redundant. Assignment is said to be finished if the next_due_date is nil.

Solution

We have created a new method "finished?" that checks if the next_due_date is nil (which means that the assignment is "finished").

  # New function to check if the assignment is finished
  def finished?( topic_id = nil )
    DueDate.get_next_due_date(self.id, topic_id).nil?
  end

We have called this method at all the places where previously different methods were being used to check the same thing.

  • Signup sheet table uses assignment finished? method instead of current_stage_name


  • Use assignment finished? method where only a comparison to "Finished" was being done using get_current_stage and find_current_stage

Problem 2

The check for a topic_id to be nil when it is a staggered assignment and return 'Unknown' when it is true was being done at many places.This was not following Ruby and Rails rules.

Solution

To make the code DRY and more easy to understand,we have created a new private method "topic_missing?" to check if the topic_id is nil in case of staggered assignment.

  # Function to check if topic id is null when its a staggered assignment
  def topic_missing?( topic_id = nil)
    topic_id.nil? and self.staggered_deadline?
  end
  • Refactoring with new method topic_missing?

Problem 3

get_current_stage method is returning the stage name which the assignment is in at current time.This is not very clear from the name of the method.

Solution

We have changed the method name to get_current_stage_name(topic_id=nil) to make it more clear to understand.

  # Function to check if topic id is null when its a staggered assignment
  def topic_missing?( topic_id = nil)
    topic_id.nil? and self.staggered_deadline?
  end
  • Refactored get_current_stage with get_current_stage_name

Problem 4

current_stage_name(topic_id=nil) method was implementing things which was already being done by other methods and thus this method was redundant.The initial code given was:

  def get_current_stage_name(topic_id = nil)
    return 'Unknown' if topic_missing?(topic_id)
    finished?(topic_id)? "Finished" : DeadlineType.find(due_date.deadline_type_id).name
  end

Solution

This method was returning due_date.deadline_name which will actually never be returned because it will always be nil as there is no feature to add deadline_name in Expertiza.After removing this part and simplifying it the code looked like this:

  def current_stage_name(topic_id = nil)
    if self.staggered_deadline? and topic_id.nil?
      return 'Unknown'
    else
      get_current_stage(topic_id)
    end
  end

Looking at the get_current_stage_name(topic_id=nil) method, this code was surely redundant.That is why we removed this code and made appropriate changes wherever required.

   def get_current_stage_name(topic_id = nil)
     return 'Unknown' if topic_missing?(topic_id)
     finished?(topic_id)? "Finished" : DeadlineType.find(due_date.deadline_type_id).name
  end
  • Refactored current_stage_name with get_current_stage_name



Team

Jimmy Boykin
Ramandeep Kaur
Sushan Basnet

References