Index: tools/py_event_log_analyzer/misc.py |
diff --git a/tools/py_event_log_analyzer/misc.py b/tools/py_event_log_analyzer/misc.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d10940757fe499ef5e7d23bd8d3711db4df8b359 |
--- /dev/null |
+++ b/tools/py_event_log_analyzer/misc.py |
@@ -0,0 +1,66 @@ |
+# Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
+# |
+# Use of this source code is governed by a BSD-style license |
+# that can be found in the LICENSE file in the root of the source |
+# tree. An additional intellectual property rights grant can be found |
+# in the file PATENTS. All contributing project authors may |
+# be found in the AUTHORS file in the root of the source tree. |
+ |
+"""Utility functions for calculating statistics. |
+""" |
+ |
+from __future__ import division |
+import collections |
+import sys |
+ |
+ |
+def count_reordered(sequence_numbers): |
+ """Returns number of indices `i` for which |
+ sequence_numbers[i] >= sequence_numbers[i+1] |
+ """ |
+ return sum(1 for (s1, s2) in zip(sequence_numbers, |
+ sequence_numbers[1:]) if |
+ s1 >= s2) |
+ |
+ |
+def ssrc_normalized_size_table(data_points): |
+ """Returns mapping from a SSRC to its relative occurance proportion in |
+ the data. |
+ """ |
+ d = collections.defaultdict(int) |
+ for pt in data_points: |
+ d[pt.ssrc] += pt.size |
+ return normalize_counter(d) |
+ |
+ |
+def normalize_counter(counter): |
+ """Returns a normalized (i.e. divided by total to sum up to 1) version |
+ of the input dictionary `counter`. Does not modify `counter`. |
+ |
+ """ |
+ total = sum(counter.values()) |
+ return {key: counter[key] / total for key in counter} |
+ |
+ |
+def unwrap(data, mod): |
+ """Returns `data` unwrapped modulo `mod`. Does not modify data. |
+ |
+ Adds integer multiples of mod to all elements of data except the |
+ first, such that all pairs of consecutive elements (a, b) satisfy |
+ -mod / 2 <= b - a < mod / 2. |
+ |
+ E.g. unwrap([0, 1, 2, 0, 1, 2, 7, 8], 3) -> [0, 1, 2, 3, |
+ 4, 5, 4, 5] |
+ |
+ """ |
+ lst = data[:] |
+ for i in range(1, len(data)): |
+ lst[i] = lst[i - 1] + (lst[i] - lst[i - 1] + |
+ mod // 2) % mod - (mod // 2) |
+ 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
|
+ |
+# Python 2/3-compatible input function |
+if sys.version_info[0] <= 2: |
+ get_input = raw_input |
+else: |
+ get_input = input |