Logic Machine Forum
Log 250 byte string to ftp file - 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: Log 250 byte string to ftp file (/showthread.php?tid=4350)



Log 250 byte string to ftp file - Rauschentofft - 04.11.2022

Hi.

I want to log 250 byte string to ftp file.

And i also want to know how to calculate the time differrence of two 250 byte string.

See picture.

Br
MR


RE: Log 250 byte string to ftp file - admin - 04.11.2022

There are many CSV/FTP examples on the forum. There's also example on our website: https://openrb.com/example-export-last-hour-csv-object-log-file-to-external-ftp-server-from-lm2/
As for the difference calculation it should be done on numeric values not on the strings that are formatted using the numeric values. Then you can simply subtract one value from another.


RE: Log 250 byte string to ftp file - Rauschentofft - 04.11.2022

Okej, then i look it up.

If i understand it right about the difference.
Then i should compare the values before i convert it to string?

My script is done to log "on" value 1/1/1 and then add it to total value 1/1/2.
Total value shows "on" time in: year, month, week, days, h, m, s.

Br
MR


RE: Log 250 byte string to ftp file - admin - 07.11.2022

Any calculations should be done on numeric values. If you have date/time string you will to convert it back to a number before doing any calculations.


RE: Log 250 byte string to ftp file - Rauschentofft - 07.11.2022

I don´t know how to convert it to numeric.

Could you help me with this?


RE: Log 250 byte string to ftp file - admin - 07.11.2022

Please describe exactly what do you want to compare and post the code that you use. Most likely you already have a numeric value before it's converted to a formatted string that is written to 250 byte object.


RE: Log 250 byte string to ftp file - Rauschentofft - 07.11.2022

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
-------------------------------------------------------------------------



RE: Log 250 byte string to ftp file - admin - 08.11.2022

Modify storage keys and output address as needed:
Code:
key_total_1 = 'ontime_total_1'
key_total_2 = 'ontime_total_2'

output = '1/2/3'

value_1 = storage.get(key_total_1, 0)
value_2 = storage.get(key_total_2, 0)

delta = math.abs(value_1 - value_2)

formattime(output, delta)



RE: Log 250 byte string to ftp file - Rauschentofft - 08.11.2022

Thanks alot for the help.

Br
MR