Fix gestione allarmi + parametri

This commit is contained in:
Samuele Locatelli
2022-03-24 14:57:19 +01:00
parent 4bfe039623
commit a48e444fe2
4 changed files with 211 additions and 67 deletions
+50 -29
View File
@@ -1,9 +1,10 @@
--[[---------------------------------------------------
--[[---------------------------------------------------
Procedura calcolo statistiche parametri:
Variabili IN:
- vcFunct(string): tipo di processing da effettuare tra [POINT/AVG/MEDIAN/MIN/MAX]
- valList(<double>): elenco VALORI double da processare
- numRec(int): conteggio numero recorda da processare
Variabili OUT:
- calcVal(double): valore calcolato finale
@@ -17,60 +18,65 @@ if not package.path:find(ZBS,1,true) then
package.cpath = ZBS .. "/bin/?.dll;" .. ZBS .. "/bin/clibs53/?.dll;" .. package.cpath
end
-- variabile semaforo callMode (locali o remote da NLua)
callMode = callMode or ''
vcFunct = vcFunct or ''
valList = valList or {}
calcVal = 0
calcOk = false
-- se non è da NLua inizializzo variabili accessorie
local function checkInit()
if (callMode ~= 'NLua') then
-- imposto valori test
valList = { 4.0, 5.0, 3.0, 6.0, 1.0, 2.0 }
vcFunct = 'MIN'
valList = { 4467, 4468, 4467, 4467, 4467, 4467 }
numRec = #valList
--valList = { 4.0, 5.0, 3.0, 6.0, 1.0, 2.0 }
vcFunct = 'AVG'
--POINT AVG MEDIAN MIN MAX
end
end
local function setupTable()
if numRec > 0 and valList[0] ~= nil then
for i = numRec, 1, -1 do
valListTable[i] = valList[i-1]
end
else
valListTable = valList
end
end
local function doCalc()
if(#valList>0) then
if(numRec > 0) then
-- verifica il tipo di richiesta
if(vcFunct == 'AVG') then
s = 0
for i,v in ipairs(valList) do
for i,v in ipairs(valListTable) do
s = s + v
end
calcVal = s / #valList
calcVal = s / numRec
elseif(vcFunct == 'POINT') then
calcVal = valList[#valList]
calcVal = valListTable[numRec]
elseif(vcFunct == 'MEDIAN') then
table.sort(valList)
calcVal = valList[#valList/2]
table.sort(valListTable)
calcVal = valListTable[numRec/2]
elseif(vcFunct == 'MIN') then
table.sort(valList)
calcVal = valList[1]
table.sort(valListTable)
calcVal = valListTable[1]
elseif(vcFunct == 'MAX') then
table.sort(valList)
calcVal = valList[#valList]
table.sort(valListTable)
calcVal = valListTable[numRec]
end
calcOk = true
else
calcVal = 0
calcOk = false
calcVal = -999999
numRec = 1
calcOk = false
end
end
local function displayTestInfo()
if (callMode ~= 'NLua') then
print('------------------------------')
print('calcOk: ' .. tostring(calcOk))
print('vcFunct: ' .. vcFunct)
for i,val in pairs(valList) do
print('calcOk: ' .. tostring(calcOk) .. ' | vcFunct: ' .. vcFunct)
for i,val in pairs(valList) do
print("v_"..i.." | "..val)
end
end
print('calcVal: ' .. calcVal)
print('------------------------------')
end
@@ -78,7 +84,22 @@ end
-- MAIN
function doProcess()
-- variabile semaforo callMode (locali o remote da NLua)
callMode = callMode or ''
calcVal = -999
vcFunct = vcFunct or ''
valList = valList or {}
numRec = numRec or 1
calcOk = false
valListTable = {}
checkInit()
doCalc()
displayTestInfo()
checkInit()
setupTable()
doCalc()
displayTestInfo()
end
if (callMode ~= 'NLua') then
doProcess()
end