Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Added missing batch/agg functions #847

Merged
merged 4 commits into from
Feb 26, 2018

Commits on Feb 8, 2018

  1. Remove agg panics

    If 0 length is passed in, we should return math.NaN like python code
    Also follow SEP (Somebody else's problem)
    Aergonus committed Feb 8, 2018
    Configuration menu
    Copy the full SHA
    9d826b7 View commit details
    Browse the repository at this point in the history
  2. Added missing batch/agg functions

    Basically ported over https://github.com/grafana/metrictank/blob/master/expr/seriesaggregators.go
    ```
    median
    def safeMedian(values):
      safeValues = [v for v in values if v is not None]
      if safeValues:
        sortedVals = sorted(safeValues)
        mid = len(sortedVals) // 2
        if len(sortedVals) % 2 == 0:
          return float(sortedVals[mid-1] + sortedVals[mid]) / 2
        else:
          return sortedVals[mid]
    
    diff
    def safeDiff(values):
      safeValues = [v for v in values if v is not None]
      if safeValues:
        values = list(map(lambda x: x*-1, safeValues[1:]))
        values.insert(0, safeValues[0])
        return sum(values)
    
    stddev
    def safeStdDev(a):
      sm = safeSum(a)
      ln = safeLen(a)
      avg = safeDiv(sm,ln)
      if avg is None: return None
      sum = 0
      safeValues = [v for v in a if v is not None]
      for val in safeValues:
         sum = sum + (val - avg) * (val - avg)
      return math.sqrt(sum/ln)
    
    range
      'range': lambda row: safeSubtract(safeMax(row), safeMin(row)),
    
    multiply
      'multiply': lambda row: safeMul(*row),
    def safeMul(*factors):
      if None in factors:
        return None
    
      factors = [float(x) for x in factors]
      product = reduce(lambda x,y: x*y, factors)
      return product
    ```
    Aergonus committed Feb 8, 2018
    Configuration menu
    Copy the full SHA
    14de470 View commit details
    Browse the repository at this point in the history
  3. Add batch/aggfuncs to consolidation

    Note that this fixes bug --> unable to get cnt aggfunc
    Also ignores archive which seems to be different
    Aergonus committed Feb 8, 2018
    Configuration menu
    Copy the full SHA
    5136160 View commit details
    Browse the repository at this point in the history

Commits on Feb 26, 2018

  1. Address comments

    Aergonus committed Feb 26, 2018
    Configuration menu
    Copy the full SHA
    d57d220 View commit details
    Browse the repository at this point in the history