Beispiel #1
0
    def median_of_time_buckets(time_buckets):
        """
        Take a list of [seconds, count] tuples and get the median seconds.
        """
        lst = []

        # Flatten the [seconds, count] tuples
        # This is a really bad way to do this!
        # Yuuuuge number of objects created!
        for bucket in time_buckets:
            for _ in range(bucket[1]):
                lst.append(bucket[0])

        median = GoogleAnalytics.median(lst)
        return int(median)
Beispiel #2
0
    def median_of_time_buckets(time_buckets):
        """
        Take a list of [seconds, count] tuples and get the median seconds.
        """
        lst = []

        # Flatten the [seconds, count] tuples
        # This is a really bad way to do this!
        # Yuuuuge number of objects created!
        for bucket in time_buckets:
            for _ in range(bucket[1]):
                lst.append(bucket[0])

        median = GoogleAnalytics.median(lst)
        return int(median)
    def get_median(self, data):
        """
        Take the scroll depth data we have (number of people per percent)
        Then calculate how many people only got to THAT bucket (aka didn't get
        to the next percent bucket)
        """
        length = len(data)
        for i, row in enumerate(data):
            if not i == length - 1:
                row[1] = row[1] - data[i + 1][1]

        lst = []

        # Flatten the [percent, count] tuples
        # This is a really inefficient way to do this!
        for bucket in data:
            for _ in range(bucket[1]):
                lst.append(bucket[0])

        median = GoogleAnalytics.median(lst)
        return int(median)
Beispiel #4
0
 def test_median(self):
     values = [1, 1, 2, 2, 2, 3, 3]
     median = GoogleAnalytics.median(values)
     self.assertEqual(median, 2)