CSC/ECE 517 Fall 2021 - E2120. Refactor reputation web service controller.rb

From Expertiza_Wiki
Jump to navigation Jump to search

Introduction

Introduction to Expertiza

Expertiza is a peer review based system which provides incremental learning from the class. This project has been developed together by faculty and students using Ruby on Rails framework. Expertiza allows the instructor to create, edit and delete assignments, create new assignment topics, assign them to a particular class or selected students, have students work on teams and then review each other's assignments at the end. For the students, they can signup for topics, form teams, and submit their projects and assignments. Students then review the work done by other students and give suggestions to improve. Teams after reviews are allotted scores and they can refer to the peer comments to further improve their work. It also supports the submission of different file types for assignments, including the URLs and wiki pages.

About Reputation Web Service Controller

Expertiza allows student work to be peer-reviewed since peers can provide more feedback than the instructor can. However, if we want to assure that all students receive competent feedback, or even use peer-assigned grades, we need a way to judge which peer reviewers are most credible. The solution is the reputation system. Reputation systems have been deployed as web services, peer-review researchers will be able to use them to calculate scores on assignments, both past, and present (past data can be used to tune the algorithms).

Issues to be fixed

reputation_web_service_controller.rb is a fairly complex file. It contains a lot of methods that are long and hard to understand (for e.g. send_post_request). These methods need to be broken down into simpler and more specific methods that are easier to read/understand. Also, the few instances of code duplication that exist should be removed.

  1. There is a lot of unused/commented code, which should be removed.
  2. Figure out what the code is doing and write appropriate comments for it.
  3. Rename bad method names such as (db_query, json_generator). Method names should be verbs and should say what the method does. Method names should not be so general that they could apply to many different methods.
    1. In the case of db_query, the name should say what it queries for.
      1. Also, this method not only queries, but calculates sums. Since each method should do only one thing, the code for calculating sums should be in another method.
      2. And there should be comments in the code!
    2. json_generator should be generate_json
      1. There needs to be a method comment saying what the parameters are.
  4. In send_post_request, there are references to specific assignments, such as 724, 735, and 756. They were put in to gather data for a paper published in 2015. They are no longer relevant and should be removed.
    1. send_post_request is 91 lines long, far too long.
  5. There is a password for a private key in the code (and the code is open-sourced!) It should be in the db instead.
  6. Fix spelling of “dimention”.
  7. client is a bad method name; why is stuff being copied from class variables to instance variables?

Steps taken to resolve the issues


Separated out peer grade calculation

 Separated the logic of peer grade calculation from fetch_peer_reviews method as it's doing multiple things under a single method.

fetch_peer_reviews method is not following the single responsibility principle. It's actually calculating the peer review grades and performing a db query within the same method which should not be the case.

Renaming the methods

 Renamed db_query to fetch_peer_reviews

db_query method name is not conveying what exactly it's doing within the method. Also, the method names should be verbs.

 Renamed db_query_with_quiz_score to fetch_quiz_scores

db_query_with_quiz_score is not a verb. Since all method names should be verbs it is renamed to fetch_quiz_scores.

 Renamed json_generator to generate_json

json_generator is not a verb. Since all method names should be verbs it is renamed to generate_json.

Fixed spelling of dimention

Removed Unnecessary code

The logic of Assignment ids 724, 735, 756 is removed from the send_post_request method is removed, since it's used to demo for paper publishing way back in 2015 and it's not being used anymore.


Created new method to encrypt request body

send_post_request method is too big and needs to be refactored in order to handle the single responsibility principle. It has the logic of encrypting the request body. So, it is moved to a separate method and named encrypt_review_data.

Created new method to decrypt response body

send_post_request method has the logic of decrypting the response body. So, it is moved to a separate method and named decrypt_review_data.

Created new method to update reputation scores

send_post_request method has the logic to update reputation scores. So, it is moved to a separate method and named update_reputation.

Moved sensitive information to db

reputation_web_Service_controller contains private keys. Since expertiza is an open source project moved them to db.

Removed class variables

Instance variables were assigned to class variables in the controller which is a bad practice. So, class variables are removed from the controller.

Added comments in the code for better readability


Testing the Reputation_web_service_controller


1. git clone https://github.com/VarunVeginati/expertiza.git

2. Check out to beta branch

3. Then perform "bundle install" and rake db:migrate.

4. Start the rails server

5. In a new terminal, perform the following commands:

   i.  rspec spec/controllers/reputation_web_service_controller_spec.rb

Testing Peer Review Grade Calculation

This test checks whether the method "fetch_peer_reviews" calculates and returns the grades as a list.

 it 'should calculate peer review grades' do
   has_topic = !SignUpTopic.where(41).empty?
   raw_data_array = controller.fetch_peer_reviews(41, 1, has_topic, 0)
   expect(raw_data_array).to be_an_instance_of(Array)
   expect(raw_data_array).should_not be(nil)
 end

Testing Quiz Scores Calculation

This test checks whether the method "fetch_quiz_scores" calculates and returns the quiz scores as a list.

 it 'should calculate quiz scores and return an array' do
   result = controller.fetch_quiz_scores(52,0)
   expect(result).to be_an_instance_of(Array)
   expect(result).to_not eq(nil)
 end

Test cases for send_post_request and client can't be written because we don't have access to public1.pem and private2.pem key files. The remaining methods need not be tested since they are sent to self queries.



Testing using Expertiza UI


Steps to test our changes are below. Note: This testing is just to make sure that there are no breaking changes. Since it's already an existing logic there is no special scenario to test. The below steps will make sure that the UI page isn't breaking with our refactoring changes.

To test the reputation controller you must log in to the site here: http://152.7.98.254:8080/ Username: instructor6 Password: password

 To add a student to an assignment

Step 1:

On the main page, go to Manage->Assignments

Step 2:

Search for "Final Project". Then on any of those projects click on "Add Participants" in the actions column. This is also indicated by a blue-shirted person.

Step 3:

Enter a student name (such as student3321) and click on Add button to add a particular student to that assignment. The system throws an error if the student doesn't exist or if the student is already added to that particular assignment.

 To navigate to the reputation page

Step 4:

Click on Manage->Impersonate. Then in the search bar enter the student's name to Impersonate the student.

Step 5:

Click on any of the valid assignments to view the reputation score.

Step 6:

For a particular assignment, click on Alternate View

Step 7:

You will be able to see the reputation score of the student for that particular assignment.

Step 8:

The client page can't be accessed from the home page. Type in the URL http://152.7.98.254:8080/reputation_web_service/client to access the client view. Using send request button we will be able to calculate the reputation scores for an assignment. But we need to have the public key file to do that.


Team Information'

Project Members:
Varun Kumar Veginati
Srujan Ponnur
Laxmi Aishwarya Thela


References