App count?

Post your questions and help other users.

Moderator: Martin

Post Reply
Lucy
Posts: 225
Joined: 10 Aug 2019 11:24

App count?

Post by Lucy » 20 Nov 2019 18:38

For a while ive been logging:
-Apps being used
-Times initiated
-Times terminated
And periodically go through the log to see how often a particular app was used, count how many times and add the difference between initiate and tetminate to get the duration of the app process.
This has grown tedious and i was hoping someone can help me make a better logging structure by:
-Adding a counter (increased by 1 every time a particular app initiates)
-having the duration worked out in script rather than manually finding the difference
With these values i can further make a useful app usage flow to not only track app usage but also categorize the top leeching/used app, etc

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: App count?

Post by Martin » 21 Nov 2019 19:44

Hi Lucy,

Sorry, but I can not provide a flow, I can just give some hints:
I recommend playing around with action Script and maps in general. You can likely achieve what you want by storing a map in a global variable. One map could contain the package_name of the started app as the key and the starting count as the value. If the app is not available in the map yet, you can store the value 1 (started the first time). If the map already contains a value, increment the value by 1.
You can also store the duration in a similar way in a second map. Remember the package name of the last started app in a global variable and the triggertime when the app was started in another global variable. When you detect an app started event of another app, calculate the difference between triggertime and the time in the global variable and add the difference in a map.

Regards,
Martin

Lucy
Posts: 225
Joined: 10 Aug 2019 11:24

Re: App count?

Post by Lucy » 22 Nov 2019 23:14

Lol it may be a sloppy code but after some trials and errors, this done exactly what i want...

Code: Select all

if (global_app_count == null)
{
global_app_count = "1";
}
if (global_app_count != null)
{
countit = global_app_count;
}
if (countit != null)
{
addit = countit + 1;
}
global_app_count = addit;
/code]

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: App count?

Post by Desmanto » 23 Nov 2019 06:26

@Lucy : What you want to do is essentially have been done by Google's Digital Wellbeing. I have similar flow to record my learning session per app. I must reach at least 30 minutes per day. When Digital Wellbeing came out, I immediately thought it is almost similar concept, except in reverse. As Digital Wellbeing limit the app usage time, while I encourage more app usage time.

I thought of creating something similar, since DW has been known to drain battery. I disabled it at my phone. So maybe when I got the mood, I will create the similar things.

The concept is very simple, exactly the same as yours and similar to my learning flow. We only need to log the app name, time start, time end; kinda like journal based logging. We can store this in glovar nested list, with the newList(app_name, time start, time end). You don't need to count the app usage, this flow is simply to log the usage and keep adding the log. Then if we want to see the statistic, we can use another flow to read thru the glovar and total all app occurance, count the difference between the start = end, then total the time usage. We can also plot this in widget as a kind of bar chart by modifying the rectangle height. At the end of everyday, dump the glovar to a text file, so we don't pile up the glovar and slowdown all flow. The benefit of using journal based logging, is you get all the data and can process it in anyway you want. You can even specified let's say from monday to friday, how is my app usage habit. Or check only for usage during night or maybe weekend.

=====================
for your script above, it can be simplified as

Code: Select all

global_app_count = if(global_app_count == null) 1 else global_app_count + 1;
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Lucy
Posts: 225
Joined: 10 Aug 2019 11:24

Re: App count?

Post by Lucy » 23 Nov 2019 10:13

Exactly!!!!!!!!!!!! Your description of examples is exactly what i am making (word for word) almost, like you knew exactly what i was thinking.
I have already done a flow but with that old messy code. I will use list and go with you guys! As forvwidget, it is already in development. I have most of my main script operators, commands, glovars, etc created and stored. Just need to tweek, merge really. If i get this working the way i want it then it will be powerful in the shadows of googles security policies and not to mention, useful. I refuse to use other third party apps. That is why i started using this app. It has replaced almost my entire app drawer. Anyway... ima work on that.... thanks guys.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: App count?

Post by Desmanto » 23 Nov 2019 13:45

I am a psychic now 8-) I surely will take a look later for the DW replacement flow.
Last edited by Desmanto on 23 Nov 2019 18:52, edited 2 times in total.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Lucy
Posts: 225
Joined: 10 Aug 2019 11:24

Re: App count?

Post by Lucy » 23 Nov 2019 18:16

🤩

Post Reply