Recommended Posts

I am getting bad data which does not look good in a graph.

 

I tried to not include the data in the channel log with the following code.

 

         data = parse(datain,6,",")
            ? data
            data.time = systime()
            if((data < P_RAIN_C[0] +10) || (data > P_RAIN_C[0] -10))    //pick out rain counts       
            data.time = systime()
            P_RAIN_C.addValue(data)                 
            ? "RAIN = " + data  
            endif

if the datain(P_RAIN_C) is greater than the previous P_RAIN_C(P_RAIN_C[0]  by plus or minus 10 then do not addvalue.

It does not work and I am probably forgetting some basic item so your help is appreciated.

Attached is the complete sequence.

Thanks

Bill

BAD_DATA.txt

Link to comment
Share on other sites

First, watch your indentation.  Indent on all blocks, so indent for if(), outdent on endif.  Same for while(), for(), try/catch/endcatch, etc.  Code is very hard to read if you don't.

Second, your logic is wrong.  You need && (AND) not || (OR).  All values will pass through your logic.  Think about it.  Let's say the last reading was 20, you are saying if the new value is less than 30 OR greater than 10 it should be included.  The number 5 will work because its less than 30.  The number 35 will work because its greater than 10.  The number 25 will work because its less than 30 and greater than 10.  You need to change the OR to an AND.

Now if the if was trying to catch values to be excluded, you are halfway there.  You'd still want the OR, but you'd want to flip the greater/less than:

data > +10 OR data < -10.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.