Created
April 20, 2012 15:13
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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