CSC/ECE 517 Spring 2015/oss E1501 YWS: Difference between revisions
No edit summary |
No edit summary |
||
Line 38: | Line 38: | ||
===Make assignment.rb more Ruby like=== | ===Make assignment.rb more Ruby like=== | ||
There were many instances where the coding style was not according to ruby guidelines. The code was refactored to be more ruby like. Changes such as removing the return | There were many instances where the coding style was not according to ruby guidelines. The code was refactored to be more ruby like. Changes such as removing the return statements, writing .each instead of for loop and improving naming conventions were implemented. Some of the changes are described below: | ||
<p> | <p> | ||
'''Before Change''' | '''Before Change''' | ||
Line 86: | Line 86: | ||
One more gem "quite_assets" was added to avoid unnecessary log creation of background functions. | One more gem "quite_assets" was added to avoid unnecessary log creation of background functions. | ||
=Steps to verify changes= | =Steps to verify changes= | ||
Line 124: | Line 94: | ||
#[https://github.com/itsmylifesoham/expertiza GitHub Project Repository Fork] | #[https://github.com/itsmylifesoham/expertiza GitHub Project Repository Fork] | ||
#[http://expertiza.ncsu.edu/ The live Expertiza website] | #[http://expertiza.ncsu.edu/ The live Expertiza website] | ||
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki] | #[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki] | ||
= References= | = References= |
Revision as of 18:48, 23 March 2015
E1501: Refactoring Assignments.rb
This page provides information about a project which aims to refactor Assignment.rb file present in Expertiza OSS.
Introduction to Expertiza
Expertiza is an open source project developed using the Ruby on Rails platform. It provides features like team assignments, peer review, submission of projects, grading etc. The code can be cloned from GitHub. This application provides an efficient way to manage assignments, grades and reviews, which makes the process easier and faster when the class strength is large.
Assignment.rb is a file which contains the assignment model and the related functionality. It also contains the score module which is refactored to make the file more clean and easy to read.
Problem Statement
Classes involved:
assignment.rb scorable.rb Gemfile schema.rb
What they do
Assignment.rb along with the controller file is responsible for creating and editing the assignments. The file also contains the functions responsible for grading.
What needs to be done:
The assignment model needed a refactoring as it contains some modules which were responsible for generating assignment scores. Moreover, the querying module was database dependent which was made database independent. There were many function names and code lines which were not following the ruby guidelines. They were changed to more ruby like coding style.
Re-factored Instances
Instance 1 : Refactoring the Assignment.rb
Creation of separate model scorable.rb
There are many methods which are not directly related to assignments. These methods are responsible for generating the scores and related functions. These methods are:
1.get_scores
2.get_max_score_possible
3.compute_reviews_hash
4.get_average_score
All these methods are taken out of assignment.rb and pushed into a new file "scorable.rb". This made score generation a separate module and the dependency of scores on assignments have been reduced significantly.
Make assignment.rb more Ruby like
There were many instances where the coding style was not according to ruby guidelines. The code was refactored to be more ruby like. Changes such as removing the return statements, writing .each instead of for loop and improving naming conventions were implemented. Some of the changes are described below:
Before Change
quiz_response_mappings.each do |qmapping| if qmapping.response quiz_responses << qmapping.response end end
After Change
quiz_responses = quiz_response_mappings.select{ |qmapping| qmapping.response }.map(&:response)
Before Change
total = 0 self.questionnaires.each { |questionnaire| total += questionnaire.get_weighted_score(self, scores) } total
After Change
self.questionnaires.inject(0) { |total, questionnaire| total + questionnaire.get_weighted_score(self, scores) }
Instance 2 : Addition of ActiveRecord like Query
The queries where changed to function more like active record query. This made the queries database independent and more user friendly.
Before Change
DueDate.where( ['assignment_id = ? and deadline_type_id >= ?', self.id, 7]).due_at
After Change
DueDate.where(assignment_id: self.id, deadline_type_id: 7).due_at
Instance 3 : Changing Gemfile
Version of gem "EventMachine" was updated as earlier version was incompatible with ruby version 2.2.0. The version was changed from 1.0.3 to 1.0.7.
One more gem "quite_assets" was added to avoid unnecessary log creation of background functions.
Steps to verify changes
See Also
- Expertiza on GitHub
- GitHub Project Repository Fork
- The live Expertiza website
- Expertiza project documentation wiki