It is currently March 28th, 2024, 5:07 pm

Converting EPOCH time

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

Re: Converting EPOCH time

Post by jsmorley »

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: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Converting EPOCH time

Post by balala »

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

Post by Swiftzn »

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

Re: Converting EPOCH time

Post by Swiftzn »

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

Post by Swiftzn »

I keep getting this every time i use the inline option
Attachments
Capture.PNG
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Converting EPOCH time

Post by jsmorley »

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

Post by Swiftzn »

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: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Converting EPOCH time

Post by jsmorley »

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

Re: Converting EPOCH time

Post by Swiftzn »

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: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Converting EPOCH time

Post by jsmorley »

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...
Post Reply