It is currently April 19th, 2024, 7:30 am

Update ONLY every hour or when loading / refresh-problem

Get help with creating, editing & fixing problems with skins
User avatar
xenium
Posts: 865
Joined: January 4th, 2018, 9:52 pm

Update ONLY every hour or when loading / refresh-problem

Post by xenium »

Hi,
I have a parent webparser measure, which I want to update ONLY every hour or when the skin is loaded or refreshed.

Code: Select all

[MeasureH1]
Measure=WebParser
Url=#URL#
RegExp=.....
.
.
.
Disabled=1
LogSubstringErrors=0
StringIndex=1
RegExpSubstitute=1
Substitute="(\w+):(\w+) (\w+)":"\1\3","am":"ᴬ","pm":"ᴾ"
IfCondition=(MeasureH1 = 1)
IfTrueAction=[!SetVariable X1 "259"][!SetVariable Y1 "95"][!SetVariable X2 "298"][!SetVariable Y2 "135"].......[!SetVariable X12 "201"][!SetVariable Y12 "76"]
.
.
.
IfCondition12=(MeasureH1 = 12)
IfTrueAction12=.......
I added Disabled = 1 to the webparser measure.
I added OnRefreshAction=[!EnableMeasure "MeasureH1"][!UpdateMeasure "H1"], in the [Rainmeter] section.
For update every hour I use jsmorley code:

Code: Select all

[MeasureTime]
Measure=Time
Format=%#M.%#S
IfCondition=(Trunc(MeasureTime) = 0) && (Frac(MeasureTime) = 0)
IfTrueAction=[!EnableMeasure "MeasureH1"][!UpdateMeasure "H1"]
But the webparser measure continues to update and every 10-15 minutes.

How can I solve this problem ?

(Note: If I use UpdateDivider = -1 to the webparser measure, the x and y coordinates are displayed erroneously )
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Update ONLY every hour or when loading / refresh-problem

Post by jsmorley »

Do NOT use UpdateDivider on WebParser measures.
Do NOT use !UpdateMeasure on WebParser measures.
Do NOT use Disabled or !DisableMeasure / !EnableMeasure on WebParser measures.

WebParser measures should be controlled entirely by UpdateRate.

UpdateRate is a counter that tells WebParser how often to go out to the remote resource and get the data. The counter is incremented by 1 each time the parent measure is updated, until it reached the value set for UpdateRate, when it resets to zero and goes out for the data. When the values are retrieved, the parent measure automatically sets the values for all child measures.

UpdateRate does not have a -1 setting equivalent to what works with UpdateDivider, but you can just use a huge number to effectively stop it from going out to the remote resource until directed to.

Then you can use !CommandMeasure to override UpdateRate and force WebParser to go out to the remote resource on demand.
https://docs.rainmeter.net/manual/measures/webparser/#CommandMeasureUpdate
Again, do NOT use !UpdateMeasure on WebParser measures. all that will do is increment the UpdateRate counter by 1.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[MeasureTime]
Measure=Time
Format=%#M.%#S
IfCondition=(Trunc(MeasureTime) = 0) && (Frac(MeasureTime) = 0)
IfTrueAction=[!CommandMeasure MeasureSite "Update"]

[MeasureSite]
Measure=WebParser
URL=https://www.timeanddate.com/worldclock/usa/alexandria
RegExp=(?siU)<span id=ct class=h1>(.*)</span>
UpdateRate=604800
FinishAction=[!UpdateMeter MeterDate][!Redraw]

[MeasureChild]
Measure=WebParser
URL=[MeasureSite]
StringIndex=1

[MeterDate]
Meter=String
MeasureName=MeasureChild
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=It is %1
That will get the time In Alexandria, Virginia when the skin is loaded or refreshed, and after that only when the top of each hour is reached.

Oh, and once a week, when the UpdateRate counter reaches 604800 seconds... Make that number even larger if that bothers you. 31536000 would more or less be once a year...

WebParser works by going out to the remote resource each time the counter controlled by UpdateRate is zero. This will be when the skin is first loaded or refreshed, and when the counter reaches the value of UpdateRate and is started over at zero to start counting again.

Using UpdateDivider or Disabled / Enabled on WebParser parent or child measures is generally not the way to go. All that is done on the update of a WebParser parent measure is that the UpdateRate counter is incremented by 1. Nothing is done on any WebParser child measures on each update, as their values are entirely controlled by the parent. Leave UpdateDivider on all WebParser measure set to the default value of 1.

Note that Disable / Enable CAN be used on WebParser parent measures, perhaps to have a measure that doesn't execute even once on skin load or refresh until it is enabled and updated by the value of some other measure in the skin, but the cases where this makes sense are going to be few, and almost always more trouble than it is worth.
User avatar
xenium
Posts: 865
Joined: January 4th, 2018, 9:52 pm

Re: Update ONLY every hour or when loading / refresh-problem

Post by xenium »

jsmorley wrote: December 27th, 2018, 12:49 pm Do NOT use UpdateDivider on WebParser measures.
Do NOT use !UpdateMeasure on WebParser measures.
Do NOT use Disabled or !DisableMeasure / !EnableMeasure on WebParser measures.

WebParser measures should be controlled entirely by UpdateRate.

UpdateRate is a counter that tells WebParser how often to go out to the remote resource and get the data. The counter is incremented by 1 each time the parent measure is updated, until it reached the value set for UpdateRate, when it resets to zero and goes out for the data. When the values are retrieved, the parent measure automatically sets the values for all child measures.

UpdateRate does not have a -1 setting equivalent to what works with UpdateDivider, but you can just use a huge number to effectively stop it from going out to the remote resource until directed to.

Then you can use !CommandMeasure to override UpdateRate and force WebParser to go out to the remote resource on demand.
https://docs.rainmeter.net/manual/measures/webparser/#CommandMeasureUpdate
Again, do NOT use !UpdateMeasure on WebParser measures. all that will do is increment the UpdateRate counter by 1.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[MeasureTime]
Measure=Time
Format=%#M.%#S
IfCondition=(Trunc(MeasureTime) = 0) && (Frac(MeasureTime) = 0)
IfTrueAction=[!CommandMeasure MeasureSite "Update"]

[MeasureSite]
Measure=WebParser
URL=https://www.timeanddate.com/worldclock/usa/alexandria
RegExp=(?siU)<span id=ct class=h1>(.*)</span>
UpdateRate=604800
FinishAction=[!UpdateMeter MeterDate][!Redraw]

[MeasureChild]
Measure=WebParser
URL=[MeasureSite]
StringIndex=1

[MeterDate]
Meter=String
MeasureName=MeasureChild
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=It is %1
That will get the time In Alexandria, Virginia when the skin is loaded or refreshed, and after that only when the top of each hour is reached.

Oh, and once a week, when the UpdateRate counter reaches 604800 seconds... Make that number even larger if that bothers you. 31536000 would more or less be once a year...

WebParser works by going out to the remote resource each time the counter controlled by UpdateRate is zero. This will be when the skin is first loaded or refreshed, and when the counter reaches the value of UpdateRate and is started over at zero to start counting again.

Using UpdateDivider or Disabled / Enabled on WebParser parent or child measures is generally not the way to go. All that is done on the update of a WebParser parent measure is that the UpdateRate counter is incremented by 1. Nothing is done on any WebParser child measures on each update, as their values are entirely controlled by the parent. Leave UpdateDivider on all WebParser measure set to the default value of 1.

Note that Disable / Enable CAN be used on WebParser parent measures, perhaps to have a measure that doesn't execute even once on skin load or refresh until it is enabled and updated by the value of some other measure in the skin, but the cases where this makes sense are going to be few, and almost always more trouble than it is worth.
Thank you very much for the clarifications ! :bow:
Happy Holidays !
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Update ONLY every hour or when loading / refresh-problem

Post by jsmorley »

xenium wrote: December 27th, 2018, 2:07 pm Thank you very much for the clarifications ! :bow:
Happy Holidays !
Same to you!
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Update ONLY every hour or when loading / refresh-problem

Post by balala »

jsmorley wrote: December 27th, 2018, 12:49 pm Do NOT use Disabled or !DisableMeasure / !EnableMeasure on WebParser measures.
I'd rather say: Do NOT use Disabled or !DisableMeasure / !EnableMeasure on parent WebParser measures.
The child measures can be disabled, then re-enabled when the parent parses the source, with a FinishAction option.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Update ONLY every hour or when loading / refresh-problem

Post by jsmorley »

balala wrote: December 27th, 2018, 2:35 pm I'd rather say: Do NOT use Disabled or !DisableMeasure / !EnableMeasure on parent WebParser measures.
The child measures can be disabled, then re-enabled when the parent parses the source, with a FinishAction option.
Certainly, but you need to be careful about what that buys you. The values for child measures WILL be set by the parent measure when it finishes retrieving and parsing data. The only thing that disabling a child measure really does is stop any evaluation of action options like IfCondition or IfMatch, and since the values only change in conjunction with the parent, those are never going to change from "false" to "true" unless the parent changes. There is just limited value to this in my view. Any thought about maximizing efficiency is really beyond even my normal "anal retentive", as the amount of work that is done to test a value for a condition is so small as to approach nothing. The actual "actions" that might be fired by the test, which I suppose could be "expensive", will never be fired unless they "should" be fired.

If you have this:

Code: Select all

[MeasureSite]
Measure=WebParser
URL=https://www.timeanddate.com/worldclock/usa/alexandria
RegExp=(?siU)<span id=ct class=h1>(.*)</span>
UpdateRate=604800
FinishAction=[!UpdateMeter MeterDate][!Redraw]

[MeasureChild]
Measure=WebParser
URL=[MeasureSite]
Disabled=1
UpdateDivider=-1
StringIndex=1
The value of MeasureChild WILL be set and seen by any meter as the value returned by the parent. Disabled accomplishes nothing. UpdateDivider accomplishes nothing. The setting of the child measure's value is not done by the child measure. It is done by the parent.

Except for very limited circumstances, as I mentioned in my original answer, I am opposed to any use of UpdateDivider or Disabled/Enabled with WebParser. Just use UpdateRate to control things, and let WebParser be WebParser...

Make no mistake, UpdateDivider and Disabled work with WebParser, and I can imagine some hideously complicated construct where they might be of use, but very, very rarely. The better approach, certainly for anyone at all new to Rainmeter / WebParser, is to just consider those out of bounds for controlling things. Let the measures all update on each Update of the skin, and control the flow of things with UpdateRate and if needed, !CommandMeasure.

Setting UpdateDivider on a WebParser child measure makes literally no sense, ever, and setting Disabled on a WebParser child measure makes no sense in 99% of cases. Generally only if you don't want action options on child measures evaluated at all until the parent measure has a chance to retrieve data the first time. Where the initial string value of "" and number value of 0 would cause problems. Note that in my original answer, I didn't say "CAN NOT", but rather "DO NOT".