CSC/ECE 517 Spring 2023 - E2314. Reimplement the response map hierarchy

From Expertiza_Wiki
Jump to navigation Jump to search

Background

When someone writes a review in Expertiza, they are creating an instance of the Response class. Each Response is created based on a particular ResponseMap. The ResponseMap tells who the reviewer is (the reviewer_id), who the reviewee is (the reviewee_id), and what is being reviewed (the reviewed_object_id).

  • The reviewer_id is normally a record in the Participants table, which specifies an AssignmentParticipant. However, if teams rather than individuals are doing reviews for this assignment, it may be an AssignmentTeam.
  • For reviews of student work, the reviewee_id is always an AssignmentTeam. (If an assignment is set up so individuals rather than teams submit work, the reviewee will still be a 1-member AssignmentTeam.)
  • For teammate reviews, the reviewee_id is always an AssignmentParticipant.
  • The reviewed_object_id is normally an Assignment. But in the case of meta-reviews, the reviewed_object_id is another ResponseMap (because it is a review that is being reviewed).

Project Requirements

This project aims to re-implement the ResponseMap hierarchy in Expertiza to simplify its design and reduce the number of class methods. Specifically, this project will focus on re-implementing three of the ResponseMap subclasses: ReviewResponseMaps, FeedbackResponseMaps, and TeammateReviewResponseMaps.

The ResponseMap hierarchy is a critical component of Expertiza, as it defines the relationship between reviewers, reviewees, and the objects being reviewed. In the current implementation, there are several issues that need to be addressed to improve the overall design and functionality of the hierarchy. For example, the current hierarchy is cluttered with class methods, which makes it difficult to maintain and update. Additionally, some methods belong in the Response class while others belong in the ResponseMap subclasses.

To address these issues, this project will begin by creating a simplified version of the Response class that includes only the methods that belong in that class. This will make it easier to merge the new Response class with the ResponseMap subclasses that are being re-implemented.

Next, the ReviewResponseMap export operation will be re-implemented based on the new Response class framework. This will make the export operation simpler and easier to use. Additionally, the comparator method will be replaced by an overloading of the <=> operator.

Several methods that return Responses in the ResponseMap subclasses will be moved to the Response class. This will improve the overall organization of the hierarchy and make it easier to maintain and update in the future. Methods whose name begins with "get" will be renamed to follow Ruby conventions, as this will make the code easier to read and understand.

The FeedbackResponseMap is used for giving author feedback, which will be considered when re-implementing this subclass. Specifically, the methods in this subclass will be reviewed to ensure that they are properly named and that they follow Ruby conventions.

Overall, the main requirements for this project include:

  • Re-implementing three of the ResponseMap subclasses (ReviewResponseMaps, FeedbackResponseMaps, and TeammateReviewResponseMaps)
  • Simplifying the ResponseMap hierarchy to reduce the number of class methods
  • Creating a simplified version of the Response class that includes only the methods that belong in that class
  • Re-implementing the ReviewResponseMap export operation based on the new Response class framework
  • Replacing the comparator method with overloading of the <=> operator
  • Moving several methods that return Responses in the ResponseMap subclasses to the Response class
  • Renaming methods whose name begins with "get" to follow Ruby conventions
  • Reviewing the FeedbackResponseMap subclass to ensure its methods are appropriately named and follow Ruby conventions.

By completing these requirements, the ResponseMap hierarchy in Expertiza will be improved and easier to maintain and update in the future.

Design

Our Enhancements

Comment Lines

Each well-written code must contain comment lines that explain the purpose of each method's class. It is simpler for other developers to comprehend and use the code because these comment lines offer a concise and clear explanation of what the method performs. Also, comment lines contribute to the code's maintainability and scalability by supplying context and facilitating simpler debugging and modification. It can be difficult for other developers to comprehend a method's purpose without comment lines, especially if the code is complex or if they need to become more familiar with the programming language. Therefore, to ensure that the code is well-documented, maintainable, and scalable, it is crucial to include comment lines describing the purpose of a method in a class.

Each method has no comment lines in Expertiza's current implementation. All available methods in the response maps class have comment lines added as project guidelines require. The sample work with comment lines is below.


Variable and Method names

Using appropriate variable and method names while writing code is imperative for various reasons. The first benefit of giving code meaningful names is that they make it easier for future developers to read and comprehend the code. Clear and informative variable and method names simplify comprehending what a specific piece of code does, ultimately saving time and effort. Second, exact terms contribute to better code quality and error prevention. The likelihood that variables and methods may be misused, leading to problems or faults in the code, is reduced when their names appropriately reflect what they do. Finally, code is more scalable and maintainable when it has meaningful names. Well-chosen variable and method names simplify adapting and growing the code over time without creating errors or ambiguity. As a result of increased readability, reduced error rates, and increased maintainability and scalability, utilizing meaningful variable and method names is a critical best practice when writing code.

We have renamed many variable and method names as part of the project. To adhere to the Ruby standards, we have removed the word "get" when starting a method name. Our sample work is below.


Name of method changed from "email" to "send_email"

<=> Operators

The rocket operator "<=>" is a built-in comparison operator in Ruby that offers a clear and effective way to sort and compare things. The rocket operator can sort items according to their attributes rather than creating our comparator function. The rocket operator yields 0 if the two objects under comparison are equal, -1 if the left object is smaller than the right object, and 1 if the left object is larger than the right object. The rocket operator offers a consistent and dependable technique to compare and classify objects while also saving time and effort. Creating our own comparator function may be more error-prone and less effective than the built-in operator. Also, employing the rocket operator can aid in reducing code complexity and enhancing readability because other writers are more likely to be familiar with the operator than with a unique comparator function. As a result, it is advised to use the rocket operator "<=>" wherever possible rather than creating our comparator function in Ruby to ensure effective and trustworthy sorting and comparison of items.

To stick to the above Ruby standard, we have replaced the self-defined comparator functions and replaced them with the inbuilt rocket.

Methods Moved to Response Class

It is crucial to create classes in object-oriented programming that are modular, maintainable, and scalable. Understanding the overall structure of the code and effectively modifying it cannot be easy when methods are dispersed across numerous subclasses. Additionally, having functions in the main class rather than a subclass makes more sense when they are closely related to the duties of the main class. Moving these methods to the main class may result in better code organization and a more straightforward program flow. Other subclasses can access the methods in the main class without redefining them, reducing code duplication and improving code reuse. Since this can result in more maintainable, scalable, and modular code, it is generally advised to move methods to the main class when closely related to its responsibilities.

The following table contains the names of methods moved from subclasses to the "response.rb" class located at "app/models/response.rb".

Migrated Methods
File Name File Location Method Name Commit Details
response_map.rb app/models/response_map.rb self.assessments_for(team), self.reviewer_assessments_for(team, reviewer), <=>(other_response) Commit
review_response_map.rb app/models/review_response_map.rb self.get_responses_for_team_round(team, round, type) Commit

Remove Unused Code

Unused code must be removed to maintain code quality, lower code complexity, and enhance program performance in software development. Unused code can expand the size and complexity of the codebase, making it more challenging to maintain, debug, and update. Additionally, it may cause developers to become confused and raise the risk of introducing bugs or security vulnerabilities. The size and complexity of the codebase can be decreased by removing unused code, which will make it simpler to comprehend and maintain. As the compiler or interpreter does not need to allocate memory or processing power to execute inactive code, it can also enhance program performance. As the codebase becomes cleaner and more organized and the likelihood of running into issues in the future decreases, removing unused code can also aid in reducing technical debt.

As part of this project, we identified unused code and removed it from the code base. One such example is below

Test Plan

Fix Broken Tests

Significant changes were introduced into code, such as moving methods from sub-classes to the main class, as seen in the above implementations. It's common for test cases to break or no longer work as expected. It's essential to fix the test cases to ensure the code behaves as intended and to catch any potential bugs or issues introduced during the changes. By resolving the test cases, we confirmed that the code is still working as expected and that the changes have not inadvertently caused any problems. Additionally, fixing the test cases helps to identify and fix any issues that may have been present in the codebase before the changes were made. Some of the examples of test fixes made are given below.

Note

The scope of the project is limited to the model review_response_map. So, no controllers are used in the implementation. Due to this reason, it is not possible to perform functional testing or test the response using multiple controllers. We have stubbed dummy data necessary for testing the model and imitating the response from controllers. The in-built rails framework is used for Testing.

New Test Cases

In software development, testing, and unit tests are crucial because they ensure that the software works as intended and is free of bugs or errors. Before the software is made available to the general public, testing enables developers to find and address any issues, avoiding potential problems and saving time and resources. Because they test individual software units or components, unit tests are a crucial component of testing because they enable developers to pinpoint problems in a specific section of code and make targeted corrections. With this approach, developers can identify issues early on, saving time and resources while ensuring that the final product is high quality and meets users' needs. In conclusion, testing and unit testing is essential for guaranteeing the quality and dependability of software and ought to be a fundamental component of any software development process. For all the said reasons, we introduced test cases to test the response class as well as the sub classes review_response_map, teammate_review_response_map, response_map, and feedback_response_map.

Example of test cases added to test review_response_map

review_response_map_test.rb
Test No. Description
1 Tests if the right questionnaire is accessed
2 Tests if the right fields are exported
3 Tests if the metareview_response_maps function is working
4 Tests if the reviewer obtained is the right one
5 Tests if the reviewer can be retrieved with id
6 Tests if the last review for a team is available
7 Tests if the team email functionality is working
8 Tests if the prepare_final_review_versions function is returning right review id

Example of test cases added to test teammate_review_response_map

teammate_review_response_map_test.rb
Test No. Description
1 Test the working of questionnaire
2 Test if the team's questionnaire is accessable
3 Test the questionnaire with nil values
4 Test the questionnaire with non nil values
5 Test the reviewer details of a team review
6 Test the teammate_response_report functionality and see if right map is returned
7 Check the email functionality for a team assignment review

Example of test cases added to test response_map

response_map_test.rb
Test No. Description
1 Test the review functionality
2 Test if feedback can be given to a review
3 Test if the response_map was metareviewed by metareviewer
4 Test if the metareviewer to this review(response) is assigned
5 Test the reviewer details of a team review
6 Test if the right teammates are associated with a review


Example of test cases added to test feedback_response_map

feedback_response_map_test.rb
Test No. Description
1 Tests if the assignment object is available
2 Tests the show_review
3 Tests if the title function is working
4 Tests the questionnaire function and if the right question ids are returned
5 Tests if the right contributor is returned
6 Tests the email functionality

How to Test

Here are step-by-step instructions for setting up Expertiza backend repository on a CSC-517 Expertiza Development Environment VCL session.

1. Copy the "/root/setup_expertiza.sh" script to your home directory. sudo cp /root/setup_expertiza.sh ~/setup_expertiza.sh

2. Make the script executable. sudo chmod +x setup_expertiza.sh

3. Run the script. ./setup_expertiza.sh

4. Provide the GitHub repository URL. Once the script runs, you will be prompted to enter the GitHub repository URL for the project you want to work on.

5. Select the project type (Refactoring or Reimplementation)

6. Wait for the setup to complete and terminate the terminals.

7. Change the username in config/database.yml from root to dev on line 4 --- username: dev

8. cd into the root of the project

9. rake db:create

10. rake db:migrate

11. rake test TESTOPTS="-v"

Screencast

Screencast

GitHub

The code corresponding to this project is available as open source. The code is found at https://github.com/sbiyer/reimplementation-back-end

The pull request raised to be merged with https://github.com/expertiza/reimplementation-back-end original implementation is found at https://github.com/expertiza/reimplementation-back-end/pull/21

Future Work

The project required to use export functionality based on this framework. However, both the import and export frameworks are not available on the main branch of the project. This can be done as future work once the main branch of Expertiza is updated with the framework.

Contributors

Srini Iyer - LinkedIn
Aswin Itha - LinkedIn
Suparno Saha - LinkedIn