CSC/ECE 517 Spring 2024 - E2416. Reimplement the Question hierarchy

From Expertiza_Wiki
Jump to navigation Jump to search

This wiki page is for the description of changes made under E2416 OSS assignment for Spring 2024, CSC/ECE 517

Expertiza

Expertiza is an open-source project built using Ruby on Rails. It provides a platform for instructors and students to manage, submit, and evaluate assignments and projects. Instructors can create, edit, and grade assignments, while students can collaborate in teams, submit their work, and review peers' submissions.

Objective

Firstly, by removing unnecessary partials, the goal is to streamline the codebase and eliminate redundancy. The initial implementation used partials to structure HTML, but upon analysis, it was found that the distinct functionalities of each question type made these partials redundant. By removing them, the code becomes more concise, easier to maintain, and less prone to inconsistencies.

Secondly, transitioning from returning HTML to delivering JSON objects from the models offers several advantages. This shift aims to enhance efficiency, readability, and maintainability. JSON objects are more lightweight than HTML representations, facilitating faster data transmission and reducing server load. Additionally, JSON is a widely accepted format for data interchange in modern web applications, enhancing compatibility and enabling seamless integration with various front-end frameworks or technologies.

The emphasis on comprehensive testing ensures that these modifications don't compromise the system's reliability or functionality. Rigorous testing helps identify and address any potential issues, ensuring that the code modifications maintain the system's integrity while improving its performance and adaptability to modern web development practices.

Problem Statement

The current implementation of the question hierarchy within Expertiza contains unclear variables, method names, and incomplete functionality at certain places. Additionally, many methods produce complex and lengthy HTML strings, making the codebase difficult to maintain. Objective: The project aims to enhance the question hierarchy component to improve code readability, comprehensibility, and maintainability.

Explanation of the feature

The Question class and its subclasses are pivotal components utilized in Expertiza for implementing rubric items, quiz questions, and survey questions. This feature offers a versatile framework for constructing various types of questions within the platform. The hierarchy of question types within Expertiza is delineated as follows:

  • Choice questions offer users a selection of answers to choose from, categorized into scored and unscored subtypes.
    • ScoredQuestion are assigned a point value, contributing to the final score of the questionnaire. Subtypes include:
      • Scale: Presents a set of answer options covering a range of opinions, often represented numerically.
      • Criterion: Allows setting a score value AND explaining it with a text comment.
    • UnscoredQuestion do not influence the final score of the questionnaire. Subtypes include:
      • Dropdown: Presents a list of options in a dropdown menu format.
      • Multiple Choice: Provides users with multiple options for selection, available as single-select (radio buttons) or multi-select (checkboxes).
      • Checkbox: Allows users to select multiple options from a list.
  • Text Response questions enable users to input their answers directly, bypassing predefined choices. Subtypes include:
    • Text Area: A text box with adjustable height and width.
    • Text Field: A single-line input field with fixed dimensions.
  • Upload file empowers users to upload files containing valid input to utilize as questionnaires. Additionally, users can export questionnaires to a .csv file format for further analysis and sharing.

UML diagram

Commonalities and Reimplementation Goals

Dropdown, MultipleChoice, and Scale questions share common functionality in Expertiza. They all provide users with a set of alternatives to choose from. However, they also have distinct characteristics that set them apart:

  • Commonalities:
    • Display alternatives for user selection.
    • Allow users to choose one option.
  • Differences:
    • Scale: Requires a numeric sequence of choices.
    • Dropdown and MultipleChoice: May have selections that aren't necessarily numeric.

To streamline the implementation and enhance code quality, the following goals have been outlined for reimplementation:

  • Goals:
    • Improved Variable and Method Naming: Enhance clarity and accuracy in representing functionality.
    • Inclusion of Comments: Provide comprehensive comments for better code understanding and maintenance.
    • Implementation of Partials: Utilize partials to manage HTML strings efficiently, reducing redundancy and improving maintainability (DRY principle).
    • Addition of RSpec Test Cases: Ensure the functionality of existing tests and incorporate new test cases where applicable to bolster code robustness and reliability.

Enhancements and Additions to Question Handling

  • Question Construction Functionality:

The application now boasts an advanced functionality for constructing new questions within questionnaires. This enhancement allows for the seamless creation of questions, considering crucial parameters such as text content, question type, sequence, and break flags. With this feature, users can efficiently design questionnaires tailored to their specific needs.

  • UploadFile Model Introduction:

A significant addition to the application is the UploadFile model, which extends the capabilities of the existing question framework. This model inherits from the Question superclass, providing a robust foundation for managing file upload questions. With this model, users can easily edit and view question text, ensuring smooth interaction with file-based questions.

  • Database Schema Enhancements:

To support the diverse range of questions and questionnaires, the database schema underwent significant enhancements. Tables were added to manage different types of questions and questionnaire types, ensuring structured data management. These schema enhancements lay a solid foundation for efficient data storage and retrieval, enhancing the overall performance and scalability of the application.

  • TextResponse Question Type:

A new question type, TextResponse, was introduced to enrich the diversity of questions available within the application. This model extends the functionality of questions by incorporating validation for size attributes and implementing methods for editing and viewing question text. Through comprehensive testing, the TextResponse question type ensures reliability and robustness in handling text-based responses.

  • TextArea and TextField Models:

The introduction of the TextArea and TextField models enhances the application's support for text-based questions. These models facilitate the management of text area and text field questions, offering methods for completing and viewing completed questions. With comprehensive testing and validation of size attributes, users can interact seamlessly with text-based questions, ensuring accurate data collection.

  • Criterion Model and QuestionAdvice Model:

To further expand the capabilities of the application, the Criterion and QuestionAdvice models were introduced. The Criterion model extends the functionality of scored questions, incorporating validation for size attributes and implementing methods for editing, viewing, and completing questions. Additionally, the QuestionAdvice model enables the management of advice associated with questions, enhancing the user experience by providing valuable insights and recommendations.

Files modified and added: Reimplementation

During the reimplementation process, several files underwent modifications and additions to ensure the functionality of the models. The objective was to streamline interdependencies, particularly concerning questionnaires and questions, aligning them with the project's objectives. Below is a categorized list of files that were modified or added as part of the reimplementation effort:

  • Parent Files:
    • questionnaire.rb: Modifications were made to this file to accommodate changes in questionnaire functionality.
    • question.rb: Adjustments were applied to support updated question functionalities.
    • schema.rb: Changes were reflected in the database schema to align with the updated model structures.


  • Scored and Unscored Section Files:
    • scored_question.rb: This file underwent modifications to enhance functionality related to scored questions.
    • unscored_question.rb: Adjustments were made to support unscored question functionalities.
    • criterion.rb: New functionalities and validations were added to enhance the criterion question type.


  • Text Response Files:
    • text_response.rb: Modifications were made to support the text response question type with enhanced functionalities.
    • text_area_spec.rb: Tests were added or modified to ensure the proper functioning of text area questions.
    • text_field.rb: Adjustments were made to enhance functionalities related to text field questions.
    • text_field_spec.rb: Tests were added or modified to validate the behavior of text field questions.


  • Upload Files:
    • upload_file.rb: New functionalities were added to support file upload question types.
    • upload_file_spec.rb: Tests were added or modified to ensure the proper functioning of file upload functionalities.


Reimplemented Repository[1]







Testing overview

Our testing plan incorporates a comprehensive approach using RSpec to ensure the integrity, functionality, and adherence to project goals of the implemented changes in the models. Building upon previous testing strategies, we continue to focus on key aspects of the code while introducing new tests tailored to the specific functionalities introduced or modified.

Previous Testing Approach:

In our previous testing strategy, we emphasized rigorous examination of the reimplementation, particularly focusing on the validation of modified models within the question hierarchy. This involved verifying the correctness of essential methods defined within the model class, ensuring their presence for the proper operation of the model. Tests were designed to assess the generation of HTML strings for various parameters, correctness of underlying methods, and the ability to produce HTML code for different scenarios. We also evaluated the handling of various question types and the generation of HTML representations for completed and unanswered questions. This approach, coupled with general model validations, formed a robust testing framework, guaranteeing the reimplementation's integrity and alignment with project goals.

Current Testing Strategy:

Building upon the foundation laid by the previous testing strategy, our current approach focuses on ensuring consistency in the return of JSON objects within model methods across various test files. This involves validating the correctness and structure of returned JSON objects for different scenarios, such as editing, completing, and viewing questions. Tests are designed to examine methods such as edit, complete, view_completed_question, and is_valid present in various model files. Each test constructs expected JSON objects based on created instances or mock data and evaluates the generated JSON against these expected formats. We meticulously check for attribute correctness, structure integrity, and validation message accuracy. By consistently executing these tests across multiple model files, our objective is to guarantee that the JSON responses are accurate, consistent, and align with the intended functionality, irrespective of the specific model instance being tested.

Incorporation of RSpec:

Our testing plan leverages the capabilities of RSpec to ensure that the code behaves as expected and adheres to the defined specifications. Through RSpec-driven testing, we enhance the maintainability and readability of our codebase while reducing complexities associated with previous implementations. Each test case is carefully crafted to cover various scenarios, edge cases, and input combinations, providing thorough coverage of the implemented functionalities. Additionally, testing the rendering of HTML or partial templates, wherever applicable, is incorporated to confirm the correct generation of views. This comprehensive approach ensures the model's integrity, functionality, and adherence to project goals, enhancing the overall quality of our codebase.





Outcomes and overview

This document presents the completed changes to the question hierarchy module, encompassing model enhancements and updated test cases. Through rigorous development and testing efforts, we have successfully implemented JSON object returns for every question type within our hierarchy and validated their functionality across multiple test scenarios. The achieved outcomes promise improved maintainability, heightened performance, and strict adherence to coding standards. The outlined implementation plan and comprehensive testing strategy serve to mitigate risks and facilitate a seamless transition to the refined system.


Key Achievements:

  • Model Refactoring: We have meticulously refactored the question hierarchy module, introducing new models and enhancing existing ones to ensure streamlined functionality and improved data management.
  • Test Case Updates: Extensive updates to our test suite have been made, covering various aspects of model behavior and JSON object generation for different question types. These updates validate the correctness, consistency, and adherence to specifications of our model implementations.
  • JSON Object Returns: Each question type within our hierarchy now returns JSON objects as expected, facilitating seamless interaction with the system and providing structured data representations for client-side processing.


Expected Benefits:

  • Improved Maintainability: The refactored models and updated test suite contribute to a more maintainable codebase, making it easier to implement future changes and enhancements.
  • Enhanced Performance: The streamlined functionality and optimized code structure promise improved performance, ensuring efficient operation of the question hierarchy module.
  • Adherence to Coding Standards: By adhering to coding standards and best practices throughout the development process, we ensure the consistency and quality of our codebase, promoting better collaboration and code readability.


Team

  • Mentors
    • Prof. Edward F. Gehringer
    • Muhammad Ali Qureshi
  • Members
    • Akhil Namboodiri
    • Vishwa Gandhi
    • Jaiwin Shah


References

  • Expertiza[2]
  • Previous team repository[3]
  • Active Record Migrations[4]
  • Migrating changes made on model[5]
  • Layouts and Rendering in Rails[6]
  • RSpec Testing[7]


Links

  • Project Board[8]
  • GitHub repo[9]
  • Link to initial pull request[10]
  • Deployed application [11]
  • Swagger implementation for the application [12]