Exemple #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])
    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])
Exemple #3
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])
Exemple #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])
Exemple #5
0
    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)
Exemple #6
0
        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
Exemple #7
0
        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)
Exemple #8
0
    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)
Exemple #9
0
        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)
Exemple #10
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)
        # 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])