Jump to content

Time-Based


Recommended Posts

With _Timer_Diff

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Something like this perhaps.

HotKeySet("{ESC}","_Exit")

$timer = TimerInit()
For $i = 0 To 100
    Sleep(100)
    If _MyRandonNumber() <= 49 And TimerDiff($timer) <= 5000 Then
        MsgBox(0, "Alert", "Variable has dropped below half")
    EndIf
Next
Func _MyRandonNumber()
    $i = Random(0, 100, 1)
    Return $i
EndFunc   ;==>_MyRandonNumber

Func _Exit()
    Exit
EndFunc

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

It is difficult to say what should you do because we cant see codes if you dont post script that prelicate problem.

Try one more time to explain what script should do and post some codes.

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Something like this perhaps.

HotKeySet("{ESC}","_Exit")

$timer = TimerInit()
For $i = 0 To 100
    Sleep(100)
    If _MyRandonNumber() <= 49 And TimerDiff($timer) <= 5000 Then
        MsgBox(0, "Alert", "Variable has dropped below half")
    EndIf
Next
Func _MyRandonNumber()
    $i = Random(0, 100, 1)
    Return $i
EndFunc   ;==>_MyRandonNumber

Func _Exit()
    Exit
EndFunc

Well, He was right about what I wanted to do, the only problem with that is that the Variable isnt always 100 or <49, it can be anything between 1 and 100 and im trying to triger the "If" only when the variable drops like 30+ in less then 3-5 seconds..

Does that makes sence?

Thanks for the help guys!

Like So:

If $var1 'becomes' $var1 - 30 'In less than 3 Seconds' Then

MsgBox(0, "Title", "Info")

EndIf

Edited by ericnail
Link to comment
Share on other sites

Just change the function _myrandomnumber

thats just an example, not code I expect you to use

you asked for something to happen when a variable went below 50 in less than 5 seconds.

thats what that does.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Just change the function _myrandomnumber

thats just an example, not code I expect you to use

you asked for something to happen when a variable went below 50 in less than 5 seconds.

thats what that does.

Thanks, I really appreciate your help here, Im very new!

Is there a way to modify that code to make something happen if the variable dropped 50 in under 5 seconds, not necessarily dropped 50% of 100%?

Link to comment
Share on other sites

Theoretically if i understand you correctly

You can try to set in array the diff time from one drop to another and calculate last 50 drops (for $x = 1 to 50) ($last50 += $array[$x]) on every drop, if $last50 < 5000 then msgbox

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

A possible solution utilizing a queue:

HotKeySet("{ESC}","_Exit")

Global Const $qDATA = 0
Global Const $qTIME = 1
Global Const $qSIZE = 50

Global Const $timeDiff = 5 * 1000
Global Const $dataDiff = 30

; I hate global data structures, but it avoids tedious passing of
; values between functions
Global $qFront = 0
Global $qBack = 0
Global $biggest = 0
Global $Queue [$qSIZE][2]

Local $timer = TimerInit()

$Queue [0][$qDATA] = 0
$Queue [0][$qTIME] = 0

While 1
    Sleep(1000)
    Local $nowDATA = Mod ($Queue[$qBack][$qDATA] + _MyRandomNumber(), 100) ;Don't exeed 100
    If $nowDATA < 0 Then $nowData *= -1
    Local $nowTIME = TimerDiff ($timer)
    
    _AddToQueue ($nowDATA, $nowTIME)
    
    If $nowDATA > $Queue[$biggest][$qDATA] Then 
        $biggest = $qFront
    ElseIf $Queue[$biggest][$qDATA] - $nowDATA > $dataDiff Then
        ConsoleWrite ("Alert: Variable has dropped below threashold (From" & $Queue[$biggest][$qDATA] & " to " & $nowDATA & " in " & ($nowTIME - $Queue[$biggest][$qTIME]) / 1000. & " seconds)" & @LF)
        $biggest = $qFront
    EndIf
WEnd

Func _AddToQueue ($data, $time)
    If $time - $Queue[$qBack][$qTIME] > $timeDiff Then ;If the last item in the queue has timed out
        $qBack = Mod ($qBack + 1, $qSIZE)
        If $qBack - 1 = $biggest Then ;Find the next largest
            $biggest = $qBack
            ;Custom loop to deal with the Queue
            Local $temp = $qBack
            While $temp <> $qFront
                If $Queue[$temp][$qDATA] > $Queue[$biggest][$qDATA] Then $biggest = $temp
                $temp = Mod($temp + 1, $qSIZE)
            WEnd
        EndIf
    EndIf
        
    $qFront = Mod($qFront + 1, $qSIZE) ;Wraps around if we pass 50
    If $qFront > $qBack AND $qFront - $qBack > $qSIZE Then 
        $qBack = Mod ($qBack + 1, $qSIZE)
    ElseIf $qFront < $qBack AND ($qFront + 50) - $qBack > $qSIZE Then 
        $qBack = Mod ($qBack + 1, $qSIZE)
    EndIf
    
    $Queue[$qFront][$qDATA] = $data
    $Queue[$qFront][$qTIME] = $time
EndFunc

Func _MyRandomNumber()
    Return Random(0, 100, 1) - 100
EndFunc

Func _Exit()
    ExitEndFunc
Note: this is a heavily modified version of JohnOne's original solution.

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

A possible solution utilizing a queue:

HotKeySet("{ESC}","_Exit")

Global Const $qDATA = 0
Global Const $qTIME = 1
Global Const $qSIZE = 50

Global Const $timeDiff = 5 * 1000
Global Const $dataDiff = 30

; I hate global data structures, but it avoids tedious passing of
; values between functions
Global $qFront = 0
Global $qBack = 0
Global $biggest = 0
Global $Queue [$qSIZE][2]

Local $timer = TimerInit()

$Queue [0][$qDATA] = 0
$Queue [0][$qTIME] = 0

While 1
    Sleep(1000)
    Local $nowDATA = Mod ($Queue[$qBack][$qDATA] + _MyRandomNumber(), 100) ;Don't exeed 100
    If $nowDATA < 0 Then $nowData *= -1
    Local $nowTIME = TimerDiff ($timer)
    
    _AddToQueue ($nowDATA, $nowTIME)
    
    If $nowDATA > $Queue[$biggest][$qDATA] Then 
        $biggest = $qFront
    ElseIf $Queue[$biggest][$qDATA] - $nowDATA > $dataDiff Then
        ConsoleWrite ("Alert: Variable has dropped below threashold (From" & $Queue[$biggest][$qDATA] & " to " & $nowDATA & " in " & ($nowTIME - $Queue[$biggest][$qTIME]) / 1000. & " seconds)" & @LF)
        $biggest = $qFront
    EndIf
WEnd

Func _AddToQueue ($data, $time)
    If $time - $Queue[$qBack][$qTIME] > $timeDiff Then ;If the last item in the queue has timed out
        $qBack = Mod ($qBack + 1, $qSIZE)
        If $qBack - 1 = $biggest Then ;Find the next largest
            $biggest = $qBack
            ;Custom loop to deal with the Queue
            Local $temp = $qBack
            While $temp <> $qFront
                If $Queue[$temp][$qDATA] > $Queue[$biggest][$qDATA] Then $biggest = $temp
                $temp = Mod($temp + 1, $qSIZE)
            WEnd
        EndIf
    EndIf
        
    $qFront = Mod($qFront + 1, $qSIZE) ;Wraps around if we pass 50
    If $qFront > $qBack AND $qFront - $qBack > $qSIZE Then 
        $qBack = Mod ($qBack + 1, $qSIZE)
    ElseIf $qFront < $qBack AND ($qFront + 50) - $qBack > $qSIZE Then 
        $qBack = Mod ($qBack + 1, $qSIZE)
    EndIf
    
    $Queue[$qFront][$qDATA] = $data
    $Queue[$qFront][$qTIME] = $time
EndFunc

Func _MyRandomNumber()
    Return Random(0, 100, 1) - 100
EndFunc

Func _Exit()
    ExitEndFunc
Note: this is a heavily modified version of JohnOne's original solution.

Woah! My brain just exploded!

haha I am not advanced enough to understand any of that O.O

Link to comment
Share on other sites

How fast can you click F6? :0)

#Include <Array.au3>
#Include <Timers.au3>
#Include <Misc.au3>
$dropcount = 5;to monitor las 5 actions
Dim $array[$dropcount]
$array[0] = 0
For $x = 1 To $dropcount-1
    $array[$x] = 0
Next
$sw = 0
$starttime = _Timer_Init()
$data = 0
$data1 = 0

While 1
    If _IsPressed(75) And $sw =  0 Then;F6 Then
        $sw = 1
        _ArrayDelete($array,0)
        _ArrayAdd($array,Int(_Timer_Diff($starttime)))
        $starttime = _Timer_Init()
    EndIf
    If Not _IsPressed(75) And $sw = 1 Then;F6 Then
        $sw = 0
    EndIf
    For $y = 0 To $dropcount-1
        $data += $array[$y]
    Next
        If $data <> $data1 Then
            If $data < 5000 Then;in 5 secs.
                ConsoleWrite($data&" MiliSec."&@CRLF)
            Else
                ConsoleWrite("Common try faster you worm "&$data&" MiliSec."&@CRLF)
            EndIf
        EndIf
    $data1 = $data
    $data = 0
WEnd

Edit: My fastes record for 5 clicks whas 605 :(

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

hmm.. I'll describe it with real terms:

I have a network monitor and it checks the amount of usage from 0% to 100%

What I want to do, is have Autoit alert me if there is a spike(change over less than 5 seconds) larger than 30%.

Link to comment
Share on other sites

I modified it to warn on spikes, rather than drops, and added some more documentation on what I was doing. For more reading on the data structure I used wikipedia has a dryish article on queues, and a much clearer entry on bounded queues, which is the variant that I used here.

HotKeySet("{ESC}","_Exit")

OnAutoItExitRegister ("CloseLog") ;Is called on any type of exit to preserve our logs

; These constants are fore readability
Global Const $qDATA = 0
Global Const $qTIME = 1
Global Const $qSIZE = 50

; This affects how our script works
Global Const $pollingFrequency = .5 * 1000; Poll every 1/2 second
Global Const $timeDiff = 5 * 1000
; The threashold for warning about spikes
Global Const $dataDiff = 30

; I hate global data structures, but it avoids tedious passing of
; values between functions
Global $qFront = 0 ;Holds the index of the most current time
Global $qBack = 0 ;Holds the index of the oldest time
Global $qSmall = 0 ;Holds the index of the smallest time between $qFront and $qBack
Global $Queue [$qSIZE][2] ;The array that will hold our queue

Global $logHandle = FileOpen ("SomeLogFilePath.txt", 1) ;Open the log file

; Start the timer
Local $timer = TimerInit()

; Zero out the first entry
$Queue [0][$qDATA] = 0
$Queue [0][$qTIME] = 0

While 1
    Sleep($pollingFrequency)
    ; Record the current usage and time
    Local $nowDATA = _GetNetworkUsage()
    Local $nowTIME = TimerDiff ($timer)
    
    ; Add it to the queue
    _AddToQueue ($nowDATA, $nowTIME)
    
    ; Check if it is smaller than the oldest low point
    If $nowDATA < $Queue[$qSmall][$qDATA] Then 
        $qSmall = $qFront
    ElseIf $nowDATA - $Queue[$qSmall][$qDATA]  > $dataDiff Then
        _AlertMe ()
        $qSmall = $qFront
    EndIf
WEnd

Func _AlertMe ()
    FileWriteLine ($logHandle, _
    @YEAR & @MON & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & _
    " Variable has spiked past threashold: (From" & $Queue[$qSmall][$qDATA] & " to " & $nowDATA & " in " & ($nowTIME - $Queue[$qSmall][$qTIME]) / 1000. & " seconds)" & @LF)
EndFunc

Func _AddToQueue ($data, $time)
    If $time - $Queue[$qBack][$qTIME] > $timeDiff Then ;If the last item in the queue has timed out
        ;Increment $qBack
        $qBack = Mod ($qBack + 1, $qSIZE)
        
        If $qBack - 1 = $qSmall Then ;Find the next smallest
            $qSmall = $qBack
            ;Custom loop to deal with the Queue, which is treated as a circle, with end and beginning connected
            Local $temp = $qBack
            While $temp <> $qFront
                If $Queue[$temp][$qDATA] < $Queue[$qSmall][$qDATA] Then $qSmall = $temp
                ;Increment $temp, which will wrap around at the end of the array
                $temp = Mod($temp + 1, $qSIZE)
            WEnd
        EndIf
    EndIf
    
    ;Move $qFront forward
    $qFront = Mod($qFront + 1, $qSIZE) ;Wraps around if we pass $qSIZE
    
    ;Increment $qBack if we are out of space in the queue
    If $qFront > $qBack AND $qFront - $qBack > $qSIZE Then 
        $qBack = Mod ($qBack + 1, $qSIZE)
        FileWriteLine ($logHandle, @YEAR & @MON & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Size of Queue exeeded, please resize $qSIZE")
    ElseIf $qFront < $qBack AND ($qFront + 50) - $qBack > $qSIZE Then 
        $qBack = Mod ($qBack + 1, $qSIZE)
        FileWriteLine ($logHandle, @YEAR & @MON & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " Size of Queue exeeded, please resize $qSIZE")
    EndIf
    
    ;Insert our data in the new first slot
    $Queue[$qFront][$qDATA] = $data
    $Queue[$qFront][$qTIME] = $time
EndFunc

Func _GetNetworkUsage()
    Return Random(0, 100) ;Replace this with whatever call you use to check the network usage
EndFunc

Func CloseLog ()
    FileClose ($logHandle) ;Close so we don't loose our logfile
EndFunc

Func _Exit()
    ExitEndFunc
Hope this helps (and is a little clearer) :( Edited by Fulano

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

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...