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.

Log 250 byte string to ftp file
#7
I use this script.

I have four timers an i want to compare two.

Total time 7/0/4 and 7/0/14.

Code:
----------Timer for group 7/0/1 ---------------

value = event.getvalue()

key_now_1 = 'ontime_now_1'
out_now_1 = '1/0/2'

key_last_1 = 'ontime_last_1'
out_last_1 = '1/0/3'

key_total_1 = 'ontime_total_1'
out_total_1 = '1/0/4'

time = storage.get(key_now_1)
now = os.time()

if value then
  if not time then
    storage.set(key_now_1, now)
    formattime(out_now_1, 0)
    storage.set(key_last_1, now)
    formattime(out_last_1, 0)
    end
    
else
  if time then
    time_total = storage.exec('incrby', key_total_1, now - time)
    formattime(out_total_1, time_total)
    
    storage.delete(key_now_1)
    storage.delete(key_last_1)
  end

  grp.update(out_now_1, '')
  
end

-----------------------------------------------------

----------Resident Script---------Timer for group 7/0/1 ---------------

key_now_1 = 'ontime_now_1'
out_now_1 = '1/0/2'

key_last_1 = 'ontime_last_1'
out_last_1 = '1/0/3'

key_total_1 = 'ontime_total_1'
out_total_1 = '1/0/4'

time_now = storage.get(key_now_1)
time_now_1 = storage.get(key_last_1)
if time_now then
  
  time_now = os.time() - time_now
  formattime(out_now_1, time_now)
  formattime(out_last_1, time_now)
  
  time_total = storage.get(key_total_1, 0)
  formattime(out_total_1, time_total + time_now)
end

--------------------------------------------------------------------

-----------------Common Function----------------------------
function formattime(output, seconds)
  local minutes = math.floor(seconds / 60)
  local hours = math.floor(minutes / 60)
  local days = math.floor(hours / 24)
  local res = {}

  seconds = seconds % 60
  minutes = minutes % 60
  hours = hours % 24

  if days > 0 then
    res[ #res + 1 ] = days .. 'd'
  end

  if hours > 0 then
    res[ #res + 1 ] = hours .. 'h'
  end

  if minutes > 0 then
    res[ #res + 1 ] = minutes .. 'm'
  end

  if seconds > 0 or #res == 0 then
    res[ #res + 1 ] = seconds .. 's'
  end

  res = table.concat(res, ' ')
  grp.update(output, res)
end
-------------------------------------------------------------------------
Reply


Messages In This Thread
RE: Log 250 byte string to ftp file - by Rauschentofft - 07.11.2022, 19:57

Forum Jump: