Jump to content
Sign in to follow this  
Datenshi

Moving Average

Recommended Posts

Datenshi

Calculation for the Moving Average transfer speed. It calculates the average of speed samples taken approx over the last 5 seconds.

#include <Array.au3>

Func MovingAverage() ; updates stats during download
    Dim $SpeedSamples[5]
    $Accuracytimer = timerInit() ; for first loop

    While @InetGetActive
    $CalcAverage = 0

    $BytesRead1 = @InetGetBytesRead
    Sleep(1000)
    $BytesRead2 = @InetGetBytesRead

    _ArrayPush($SpeedSamples,Int($BytesRead2 - $BytesRead1)*(TimerDiff($Accuracytimer)/1000))
    $Accuracytimer = timerInit()
    $Ubound = Ubound($SpeedSamples) -1
    For $x = 0 To $Ubound
        $CalcAverage += $SpeedSamples[$x]
    Next
        $CalcAverage = $CalcAverage/$Ubound
        $AverageSpeed = Int($CalcAverage/1024)

    ConsoleWrite($AverageSpeed&" kb/s"&@CRLF)
WEnd
EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.