This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Calculate value to procent
#1
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 somethingSmile 

Code:
123456789101112131415161718192021
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; }
Reply
#2
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:
123456789101112131415161718192021222324252627
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))
Reply
#3
(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:
123456789101112131415161718192021222324252627
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 Smile
I am using this script to sum the Supply air vav. 
Code:
12345678910111213141516171819
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.
Reply
#4
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.
Reply
#5
(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.
Reply
#6
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:
12
Value= (grp.getvalue(ValueA) + grp.getvalue(ValueB)) / 2 grp.checkwrite(Output, Value)
Reply
#7
Set send delta to 1 and see if it helps.
Code:
1
grp.checkwrite(Output, Value, 1)
Reply
#8
(02.05.2022, 13:08)admin Wrote: Set send delta to 1 and see if it helps.
Code:
1
grp.checkwrite(Output, Value, 1)

Thanks, that has worked.
Reply
#9
(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:
12345678910111213141516171819202122232425
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)
Reply


Forum Jump: