Posts: 303
Threads: 87
Joined: May 2017
Reputation:
2
10.06.2021, 18:55
(This post was last modified: 10.06.2021, 18:57 by Tokatubs.)
I'm trying to figure out the calculation for finding the percentage between two values that a third value is.
Example: The range is 46 to 195 m3h. The value 46 would 0%, and the value 195 would be 100% of the range. What percentage of this range is the value 65?
rangeMin=46
rangeMax=195
inputValue=65
inputPercentage = ?
Usage of this is i have calculated three Vav. And then i need the sum of these to give me back a procent value to give the regulator.
Found this code on different site. But i think that this is missing something
Code: function rangePercentage (input, range_min, range_max, range_2ndMax){
var percentage = ((input - range_min) * 100) / (range_max - range_min);
if (percentage > 100) {
if (typeof range_2ndMax !== 'undefined'){
percentage = ((range_2ndMax - input) * 100) / (range_2ndMax - range_max);
if (percentage < 0) {
percentage = 0;
}
} else {
percentage = 100;
}
} else if (percentage < 0){
percentage = 0;
}
return percentage;
}
Posts: 139
Threads: 44
Joined: Dec 2017
Reputation:
4
11.06.2021, 02:51
(This post was last modified: 11.06.2021, 02:51 by benanderson_475.)
Looks like the above function you posted is javascript... are you running this in the custom javascript scripting part of lm?
if not and assuming you want lua try the below.
Code: function rangePercentage (input, range_min, range_max, range_2ndMax)
percentage = ((input - range_min) * 100) / (range_max - range_min)
if percentage > 100 then
if range_2ndMax then
percentage = ((range_2ndMax - input) * 100) / (range_2ndMax - range_max)
if percentage < 0 then
percentage = 0
else
percentage = 100
end
end
else if percentage < 0 then
percentage = 0
end
end
return percentage
end
log(rangePercentage (65, 46, 195, 195))
Posts: 303
Threads: 87
Joined: May 2017
Reputation:
2
(11.06.2021, 02:51)benanderson_475 Wrote: Looks like the above function you posted is javascript... are you running this in the custom javascript scripting part of lm?
if not and assuming you want lua try the below.
Code: function rangePercentage (input, range_min, range_max, range_2ndMax)
percentage = ((input - range_min) * 100) / (range_max - range_min)
if percentage > 100 then
if range_2ndMax then
percentage = ((range_2ndMax - input) * 100) / (range_2ndMax - range_max)
if percentage < 0 then
percentage = 0
else
percentage = 100
end
end
else if percentage < 0 then
percentage = 0
end
end
return percentage
end
log(rangePercentage (65, 46, 195, 195))
Just to clearify. I picked this script up site describing the calculation, so i was sure i was missing something
I am using this script to sum the Supply air vav.
Code: function tag_sum(tag)
local objects, result
result = 0
objects = grp.tag(tag)
for _, object in ipairs(objects) do
result = result + object.data
end
return result
end
sum = tag_sum('Supply')
grp.checkwrite('1/1/1', sum)
Since i only have one central extract vav. I then want to convert the supply sum to an control value 0-100 % to control the Extract vav.
Given that i know the Min/Max flow values of the Vav.
Been searching forum, but have not seen anything.
Posts: 7720
Threads: 42
Joined: Jun 2015
Reputation:
446
If min/max is common for all objects then you can use the same percentage formula after calculating the average by dividing the sum by the total number of objects.
If min/max is different then you can convert each value to a percentage and then calculate the average value from that.
Posts: 303
Threads: 87
Joined: May 2017
Reputation:
2
(11.06.2021, 08:11)admin Wrote: If min/max is common for all objects then you can use the same percentage formula after calculating the average by dividing the sum by the total number of objects.
If min/max is different then you can convert each value to a percentage and then calculate the average value from that.
Example:
Supply Vav 1: 200 m3h
Supply Vav 2: 300 m3h
Supply Vav 3: 400 m3h
Total airflow 900 m3h.
The extract Vav has min 100 m3h and 1000 m3h max.
Calculation show that this gives an output 90 % to the extract vav which will then open to 900 m3h.
So my wish is that using the "sum", putting the "sum" into the Range between min/max. And then calculate a % ouput in that range.
Posts: 264
Threads: 36
Joined: Apr 2019
Reputation:
4
Hello, I have a resident script to calculate the average between two values in percentage, but the value is sent continuously. How can it be corrected?
Code: Value= (grp.getvalue(ValueA) + grp.getvalue(ValueB)) / 2
grp.checkwrite(Output, Value)
Posts: 7720
Threads: 42
Joined: Jun 2015
Reputation:
446
Set send delta to 1 and see if it helps.
Code: grp.checkwrite(Output, Value, 1)
Posts: 264
Threads: 36
Joined: Apr 2019
Reputation:
4
(02.05.2022, 13:08)admin Wrote: Set send delta to 1 and see if it helps.
Code: grp.checkwrite(Output, Value, 1)
Thanks, that has worked.
Posts: 207
Threads: 60
Joined: May 2018
Reputation:
4
(11.06.2021, 08:27)Tokatubs Wrote: (11.06.2021, 08:11)admin Wrote: If min/max is common for all objects then you can use the same percentage formula after calculating the average by dividing the sum by the total number of objects.
If min/max is different then you can convert each value to a percentage and then calculate the average value from that.
Example:
Supply Vav 1: 200 m3h
Supply Vav 2: 300 m3h
Supply Vav 3: 400 m3h
Total airflow 900 m3h.
The extract Vav has min 100 m3h and 1000 m3h max.
Calculation show that this gives an output 90 % to the extract vav which will then open to 900 m3h.
So my wish is that using the "sum", putting the "sum" into the Range between min/max. And then calculate a % ouput in that range.
Hello. See if this might help. I'm using this to sum up supply dampers for controlling one exctract damper
Code: value1 = grp.getvalue('203_VAV_T_PV1')
value2 = grp.getvalue('202_VAV_T_PV1')
valueTot = value1+value2
function VAVsum(totalIN, Vmin, Vmax)
local valueM3H = (totalIN * 3600)
local value = ((valueM3H - Vmin)/(Vmax - Vmin))*100
local result
if value < 0 then
result = 0
elseif value > 100 then
result = 100
else
result = math.floor(value)
end
return result
end
valueOut=VAVsum(valueTot, 190, 370)
log(valueOut)
grp.write('201_VAV_A_SP', valueOut)
|