19.12.2023, 16:39
great this work for me !! Your top
Code:
ffi = require('ffi')
typName=true
typCat=false
typTotal=false
maxVal=4/60/60
function check(value)
max = math.max(max, value)
log(value)
if value > maxVal then
value=maxVal
--log(value)
end
return value
end
function stringtodouble(chunk)
local dbl = ffi.new('double[1]')
ffi.copy(dbl, chunk, 8)
return dbl[ 0 ]
end
function doubletostring(val)
local dbl = ffi.new('double[1]')
dbl[ 0 ] = val
return ffi.string(dbl, 8)
end
function wash(filename,maxVal)
max = 0
info = require('rrd').info(filename)
data = io.readfile(filename)
offset = info.header_size
buf = { data:sub(1, offset) }
while true do
chunk = data:sub(offset + 1, offset + 8)
if #chunk == 8 then
value = stringtodouble(chunk)
-- skip NaN (empty/undefined value)
if value == value then
value=check(value)
end
buf[ #buf + 1 ] = doubletostring(value)
else
break
end
offset = offset + 8
end
log('MAX:'..max)
data = table.concat(buf)
io.writefile(filename, data)
end
if typName then
tabCurveName= {
--'ADLC-TOTAL-KWH',
--'TG2-TOTAL-KWH',
--'ECLAIRAGE-TOTAL-KWH',
--'GENERAL_ELEC-TOTAL-KWH',
--'ADLC-01_ECLAIRAGE-KWH-ECL',
--'CHAUFFAGE_CLIMATISATION_VENTILATION-TOTAL-KWH',
--'RECE-01_ECLAIRAGE-KWH-ECL'
--'ADN0-TOTAL-KWH',
--'RECE-TOTAL-KWH'
--'DIVERS-TOTAL-KWH',
--'EAU_CHAUDE-TOTAL-KWH',
--'PRISES-TOTAL-KWH',
--'TG1-TOTAL-KWH',
--'RECE-01_LOCAL_FROID-M3-FLU',
'ADN2-01_ECLAIRAGE-KWH-ECL'
}
for _, curveName in ipairs(tabCurveName) do
id = db:getone('SELECT id FROM trends WHERE name=?', curveName)
if id then
filename = '/tmp/trends/t' .. id .. '.trend'
--os.remove(file)
wash(filename,maxVal)
end
end
end
-----------
FRANCE SMARTHOME & SMARTBUILDING INTEGRATION
SE ECO EXPERT
FRANCE SMARTHOME & SMARTBUILDING INTEGRATION
SE ECO EXPERT