Hello I’m creating a habit streak system for my app . I created two dates options sets , one" per day" that sets the current user starting date at " days:+1 and the other one “per week” at "days:+7 depending on the user starting date .
Created also a second date data for a deadline and a button to add +1 to the current habit point only avalaible if the current habit deadline is less than current datetime . If the deadline date is reached the streak is lost
Is there an easier way to make this streak system and how to schedule a reminder ( ex: 1 hour before ) to start the habit , please
You can calculate the streak dynamically, without any workflow scheduling. This is helpful because scheduling workflows/increasing a count in the backend falls apart when deleting activity logs/changing their date of etc.
It’s a little complex but the logic should work.
I will refer to two lists of dates. List of Dates A is a list of every date between the first date the user recorded a something, and the Current date/time.
List of Dates B is the user’s date entries. For an ‘activity’ streak, it’d be Search for Activities:each item’s date:each item rounded down to day:unique elements:sorted by date (ascending)
Generate a list of dates (List of Dates A) that are all dates between the first date and last date you’re checking
Find the most recent ‘missing’ (streak broken) date with ‘List of Dates A:minus list List of Dates B:last item
Find the second most recent missing date with List of Dates A minus list List of Dates B:minus item # (List of Dates A minus List of Dates B:count - 1)
Calculate the days between 3 and 2 (date 3 minus date 2:formatted as days) to calculate the current streak length.
You will find it is easiest to place these expressions in their own groups or use custom events rather than try to create one humongous expression. There are edge cases (e.g no streak at all) that can be accounted for with some simple logic.