It is currently May 3rd, 2024, 6:35 pm

Use 'Calculate' to extract hightest or lowest value

Get help with creating, editing & fixing problems with skins
methyer
Posts: 4
Joined: March 3rd, 2012, 7:54 pm

Use 'Calculate' to extract hightest or lowest value

Post by methyer »

Hello dear fellow designers and skinners,

I have been doing quite well on my own so far, but have reached a certain dificulty lately:
My intent is to determine the lowest (and, separately, the highest) value out of a wide range of values, while making use of the following calculation formula:

Code: Select all

[CalcLowestTemp]
Measure=CALC
Formula=(Day0TempLow <= Day1TempLow ? (Day1TempLow <= Day2TempLow ? (Day2TempLow <= Day3TempLow ? (Day3TempLow <= Day4TempLow ? (Day4TempLow <= Day5TempLow ? (Day5TempLow <= Day6TempLow ? (Day6TempLow <= Day7TempLow ? (Day7TempLow <= Day8TempLow ? (Day8TempLow <= Day9TempLow ? (Day9TempLow <= Day10TempLow ? (Day10TempLow <= Day11TempLow ? (Day11TempLow <= Day12TempLow ? (Day12TempLow <= Day13TempLow ? (Day13TempLow <= Day14TempLow ? Day14TempLow) : Day13TempLow) : Day12TempLow) : Day11TempLow) : Day10TempLow) : Day9TempLow) : Day8TempLow) : Day7TempLow) : Day6TempLow) : Day5TempLow) : Day4TempLow) : Day3TempLow) : Day2TempLow) : Day1TempLow) : Day0TempLow)
Using the following Meter I was trying to display it:

Code: Select all

[15DayForecastLowestTemp]
Meter=String
MeterStyle=Regular
MeasureName=CalcLowestTemp
H=12
W=20
Text="%1°C"
Nevertheless - and until now the only obsacle I was not able to overcome on my own - it does not work.

The error-message presented by rainmeter reports the following:
Error - [time-code] - The meter [15DayForecastLowestTemp] cannot be bound with [CalcLowestTemp]
Error - [time-code] - Calc: Unmatched brackets in [CalcLowestTemp]


As I mentioned, I was trying to solve this on my own. Besides that I was also investigating before making this request for help for quite a while; with no results of any productive aid to this particular problem.

Thank you in advance for you patience and help.
User avatar
Brian
Developer
Posts: 2689
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Use 'Calculate' to extract hightest or lowest value

Post by Brian »

You have an extra ")" on your inner most pair.
Basically, this: (Day13TempLow <= Day14TempLow ? Day14TempLow[b])[/b] : Day13TempLow)
Should be this: (Day13TempLow <= Day14TempLow ? Day14TempLow : Day13TempLow).

Having said that, I am not sure if this many conditional statements will work, I believe there is a limit of 9, but I might be wrong.

-Brian
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Use 'Calculate' to extract hightest or lowest value

Post by poiru »

Brian wrote:Having said that, I am not sure if this many conditional statements will work, I believe there is a limit of 9, but I might be wrong.
The limit has been increased to 30 in 2.3 beta.
methyer
Posts: 4
Joined: March 3rd, 2012, 7:54 pm

Re: Use 'Calculate' to extract hightest or lowest value

Post by methyer »

It appears that I have committed a mistake not just in the spelling of the formula but also in the syntax.
Apparently this formula only displays the lowest value that come right after Day0 not comparing it further with the subsequent values, leaving those out of the extraction-progress to determine the lowest value out of the entire range of values (value-count: 15).

I am reaching my math-skills here - I am rather a language/grammer junkie than a math-talent.
Should I, prehaps, rather workout a formula using and / or? - but than I dont see how I will draw the final conclusion: extracting the lowest value out of 15 different values.

I hope for more suggestions, you have helped me very much until now. In science and failure is as much a success as a real success - we, so, learn more for the next intent. :)

I will continue to work on this myself, even-though I believe there are more qualified people in this community who will handle such a problem with ease, while other (me) must squeeze the bits and peaces out of their brain's grey-matter. Therefore, if there won't be any suggestions, I will post my result, in order to help other's who might want to solve a similar problem - if ever I conclude in a result. :P
User avatar
MaroonED
Posts: 61
Joined: November 6th, 2011, 4:50 pm
Location: Germany

Re: Use 'Calculate' to extract hightest or lowest value

Post by MaroonED »

Hi Methyer,
this is probably easier to solve using a lua script. Lua has many powerful mathematical functions, like
  • math.max (x, ···)
    math.min (x, ···)
which would be ideal for getting the values you need.
MaroonED
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Use 'Calculate' to extract hightest or lowest value

Post by jsmorley »

Yes, Lua is one good way to do this. Here is a little sample of how one might attack this problem:

Here is the skin. I just used some Calc measures to gin up some random numbers between 0 and 100 every 5 seconds, to use as the values we want to find the least of. I don't have your full skin, so I assume you are getting the values from some weather skin or SpeedFan skin returning temperatures, You should be able to use this approach with what you are doing.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeasureTemp1]
Measure=Calc
Formula=Random
UpdateRandom=1
HighBound=100
LowBound=0
UpdateDivider=5

[MeasureTemp2]
Measure=Calc
Formula=Random
UpdateRandom=1
HighBound=100
LowBound=0
UpdateDivider=5

[MeasureTemp3]
Measure=Calc
Formula=Random
UpdateRandom=1
HighBound=100
LowBound=0
UpdateDivider=5

[MeasureTemp4]
Measure=Calc
Formula=Random
UpdateRandom=1
HighBound=100
LowBound=0
UpdateDivider=5

[MeasureTemp5]
Measure=Calc
Formula=Random
UpdateRandom=1
HighBound=100
LowBound=0
UpdateDivider=5

[MeasureTemp6]
Measure=Calc
Formula=Random
UpdateRandom=1
HighBound=100
LowBound=0
UpdateDivider=5

[MeasureTemp7]
Measure=Calc
Formula=Random
UpdateRandom=1
HighBound=100
LowBound=0
UpdateDivider=5

[MeasureTemp8]
Measure=Calc
Formula=Random
UpdateRandom=1
HighBound=100
LowBound=0
UpdateDivider=5

[MeasureLua]
Measure=Script
ScriptFile=Test.Lua
MeasureCount=8
UpdateDivider=5

[MeterOne]
Meter=String
MeasureName=MeasureLua
FontSize=12
FontColor=255,255,255,255
AntiAlias=1
StringStyle=Bold
If you look, the key here is how you name the measures. Just name them all the same, tacking a number from 1 to whatever on the end. Note: If at all possible, use numbers from "1" to xxx, not "0" to xxx, as Lua is much happier with tables that are indexed starting with 1 and not 0.

So what this does is get the 8 values into measures, then call the Lua script. As you can see, I am telling the Lua script how many measures there are with MeasureCount=8, so it knows how many to get the values for.

Then there is a reasonably simple Lua script. I called mine Test.Lua in the same folder with the skin:

Code: Select all

PROPERTIES =
{

	MeasureCount = "";
	
}

function Initialize()

	iCount = tonumber(PROPERTIES.MeasureCount)
	tMeasures = {}
	for inc = 1, iCount do
		tMeasures[inc] = SKIN:GetMeasure('MeasureTemp'..inc)
	end

end -->Initialize

function Update()
	
	local tValues = {}
	for inc = 1, iCount do
		tValues[inc] = tMeasures[inc]:GetValue()
	end
	
	table.sort(tValues)
	return tValues[1]

end -->Update
What it does is get the number of measures to check using that "MeasureCount" setting, then build a table "tMeasures" that has the handles to the 8 measures in the skin.

Then on each update of the script in the skin, it creates another table "tValues" that holds the current value of each measure.

Then it simply sorts the table tValues, so the lowest number will be in index "1".

Then it returns that value of tValues[1] to the skin, to use in your meter.

Note: You could easily return the "highest" number instead, by using return tValues[iCount].

Caution: If you are using WebParser measures to return the values, the measures will return strings instead of real numbers. (even if they look like numbers) You can address that by using tValues[inc] = tMeasures[inc]:GetStringValue() instead of tValues[inc] = tMeasures[inc]:GetValue() in the Lua.

Let me know if you have any questions about why / how this works, or if you have trouble fitting the idea into your skin.
methyer
Posts: 4
Joined: March 3rd, 2012, 7:54 pm

Re: Use 'Calculate' to extract hightest or lowest value

Post by methyer »

jsmorley,

just as much as all of you, fellow designers, who have responded to my calling... you are so very much out of my league, I can not even commence to comprehend how much I still have to learn about this subject. I have been developping several skins since I have recently begun skinning, but seldomly reached my limits (as afforementioned). And now I am to discover that there is an entire new, as of yet - to me, undiscovered section of scripting within rainmeter.

I am most certainly confused with your product, but see (after running your scripts) where it leads to.

Furthermore, I realize that my request hindered you from being able of constructing just what I was searching for - due to my vagueness. Please accept my appologies for thus - I will be rather specific now:

I intent to script a weather app that returns Temperatures (the high and low for each day) for 15days to come, using the WebParser-Plugin (as you had guessed, jsmorley). Unlike the script you produced, I wish to return the tempreatures merely once per actual (skin-)update, not in a consecutive changing (and random) pattern. The information exracted by the WebParser is constant. (Again: I wish to appologize for the wasted time.)

This is what I have so far:

Code: Select all

[Rainmeter]
Update=900
DynamicWindowSize=1

[1to5]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=900
Url=http://www.accuweather.com/en/gb/london/w1b-2/daily-weather-forecast/328328?day=1
RegExp="(?siU)id="feed-tabs".*href="#">(.*)<.*<h4>(.*)<.*class="cond">(.*)<.*href="#">(.*)<.*<h4>(.*)<.*class="cond">(.*)<.*class="temp">(.*)<.*Lo</span> (.*)&.*href="#">(.*)<.*<h4>(.*)<.*class="cond">(.*)<.*class="temp">(.*)<.*Lo</span> (.*)&.*href="#">(.*)<.*<h4>(.*)<.*class="cond">(.*)<.*class="temp">(.*)<.*Lo</span> (.*)&.*href="#">(.*)<.*<h4>(.*)<.*class="cond">(.*)<.*class="temp">(.*)<.*Lo</span> (.*)&.*id="detail-day-night".*class="temp">(.*)<.*class="temp">(.*)<"

[6to10]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=900
Url=http://www.accuweather.com/en/gb/london/w1b-2/daily-weather-forecast/328328?day=6
RegExp="(?siU)id="feed-tabs".*href="#">(.*)<.*<h4>(.*)<.*class="cond">(.*)<.*class="temp">(.*)<.*Lo</span> (.*)&.*href="#">(.*)<.*<h4>(.*)<.*class="cond">(.*)<.*class="temp">(.*)<.*Lo</span> (.*)&.*href="#">(.*)<.*<h4>(.*)<.*class="cond">(.*)<.*class="temp">(.*)<.*Lo</span> (.*)&.*href="#">(.*)<.*<h4>(.*)<.*class="cond">(.*)<.*class="temp">(.*)<.*Lo</span> (.*)&.*href="#">(.*)<.*<h4>(.*)<.*class="cond">(.*)<.*class="temp">(.*)<.*Lo</span> (.*)&"

[11to15]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=900
Url=http://www.accuweather.com/en/gb/london/w1b-2/daily-weather-forecast/328328?day=11
RegExp="(?siU)id="feed-tabs".*href="#">(.*)<.*<h4>(.*)<.*class="cond">(.*)<.*class="temp">(.*)<.*Lo</span> (.*)&.*href="#">(.*)<.*<h4>(.*)<.*class="cond">(.*)<.*class="temp">(.*)<.*Lo</span> (.*)&.*href="#">(.*)<.*<h4>(.*)<.*class="cond">(.*)<.*class="temp">(.*)<.*Lo</span> (.*)&.*href="#">(.*)<.*<h4>(.*)<.*class="cond">(.*)<.*class="temp">(.*)<.*Lo</span> (.*)&.*href="#">(.*)<.*<h4>(.*)<.*class="cond">(.*)<.*class="temp">(.*)<.*Lo</span> (.*)&"

[Day0TemperatureHigh]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[1to5]
StringIndex=24
Substitute="":"?"

[Day0TemperatureLow]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[1to5]
StringIndex=25
Substitute="":"?"

[Day1TemperatureHigh]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[1to5]
StringIndex=7
Substitute="":"?"

[Day1TemperatureLow]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[1to5]
StringIndex=8
Substitute="":"?"

[Day2TemperatureHigh]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[1to5]
StringIndex=12
Substitute="":"?"

[Day2TemperatureLow]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[1to5]
StringIndex=13
Substitute="":"?"

[Day3TemperatureHigh]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[1to5]
StringIndex=17
Substitute="":"?"

[Day3TemperatureLow]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[1to5]
StringIndex=18
Substitute="":"?"

[Day4TemperatureHigh]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[1to5]
StringIndex=22
Substitute="":"?"

[Day4TemperatureLow]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[1to5]
StringIndex=23
Substitute="":"?"

[Day5TemperatureHigh]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[6to10]
StringIndex=4
Substitute="":"?"

[Day5TemperatureLow]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[6to10]
StringIndex=5
Substitute="":"?"

[Day6TemperatureHigh]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[6to10]
StringIndex=9
Substitute="":"?"

[Day6TemperatureLow]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[6to10]
StringIndex=10
Substitute="":"?"

[Day7TemperatureHigh]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[6to10]
StringIndex=14
Substitute="":"?"

[Day7TemperatureLow]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[6to10]
StringIndex=15
Substitute="":"?"

[Day8TemperatureHigh]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[6to10]
StringIndex=19
Substitute="":"?"

[Day8TemperatureLow]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[6to10]
StringIndex=20
Substitute="":"?"

[Day9TemperatureHigh]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[6to10]
StringIndex=24
Substitute="":"?"

[Day9TemperatureLow]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[6to10]
StringIndex=25
Substitute="":"?"

[Day10TemperatureHigh]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[11to15]
StringIndex=4
Substitute="":"?"

[Day10TemperatureLow]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[11to15]
StringIndex=5
Substitute="":"?"

[Day11TemperatureHigh]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[11to15]
StringIndex=9
Substitute="":"?"

[Day11TemperatureLow]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[11to15]
StringIndex=10
Substitute="":"?"

[Day12TemperatureHigh]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[11to15]
StringIndex=14
Substitute="":"?"

[Day12TemperatureLow]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[11to15]
StringIndex=15
Substitute="":"?"

[Day13TemperatureHigh]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[11to15]
StringIndex=19
Substitute="":"?"

[Day13TemperatureLow]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[11to15]
StringIndex=20
Substitute="":"?"

[Day14TemperatureHigh]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[11to15]
StringIndex=24
Substitute="":"?"

[Day14TemperatureLow]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[11to15]
StringIndex=25
Substitute="":"?"

[aDay0]
Meter=IMAGE
X=20
Y=20
W=41
H=60
SolidColor=0, 0, 0, 20
ToolTipTitle=Condition
ToolTipText=[Day0TemperatureHigh] | [Day0TemperatureLow]°C
ToolTipType=0
DynamicVariables=1

[aDay1]
Meter=IMAGE
X=42r
Y=r
W=41
H=60
SolidColor=255, 255, 255, 20
ToolTipTitle=Condition
ToolTipText=[Day1TemperatureHigh] | [Day1TemperatureLow]°C
ToolTipType=0
DynamicVariables=1

[aDay2]
Meter=IMAGE
X=42r
Y=r
W=41
H=60
SolidColor=0, 0, 0, 20
ToolTipTitle=Condition
ToolTipText=[Day2TemperatureHigh] | [Day2TemperatureLow]°C
ToolTipType=0
DynamicVariables=1

[aDay3]
Meter=IMAGE
X=42r
Y=r
W=41
H=60
SolidColor=255, 255, 255, 20
ToolTipTitle=Condition
ToolTipText=[Day3TemperatureHigh] | [Day3TemperatureLow]°C
ToolTipType=0
DynamicVariables=1

[aDay4]
Meter=IMAGE
X=42r
Y=r
W=41
H=60
SolidColor=0, 0, 0, 20
ToolTipTitle=Condition
ToolTipText=[Day4TemperatureHigh] | [Day4TemperatureLow]°C
ToolTipType=0
DynamicVariables=1

[aDay5]
Meter=IMAGE
X=42r
Y=r
W=41
H=60
SolidColor=255, 255, 255, 20
ToolTipTitle=Condition
ToolTipText=[Day5TemperatureHigh] | [Day5TemperatureLow]°C
ToolTipType=0
DynamicVariables=1

[aDay6]
Meter=IMAGE
X=42r
Y=r
W=41
H=60
SolidColor=0, 0, 0, 20
ToolTipTitle=Condition
ToolTipText=[Day6TemperatureHigh] | [Day6TemperatureLow]°C
ToolTipType=0
DynamicVariables=1

[aDay7]
Meter=IMAGE
X=42r
Y=r
W=41
H=60
SolidColor=255, 255, 255, 20
ToolTipTitle=Condition
ToolTipText=[Day7TemperatureHigh] | [Day7TemperatureLow]°C
ToolTipType=0
DynamicVariables=1

[aDay8]
Meter=IMAGE
X=42r
Y=r
W=41
H=60
SolidColor=0, 0, 0, 20
ToolTipTitle=Condition
ToolTipText=[Day8TemperatureHigh] | [Day8TemperatureLow]°C
ToolTipType=0
DynamicVariables=1

[aDay9]
Meter=IMAGE
X=42r
Y=r
W=41
H=60
SolidColor=255, 255, 255, 20
ToolTipTitle=Condition
ToolTipText=[Day9TemperatureHigh] | [Day9TemperatureLow]°C
ToolTipType=0
DynamicVariables=1

[aDay10]
Meter=IMAGE
X=42r
Y=r
W=41
H=60
SolidColor=0, 0, 0, 20
ToolTipTitle=Condition
ToolTipText=[Day10TemperatureHigh] | [Day10TemperatureLow]°C
ToolTipType=0
DynamicVariables=1

[aDay11]
Meter=IMAGE
X=42r
Y=r
W=41
H=60
SolidColor=255, 255, 255, 20
ToolTipTitle=Condition
ToolTipText=[Day11TemperatureHigh] | [Day11TemperatureLow]°C
ToolTipType=0
DynamicVariables=1

[aDay12]
Meter=IMAGE
X=42r
Y=r
W=41
H=60
SolidColor=0, 0, 0, 20
ToolTipTitle=Condition
ToolTipText=[Day12TemperatureHigh] | [Day12TemperatureLow]°C
ToolTipType=0
DynamicVariables=1

[aDay13]
Meter=IMAGE
X=42r
Y=r
W=41
H=60
SolidColor=255, 255, 255, 20
ToolTipTitle=Condition
ToolTipText=[Day13TemperatureHigh] | [Day13TemperatureLow]°C
ToolTipType=0
DynamicVariables=1

[aDay14]
Meter=IMAGE
X=42r
Y=r
W=41
H=60
SolidColor=0, 0, 0, 20
ToolTipTitle=Condition
ToolTipText=[Day14TemperatureHigh] | [Day14TemperatureLow]°C
ToolTipType=0
DynamicVariables=1
Once you run it you will notice that this idea of mine has just recently begun - it is rather undevelopped.
As commonly known, images expess more than a thousand words:
I attached an image of the result how I imagine it to be.

Regarding the image:
As you notice, I do not just wish to determine the lowest and hightest temperature within the range of the 15 days of forecast temp. values to limit the lines/graphs parameter - but I wish also to display the information in two graphs (each dot for its appointed day, in its corresponding height on the temperature scale, in proportional relation to the other values and all within the margin that has been determined by the affore-calculated lowest and highest temperatures).

I hope that was not too mixed up and uncomprehendible - people keep telling me to write shorter sentenses :P.

Again: Thank you so much!
I would like to mention your name (and the one's of the other productive supportes) in my project once I have finished it. I will then also present it here of cause.

Methyer
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Use 'Calculate' to extract hightest or lowest value

Post by jsmorley »

Much bigger project than I can dig into, but if you run into something where you have a specific question about how to do something in Rainmeter, feel free to ask.
methyer
Posts: 4
Joined: March 3rd, 2012, 7:54 pm

Re: Use 'Calculate' to extract hightest or lowest value

Post by methyer »

Thank you.

I will intend to solve this on my own - you have already layed out the basics to me. I will refer back to you if I encounter any obsacles.

:D