code: def calculate_clock_skew(self):
          
          n = self.statx_n(self.data_points)
  
          """
          Required to be able to compute the standard
          deviation.
          """
          if n < 1:
              return Decimal("0")
  
          avg = self.statx_avg(self.data_points)
          sdev = self.statx_sdev(self.data_points)
  
          """
          Incrementally remove aberration points.
          """
          for k in range(0, self.clean_steps):
              """
              Remove aberration points: keep only
              the sigma range around the average.
              """
              min_val = avg - sdev
              max_val = avg + sdev
  
              cleaned_data_points = []
              for i in range(0, n):
                  v = self.data_points[i]
                  if v < min_val or v > max_val:
                      continue
                  cleaned_data_points.append(v)
  
              self.data_points = cleaned_data_points[:]
  
              """
              Recompute the new average using the
              "sound" points we kept.
              """
              n = self.statx_n(self.data_points)
  
              """
              Not enough data to compute standard
              deviation.
              """
              if n < 2:
                  break
  
              avg = self.statx_avg(self.data_points)
              sdev = self.statx_sdev(self.data_points)
  
              if sdev <= self.max_sdev or n < self.min_data:
                  break
  
          """
          If standard deviation is too large still, we
          cannot update our clock. Collect more points.
  
          If we don't have a minimum amount of data,
          don't attempt the update yet, continue collecting.
          """
          if sdev > self.max_sdev or n < self.min_data:
              return Decimal("0")
  
          return avg
docs: Computer average and standard deviation
          using all the data points.