It is currently March 28th, 2024, 10:41 am

code simplification

Get help with creating, editing & fixing problems with skins
User avatar
Active Colors
Moderator
Posts: 1251
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany
Contact:

Re: code simplification

Post by Active Colors »

eclectic-tech wrote: July 13th, 2020, 8:18 pm Yes, not in native Rainmeter, but it can be easily accomplished using a template, and the Lua string:gsub function (as described by JSMorley) to replace 'incremental' values.
If their case is like in the first post then it is possible in native Rainmeter.
User avatar
AnimaliX
Posts: 33
Joined: August 22nd, 2016, 9:22 pm

Re: code simplification

Post by AnimaliX »

Active Colors wrote: July 13th, 2020, 8:00 pm It is possible to do it . Can you send your example code?
its nothing complicated, but that more annoying if you parsing lots of strings > for example:

Code: Select all

[Measure01]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=1

[Meter01]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure01
Y=-3

[Measure02]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=2

[Meter02]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure02

[Measure03]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=3

[Meter03]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure03

[Measure04]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=4

[Meter04]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure04

[Measure05]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=5

[Meter05]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure05

[Measure06]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=6

[Meter06]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure06

[Measure07]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=7

[Meter07]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure07

[Measure08]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=8

[Meter08]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure08

[Measure09]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=9

[Meter09]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure09

[Measure10]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=10

[Meter10]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure10

[Measure11]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=11

[Meter11]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure11

[Measure12]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=12

[Meter12]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure12

[Measure13]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=13

[Meter13]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure13

[Measure14]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=14

[Meter14]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure14

[Measure15]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=15

[Meter15]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure15

[Measure16]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=16

[Meter16]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure16

[Measure17]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=17

[Meter17]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure17

[Measure18]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=18

[Meter18]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure18

[Measure19]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=19

[Meter19]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure19

[Measure20]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=20

[Meter20]
Meter=STRING
MeterStyle=StyleItem
MeasureName=Measure20
Last edited by AnimaliX on July 13th, 2020, 8:40 pm, edited 1 time in total.
User avatar
Active Colors
Moderator
Posts: 1251
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany
Contact:

Re: code simplification

Post by Active Colors »

AnimaliX wrote: July 13th, 2020, 8:33 pm for example:
Let me just clarify this. You use all the measures and meters at the same time? So, all the measures from 01 to 20 are operating in the skin at the same time, right?
User avatar
AnimaliX
Posts: 33
Joined: August 22nd, 2016, 9:22 pm

Re: code simplification

Post by AnimaliX »

yes, that example is base (.inc) which is included to skin (.ini) for webparsing RSS sources - 10-20 items per one skin
Last edited by AnimaliX on July 14th, 2020, 7:36 am, edited 1 time in total.
User avatar
Active Colors
Moderator
Posts: 1251
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany
Contact:

Re: code simplification

Post by Active Colors »

AnimaliX wrote: July 13th, 2020, 8:43 pm yes, that example is base (.inc) which is included to skin (.ini) for webparsing RSS sources - 10-20 items in one skin
I can help you with simplifying your meters further but the measures should be approached in a different way because there are no MeasureStyles, which would be handy here. Maybe devs will make it someday.
Let me think for a while if I can simplify the measures.
User avatar
Active Colors
Moderator
Posts: 1251
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany
Contact:

Re: code simplification

Post by Active Colors »

Active Colors wrote: July 13th, 2020, 9:09 pm I can help you with simplifying your meters further but the measures should be approached in a different way because there are no MeasureStyles, which would be handy here. Maybe devs will make it someday.
Let me think for a while if I can simplify the measures.
I combined my technique of accessing current section indexes with !SetOptionGroup. I don't have an example skin with webparser measures to test but I tried with calc measures and it works. I have readopted your code example (didn't test but supposedly should work) and it looks like this:

Code: Select all

[Variables]
Measure=
Meter=


[StyleItem]
MeasureName=#*Measure*#[#CURRENTSECTION]

[StyleMeasure]
Measure=Calc
Formula=1
OnUpdateAction=[!SetOptionGroup GroupMeasure Url "[&*Feed*]"][!SetOptionGroup GroupMeasure Substitute "#*Substitute*#"][!SetOptionGroup GroupMeasure RegExpSubstitute "1"][!SetOptionGroup GroupMeasure StringIndex "[#*CURRENTSECTION*]"][!UpdateMeasureGroup GroupMeasure][!Redraw]
UpdateDivider=-1


[#Measure#1]
Measure=WebParser
Group=GroupMeasure 

[#Measure#2]
Measure=WebParser
Group=GroupMeasure 

[#Measure#3]
Measure=WebParser
Group=GroupMeasure 


[#Meter#1]
Meter=String
MeterStyle=StyleItem
Y=-3

[#Meter#2]
Meter=String
MeterStyle=StyleItem

[#Meter#3]
Meter=String
MeterStyle=StyleItem
1. By enclosing section names into variables and establishing those variables as empty variables you can access section indexes that are outside of the enclosed, so in this example I was able to simplify StringIndexN in MeasureN and MeasureNameN in MeterN.
2. Since there is no MeasureStyles you can keep your template key=value pairs somewhere in OnUpdateAction with UpdateDivider=-1 to make it set the key=value pairs once during skin load/refresh, and using !SetOptionGroup you hit all the necessary measures with just one bang. Utilizing current section name index technique you don't need to indicate the same numbers as in section names like in StringIndex.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5380
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA
Contact:

Re: code simplification

Post by eclectic-tech »

Active Colors wrote: July 13th, 2020, 11:08 pm I combined my technique of accessing current section indexes with !SetOptionGroup. I don't have an example skin with webparser measures to test but I tried with calc measures and it works. I have readopted your code example (didn't test but supposedly should work)
...
Sorry, but how is this a simplification?

You still nave to create 20 measures and 20 meters, yes they are smaller, but it take almost as long to write these as it would be to write the measures using the actual numbers and stringindexes and the meters with styles.

What if you also want the pub date, link, author, description, etc.?
Now you are writing ~100 measures and ~100 meters! (99 is the webparser limit)

In the example given, by creating just 2 single-section templates, you can create as many measures/meter as needed...

RSSMeasureTemplate:

Code: Select all

[MeasureRepeat#]
Measure=WebParser
Url=[Feed]
Substitute=#Substitute#
RegExpSubstitute=1
StringIndex=Repeat#
RSSMeterTemplate:

Code: Select all

[MeterRepeat#]
Meter=STRING
MeterStyle=StyleItem
MeasureName=MeasureRepeat#
Every instance of 'Repeat#' will be replaced by an incrementing value by the Template generator scripts, and repeated as many times as desired to create the measures and meters, then those files are saved in @Resources for use in the skin.

In the case of more captures, you can use a formula for the index numbers and write 5 measure sections and 5 meter sections in the template.

Would you rather write 100 measures and 100 meters, even if they are only a few lines, or 5 of each?

To see this working in an RSS skin that captures Title, Pubdate, Description, and Link look at my Template Google News skin.

Aside: I will step aside and let this subject rest. I am not good at explaining my personal method and many people may find this too involved to be useful for them.
User avatar
AnimaliX
Posts: 33
Joined: August 22nd, 2016, 9:22 pm

Re: code simplification

Post by AnimaliX »

Active Colors wrote: July 13th, 2020, 11:08 pm I combined my technique of accessing current section indexes with !SetOptionGroup. I don't have an example skin with webparser measures to test but I tried with calc measures and it works.
@Active Colors, thanks for interesting approach maybe something can be used
eclectic-tech wrote: July 14th, 2020, 1:38 am To see this working in an RSS skin that captures Title, Pubdate, Description, and Link look at my Template Google News skin.
@eclectic-tech, I looked on your script before and yes, without simple counter script this cant be done (probably)


but result for all of this is the same, there still isnt simple way how do this... maybe in future :)
Last edited by AnimaliX on July 14th, 2020, 2:55 pm, edited 1 time in total.
User avatar
Active Colors
Moderator
Posts: 1251
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany
Contact:

Re: code simplification

Post by Active Colors »

AnimaliX wrote: July 14th, 2020, 8:10 am @Active Colors, thanks for interesting approach maybe something can be used

@eclectic-tech, yes, I looked on your script before and I believe that without similar small "counter" script this cant be done

but result for all of this is the same, there still isnt simple way how do this... maybe in future :)
Well I didn't know what you assumed by simplification.

You can see if the ignition technique is a use for you. There I have made an example for creating Variables, and in the same way you can use it for creating meters and measures.

For example:

Code: Select all

[MeasureIgnition]
Measure=Calc
Formula=MeasureIgnition+1
OnUpdateAction=[!WriteKeyValue Measure[MeasureIgnition] StringIndex [MeasureIgnition]][!WriteKeyValue Meter[MeasureIgnition] MeasureName Measure[MeasureIgnition]][!UpdateMeasure MeasureIgnition]
Disabled=1
IfEqualValue=20
IfEqualAction=[!DisableMeasure MeasureIgnition][!Refresh]
DynamicVariables=1
This will create 20 measures and meters from Measure1/Meter1 to Measure20/Meter20 with the corresponding StringIndex number and MeasureName reference. This particular code is launched with [!EnableMeasure MeasureIgnition] bang but it can be adopted to your needs and expanded as you like.
User avatar
Yincognito
Rainmeter Sage
Posts: 7017
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: code simplification

Post by Yincognito »

This is a great thread, actually, because it "aggregates" various methods of either automating or templating measure or meter creation. While I knew of both eclectic-tech and Active Colors methods, and was aware that they were both ingenious and working in what they are expected to do, AnimaliX is right: neither of them is simple for a beginner, especially one looking not just to use them, but also to understand every bit of them, plus, they both create those measures and meters one way or another (either manually or automatically), so in the end the outcome is the same: hundreds of measures and meters will be present in the final code.

My method takes a different approach and avoids creating more measures or meters than actually used or displayed at a certain time, by minimizing the amount of meters displayed to just those for a single repetitive set or group (a single or a minimal group of days / day parts in a weather skin, a single or a minimal group of feed items in a feeds skin, etc.), and minimizing the amount of measures present to those absolutely needed for that repetitive set or group. Both the measures and the meters will only output the data for the currently selected or iterated set or group, as the iteration can be relatively easy to achieve by dynamically setting options in the existing measures and meters, in effect reusing them, and controlled by scrolling, clicking some buttons, etc.

That being said, there is no way of avoiding creating (either manually or automatically) the measures and meters one uses at a certain point in time. The only way of avoiding creating hundreds of measures and meters altogether in a skin is by minimizing the amount of actually used ones, really.
Post Reply