Revisiting addMinutes (and all add with day, hour etc.)

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
husky
Posts: 132
Joined: 29 Oct 2016 13:41
Location: Omaha, Nebraska, USA
Contact:

Revisiting addMinutes (and all add with day, hour etc.)

Post by husky » 23 Sep 2017 13:46

Hello,

I give up. I just can't make a simple addMinutes to work.

Tested:

Code: Select all

 
date_now="{getDate(), dateformat,hhmm}";
min_added= addMinutes(date_now, 2);
Upon displaying on screen I get:

date_now=0828
min_added=120828

Then I tested:

Code: Select all

min_added= addMinutes("{getDate(), dateformat,hhmm}",2);
results in:
min_added=120828

So, my questions:

1. in addMinutes( Date d , Number a)
what should be coded for Date d
2. Why am I getting as result, after adding 2 minutes the value Date d, 120828?
3. Where the 12 came from?
4. Why after adding 2 minutes still shows 120828?

REQUEST:

Can someone show me an example that works as expected. Please don't tell me to use Debug. It's useless in this case.



Thank You


Husky
"Basic research is what I'm doing when I don't know what I'm doing"

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

Re: Revisiting addMinutes (and all add with day, hour etc.)

Post by Desmanto » 23 Sep 2017 14:29

It is working as expected.

When you use

Code: Select all

date_now="{getDate(), dateformat,hhmm}";
You have turn the current time into string, date_now = "0828";

When you add it

Code: Select all

min_added= addMinutes(date_now, 2);
Automagic can't add minutes to string "0828". It doesn't recognize "0828" as number. (using debug dialog, will show it as number, even though it is string). So it just uses its intelligence to guess if the string can be parsed to number. It is the same as using toNumber("0828") before the calculation and resolved into number 828. Since automagic by default count time in miliseconds, this means 828 miliseconds. When you add 2 minutes to it, that means 2 x 60000 miliseconds = 120000. Then 120000 + 828 = 120828. Correct right?

The same with

Code: Select all

min_added= addMinutes("{getDate(), dateformat,hhmm}",2);
Time has been turned to string before adding, will still give the same result.

Those above should have answered question number 2, 3, 4.

For question 1, date should be leave as it. just use

Code: Select all

date_now = getDate();
So to add the minutes, use the same as before. It will give correct result, since the data type of date_now still date, not yet turned to string.

Code: Select all

min_added= addMinutes(date_now, 2);
If you still need to add, minus or manipulate the date, don't turn it to string or any dateformat first. Use it only at the last moment when you are ready to output the data (as toast message, widget or anything).
If possible just leave it as it. At the Notification on screen or widget, just use {date_now,dateformat,hhmm"} instead of just {date_now}. So you never turn it into any dateformat before output it anywhere.
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.

User avatar
husky
Posts: 132
Joined: 29 Oct 2016 13:41
Location: Omaha, Nebraska, USA
Contact:

Re: Revisiting addMinutes (and all add with day, hour etc.)

Post by husky » 23 Sep 2017 19:05

Hello Desmanto,

You just gave me a superior lecture that makes me ashamed of thinking I know how to code AutoMagic flows.
The answer was in front of my nose all the but since my nose is too big, I couldn't see farther that that.
I need to work more on the concepts and pay more attention. The devil is in the details that you explained very well. Kudos for you.

So, I'm now on my way to fully understand when I get me a string or a number. Perhaps some visit to Elementary Java might help.
I was mainframe systems programmer, programming 99.9% of the time in IBM assembler for over 30 years or so any date handling was done the hard way. Coming up with a feasible algorithm and translate it in assembler code. Easier than in any another language for me.

All in all, following your explanation solved the problem. Thank You very much for your explanation and patience with dumb-nuts like me.


Best Regards


Husky

"Basic Research is what I'm do when I don't know what I'm doing" .-
"Basic research is what I'm doing when I don't know what I'm doing"

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

Re: Revisiting addMinutes (and all add with day, hour etc.)

Post by Desmanto » 24 Sep 2017 03:24

Hi Husky,

My journey is still long :) It is just because I am typing the documentation for comparing automagic to tasker, that's why I made a lot of tests.
I got so many insight of how it works. Playing with the script is always fun and challenging.

Regards,
Desmanto
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.

User avatar
husky
Posts: 132
Joined: 29 Oct 2016 13:41
Location: Omaha, Nebraska, USA
Contact:

Re: Revisiting addMinutes (and all add with day, hour etc.)

Post by husky » 25 Sep 2017 14:31

hi,

I agree with you. It IS funny and challenging.

Unfortunately I'm running out of fresh ideas to develop more useful flows. All I could think of with battery issues has been exhausted (or so I think).
Some of them retrieve data (with Control UI) from useful android apps.

I wish there were a way to check CPU behavior. I just can't find any way to get there. Lots of widgets(shortcuts) developed, statistics collection data and so on but no cpu temperature for example.
I guess I'll have to start learning android code but that will possibly my next project for the entire winter.

Testing Automagic against Tasker is a sure way to learn a lot of Automagic.


Regards

Husky
"Basic research is what I'm doing when I don't know what I'm doing"

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

Re: Revisiting addMinutes (and all add with day, hour etc.)

Post by Desmanto » 25 Sep 2017 16:32

I also sometimes run out of idea. :D But so far, 3 and half months since migrated from tasker, I thought I have accomplished more than what I have done in the last 3 years with tasker.
There are many variable parsing which is kinda next to impossible to do in tasker, now can be done in Automagic. So I am revisiting most of my previous project and expand it from there.
Doing something like automatic restart the wifi router every night; connect to router, check the DHCP and scan for any rogue device that is not in the authorized list; logging app usage in minutes perday; these probably very difficult to be done outside of automagic.

I just simply think of something I wish it can be done automatically and proceed with the easiest one first. Later I just make adjustment until it become a flow. Sometimes it is the complexity that makes us lazy to continue the project. So I can chop down to smaller version first, doing it kinda like a small module. Later passing the variable to the next module, finally combined the into single flow.

CPU or any system value can be accessed from /sys/class. But it can be different in each device. Need root to browse the folder and check which one can work. At mine, execute root command

Code: Select all

cat /sys/class/thermal/thermal_zone0/temp
But at my phone, this also work, to check battery temp

Code: Select all

cat /sys/class/hwmon/hwmon1/temp1_input
I don't know how app like CPU-Z can query data without root. But if we know, we can replicate it in automagic.
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.

User avatar
husky
Posts: 132
Joined: 29 Oct 2016 13:41
Location: Omaha, Nebraska, USA
Contact:

Re: Revisiting addMinutes (and all add with day, hour etc.)

Post by husky » 17 Oct 2017 17:44

Hello Desmanto,

Sorry for the late reply. :oops:

Nice to hear from you. Experience comes with 99% of hit-and-miss and 1% sheer luck. :D

Yes, sometimes I think I'm finished with my ideas but somehow I have to dig a bit more and then something new comes up.

Just finishing a flow and widget to extract data from an app using Control UI.
This will give me the status of my phone and Table.

I would suggest is an improvement of the editor.
For example allow me to find and replace all data on the screen. Like Find and changeAll( xxx, "text_1", Text_x") all over the flow I might need to change. Not the same as "replaceAll" .I could do it making a copy of the flow and using and external editor to do the changes on the exported XML. it might work way but is cumbersome and Not elegant.

I obtain battery temperature by using Battery Level in the flow. From there I use the the supplied variables , Battery_level, Percentage... and so on. No need to access data from root. I developed a small flow that warns me when the battery is overheating. As of CPU-Z I'm not current with this app.
reach. One idea I could suggest if you will , use the Launch App from Automagic and work on it. I'd try that. You gave an idea on how to accomplish this. Will try and get back to you if you wish so. If it works I can send it over to you.

Another is out of our reach. It is the limitation of 4 GB in the phone/tablet. I don't know any android running phone/tablet with memory (RAM) > 4 GB.
One nice thing I found out was the possibility to connect to the laptop and tablet , TeamViewer. Works like a charm with my Samsung tablet . I'll try Teamviewer with Nexus 6P today. I'm using Windows 10 as partner and I can control the laptop from the tablet and the installation is very easy.


Cheers

Husky
"Basic research is what I'm doing when I don't know what I'm doing"

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

Re: Revisiting addMinutes (and all add with day, hour etc.)

Post by Desmanto » 18 Oct 2017 16:40

Hi,

Control UI in automagic is the best implementation of accessibility I have ever used. Sometimes I run some Control UI script just for fun and to test how far it can be done :D

For editing, sometimes I just copy-paste the script to another text editor and edit it there. But most of the time I just edit it directly. Adding find and replace in editing surely will help a lot, especially when we want to change some variable name to avoid overlapping name.

Just realized condition battery level can provide so many data. I don't install CPU-Z all the time, just to take it as example how to access system information without root. But yes, we can use control UI to extract the data and pass back to Automagic. But there will be a small distraction when the flow is running, as it will switch to CPU-Z for a while and come back again to current app.

There are several android phones running with 6 GB RAM already; some of them were from last year phones. I usually just use VNC, but seldom use it now. Most of the simple data communication pass thru HTTP request server from automagic to eventghost. Sharing clipboard or open tab in browser is easy.

Regards,
Desmanto
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.

User avatar
husky
Posts: 132
Joined: 29 Oct 2016 13:41
Location: Omaha, Nebraska, USA
Contact:

Re: Revisiting addMinutes (and all add with day, hour etc.)

Post by husky » 20 Oct 2017 15:01

Hi,

I have very simple and very complicated flows using Launch and then Control UI. Very handy as you can access apps data from the screen.


The other minor issue. I'm trying to solve is the screen that's in background. I need to find a way to click the "x" of the screen used to get the data from.
Some apps, when in the background ( the one hiding from you) leave "garbage" and when executing again the same flow, the results are garbage.
So, I have to "x" click the one hidden(the one I extracted the data) and then run the flow again. I can live with that of annoying part.

Being retired helps me on the development of flows. I have all day to mess with ( or mess up) flows. I wish they would have an editor specific to Automagic in Windows. I waste a lot of time typing the flow directly to the phone or the tablet. That sucks.

See ya later,

Husky
"Basic research is what I'm doing when I don't know what I'm doing"

Post Reply