Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
| 2 # | |
| 3 # Use of this source code is governed by a BSD-style license | |
| 4 # that can be found in the LICENSE file in the root of the source | |
| 5 # tree. An additional intellectual property rights grant can be found | |
| 6 # in the file PATENTS. All contributing project authors may | |
| 7 # be found in the AUTHORS file in the root of the source tree. | |
| 8 | |
| 9 """Utility functions for calculating statistics. | |
| 10 """ | |
| 11 | |
| 12 from __future__ import division | |
| 13 import collections | |
| 14 import sys | |
| 15 | |
| 16 | |
| 17 def count_reordered(sequence_numbers): | |
| 18 """Returns number of indices `i` for which | |
| 19 sequence_numbers[i] >= sequence_numbers[i+1] | |
| 20 """ | |
| 21 return sum(1 for (s1, s2) in zip(sequence_numbers, | |
| 22 sequence_numbers[1:]) if | |
| 23 s1 >= s2) | |
| 24 | |
| 25 | |
| 26 def ssrc_normalized_size_table(data_points): | |
| 27 """Returns mapping from a SSRC to its relative occurance proportion in | |
| 28 the data. | |
| 29 """ | |
| 30 d = collections.defaultdict(int) | |
| 31 for pt in data_points: | |
| 32 d[pt.ssrc] += pt.size | |
| 33 return normalize_counter(d) | |
| 34 | |
| 35 | |
| 36 def normalize_counter(counter): | |
| 37 """Returns a normalized (i.e. divided by total to sum up to 1) version | |
| 38 of the input dictionary `counter`. Does not modify `counter`. | |
| 39 | |
| 40 """ | |
| 41 total = sum(counter.values()) | |
| 42 return {key: counter[key] / total for key in counter} | |
| 43 | |
| 44 | |
| 45 def unwrap(data, mod): | |
| 46 """Returns `data` unwrapped modulo `mod`. Does not modify data. | |
| 47 | |
| 48 Adds integer multiples of mod to all elements of data except the | |
| 49 first, such that all pairs of consecutive elements (a, b) satisfy | |
| 50 -mod / 2 <= b - a < mod / 2. | |
| 51 | |
| 52 E.g. unwrap([0, 1, 2, 0, 1, 2, 7, 8], 3) -> [0, 1, 2, 3, | |
| 53 4, 5, 4, 5] | |
| 54 | |
| 55 """ | |
| 56 lst = data[:] | |
| 57 for i in range(1, len(data)): | |
| 58 lst[i] = lst[i - 1] + (lst[i] - lst[i - 1] + | |
| 59 mod // 2) % mod - (mod // 2) | |
| 60 return lst | |
|
kwiberg-webrtc
2016/05/31 12:30:53
return [data[0]] + [a + (b - a + mod // 2) % mod -
aleloi
2016/05/31 12:40:32
No, wont work, because 'a' comes from the original
kwiberg-webrtc
2016/05/31 12:53:59
Ah, right. Then it's not possible to write as just
| |
| 61 | |
| 62 # Python 2/3-compatible input function | |
| 63 if sys.version_info[0] <= 2: | |
| 64 get_input = raw_input | |
| 65 else: | |
| 66 get_input = input | |
| OLD | NEW |