コード例 #1
0
    def test_aggregate(self):
        """
        aggregate functions
        """
        # min of 1-4
        self.assertEqual(whisper.aggregate('min', [1, 2, 3, 4]), 1)
        # max of 1-4
        self.assertEqual(whisper.aggregate('max', [1, 2, 3, 4]), 4)
        # last element in the known values
        self.assertEqual(whisper.aggregate('last', [3, 2, 5, 4]), 4)
        # sum ALL THE VALUES!
        self.assertEqual(whisper.aggregate('sum', [10, 2, 3, 4]), 19)
        # average of the list elements
        self.assertEqual(whisper.aggregate('average', [1, 2, 3, 4]), 2.5)
        avg_zero = [1, 2, 3, 4, None, None, None, None]
        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)

        with AssertRaisesException(
                whisper.InvalidAggregationMethod(
                    'Unrecognized aggregation method derp')):
            whisper.aggregate('derp', [12, 2, 3123, 1])
コード例 #2
0
    def test_aggregate(self):
        """
        aggregate functions
        """
        # min of 1-4
        self.assertEqual(whisper.aggregate('min', [1, 2, 3, 4]), 1)
        # max of 1-4
        self.assertEqual(whisper.aggregate('max', [1, 2, 3, 4]), 4)
        # last element in the known values
        self.assertEqual(whisper.aggregate('last', [3, 2, 5, 4]), 4)
        # sum ALL THE VALUES!
        self.assertEqual(whisper.aggregate('sum', [10, 2, 3, 4]), 19)
        # average of the list elements
        self.assertEqual(whisper.aggregate('average', [1, 2, 3, 4]), 2.5)
        avg_zero = [1, 2, 3, 4, None, None, None, None]
        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)

        with AssertRaisesException(whisper.InvalidAggregationMethod('Unrecognized aggregation method derp')):
            whisper.aggregate('derp', [12, 2, 3123, 1])
コード例 #3
0
ファイル: test_whisper.py プロジェクト: TheNoButton/whisper
 def test_aggregate(self):
     """aggregate functions"""
     # min of 1-4
     self.assertEqual(whisper.aggregate('min', [1, 2, 3, 4]), 1)
     # max of 1-4
     self.assertEqual(whisper.aggregate('max', [1, 2, 3, 4]), 4)
     # last element in the known values
     self.assertEqual(whisper.aggregate('last', [3, 2, 5, 4]), 4)
     # sum ALL THE VALUES!
     self.assertEqual(whisper.aggregate('sum', [10, 2, 3, 4]), 19)
     # average of the list elements
     self.assertEqual(whisper.aggregate('average', [1, 2, 3, 4]), 2.5)
     with self.assertRaises(whisper.InvalidAggregationMethod):
         whisper.aggregate('derp', [12, 2, 3123, 1])
コード例 #4
0
 def test_aggregate(self):
     """aggregate functions"""
     # min of 1-4
     self.assertEqual(whisper.aggregate('min', [1, 2, 3, 4]), 1)
     # max of 1-4
     self.assertEqual(whisper.aggregate('max', [1, 2, 3, 4]), 4)
     # last element in the known values
     self.assertEqual(whisper.aggregate('last', [3, 2, 5, 4]), 4)
     # sum ALL THE VALUES!
     self.assertEqual(whisper.aggregate('sum', [10, 2, 3, 4]), 19)
     # average of the list elements
     self.assertEqual(whisper.aggregate('average', [1, 2, 3, 4]), 2.5)
     with self.assertRaises(whisper.InvalidAggregationMethod):
         whisper.aggregate('derp', [12, 2, 3123, 1])
コード例 #5
0
ファイル: whisper-resize.py プロジェクト: Maigard/whisper
    print("(%s,%s,%s)" % (fromTime,untilTime, step))
    timepoints_to_update = range(fromTime, untilTime, step)
    print("timepoints_to_update: %s" % timepoints_to_update)
    newdatapoints = []
    for tinterval in zip( timepoints_to_update[:-1], timepoints_to_update[1:] ):
      # TODO: Setting lo= parameter for 'lefti' based on righti from previous
      #       iteration. Obviously, this can only be done if
      #       timepoints_to_update is always updated. Is it?
      lefti = bisect.bisect_left(oldtimestamps, tinterval[0])
      righti = bisect.bisect_left(oldtimestamps, tinterval[1], lo=lefti)
      newvalues = oldvalues[lefti:righti]
      if newvalues:
        non_none = filter( lambda x: x is not None, newvalues)
        if 1.0*len(non_none)/len(newvalues) >= xff:
          newdatapoints.append([tinterval[0],
                                whisper.aggregate(aggregationMethod,
                                                  non_none, newvalues)])
    whisper.update_many(newfile, newdatapoints)
else:
  print('Migrating data without aggregation...')
  for archive in old_archives:
    timeinfo, values = archive['data']
    datapoints = zip( range(*timeinfo), values )
    datapoints = filter(lambda p: p[1] is not None, datapoints)
    whisper.update_many(newfile, datapoints)

if options.newfile is not None:
  sys.exit(0)

backup = path + '.bak'
print('Renaming old database to: %s' % backup)
os.rename(path, backup)
コード例 #6
0
ファイル: whisper-resize.py プロジェクト: debedb/kupuestra2
        print "timepoints_to_update: %s" % timepoints_to_update
        newdatapoints = []
        for tinterval in zip(timepoints_to_update[:-1],
                             timepoints_to_update[1:]):
            # TODO: Setting lo= parameter for 'lefti' based on righti from previous
            #       iteration. Obviously, this can only be done if
            #       timepoints_to_update is always updated. Is it?
            lefti = bisect.bisect_left(oldtimestamps, tinterval[0])
            righti = bisect.bisect_left(oldtimestamps, tinterval[1], lo=lefti)
            newvalues = oldvalues[lefti:righti]
            if newvalues:
                non_none = filter(lambda x: x is not None, newvalues)
                if 1.0 * len(non_none) / len(newvalues) >= xff:
                    newdatapoints.append([
                        tinterval[0],
                        whisper.aggregate(aggregationMethod, non_none)
                    ])
        whisper.update_many(newfile, newdatapoints)
else:
    print 'Migrating data without aggregation...'
    for archive in old_archives:
        timeinfo, values = archive['data']
        datapoints = zip(range(*timeinfo), values)
        datapoints = filter(lambda p: p[1] is not None, datapoints)
        whisper.update_many(newfile, datapoints)

if options.newfile is not None:
    sys.exit(0)

backup = path + '.bak'
print 'Renaming old database to: %s' % backup
コード例 #7
0
ファイル: whisper-resize.py プロジェクト: wukan1986/whisper
        print("timepoints_to_update: %s" % timepoints_to_update)
        newdatapoints = []
        for tinterval in zip(timepoints_to_update[:-1],
                             timepoints_to_update[1:]):
            # TODO: Setting lo= parameter for 'lefti' based on righti from previous
            #       iteration. Obviously, this can only be done if
            #       timepoints_to_update is always updated. Is it?
            lefti = bisect.bisect_left(oldtimestamps, tinterval[0])
            righti = bisect.bisect_left(oldtimestamps, tinterval[1], lo=lefti)
            newvalues = oldvalues[lefti:righti]
            if newvalues:
                non_none = list(filter(lambda x: x is not None, newvalues))
                if non_none and 1.0 * len(non_none) / len(newvalues) >= xff:
                    newdatapoints.append([
                        tinterval[0],
                        whisper.aggregate(aggregationMethod, non_none,
                                          newvalues)
                    ])
        whisper.update_many(newfile, newdatapoints)
else:
    print('Migrating data without aggregation...')
    for archive in old_archives:
        timeinfo, values = archive['data']
        datapoints = zip(range(*timeinfo), values)
        datapoints = filter(lambda p: p[1] is not None, datapoints)
        whisper.update_many(newfile, datapoints)

if options.newfile is not None:
    sys.exit(0)

backup = path + '.bak'
print('Renaming old database to: %s' % backup)
コード例 #8
0
ファイル: whisper-resize.py プロジェクト: B-Rich/whisper
    print "(%s,%s,%s)" % (fromTime,untilTime, step)
    timepoints_to_update = range(fromTime, untilTime, step)
    print "timepoints_to_update: %s" % timepoints_to_update
    newdatapoints = []
    for tinterval in zip( timepoints_to_update[:-1], timepoints_to_update[1:] ):
      # TODO: Setting lo= parameter for 'lefti' based on righti from previous
      #       iteration. Obviously, this can only be done if
      #       timepoints_to_update is always updated. Is it?
      lefti = bisect.bisect_left(oldtimestamps, tinterval[0])
      righti = bisect.bisect_left(oldtimestamps, tinterval[1], lo=lefti)
      newvalues = oldvalues[lefti:righti]
      if newvalues:
        non_none = filter( lambda x: x is not None, newvalues)
        if 1.0*len(non_none)/len(newvalues) >= xff:
          newdatapoints.append([tinterval[0],
                                whisper.aggregate(aggregationMethod,
                                                  non_none)])
    whisper.update_many(newfile, newdatapoints)
else:
  print 'Migrating data without aggregation...'
  for archive in old_archives:
    timeinfo, values = archive['data']
    datapoints = zip( range(*timeinfo), values )
    datapoints = filter(lambda p: p[1] is not None, datapoints)
    whisper.update_many(newfile, datapoints)

if options.newfile is not None:
  sys.exit(0)

backup = path + '.bak'
print 'Renaming old database to: %s' % backup
os.rename(path, backup)
コード例 #9
0
ファイル: whisper-resize.py プロジェクト: leonworkshop/basin
        untilTime = now + now % step + step
        print "(%s,%s,%s)" % (fromTime, untilTime, step)
        timepoints_to_update = range(fromTime, untilTime, step)
        print "timepoints_to_update: %s" % timepoints_to_update
        newdatapoints = []
        for tinterval in zip(timepoints_to_update[:-1], timepoints_to_update[1:]):
            # TODO: Setting lo= parameter for 'lefti' based on righti from previous
            #       iteration. Obviously, this can only be done if
            #       timepoints_to_update is always updated. Is it?
            lefti = bisect.bisect_left(oldtimestamps, tinterval[0])
            righti = bisect.bisect_left(oldtimestamps, tinterval[1], lo=lefti)
            newvalues = oldvalues[lefti:righti]
            if newvalues:
                non_none = filter(lambda x: x is not None, newvalues)
                if 1.0 * len(non_none) / len(newvalues) >= xff:
                    newdatapoints.append([tinterval[0], whisper.aggregate(aggregationMethod, non_none)])
        whisper.update_many(newfile, newdatapoints)
else:
    print "Migrating data without aggregation..."
    for archive in old_archives:
        timeinfo, values = archive["data"]
        datapoints = zip(range(*timeinfo), values)
        datapoints = filter(lambda p: p[1] is not None, datapoints)
        whisper.update_many(newfile, datapoints)

if options.newfile is not None:
    sys.exit(0)

backup = path + ".bak"
print "Renaming old database to: %s" % backup
os.rename(path, backup)
コード例 #10
0
ファイル: test_whisper.py プロジェクト: Kixeye/whisper
    def test_aggregate(self):
        """
        aggregate functions
        """
        # min of 1-4
        self.assertEqual(whisper.aggregate('min', [1, 2, 3, 4]), 1)
        # max of 1-4
        self.assertEqual(whisper.aggregate('max', [1, 2, 3, 4]), 4)
        # last element in the known values
        self.assertEqual(whisper.aggregate('last', [3, 2, 5, 4]), 4)
        # sum ALL THE VALUES!
        self.assertEqual(whisper.aggregate('sum', [10, 2, 3, 4]), 19)
        # average of the list elements
        self.assertEqual(whisper.aggregate('average', [1, 2, 3, 4]), 2.5)
        # 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])