CSC/ECE 517 Fall 2013/oss E804 spb: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 21: | Line 21: | ||
== Design Changes == | == Design Changes == | ||
:The model scores.rb has only two methods that compute scores for the participants and | :The model scores.rb has only two methods that compute scores for the participants based on assignments and courses. But these methods have used hashes extensively to handle data. Also, the method get_total_score() makes many sequential queries to the database which increases the loading time for the page. These functions have logic which can be separated into two methods to make it more modular. | ||
=== | === Created Database views === | ||
=== Separated functionality === | |||
:The get_total_scores function computes total scores and also has the code to check if a response is valid or invalid. This code is independent of computation of scores and can be separated into a separate function. We have created a function 'submission_valid?' to check if a given response is valid or not. | |||
=== Reduced the use of hash === | |||
:the get_total_scores function accepts a hash as a parameter, which can be avoided. We have refactored the method to accept three arguments instead of a hash. We had to change all the dependent classes that call this method. | |||
:the compute_scores method returns a hash that stores the minimum, maximum and average score. We created a class ParticipantScore.rb that has attributes min, max and avg which store the minimum, maximum and average score of a particpant. This object could be used to maintain state as against an hash. Now the compute_score method returns an object of class ParticipantScore instead of an hash. |
Revision as of 05:11, 30 October 2013
Expertiza Code Refactoring
Introduction
A way to query db models to return scores, without UI changes
Project Description
Classes:
- models/score.rb (159 lines)
- grades_controller.rb (241 lines)
What needs to be done:
- This code is very slow, due to many factors. Two of the most prominent are the fact that separate db queries are used for each rubric that has been filled out by anyone associated with the assignment; these queries are made sequentially while the HTML page is being written; and the fact that HTML for the whole page is generated, largely by controller methods, before anything is displayed.
- Need to refactor the score.rb model which contains complex methods.
Design Changes
- The model scores.rb has only two methods that compute scores for the participants based on assignments and courses. But these methods have used hashes extensively to handle data. Also, the method get_total_score() makes many sequential queries to the database which increases the loading time for the page. These functions have logic which can be separated into two methods to make it more modular.
Created Database views
Separated functionality
- The get_total_scores function computes total scores and also has the code to check if a response is valid or invalid. This code is independent of computation of scores and can be separated into a separate function. We have created a function 'submission_valid?' to check if a given response is valid or not.
Reduced the use of hash
- the get_total_scores function accepts a hash as a parameter, which can be avoided. We have refactored the method to accept three arguments instead of a hash. We had to change all the dependent classes that call this method.
- the compute_scores method returns a hash that stores the minimum, maximum and average score. We created a class ParticipantScore.rb that has attributes min, max and avg which store the minimum, maximum and average score of a particpant. This object could be used to maintain state as against an hash. Now the compute_score method returns an object of class ParticipantScore instead of an hash.