Open diegoabeltran16 opened 2 weeks ago
The roadmap for implementing the feature/expense-reports in the next cycle focuses on creating a robust and user-friendly reporting system for the Passive Expenses Bot. This roadmap incorporates best practices, project architecture, and details from the provided files. The goal is to ensure the feature is both scalable and efficient. Here’s a detailed plan:
Goal: Develop a comprehensive reporting system that allows users to generate expense reports based on different filters (e.g., date ranges, categories, or types of expenses). User Commands: /generate_report – generate reports based on user-specified criteria. /list_reports – view past generated reports. /delete_report – delete an existing report.
Command Inputs: Users should specify filters like date range (start_date, end_date), expense category (e.g., subscription, utility), and report format (CSV, PDF). Output Formats: Allow for multiple formats, including plain text (for quick viewing in Discord), CSV (for download), and PDF (formatted report). Security Considerations: Ensure reports only access and display data belonging to the requesting user. Data Persistence: Store generated reports temporarily for retrieval and management through commands like /list_reports and /delete_report.
Add a reports table in the database to keep track of user-generated reports, including metadata (e.g., user_id, creation_date, filters, file_path). Review the current database schema (referencing /mnt/data/src-utils-db.md) and design the migration file (/mnt/data/src-migrations-migrate_database.md) to support this new table structure. Command Handling: Implement new command handlers (/mnt/data/src-commands-) for: /generate_report: To process the user's filters and generate reports. /list_reports: To retrieve and display the list of available reports for the user. /delete_report: To delete a specific report based on user input. Report Generation Utility: Develop a utility function for generating reports. This function will pull data from the database, apply filters, and format the output in various formats (text, CSV, PDF). This should be placed under the utils module (/mnt/data/src-utils-). File Storage: Store generated reports securely, ensuring file paths and permissions are handled appropriately. Consider adding file path validations for security.
Review the existing command interaction patterns in /mnt/data/6_interaction-flow.md to ensure consistency. The /generate_report command should have a dynamic interaction flow: User inputs /generate_report. Bot responds with options (filters) and formats. User selects or inputs values, and the bot confirms and generates the report. The /list_reports and /delete_report commands should use interactive menus for selection, maintaining a coherent user experience.
Phase 1: Database & Utility Implementation Implement database migration for the reports table. Develop the core utility for report generation, including data extraction and formatting modules. Phase 2: Command Development Implement /generate_report, ensuring it integrates with the new utility and database schema. Implement /list_reports and /delete_report, allowing users to manage reports seamlessly. Phase 3: Testing & Integration Perform unit and integration testing for each command and the report generation utility. Test the command flow in a local Discord environment to ensure smooth interaction and output.
Modular Design: Keep the report generation logic separate from command handling to ensure reusability and modularity. This follows the modular structure outlined in /mnt/data/9_project-structure.md. Error Handling: Implement robust error handling in the utility and command layers to manage potential issues like invalid dates or database connection failures gracefully. Localization Support: Ensure that messages and errors are compatible with the multilingual support system introduced in feature/multilingual-support-expansion. Refer to /mnt/data/src-utils-lang.md to integrate translated messages into the new commands. Logging: Integrate logging for report generation activities to help with troubleshooting and audit trails. Follow patterns established in /mnt/data/3_best-practices.md for consistent logging.
Strengths: . Enhances user engagement by providing useful insights. . Leverages existing database and command patterns for consistent development. Weaknesses: . Complexity in formatting reports across multiple formats (text, CSV, PDF). . Potential performance concerns if queries and report generation are not optimized. Opportunities: . Opportunity to introduce more analytics features in the future (e.g., monthly summaries, visual graphs). . Can expand the feature to include automatic monthly reports for users. Threats: . Potential scalability challenges as the user base grows; might need optimizations in data handling. . Security concerns regarding file storage and access must be carefully managed.
Develop unit tests for each module, particularly focusing on the report generation utility to verify the accuracy of data aggregation and formatting. Perform integration tests for the commands in a local Discord environment. Ensure edge cases (e.g., invalid date ranges, no data matching filters) are handled gracefully. Conduct a code review to ensure adherence to standards and best practices outlined in /mnt/data/7_algorithms-and-math.md.
Update the documentation for new commands and utilities following the existing structure. Ensure clear usage examples are provided. Update architecture and project structure documentation to include the new reports module and the associated files and commands (/mnt/data/4_architecture.md, /mnt/data/5_components.md).
To implement the feature/expense-reports while following the KISS (Keep It Simple, Stupid) and YAGNI (You Aren't Gonna Need It) principles, we need to maintain simplicity and avoid unnecessary complexity. We should build only what is necessary to fulfill the core functionality of expense reporting. Here’s how we will structure the new and updated files, ensuring minimalistic and efficient implementation:
src/commands/generate_report.py
Command to handle /generate_report.
src/commands/list_reports.py
Command to handle /list_reports.
src/commands/delete_report.py
Command to handle /delete_report.
src/utils/report_generator.py
csv
for CSV and reportlab
for PDF.src/utils/file_manager.py
src/migrations/add_reports_table.py
Database migration script to add the reports table.
report_id
, user_id
, creation_date
, filters
, and file_path
.src/commands/init.py
/generate_report
, /list_reports
, /delete_report
).src/utils/db.py
insert_report
).get_reports_by_user
).delete_report
).src/utils/lang.py
tests/test_commands/test_generate_report.py
Test for the /generate_report command, covering:
tests/test_commands/test_list_reports.py
Test for the /list_reports command, ensuring:
tests/test_commands/test_delete_report.py
Test for the /delete_report command:
tests/test_utils/test_report_generator.py
Test cases for generating reports:
tests/test_utils/test_file_manager.py
Test cases for file management, including:
src/migrations/migrate_database.py
add_reports_table.py
) as part of the migration process.KISS: We avoid complex abstractions and keep each component focused on its primary responsibility. For instance:
report_generator
utility is focused solely on fetching and formatting data.file_manager
utility handles file storage and deletion without unnecessary complexity.YAGNI: We build only the necessary features:
report_generator
, file_manager
) needed for report generation and file handling.This structure ensures a minimalistic and efficient addition to the existing project while adhering to our good practices.
For a modular and progressive development approach, we want to build the new feature step by step, ensuring each component is functional and tested before moving on to the next. This helps in maintaining code quality, catching issues early, and keeping the development cycle efficient. Here's the best order to work on these files:
Start with the database and core utilities as these form the foundation of the feature. Without these components, the commands and tests would not function correctly.
src/migrations/add_reports_table.py
src/utils/db.py
insert_report
, get_reports_by_user
, and delete_report
.tests/test_utils/test_database.py
to confirm these functions work as expected.Once the database foundation is in place, build the core utilities responsible for the feature's functionality.
src/utils/report_generator.py
tests/test_utils/test_report_generator.py
for each format to ensure data is correctly aggregated and formatted.src/utils/file_manager.py
tests/test_utils/test_file_manager.py
to ensure files are stored, retrieved, and deleted correctly.With the core utilities functional and tested, move on to implementing the commands. This ensures that the commands can correctly leverage the underlying utility functions.
src/commands/generate_report.py
/generate_report
command, tying together user input, report generation, and output delivery.report_generator
to produce the report and use file_manager
for storage if necessary.tests/test_commands/test_generate_report.py
to validate various inputs and ensure correct report generation and user response.src/commands/list_reports.py
/list_reports
command, displaying available reports for the user.tests/test_commands/test_list_reports.py
to verify report listing, including cases where no reports exist.src/commands/delete_report.py
/delete_report
command for removing reports.delete_report
function) and the file system (file_manager
utility).tests/test_commands/test_delete_report.py
to confirm that reports are correctly deleted from both the database and file system.After building the core functionality, ensure that localization is correctly implemented for multilingual support.
src/utils/lang.py
and src/lang/en/reports_commands.json
src/commands/__init__.py
/generate_report
, /list_reports
, /delete_report
).docs/commands.md
docs/database.md
File Created: src/migrations/add_reports_table.py
Purpose: Establish the schema for the reports table, which will store information about reports logged by users.
Table Structure:
report_id
: Auto-incremented primary key for each report.user_id
: ID of the user who created the report.creation_date
: Timestamp indicating when the report was created (defaults to the current timestamp).filters
: A text field to store any filters used when generating the report.file_path
: The path to the file where the report is stored.Migration Logic:
Testing:
File Updated: src/utils/db.py
Purpose: Extend the utility functions in this file to support the reports table.
Functions Implemented:
insert_report()
: Inserts a new report into the database and returns its ID.get_reports_by_user()
: Retrieves all reports created by a specific user.delete_report()
: Deletes a report based on its ID.Testing:
Files Created/Updated:
src/commands/log_report.py
src/commands/get_reports.py
src/commands/delete_report.py
Commands Implemented:
log_report
: Logs a report based on user input (report name and file path) and stores it in the database.get_reports
: Fetches and displays all reports created by the user invoking the command.delete_report
: Deletes a report using its ID provided by the user.Challenges Faced:
Testing and Debugging:
log_report
command successfully logged reports and confirmed their entries in the database.get_reports
command was tested and adjusted to properly format and display data retrieved from the database.delete_report
command was tested to ensure that reports could be deleted using the correct ID.Discord Intents Configuration:
Bot Initialization:
config.yaml
file.Full Feature Test:
Debugging Common Errors:
With these steps completed, the bot's database and utility foundation is fully functional, and the related commands work as expected.
feature/expense-reports