hiyaryan / the-cdj

The Cognitive Distortion Journal (CDJ) is a smart journaling tool that helps remedy distorted thinking. It can feel impossible to follow the CBT technique of labeling distorted thinking and finding alternative modes of thought (i.e. reframing) while cognitive distortions are occurring. The CDJ does that work for you. -- The CDJ is in beta testing!!
https://thecdj.app
2 stars 0 forks source link

Weekly reports. #120

Open hiyaryan opened 5 months ago

hiyaryan commented 5 months ago

Implement weekly reports. Note that #64 should be implemented first as this will require looking at entry documents in the database to build out an aggregation feature that compiles a set of entries to be analyzed for the report.

Consider if this should be automated or if this should be manually requested. It could be both. Start of manual, allow the user to tick a box to automate it. Also, consider how entries before this new feature has been implemented will implement this feature. It might be best to have prior entries in a certain week be manually selected.

This will require a new page and this a new design layout. It should still remain clean and relatively simple. It might be nice to have this layout as a single column page with a loading scroll and ability to search for reports by date and tags which should be listed (and should be the cognitive distortion itself).

This will also require a new Reports model, that references different types of reports. For this one, the model will be WeeklyReports. Potential designs for these new models will be discussed here.

hiyaryan commented 4 months ago

Reports API Design

The CDJ Reports Architectural flow for requesting a weekly report. This can be generalized to all types of reports generated by GPT.

Summary

The client requests a weekly report to the CDJ API (backend). The CDJ backend evokes the Assistant/CdGPT object that prompts the GPT. The GPT interfaces with the Assistant/CdGPT object that makes an API request to a private (/reports) route on the CDJ backend. The CDJ API (/weekly) endpoint pulls from MongoDB returning the data to Assistant/CdGPT. The Assistant/CdGPT prompts GPT with the requested data. GPT analyzes the data then generates a serialized (json) report. The report is then sent back down the stack to the client.

Note on Cost

Note that this process can be costly, particularly if there are lot of entries posted that week. To reduce the server compute and the GPT token cost, there should be a rate limit applied to this endpoint (/weekly). A a once-per-week rate is reasonable. This could either be different for each account based on when it was created, or it can be standardized (e.g. for all accounts on Sunday).