title: Vehicle Fuel Level Error Detection, and Refueling Detection c# or SQL
body: <p>I'm readying Vehicle Fuel Levels using an electronic Fuel Stick.</p>
  
  <p>I have continuous readings from a GPS device which transmits this data in 1 minute intervals. I currently store this data in my Microsoft SQL Database, and can produce nice looking graphs.</p>
  
  <p>I am trying to figure out what is the best way to detect</p>
  
  <ol>
  <li>Refueling Events</li>
  <li>Siphoning Events</li>
  </ol>
  
  <p>There are several issues when it comes to the readings.
  There are times when each fuel level reading spikes, and comes back down to somewhere close to the previous level. This make false positives a challenge.</p>
  
  <p>There are times when there are spikes for a prolonged period of time (seen after a refueling sometimes), then the fuel level decreases linearly as you would expect. See the second graph below.</p>
  
  <p>I have the ODO Meter Reading, and the Fuel Level Reading (in Litres).</p>
  
  <p>Given the above problems, I need a way detect these noisy samples which have a high deviation from the expected linear decrease over time.</p>
  
  <p>Here is a sample of data for 2 Vehicles (as a Graph).
  The Blue Line is the actual data.
  The Red Line is my attempt at using a running average of 10 samples to try "smooth" out the large deviations.</p>
  
  <p><a href="https://i.stack.imgur.com/B9ltb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B9ltb.png" alt="Fuel Level Graph for 2 Vehicles"></a></p>
  
  <p>Now for research and ideas:
  I have found 4 different methods to help identify large deviations. (I think)</p>
  
  <ol>
  <li><a href="https://en.wikipedia.org/wiki/Step_detection" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Step_detection</a></li>
  <li><a href="https://en.wikipedia.org/wiki/Western_Electric_rules" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Western_Electric_rules</a></li>
  <li><a href="https://en.wikipedia.org/wiki/Nelson_rules" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Nelson_rules</a></li>
  <li><a href="https://en.wikipedia.org/wiki/Wiener_filter" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Wiener_filter</a></li>
  </ol>
  
  <p>Are there any better alternatives that I should consider?</p>
  
  <p>Anyone know of an implementation that can be achieved using C# or TSQL?</p>
  
  <p>Any advise or ideas would be great.</p>