From 44ec0cf299757729e3be57727449aa45158cc0d2 Mon Sep 17 00:00:00 2001 From: "marco.locatelli@steamware.net" Date: Mon, 7 Jun 2021 16:02:19 +0200 Subject: [PATCH] media della risultante + fix refresh --- sampler/FTSampler.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sampler/FTSampler.py b/sampler/FTSampler.py index 1099e1f..bd83b3e 100644 --- a/sampler/FTSampler.py +++ b/sampler/FTSampler.py @@ -195,7 +195,6 @@ def checkPowerOff(): def calculateValue(): decimalsCount = int(getRedisVal('SETTINGS:DECIMALS:COUNT')) - smoothFact= int(getRedisVal('SETTINGS:SMOOTHING:FACTOR')) ch1 = getRedisVal('SETTINGS:CHANNEL:A') ch2 = getRedisVal('SETTINGS:CHANNEL:B') v1 = getRedisVal('RTDATA:OUT:' + ch1) @@ -208,8 +207,13 @@ def calculateValue(): strValIn = newValue # EWMA: RILEGGO DA REDIS vecchio valore oldVal = float(redSrv0.get('RTDATA:VALUE')) - # effettuo smoothing valore - strValIn = (newValue/smoothFact) + (oldVal * (smoothFact-1) / smoothFact) + if(oldVal == 0): + oldVal = 0.01 + # se variazione < 50% smooth + if((abs(newValue - oldVal) / oldVal) < 0.5): + # effettuo smoothing valore + eFact = 4 + strValIn = (newValue/eFact) + (oldVal * (eFact-1) / eFact) redSrv0.set('RTDATA:VALUE',round(strValIn,decimalsCount)) # init oggetto lettura da