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..0d6381639f6e3b6d0b9a44c9f8b340fab7f60a19 |
--- /dev/null |
+++ b/tools/py_event_log_analyzer/misc.py |
@@ -0,0 +1,68 @@ |
+# 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 |
+ 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
|
+ return normalize_counter(d) |
+ |
+ |
+def normalize_counter(counter): |
+ """Normalizes (i.e. divides by total to sum up to 1) values in input |
+ dictionary. |
+ |
+ """ |
+ total = sum(counter.values()) |
+ for key in counter: |
+ counter[key] /= total |
+ 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.
|
+ |
+ |
+def unwrap(data, mod): |
+ """Unwraps `data` modulo `mod`. |
+ |
+ 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] |
+ |
+ """ |
+ for i in range(1, len(data)): |
+ data[i] = (data[i - 1] + |
+ (data[i] - data[i - 1] + mod // 2) % mod - mod // 2) |
+ return data |
kwiberg-webrtc
2016/05/31 09:04:47
Here too.
aleloi
2016/05/31 09:49:48
Done.
|
+ |
+# Python 2/3-compatible input function |
+if sys.version_info[0] <= 2: |
+ get_input = raw_input |
+else: |
+ get_input = input |