예제 #1
0
 def __init__(self, results_db, performer_constraint_list,
              baseline_constraint_list):
     """Initializes the PercentilesGetter with a results database,
     a performer_constraint_list and a baseline_constraint_list."""
     self._results_db = results_db
     self._performer_constraint_list = performer_constraint_list
     self._baseline_constraint_list = baseline_constraint_list
     # we only care about the values on the same queries:
     common_ids = list(set(self._performer_ids) & set(self._baseline_ids))
     performer_latencies = [
         this_lat
         for (this_id, this_lat
              ) in zip(self._performer_ids, self._performer_latencies)
         if this_id in common_ids
     ]
     baseline_latencies = [
         this_lat
         for (this_id,
              this_lat) in zip(self._baseline_ids, self._baseline_latencies)
         if this_id in common_ids
     ]
     # compute the percentiles:
     self._performer_percentiles = [
         pf.PercentileFinder(performer_latencies).getPercentile(index)
         for index in xrange(1, 101)
     ]
     self._baseline_percentiles = [
         pf.PercentileFinder(baseline_latencies).getPercentile(index)
         for index in xrange(1, 101)
     ]
예제 #2
0
 def test_twonumber(self):
     """
     To see what happens when there is a two-number list
     """
     x = pf.PercentileFinder([0, 5])
     t = x.getPercentile(50)
     self.assertEqual(t, 0)
예제 #3
0
 def test_range4(self):
     """
     To see what happens when the percentile is towards the upper range boundary
     """
     x = pf.PercentileFinder([1, 2, 3, 4, 5, 6, 7, 8])
     t = x.getPercentile(99)
     self.assertEqual(t, 8)
예제 #4
0
 def test_range1(self):
     """
     To see what happens when the percentile is at the top of the accepted range
     """
     x = pf.PercentileFinder([1, 2, 3, 4, 5, 6])
     t = x.getPercentile(100)
     self.assertEqual(t, 6)
예제 #5
0
 def test_nullset(self):
     """
     To see what the function does with a null set
     """
     x = pf.PercentileFinder([])
     t = x.getPercentile(25)
     self.assertEqual(t, None)
예제 #6
0
 def test_twonumberlow(self):
     """
     To see what the function does with a two-item list and a low percentile
     """
     x = pf.PercentileFinder([5, 6])
     t = x.getPercentile(1)
     self.assertEqual(t, 5)
예제 #7
0
 def test_midrange_odd(self):
     """
     To see what the function does with a five-item list and a 50th percentile
     """
     x = pf.PercentileFinder([10, 20, 30, 40, 50])
     t = x.getPercentile(50)
     self.assertEqual(t, 30)
예제 #8
0
 def test_sort(self):
     """
     To see if the sorting truly works
     """
     x = pf.PercentileFinder([8, 1, 7, 2, 6, 3, 5, 4])
     t = x.getPercentile(50)
     self.assertEqual(t, 4)
예제 #9
0
 def test_largelist(self):
     """
     To see what happens when the list given is enormous.
     """
     my_list = range(1, 10000)
     x = pf.PercentileFinder(my_list)
     t = x.getPercentile(75)
     self.assertEqual(t, 7500)
예제 #10
0
def distribution_compare(function, a_list, b_list):
    """
    This function is designed to compare two lists of times using a criteria
    determined in the function.  It individually compares two elements of the
    lists and if the elements meet the criteria, then a value, True, is appended
    to the compare_list.  If all of the items in the compare_list are True,
    then True is returned.
    
    Simple use:

    import single_percentile_comparator as sp
    
    if:
        a_list = [1,2,3,4,5,6,7,8]
        b_list = [50,100,150,200,250,300,350,400]
        function() = sp.baa_criteria
    then:
        10 * 50 + 15 >= 1
        10 * 100 + 15 >= 2
        10 * 150 + 15 >= 3
        10 * 200 + 15 >= 4
        10 * 250 + 15 >= 5
        10 * 300 + 15 >= 6
        10 * 350 + 15 >= 7
        10 * 400 + 15 >= 8
    and:
        distribution_compare(sp.baa_criteria, a_list, b_list) returns True
    """

    #Every possible percentile needs to be checked,
    #which is why there is a range from 1 to 100.

    a_list_percentile_finder = pf.PercentileFinder(a_list)
    b_list_percentile_finder = pf.PercentileFinder(b_list)
    for i in range(1, 101):
        if not function(a_list_percentile_finder.getPercentile(i),
                        b_list_percentile_finder.getPercentile(i)):
            return False
    return True
예제 #11
0
 def test_range5(self):
     """
     To see what happens when the percentile is above of the accepted range
     """
     x = pf.PercentileFinder([1, 2, 3, 4, 5, 6])
     self.assertRaises(AssertionError, x.getPercentile, 101)
예제 #12
0
 def test_stringpercentile(self):
     """
     To see what happens when there is a string for the percentile
     """
     x = pf.PercentileFinder([0, 5])
     self.assertRaises(AssertionError, x.getPercentile, 'Hi!')