Jump to content

Moving Average


Datenshi
 Share

Recommended Posts

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...