Vice Underdogs
Scripting => Script Showroom => Topic started by: stormeus on August 16, 2016, 08:47:39 pm
-
This is a small snippet I wrote for the VCDC server which would measure a player's latency jitter. Pingtest.net defines jitter as:
the variance in measuring successive ping tests. Zero jitter means the results were exactly the same every time, and anything above zero is the amount by which they varied.
Which makes it a decent measure of the instability of a player's connection. In VCDC, a player would be kicked not only due to high ping, but also due to a high jitter and consistently unstable connection that could cause warping.
The code below calculates the standard deviation (http://www.mathsisfun.com/data/standard-deviation.html) of an array of ping measurements to find jitter.
function CalculateAvg(arr) {
local sum = 0, count = 0;
foreach(entry in arr) {
sum += entry;
count++;
}
return sum.tofloat() / count.tofloat();
}
function CalculateVariance(arr) {
local avg = CalculateAvg(arr);
local sum = 0, count = 0;
foreach (entry in arr) {
sum += pow(entry - avg, 2);
count++;
}
return sum.tofloat() / count.tofloat();
}
function CalculateJitter(arr) {
return sqrt(CalculateVariance(arr));
}
Test cases
sq>print(CalculateJitter([250, 280, 230, 240, 250, 290, 240, 310, 230, 250]));
25.7099
sq>print(CalculateJitter([10, 10, 15, 10, 10, 12, 10, 9, 10, 10]));
1.62481
sq>print(CalculateJitter([80, 80, 80, 350, 360, 320, 330, 167, 95, 80]));
121.974
sq>print(CalculateJitter([5, 10, 15, 20, 25, 30, 35, 40, 45]));
12.9099
-
Nice snippet :)
Might be useful for people to mention what kind of values should be seen as high jitter.
-
Great Work !
-
Great Work !
-
nice
now fix tommy face
top fun + coach 2 seats only BUG
(https://viceunderdogs.com/proxy.php?request=http%3A%2F%2Fi.imgur.com%2F0jvs1QH.jpg&hash=0a6003480d4ab3c8ebc9a1af97f0a6edd45bf52c)
-
Nice job