It is currently October 15th, 2019, 7:59 pm

Converting EPOCH time

Discuss the use of Lua in Script measures.
User avatar
jsmorley
Developer
Posts: 19558
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Converting EPOCH time

jsmorley » December 15th, 2017, 6:57 pm

While executing this function on each update of the String uses almost no resources, you could "perfect" it from that standpoint by:

Code: Select all

[MeasureTransactions]
Measure=Plugin
Plugin=WebParser
URL=https://vertcoin.easymine.online/json/minertx.php?address=#RxAddress#
RegExp=(?siU):\[\{"ts":(.*),"type".*","amount":"(.*)",.*,"balance":"(.*)".*\{"ts":(.*),"type".*","amount":"(.*)",.*,"balance":"(.*)".*\{"ts":(.*),"type".*","amount":"(.*)",.*,"balance":"(.*)".*\{"ts":(.*),"type".*","amount":"(.*)",.*,"balance":"(.*)".*\{"ts":(.*),"type".*","amount":"(.*)",.*,"balance":"(.*)"
UpdateRate=120
FinishAction=[!SetOption MeterTXOneTime Text "[&MeasureConvertTime:ConvertTime([&MeasureTXOneTime])]"]

...

[MeterTXOneTime]
Meter=String
MeterStyle=styleRightText
X=230
Y=20r
H=50
Then the result is only asked for and set on each UpdateRate of the parent WebParser measure, and no DynamicVariables is needed on the String meter. Same result, slightly more efficient.
User avatar
balala
Rainmeter Sage
Posts: 8823
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Converting EPOCH time

balala » December 15th, 2017, 7:06 pm

jsmorley wrote:Not really a disadvantage as such, but just not the logical way to do it in my view. You want the result "on demand", as requested by the String meter. The inline function approach is clean and simple. When the String meter is updated, it asks for the result and uses it.

If you use Update(), you will get at least one execution that can't possibly return a valid result, as when the Lua Script measure is executed the first time on load / refresh, there can't be any value for the WebParser measure. So even with UpdateDivicer=-1 you will get one invalid / empty response. You can set UpdateDivider=-1 and Disabled=1 on the Lua measure, and have a FinishAction on the WebParser parent enable and update it, but seems like a lot of effort.

There are lots of ways you can get this result, but I feel like what I did is the simplest and uses the least code.
Oh, I see, thanks for the details.
User avatar
Swiftzn
Posts: 13
Joined: December 13th, 2017, 9:07 am

Re: Converting EPOCH time

Swiftzn » December 18th, 2017, 11:47 am

Thank you both
User avatar
Swiftzn
Posts: 13
Joined: December 13th, 2017, 9:07 am

Re: Converting EPOCH time

Swiftzn » December 18th, 2017, 9:46 pm

jsmorley wrote:While executing this function on each update of the String uses almost no resources, you could "perfect" it from that standpoint by:

Code: Select all

[MeasureTransactions]
Measure=Plugin
Plugin=WebParser
URL=https://vertcoin.easymine.online/json/minertx.php?address=#RxAddress#
RegExp=(?siU):\[\{"ts":(.*),"type".*","amount":"(.*)",.*,"balance":"(.*)".*\{"ts":(.*),"type".*","amount":"(.*)",.*,"balance":"(.*)".*\{"ts":(.*),"type".*","amount":"(.*)",.*,"balance":"(.*)".*\{"ts":(.*),"type".*","amount":"(.*)",.*,"balance":"(.*)".*\{"ts":(.*),"type".*","amount":"(.*)",.*,"balance":"(.*)"
UpdateRate=120
FinishAction=[!SetOption MeterTXOneTime Text "[&MeasureConvertTime:ConvertTime([&MeasureTXOneTime])]"]

...

[MeterTXOneTime]
Meter=String
MeterStyle=styleRightText
X=230
Y=20r
H=50
Then the result is only asked for and set on each UpdateRate of the parent WebParser measure, and no DynamicVariables is needed on the String meter. Same result, slightly more efficient.
Only problem with this is i have 4 other meters that will be calling the convert, so your previous answer would probably be the best bet
User avatar
Swiftzn
Posts: 13
Joined: December 13th, 2017, 9:07 am

Re: Converting EPOCH time

Swiftzn » December 18th, 2017, 9:53 pm

I keep getting this every time i use the inline option
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 19558
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Converting EPOCH time

jsmorley » December 19th, 2017, 12:35 am

Swiftzn wrote:I keep getting this every time i use the inline option
Make sure you have DynamicVariables=1 on the meters.
User avatar
Swiftzn
Posts: 13
Joined: December 13th, 2017, 9:07 am

Re: Converting EPOCH time

Swiftzn » December 19th, 2017, 9:45 am

So this is what my meter looks like

Code: Select all

[MeterTXOneTime]
Meter=String
Text=[&MeasureConvertTime:ConvertTime([&MeasureTXOneTime])]
MeterStyle=styleLeftText
X=15
Y=25r
W=125
DynamicVariables=1
My LUA Measure

Code: Select all

[MeasureConvertTime]
Measure=Script
ScriptFile=ConvertTime.lua
My Lua Script

Code: Select all

function ConvertTime(n)

   return os.date('%B %d %Y %H:%M:%S', n)

end
Still results in not evaluating the inline LUA call.
User avatar
jsmorley
Developer
Posts: 19558
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Converting EPOCH time

jsmorley » December 19th, 2017, 12:44 pm

You using Rainmeter 4.1?
User avatar
Swiftzn
Posts: 13
Joined: December 13th, 2017, 9:07 am

Re: Converting EPOCH time

Swiftzn » December 19th, 2017, 1:57 pm

wow my bad.

Didn't realize Inline lua was only release in november.. was running rainmeter 4.0 all fixed thanks
User avatar
jsmorley
Developer
Posts: 19558
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Converting EPOCH time

jsmorley » December 19th, 2017, 2:05 pm

Swiftzn wrote:wow my bad.

Didn't realize Inline lua was only release in november.. was running rainmeter 4.0 all fixed thanks
Great. I do encourage you to stay current with at least the latest "release" version of Rainmeter, and to be honest I strongly encourage staying current with the latest beta version. Almost everything I do in helping here on the forums will assume that at a minimum you have the latest release, and while I will try to warn, I will use features from the latest beta if I think they help.

Inline Lua is a big deal...