CSC/ECE 517 Spring 2024 - E2418. Reimplement of due date.rb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 14: Line 14:
In this project, the following specific changes were implemented:
In this project, the following specific changes were implemented:


*
* Renamed methods and variables to accurately describe their responsibilities.
*
* Refactored each method to comply with DRY (Don't Repeat Yourself), SRP (Single Responsibility Principle), and other Ruby conventions.
*
*
*
*
Line 69: Line 69:


[[File:DueDateRename5.png|1000px|thumb|none|]]
[[File:DueDateRename5.png|1000px|thumb|none|]]
=== Refactored each method according to DRY, SRP, and other Ruby conventions ===
* '''Problem''': Methods were potentially repetitive, non-optimized, or didn't adhere to best practices, causing inefficiencies and confusion.
* '''Solution''': Method refactoring according to DRY, SRP, and Ruby conventions optimized the code for clarity, efficiency, and maintainability, ensuring each method has a clear purpose and follows standard practices.
[[File:DueDateRuby1.png|1000px|thumb|none|]]
[[File:DueDateRuby2.png|1000px|thumb|none|]]
[[File:DueDateRuby3.png|1000px|thumb|none|]]
[[File:DueDateRuby4.png|1000px|thumb|none|]]
[[File:DueDateRuby5.png|1000px|thumb|none|]]





Revision as of 21:50, 23 March 2024

E2368. Reimplement due_date.rb

This page provides a description of the Expertiza based OSS project.



About Expertiza

Expertiza is an open source project based on Ruby on Rails framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.

Project Changes

In this project, the following specific changes were implemented:

  • Renamed methods and variables to accurately describe their responsibilities.
  • Refactored each method to comply with DRY (Don't Repeat Yourself), SRP (Single Responsibility Principle), and other Ruby conventions.

These changes aimed to enhance code quality, organization, and adherence to best practices in the Expertiza project.

Current Implementation of DueDate Class

The current implementation of the `DueDate` class can be summarized in a few key points:

Validation of Due Date Format

The class includes a validation method due_at_is_valid_datetime to ensure that the due date is in a valid datetime format. It checks if the due_at attribute is present and attempts to parse it using DateTime.strptime. If parsing fails and raises an ArgumentError, the method adds an error to the due_at attribute indicating that it must be a valid datetime.

Default Permission Handling

The class provides a default_permission method, which retrieves the default permission for a given deadline type and permission type. It accesses the DEFAULT_PERMISSION constant defined in the DeadlineRight module and returns the corresponding permission value.

Current Due Date Retrieval

It offers functionality through the current_due_date method to retrieve the current due date from a list of due dates. This method iterates over the provided due dates and checks if any due date lies in the future compared to the current time. It returns the first future due date encountered, indicating the current due date.

Flag Setting

It includes a set_flag method to set the flag attribute to true for a DueDate instance. This method updates the flag attribute and saves the record to the database.

Due Date Copying

The class implements functionality to copy due dates from one assignment to another using the copy method. It retrieves due dates associated with a given assignment ID, duplicates each due date record, assigns the new parent ID, and saves the duplicated records for the new assignment.

Due Date Setting

Provides a set_duedate method to set due dates for assignments with specified parameters. It creates a new DueDate instance with the provided parameters, including the deadline type, parent assignment ID, round, and saves the record to the database.

Sorting of Due Dates

Implements a method deadline_sort to sort due dates based on the due date attribute. This method sorts the provided list of due dates in ascending order of their due dates, ensuring that due dates without due_at values are placed at the end.

Assignment Round Calculation

Calculates the round of the response within an assignment based on due dates using the done_in_assignment_round method. It retrieves due dates associated with the given assignment ID, sorts them by due date, and iterates over them to determine the round based on the response's creation time.

Next Due Date Retrieval

Offers functionality through the get_next_due_date method to retrieve the next due date for an assignment or topic. Depending on whether the assignment has staggered deadlines, it queries either AssignmentDueDate or TopicDueDate records and returns the next due date after the current time.

The DueDate class in the Expertiza project serves as a pivotal component responsible for managing, validating, and retrieving due dates associated with assignments, encompassing functionalities such as validation of datetime formats, permission handling, and determining the current and next due dates for assignments and topics.

Improvements in the New Implementation of DueDate Class

Renamed methods to describe their responsibility

  • Problem: Method names might not have accurately described their functionality, leading to confusion for developers.
  • Solution: Method renaming with descriptive names clarified their purpose, improving code readability and comprehension for developers to understand method functionalities without deep code inspection.

Refactored each method according to DRY, SRP, and other Ruby conventions

  • Problem: Methods were potentially repetitive, non-optimized, or didn't adhere to best practices, causing inefficiencies and confusion.
  • Solution: Method refactoring according to DRY, SRP, and Ruby conventions optimized the code for clarity, efficiency, and maintainability, ensuring each method has a clear purpose and follows standard practices.
File:DueDateRuby5.png


Test Plan for DueDateHelper Specs

The following outlines the scenarios and cases to be tested for the DueDateHelper functionality within the system.


References

  1. Expertiza on GitHub
  2. GitHub Project Repository Fork
  3. The live Expertiza website
  4. Expertiza project documentation wiki
  5. Rspec Documentation
  6. Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin