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 print(d) | |
kwiberg-webrtc
2016/05/31 09:04:47
This looks like debug code.
aleloi
2016/05/31 09:49:48
Removed, thank you! (I did run the code before upl
| |
34 return normalize_counter(d) | |
35 | |
36 | |
37 def normalize_counter(counter): | |
38 """Normalizes (i.e. divides by total to sum up to 1) values in input | |
39 dictionary. | |
40 | |
41 """ | |
42 total = sum(counter.values()) | |
43 for key in counter: | |
44 counter[key] /= total | |
45 return counter | |
kwiberg-webrtc
2016/05/31 09:04:47
The standard operating procedure in Python is to e
aleloi
2016/05/31 09:49:48
Done.
| |
46 | |
47 | |
48 def unwrap(data, mod): | |
49 """Unwraps `data` modulo `mod`. | |
50 | |
51 Adds integer multiples of mod to all elements of data except the | |
52 first, such that all pairs of consecutive elements (a, b) satisfy | |
53 -mod / 2 <= b - a < mod / 2. | |
54 | |
55 E.g. unwrap([0, 1, 2, 0, 1, 2, 7, 8], 3) -> [0, 1, 2, 3, | |
56 4, 5, 4, 5] | |
57 | |
58 """ | |
59 for i in range(1, len(data)): | |
60 data[i] = (data[i - 1] + | |
61 (data[i] - data[i - 1] + mod // 2) % mod - mod // 2) | |
62 return data | |
kwiberg-webrtc
2016/05/31 09:04:47
Here too.
aleloi
2016/05/31 09:49:48
Done.
| |
63 | |
64 # Python 2/3-compatible input function | |
65 if sys.version_info[0] <= 2: | |
66 get_input = raw_input | |
67 else: | |
68 get_input = input | |
OLD | NEW |