Refactoring, fixes and new features for the 'chat.py' module #12

Merged
juk0de merged 12 commits from chat_refactoring into main 2023-09-18 14:23:52 +02:00
Collaborator

This Pull Request introduces several improvements in Chat and ChatDB classes defined in chat.py file of the chatmastermind module. The changes are aimed at optimizing code for better reusability and clarity, as well as introducing new features in the classes.

Changes:

  1. New string constants (db_next_file, ignored_files, msg_location) are introduced for easier management of file related operations.
  2. In the read_dir() and clear_dir() functions, an additional check is added to ignore certain files while processing chat data.
  3. The Chat class is refactored to improve method naming and structuring. Several methods are renamed to follow a msg_<operation> pattern for better clarity. New methods such as msg_unique_id(), msg_unique_content() are added to handle more specific operations.
  4. A new function validatate() has been introduced that performs checks on the chat messages when instantiating a new Chat or ChatDB instance.
  5. The ChatDB class inherits the changes from Chat class. In addition, it's also extensively refactored. New methods like msg_gather(), msg_in_cache(), msg_in_db() etc. are added for more granular operations. Access to disk-level operations is now controlled by loc parameter in several methods. Functions that operate exclusively on the cache and DB directories now all have the prefix cache_ or db_.
  6. Two new methods cache_move() and db_move() are added in ChatDB class to allow moving a given message to the cache directory and db directory respectively.

Testing:

New unit tests have been added to test_chat.py and existing tests have been modified to cover the new functions.

Impact:

These changes will improve overall code maintainability and extensibility of chat classes, will provide better error handling and allow more granular control over operations like moving messages, finding messages, sorting messages etc.

This Pull Request introduces several improvements in `Chat` and `ChatDB` classes defined in `chat.py` file of the `chatmastermind` module. The changes are aimed at optimizing code for better reusability and clarity, as well as introducing new features in the classes. ## Changes: 1. New string constants (`db_next_file`, `ignored_files`, `msg_location`) are introduced for easier management of file related operations. 2. In the `read_dir()` and `clear_dir()` functions, an additional check is added to ignore certain files while processing chat data. 3. The `Chat` class is refactored to improve method naming and structuring. Several methods are renamed to follow a `msg_<operation>` pattern for better clarity. New methods such as `msg_unique_id()`, `msg_unique_content()` are added to handle more specific operations. 4. A new function `validatate()` has been introduced that performs checks on the chat messages when instantiating a new `Chat` or `ChatDB` instance. 5. The `ChatDB` class inherits the changes from `Chat` class. In addition, it's also extensively refactored. New methods like `msg_gather()`, `msg_in_cache()`, `msg_in_db()` etc. are added for more granular operations. Access to disk-level operations is now controlled by `loc` parameter in several methods. Functions that operate exclusively on the cache and DB directories now all have the prefix `cache_` or `db_`. 6. Two new methods `cache_move()` and `db_move()` are added in `ChatDB` class to allow moving a given message to the cache directory and db directory respectively. ## Testing: New unit tests have been added to `test_chat.py` and existing tests have been modified to cover the new functions. ## Impact: These changes will improve overall code maintainability and extensibility of chat classes, will provide better error handling and allow more granular control over operations like moving messages, finding messages, sorting messages etc.
juk0de added 12 commits 2023-09-17 09:43:37 +02:00
juk0de self-assigned this 2023-09-17 09:43:52 +02:00
juk0de added the enhancement label 2023-09-17 09:48:18 +02:00
juk0de marked the pull request as work in progress 2023-09-17 10:47:39 +02:00
juk0de force-pushed chat_refactoring from 59782f54ca to 25fffb6fea 2023-09-17 11:05:17 +02:00 Compare
juk0de marked the pull request as ready for review 2023-09-17 11:09:39 +02:00
juk0de merged commit f964c5471e into main 2023-09-18 14:23:52 +02:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kaizenkodo/ChatMastermind#12