06.04.2022, 20:49
(This post was last modified: 06.04.2022, 21:11 by manos@dynamitec.)
Hello admin,
Can the part below be edit to be able to calculate with a resolution of 1 decimal point the average value of 2byte float or any byte value (temp, brightness, power ...)? Now in the script says the value must be between 0-100.
Thank you in advance
I guess just removing math.floor(..........+0.5) is the solution to this?
Can the part below be edit to be able to calculate with a resolution of 1 decimal point the average value of 2byte float or any byte value (temp, brightness, power ...)? Now in the script says the value must be between 0-100.
Code:
-- AVERAGE value
calc['avg'] = function(group)
local result, count, value = 0, 0
for _, address in ipairs(group.objects) do
value = values[ address ]
-- number must be in [0..100] range!!!!!!!!!!!!!!!!!
if type(value) == 'number' then
result = result + value
count = count + 1
-- boolean true is 100%, false is 0%
elseif type(value) == 'boolean' then
if toboolean(value) then
result = result + 100
end
count = count + 1
end
end
if count > 0 then
result = math.floor(result / count + 0.5)
grp.checkwrite(group.output, result)
end
end
Thank you in advance
(06.04.2022, 20:49)manos@dynamitec Wrote: Hello admin,
Can the part below be edit to be able to calculate with a resolution of 1 decimal point the average value of 2byte float or any byte value (temp, brightness, power ...)? Now in the script says the value must be between 0-100.
Code:-- AVERAGE value
calc['avg'] = function(group)
local result, count, value = 0, 0
for _, address in ipairs(group.objects) do
value = values[ address ]
-- number must be in [0..100] range!!!!!!!!!!!!!!!!!
if type(value) == 'number' then
result = result + value
count = count + 1
-- boolean true is 100%, false is 0%
elseif type(value) == 'boolean' then
if toboolean(value) then
result = result + 100
end
count = count + 1
end
end
if count > 0 then
result = math.floor(result / count + 0.5)
grp.checkwrite(group.output, result)
end
end
Thank you in advance
I guess just removing math.floor(..........+0.5) is the solution to this?