Algabraeic expression help with stats

Hi all,

I’m a bit stuck on how to build this expression.

Some context:

I have a data type that tracks whenever a User subscribes and unsubscribes from a Creator. This is captured whenever the User toggles on/off to follow that subscriber. It’s stored as a yes/no field called action.

What I get is, in some cases, a series of yes, no, yes, no, yes, no, yes for a single User who is a bit too trigger happy while they subscribe/unsubscribe from a Creator.

What I want to do is get the final decision the user had for each day so that I can display it (eventually) in a chart for Creators. This will give them a sense of the trend of subscribers they have over time.

What I’m thinking is that I’ll have to look for the :last item somehow for the day for the Creator and unique Users.

My Stats dt has two custom fields: action (yes/no) and creator (Creator).

Does anyone a sense of how to get this data to display?

:pray:

Hi there, @nunesr… I could be missing something here, but couldn’t you simplify things by creating a thing in the Stats data type when a user flips the toggle to subscribe to a creator and (only when) a count of things created by the current user with the specific creator is 0? Then, if the user flips the toggle to unsubscribe from a creator, search for the thing I just described and delete it. So, in short, you get rid of the action concept, and you only ever have one thing in the Stats data type for any user/creator combination.

It seems like what I described would be a “cleaner” way to go, and it should make getting the stats a lot easier.

Hope this helps.

Best…
Mike

1 Like

This is super helpful, thanks for sharing. Going into my box to chew on this for a bit and come back.

1 Like

I’m back out of my hole @mikeloc

Here’s a specific use case that your suggestion might conflict with.

Let’s say that the Creator has a dashboard with a line chart that shows their subscription analytics over time.

If I use your suggestion, it would delete the historical data completely from the database. So their historical data can look different every time someone decides to unsubscribe.

Ideally, I’d like to show a view of when people are subscribing/unsubscribing over time.

What do you think?

When they click subscribe/unsubscribe, you’ll have two workflows (Make one of these then Right click-> Copy/paste and modify the other one):

WF 1
Only when condition: Do a search for Stat with the constraints
Creator = Current User
Created date ≥ Current date/time: rounded down to date
Created date < Current date/time: rounded down to date: +(days) 1

After the search do :count > 0
So this passes if it finds an existing stat for today for the current user

Action
Make changes to Stat
Do a search for Stat with the constraints
Creator = Current User
Created date ≥ Current date/time: rounded down to date
Created date < Current date/time: rounded down to date: +(days) 1
then do :first item
And change the Action field to This Stat's Action is "no"

So if it was “no” already, it returns a yes and sets it to yes.
If it is yes already, it returns a no and sets it to no.


WF 2
Same thing but :count is 0
This passes if it doesn’t find a Stat for today by the current user

Action
Create a Stat
Set the Action field to Do a search for Stat with the constraints
Creator = Current User
Sorted by Creation date, descending no, then do :last item's Action is "no"

So it finds the last one in the database by the current user, and sets this newly created one as the opposite of the last one.

1 Like

Thanks, @tylerboodman back in my hole I go.

1 Like

And this would still be separate from their actual Subbed/not subbed status. So when they click you can have your other logic (probably two more workflows) creating/deleting a Subscription, this is for logging in the background but not over-logging if they get trigger happy

1 Like

That makes sense.

Right now it’s definitely over-logging and it’s running as a backend workflow.

I’ll try this out and see if I don’t break everything. :grimacing:

1 Like

So far this looks great. I’m going to try again tomorrow to make sure that the dates work well (because I’m not sophisticated enough to test in smaller time windows :laughing:)

Here are some screenshots for others to reference based on what @tylerboodman shared:

Keep in mind that I put these into 4 total actions within existing backend workflows I already had. YMMV

This example is the subscribe workflow. Duplicate the actions below and change the action to tono for the unsubscribe workflow
image

Action 1:
image

action value
image

Only when
image

Action 2:
image

Thing to change:
image

Only when
image

1 Like

Great!
If you modify all the constraints Created date <and change it to Current date/time + minutes (5) then it would modify the last Stat within 5 minutes, otherwise it would make a new one

Also switch those all to :rounded down to date not :day

Date is 00:00, Day is 8:00 I believe

1 Like

I ended up only testing today and it’s working as expected :smiley:

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.