Logic Machine Forum
VAV Optimiser, Max Function - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: VAV Optimiser, Max Function (/showthread.php?tid=3508)



VAV Optimiser, Max Function - christian.troen@haaland.no - 11.08.2021

Is there a way to do the following:

Today I write the highest value of tag MaxExtDmpPos to a virtual object. It works fine.
All values with in the tag will be considered in the function. 
If I want the function to check another value before  to include the value in this function.

Example: 6/5/28 is in MaxExtDmpPos tag. Another group-address for this VAV shows if it is any errors in the VAV. This group-address will be "True" if there is any error. 
If this is the case, I want 6/5/28 to not be included in the function. 
 

Script for the function:

Code:
function tag_max(tag)
  local objects = grp.tag(tag)
  local result = -math.huge

  for _, object in ipairs(objects) do
    result = math.max(result, object.value)
  end

  return result
end

max = tag_max('MaxExtDmpPos')
log(max)

grp.checkwrite('32/1/23', max)



RE: VAV Optimiser, Max Function - admin - 12.08.2021

Fault objects should have similar names to the value objects that you are using for calculation. You need to change the "search_for" and "replace_with" parameters in gsub so the value object name is converted to the fault object name.

Code:
function tag_max(tag)
  local objects = grp.tag(tag)
  local result = -math.huge

  for _, object in ipairs(objects) do
    local faultname = obj.name:gsub('search_for', 'replace_with')
    local faultobj = grp.find(faultname)
    local fault = false

    if faultobj then
      fault = faultobj.value
    end

    if not fault then
      result = math.max(result, object.value)
    end
  end

  return result
end
max = tag_max('MaxExtDmpPos')
log(max)

grp.checkwrite('32/1/23', max)