GeriLife / caregiving

GeriLife is a comprehensive toolkit designed to empower caregivers in elder-care communities, promoting wellness and ensuring equitable engagement in life-enriching activities. This project, rooted in real-world insights and collaborative innovation, aims to transform elder care by making quality-of-life activities visible and coordinated.
European Union Public License 1.2
7 stars 7 forks source link

Implement 'ResidentActivity' Model in New 'Metrics' App for Efficient Data Aggregation #44

Closed brylie closed 12 months ago

brylie commented 1 year ago

Overview

Our current Activity data model, while robust, presents challenges in generating charts and reports due to its complex relationships, particularly the ManyToMany relationship between Residents and Activities. To streamline data aggregation and improve performance, we propose creating a new Django application, metrics, featuring a more efficient data model.

Proposed Model: ResidentActivity

Synchronization with Activity Model

Ensuring data consistency between the Activity and ResidentActivity models is critical. We are considering two approaches:

  1. Custom Django Model Manager:

    • Implement Create, Read, Update, Delete (CRUD) operations within a transaction.
    • Automatically handle ResidentActivity entries whenever an Activity record is modified.
    • Rollback changes if any part of the transaction fails.
  2. Django Signals:

    • Utilize signals to update ResidentActivity entries upon CRUD operations on Activity records.
    • This approach decouples the logic but still ensures data synchronization.

Task Breakdown

  1. Create metrics App: Develop the new Django application within our project.
  2. Model Implementation: Define and implement the ResidentActivity model.
  3. Data Synchronization Strategy: Choose and implement the most suitable method (Model Manager or Signals) for data synchronization.
  4. Testing and Validation: Ensure that the new model accurately reflects changes in the Activity model and that data integrity is maintained.
  5. Performance Benchmarking: Assess the impact on performance and the efficiency of data aggregation.

Next Steps

Once the metrics application and ResidentActivity model are established, we will focus on defining specific metrics and developing visualizations to support caregiving in elder care communities.

Conclusion

This initiative aims to enhance our data handling capabilities, making it easier to generate meaningful insights and reports. The success of this implementation will lay the groundwork for advanced analytics in our caregiving project.

brylie commented 1 year ago

We aim to create a flattened Activities table (ResidentActivity) for more efficient data aggregation and visualization in our Django-based caregiving project. This table should synchronize with the main Activity table and related entities. Our current challenge involves deciding on the most effective method to achieve this synchronization.

Proposed Solutions and Their Trade-offs:

1. Django Signals

2. Custom Transactions in Model Save Method

3. Asynchronous Tasks with Celery

adrienneli104 commented 1 year ago

I agree, could I be assigned to this issue as well then?

adrienneli104 commented 1 year ago

Hey, I finished the metrics app and implemented the stacked bar chart. I manually tested to see if when an activity is created, the resident_activity table is also triggered and the activity is recorded. I wasn't sure how to go about writing tests. I tried using self.client.post to create an activity object. I receive a 200 response but no activity object is created. Could you take a look and help with writing tests?

Also since updating activity isn't currently a feature, I haven't implemented updating resident_activity_table.

https://github.com/adrienneli104/caregiving/tree/aeli_graphs

brylie commented 12 months ago

Great work! Go ahead and open a pull request so I can test the code.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests

adrienneli104 commented 12 months ago

Hey I've made a PR and my teammates have made PRs for the other issues. Would be great if you could test it out sometime!