![]() |
|
Table and CSV - Printable Version +- LogicMachine 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: Table and CSV (/showthread.php?tid=3407) |
Table and CSV - Frank68 - 08.06.2021 Hello I created a scrip that populates a 'MyPowerLog' table for me below Code: data = storage.get('MyPowerLog', {})
table.insert(data, {
-- usare os.date formattare la stringa
['time'] = os.time(),
['Totale Attiva'] = grp.getvalue('4/0/108'),
['Totale Reattiva'] = grp.getvalue('4/1/108'),
})
storage.set('MyPowerLog', data)I should export it to CSV only the data of the last month as I can do Furthermore, once the data has been exported, I should delete it in order not to have a continuous table that increases the space occupied dramatically. the script command to delete the table which is it? Thanks so much RE: Table and CSV - admin - 08.06.2021 Use this to delete the storage entry: Code: storage.delete('MyPowerLog')RE: Table and CSV - Frank68 - 08.06.2021 (08.06.2021, 06:49)admin Wrote: Use this to delete the storage entry:Where is the mistake? i read data from my table, prepare csv header, look for data in my table and for each row i would like to add them to csv file, but nothing i have only headers. Code: --date.day, date.hour, date.min, date.sec = 1, 0, 0, 0
--ts_start = os.time(date)
--date.month = date.month + 1
--ts_end = os.time(date)
--PowTable = db:getall('SELECT * FROM MyPowerLog where time BETWEEN ? AND ? ORDER BY id DESC', ts_start, ts_end)
PowTable = db:getall('SELECT * FROM MyPowerLog')
-- csv buffer
buffer = {}
-- format csv row
csv = string.format('%q,%q,%q', "Time", "Attiva", "Reattiva")
-- add to buffer
table.insert(buffer, csv)
-- add empty line to buffer
table.insert(buffer, "")
-- Loop through PowTable
for _, Measure in ipairs(PowTable) do
-- format csv row
csv = string.format('%q,%q,%q', os.date("%d.%m.%Y %X", Measure.time),Measure.Attiva, Measure.Reattiva )
-- add to buffer
table.insert(buffer, csv)
end
--Create attachment inside FTP server
src = os.date('%Y-%m') .. '.csv'
dst = '/home/ftp/' .. src
io.writefile(dst, buffer)thank you RE: Table and CSV - admin - 08.06.2021 Your log in not a database table but a storage entry, so use this: Code: PowTable = storage.get('MyPowerLog', {})RE: Table and CSV - Frank68 - 08.06.2021 (08.06.2021, 08:40)admin Wrote: Your log in not a database table but a storage entry, so use this: Found problem my error now work all Thank |