Vice Underdogs

Scripting => Script Showroom => Topic started by: stormeus on August 16, 2016, 08:47:39 pm

Title: Measuring ping jitter in Squirrel
Post 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:
Quote
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.

Code: (Jitter calculation functions) [Select]
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
Code: [Select]
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
Title: Re: Measuring ping jitter in Squirrel
Post by: Thijn on August 17, 2016, 06:04:29 am
Nice snippet :)

Might be useful for people to mention what kind of values should be seen as high jitter.
Title: Re: Measuring ping jitter in Squirrel
Post by: Roystang on August 17, 2016, 02:04:26 pm
Great Work !
Title: Re: Measuring ping jitter in Squirrel
Post by: SanaullaH on August 17, 2016, 02:59:51 pm
Great Work !
Title: Re: blablabla
Post by: krystianoo on August 18, 2016, 07:58:06 am
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)
Title: Re: Measuring ping jitter in Squirrel
Post by: QarZ on August 18, 2016, 01:47:35 pm
Nice job