Skip to content

Instantly share code, notes, and snippets.

@mleinart
Created April 20, 2012 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mleinart/2429514 to your computer and use it in GitHub Desktop.
Save mleinart/2429514 to your computer and use it in GitHub Desktop.
Modify data in existing whisper files to be derived from existing counter values
#!/usr/bin/env python
import sys, time, whisper, shutil
from optparse import OptionParser
now = int( time.time() )
option_parser = OptionParser(
usage='''%prog path from''')
(options, args) = option_parser.parse_args()
if len(args) != 2:
option_parser.print_help()
sys.exit(1)
path = args[0]
time_from = int(args[1])
time_info, points = whisper.fetch(path, time_from)
print "Processing %s" % path
shutil.copy(path, path + '.bak')
previous = None
timestamp = time_info[0]
new_points = [(time_info[0], 0)]
for value in points:
if value and previous:
difference = value - previous
if difference < 0:
break
else:
new_points.append( (timestamp, difference) )
else:
new_points.append( (timestamp, 0) )
previous = value
timestamp += time_info[2]
whisper.update_many(path, new_points)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment