Skip to content

Commit

Permalink
Merge 1fac0ff into 6d9a9ec
Browse files Browse the repository at this point in the history
  • Loading branch information
yadsirhc committed Aug 2, 2016
2 parents 6d9a9ec + 1fac0ff commit 2250e63
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -35,7 +35,7 @@ Options:
--aggregationMethod=AGGREGATIONMETHOD
The consolidation function to fetch from on input and
aggregationMethod to set on output. One of: average,
last, max, min
last, max, min, avg_zero, absmax, absmin
```

whisper-create.py
Expand All @@ -59,7 +59,7 @@ Options:
--xFilesFactor=XFILESFACTOR
--aggregationMethod=AGGREGATIONMETHOD
Function to use when aggregating values (average, sum,
last, max, min)
last, max, min, avg_zero, absmax, absmin)
--overwrite
--estimate Don't create a whisper file, estimate storage requirements based on archive definitions
```
Expand Down Expand Up @@ -154,7 +154,7 @@ Options:
Change the xFilesFactor
--aggregationMethod=AGGREGATIONMETHOD
Change the aggregation function (average, sum, last,
max, min)
max, min, avg_zero, absmax, absmin)
--force Perform a destructive change
--newfile=NEWFILE Create a new database file without removing the
existing one
Expand All @@ -169,7 +169,7 @@ whisper-set-aggregation-method.py
Change the aggregation method of an existing whisper file.

```
Usage: whisper-set-aggregation-method.py path <average|sum|last|max|min>
Usage: whisper-set-aggregation-method.py path <average|sum|last|max|min|avg_zero|absmax|absmin>
Options:
-h, --help show this help message and exit
Expand Down
4 changes: 4 additions & 0 deletions bin/rrd2whisper.py
Expand Up @@ -23,6 +23,10 @@

# RRD doesn't have a 'sum' or 'total' type
aggregationMethods.remove('sum')
# RRD doesn't have a 'absmax' type
aggregationMethods.remove('absmax')
# RRD doesn't have a 'absmin' type
aggregationMethods.remove('absmin')

option_parser = optparse.OptionParser(usage='''%prog rrd_path''')
option_parser.add_option(
Expand Down
9 changes: 8 additions & 1 deletion test_whisper.py
Expand Up @@ -190,9 +190,16 @@ def test_aggregate(self):
non_null = [i for i in avg_zero if i is not None]
self.assertEqual(whisper.aggregate('avg_zero', non_null, avg_zero), 1.25)
# avg_zero without neighborValues

with self.assertRaises(whisper.InvalidAggregationMethod):
whisper.aggregate('avg_zero', non_null)
# absmax with negative max
self.assertEqual(whisper.aggregate('absmax', [-3, -2, 1, 2]), -3)
# absmax with positive max
self.assertEqual(whisper.aggregate('absmax', [-2, -1, 2, 3]), 3)
# absmin with positive min
self.assertEqual(whisper.aggregate('absmin', [-3, -2, 1, 2]), 1)
# absmin with negative min
self.assertEqual(whisper.aggregate('absmin', [-2, -1, 2, 3]), -1)

with AssertRaisesException(whisper.InvalidAggregationMethod('Unrecognized aggregation method derp')):
whisper.aggregate('derp', [12, 2, 3123, 1])
Expand Down
8 changes: 7 additions & 1 deletion whisper.py
Expand Up @@ -112,7 +112,9 @@ def _py_fallocate(fd, offset, len_):
3: 'last',
4: 'max',
5: 'min',
6: 'avg_zero'
6: 'avg_zero',
7: 'absmax',
8: 'absmin'
})
aggregationMethodToType = dict([[v, k] for k, v in aggregationTypeToMethod.items()])
aggregationMethods = aggregationTypeToMethod.values()
Expand Down Expand Up @@ -468,6 +470,10 @@ def aggregate(aggregationMethod, knownValues, neighborValues=None):
raise InvalidAggregationMethod("Using avg_zero without neighborValues")
values = [x or 0 for x in neighborValues]
return float(sum(values)) / float(len(values))
elif aggregationMethod == 'absmax':
return max(knownValues, key=abs)
elif aggregationMethod == 'absmin':
return min(knownValues, key=abs)
else:
raise InvalidAggregationMethod("Unrecognized aggregation method %s" %
aggregationMethod)
Expand Down

0 comments on commit 2250e63

Please sign in to comment.