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 | |
15 | |
16 def count_reordered(sequence_numbers): | |
17 """Returns number of indices `i` for which | |
18 sequence_numbres[i] >= sequence_numbres[i+1] | |
kwiberg-webrtc
2016/05/25 12:42:41
There's an extra space here. Also, Spanish-soundin
hlundin-webrtc
2016/05/25 12:54:23
numbres -> numbers, twice.
| |
19 """ | |
20 largest = sequence_numbers[0] | |
peah-webrtc
2016/05/26 06:44:18
I also think the numbres<->numbers confusion will
| |
21 result = 0 | |
22 for sequence_number in sequence_numbers: | |
hlundin-webrtc
2016/05/25 12:54:23
You could start the loop on the second item, but i
peah-webrtc
2016/05/26 06:44:18
I don't think this tests really what the method st
aleloi2
2016/05/30 14:57:55
I rewrote it to match the specification.
| |
23 if sequence_number < largest: | |
24 result += 1 | |
25 else: | |
26 largest = sequence_number | |
27 return result | |
kwiberg-webrtc
2016/05/25 12:42:41
Unit test this function!
kwiberg-webrtc
2016/05/25 12:42:41
Hmm.
return sum(1 for (s1, s2) in zip(sequence_
aleloi2
2016/05/30 14:57:55
Your suggestion is simpler to read. I went with th
| |
28 | |
29 | |
30 def ssrc_size_table(data_points): | |
hlundin-webrtc
2016/05/25 12:54:23
The naming of this and the next functions are inco
hlundin-webrtc
2016/05/25 12:54:23
Can't this be implemented in terms of percent_tabl
aleloi2
2016/05/30 14:57:55
Both changed in next version.
| |
31 """Returns mapping from a SSRC to its relative occurance proportion in | |
32 the data. | |
33 """ | |
34 d = collections.Counter(dt.ssrc for dt in data_points) | |
35 total = sum(d.values()) | |
36 for key in d: | |
37 d[key] /= total | |
38 return d | |
kwiberg-webrtc
2016/05/25 12:42:41
This method is practically identical to percent_ta
aleloi2
2016/05/30 14:57:55
See next version!
| |
39 | |
40 | |
41 def percent_table(data): | |
kwiberg-webrtc
2016/05/25 12:42:41
The name is misleading, since you give relative fr
| |
42 """Returns mapping from data element to its relative occurance | |
43 proportion in the data. | |
44 """ | |
45 d = collections.Counter(data) | |
46 total = sum(d.values()) | |
peah-webrtc
2016/05/26 06:44:18
This looks very similar to lines 35-38. It would b
| |
47 for key in d: | |
48 d[key] /= total | |
49 return d | |
50 | |
51 | |
52 def unwrap(data, mod): | |
53 """Unwraps `data` modulo `mod`. | |
54 | |
55 If data contains consecutive elements with difference above `mod/2`, | |
56 an integer multiple of `mod` is added to one of the elements in a | |
57 way that makes the sum of absolute consecutive differences | |
58 minimized. E.g. unwrap([0, 1, 2, 0, 1, 2, 7, 8], 3) -> [0, 1, 2, 3, | |
59 4, 5, 4, 5] | |
kwiberg-webrtc
2016/05/25 12:42:41
This description isn't quite correct. You also add
aleloi2
2016/05/30 14:57:55
Thank you, updated!
| |
60 | |
61 """ | |
62 prev = data[0] | |
63 for idxm1, curr in enumerate(data[1:]): | |
64 idx = idxm1 + 1 | |
65 | |
66 # calculate positive & negative modular difference | |
67 delta_pos = (curr-prev)%mod | |
68 delta_neg = (curr-prev)%mod - mod | |
69 | |
70 # update next value with minimal absolute difference from previous | |
71 delta = delta_pos if abs(delta_pos) < abs(delta_neg) else delta_neg | |
72 curr = prev + delta | |
73 data[idx] = curr | |
74 prev = curr | |
75 return data | |
kwiberg-webrtc
2016/05/25 12:42:41
Unit test this function!
kwiberg-webrtc
2016/05/25 12:42:41
I think this does the same thing with less overhea
aleloi2
2016/05/30 14:57:55
Yes, it does the same thing simpler. Changed!
| |
OLD | NEW |