Tracking streaks

Options
Hi community!

I'm working on a journaling app and want to add in a function that counts streaks, eg. for how many days are there entries from a specific user.

How can I set up an API with some functions that counts entries in a database but only if they are dated concurrently in the past from yesterday. 

Thanks!

Comments

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    THere are a few ways to handle this. Here's one: select all entries from the current user, limiting the fields in your output to just the create date for performance reasons, and sort by date descending. Then in your function stack, create variables "previous" and "counter." Loop over your result from the query. Compare this entry with the previous - are they same day? leave counter alone. Are they one day apart? tick counter up by one. are they more? Break the loop. Then (assuming loop isn't broken this round) set previous to current and then go around again.

    The result should be a counter of the contiguous days of records as of the present day. It should be pretty cheap to run.

    I appreciate I packed some stuff in there - looping logic can get complex! Let me know if you have qs or want to book a 1-1 session to look at your situation in detail. 
  • Steve Wright-2225084
    Options
    Thanks Ray! I'll take a look at this method and if I need any more help I'll book in a session :) 
  • Steve Wright-2225084
    Options

    Hi Ray!


    I've started setting this up and could use some instruction, can you share some details on booking a 1 on 1? Thanks!

    Steve

  • Steve Wright-2225084
    Options

    @Ray Deck Just tagging you in response to the above :)

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    @Steve Wright-2225084 thanks for the heads-up! I now run a group mentoring program with daily office hours that you might find helpful: State Change Pro. It's a more affordable access to more frequent help. I have 1-1 sessions too, but you might get more bang for less buck by starting with the office hours approach. The next one is at 6 pm EST this evening - join us!

  • Steve Wright-2225084
    Options

    Thanks @Ray Deck this sounds exactly what I need! I'm back in the office in a few weeks and will sign up and join!

    Thanks buddy.