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.

lua table find higest value
#1
I want to get the highest time and then switch the groups on in the order from highest time(stored in on_time) to lowest time until all the groups are on, groups/ range i am interested in are 1/1/1 to 1/1/20
i am storing the obj.updatetime in a table with the associated address etc as below
Code:
function chk_off()
  t ={}

for i = 1, 20 do
    addr = '1/1/'.. tostring(i)
    obj = grp.find(addr)
   
  if obj and obj.value == 0  then
     --put all off obj in table with update time
      table.insert(t, {address = addr, level = obj.value, upd_time = obj.updatetime, on_time = os.time() -obj.updatetime }  )
    end     
end
  return t
end 

Then i want to get the highest value from all the t.on_time/s and switch each off, in order from the longest off value (stored in on_time) until all the complete range 1/1/1 - 1/1/20 are all off
this runs from a function which is called from a scheduled script every x minutes.
This is where i am stuck, this is what i have so far, my question is how can i calculate the highest on_time value and what will happen if two possibility have the same on_time value?
I hope this is making sense....

Code:
function load_time_off()
t = chk_off()
if t then  
for k, v in ipairs(t) do
log(v.on_time) -- this gives me all the on_time vals
-- how to get highest on_time value?? and switch on the associated address
   end
end    
end
Reply


Messages In This Thread
lua table find higest value - by benanderson_475 - 23.06.2020, 05:46
RE: lua table find higest value - by admin - 23.06.2020, 06:28
RE: lua table find higest value - by admin - 08.04.2024, 14:07

Forum Jump: