Sign in to follow this  
Followers 0
ericnail

Time-Sensitive Conundrum

8 posts in this topic

Okay, So I've been trying at this for a LOOOONG time and I just can't seem to get it.

I've tried to use _ArrayPush as well as Queues, however I always get lost in the code others have posted for me to reference and I cannot find any help from google either.

What I am trying to do is this:

I have 4 network monitors and they each constantly update and return a Value between 1 and 100.

I want to have autoit constantly read this and send me a MSGBOX if the value drops at any point more than 30% within a period of 2 seconds. for instance:

Say network 1 is running at 80% (Value = 80) and then all of the sudden it drops to 56, thus losing 30% (.30 * 80 = 24 ~ 24 - 80 = 56), If that drop happened in under 2 seconds (2000 MS), I want it to send me a message box saying: "Network 1 has spiked more than 30%".

Meanwhile, Network 2 could be at 35% (Value = 35), and never drop 30%(or to 24), thus not sending an alert MSGBOX message.

This project has turned out to be my ineptitude and I cannot seem to find a solution. I want to say THANK YOU to everyone who has helped me with this before, and also thank you in advance to anyone who can/will help me.

Thanks,

Eric

Share this post


Link to post
Share on other sites



ericnail,

Not sure I count as "Super-Advanced people", but I am happy to give it a shot. :)

However a couple of questions first:

- 1. How do you get the values from the network monitors into AutoIt? You say "I want to have autoit constantly read this" - what is it you are trying to read? A control in another window?

- 2. You are looking for a drop over 2 secs. How often do you get the updated values? If you have to read them, how often do you want to read them? Given that you are only looking for a drop over 2 secs, logically there is no point in reading at less than 2 sec intervals.

Over to you. :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

ericnail,

Not sure I count as "Super-Advanced people", but I am happy to give it a shot. :)

However a couple of questions first:

- 1. How do you get the values from the network monitors into AutoIt? You say "I want to have autoit constantly read this" - what is it you are trying to read? A control in another window?

- 2. You are looking for a drop over 2 secs. How often do you get the updated values? If you have to read them, how often do you want to read them? Given that you are only looking for a drop over 2 secs, logically there is no point in reading at less than 2 sec intervals.

Over to you. :(

M23

Hey, thank you!

I get the values from a DLL call, so the updates come as fast as the computer can process them.

The problem is this:

If you take every 2 seconds, you leave the middle-ground open to non-detection because the values could drop 30% then go back up in under a second. If the even occurs 1 second in, it wont be updated until a second later, thus leaving the spike unnoticed. Make sense?

Edited by ericnail

Share this post


Link to post
Share on other sites

ericnail,

Here is my attempt to solve your problem.

At the moment we poll the dll every 100ms (although we could make it faster - it depends on the time it takes to get the return). As you are only looking for a drop over 2 secs, that means we need to keep the last 20 reading for comparision purposes - so we use an array as storage with an index to show where the newest entry is to overwrite the oldest (this type of array is an old friend, but often useful :) )

A few explanatory points:

- 1. The HotKey settings between the ##### lines at the beginning are only there to allow the simulation of changes in the network value returned - you can ignore them.

- 2. We set up an array to hold the returned values and start the reading timer.

- 3. When the reading is returned, we put it into the array and check if there has been a drop. If there has, we pause the reading timer (or you could get stacked alerts), show the alert, and then restart the process.

; ###############################

HotKeySet("{ESC}", "On_Exit")
Func On_Exit()
    Exit
EndFunc

; Simulate return from dll call
Global $iNetWorkInput = 80

; Simulate changes to the returned value
HotKeySet("1", "_10")
HotKeySet("2", "_20")
HotKeySet("3", "_30")
HotKeySet("4", "_40")
HotKeySet("5", "_50")
HotKeySet("6", "_60")
HotKeySet("7", "_70")
HotKeySet("8", "_80")
HotKeySet("9", "_90")

Func _10()
    $iNetWorkInput = 10
EndFunc

Func _20()
    $iNetWorkInput = 20
EndFunc

Func _30()
    $iNetWorkInput = 30
EndFunc

Func _40()
    $iNetWorkInput = 40
EndFunc

Func _50()
    $iNetWorkInput = 50
EndFunc

Func _60()
    $iNetWorkInput = 60
EndFunc

Func _70()
    $iNetWorkInput = 70
EndFunc

Func _80()
    $iNetWorkInput = 80
EndFunc

Func _90()
    $iNetWorkInput = 90
EndFunc

; ###############################

; I am assuming we read the dll every 100 ms.
; We may have to adjust this depending on the return time of each dll call to the 4 monitors

; Set up an array to hold the detected values - we know we need 20 values to hold 2 secs worth of returns
Global $aNetWorkValue[21] = [1]
; the [0] eleent is an index to tell us where the next value is to be placed in the array

; Start reading the value
AdlibRegister("_Read_NetWork", 100)

Func _Read_Network()

    ; We read the value from the dll - here we just read $iNetWorkInput

    ; Note the current value
    $iCurrValue = $iNetWorkInput
    ; Put the value into the array at the indexed element
    $aNetWorkValue[$aNetWorkValue[0]] = $iNetWorkInput

    ; Now check over the past array entries to see if there has been a drop

    ; First determine the lowest higher value that we need to find to trigger the alert
    $iHiValue = $iCurrValue * 10 / 7

    ; Now scan the array
    For $i = 1 To 20
        If $aNetWorkValue[$i] >= $iHiValue Then ExitLoop
    Next

    ; Check if we exited early - if we did then we found a high enough value
    If $i < 21 Then
        ; Stop reading of the network - or we might get multiple alerts
        AdlibUnRegister("_Read_NetWork")
        ; Show alert
        MsgBox(0, "Alert", "Network has dropped 30% within 2 secs")
        ; Now the alert is cancelled:
        ; Reset the array or we will continue getting alerts!
        Global $aNetWorkValue[21] = [1]
        ; Restart the reading
        AdlibRegister("_Read_NetWork", 100)
    EndIf

    ; Increase the index, looping if required
    $aNetWorkValue[0] += 1
    If $aNetWorkValue[0] = 21 Then $aNetWorkValue[0] = 1

EndFunc

; Keep the script active
While 1
    Sleep(10)
WEnd

Play around with the script, using the 1-9 HotKeys to simulate changes to the Network value. In my testing it is working fine - slow changes are ignored, but rapid ones trigger an alert. There are a lot of comments to help you understand what is going on.

I hope this helps. :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I think that's working!!

how would I do that with 4 networks at the same time? I dont want to change anything and break it!

Hmm.. Where are you clerifying the 30% value? It's working but I cant figure out where you tell it to check for 30%

Edited by ericnail

Share this post


Link to post
Share on other sites

ericnail,

how would I do that with 4 networks at the same time?

Like this: :(

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

; Set up a 2D array to hold the detected values from the 4 networks - dimensions = [network][reading]
Global $aNetWorkValue[4][21]

; Now set the [][0] elements as indices
For $i = 0 To 3
    $aNetWorkValue[$i][0] = 1
Next

; Still assuming we read each dll every 100 ms start reading the values
; We spread them out a bit so they (hopefully) do not interfere too much
AdlibRegister("_Read_NetWork_1", 100)
Sleep(20)
AdlibRegister("_Read_NetWork_2", 100)
Sleep(20)
AdlibRegister("_Read_NetWork_3", 100)
Sleep(20)
AdlibRegister("_Read_NetWork_4", 100)

; Keep the script active
While 1
    Sleep(10)
WEnd

Func _Read_Network_1()

    Local $iNetWorkInput = "Your_DLL_Call_to_Network_1_code_here"
    Local $iCurrValue = $iNetWorkInput
    $aNetWorkValue[0][$aNetWorkValue[0][0]] = $iNetWorkInput
    $iHiValue = $iCurrValue * 10 / 7
    For $i = 1 To 20
        If $aNetWorkValue[0][$i] >= $iHiValue Then ExitLoop
    Next
    If $i < 21 Then
        AdlibUnRegister("_Read_NetWork_1")
        MsgBox(0, "Alert", "Network 1 has dropped 30% within 2 secs")
        For $i = 0 To 20
            $aNetWorkValue[0][$i] = 0
        Next
        AdlibRegister("_Read_NetWork_1", 100)
    EndIf
    $aNetWorkValue[0][0] += 1
    If $aNetWorkValue[0][0] = 21 Then $aNetWorkValue[0][0] = 1

EndFunc

Func _Read_Network_2()

    Local $iNetWorkInput = "Your_DLL_Call_to_Network_2_code_here"
    Local $iCurrValue = $iNetWorkInput
    $aNetWorkValue[1][$aNetWorkValue[1][0]] = $iNetWorkInput
    $iHiValue = $iCurrValue * 10 / 7
    For $i = 1 To 20
        If $aNetWorkValue[1][$i] >= $iHiValue Then ExitLoop
    Next
    If $i < 21 Then
        AdlibUnRegister("_Read_NetWork_2")
        MsgBox(0, "Alert", "Network 2 has dropped 30% within 2 secs")
        For $i = 0 To 20
            $aNetWorkValue[1][$i] = 0
        Next
        AdlibRegister("_Read_NetWork_2", 100)
    EndIf
    $aNetWorkValue[1][0] += 1
    If $aNetWorkValue[1][0] = 21 Then $aNetWorkValue[1][0] = 1

EndFunc

Func _Read_Network_3()

    Local $iNetWorkInput = "Your_DLL_Call_to_Network_3_code_here"
    Local $iCurrValue = $iNetWorkInput
    $aNetWorkValue[2][$aNetWorkValue[2][0]] = $iNetWorkInput
    $iHiValue = $iCurrValue * 10 / 7
    For $i = 1 To 20
        If $aNetWorkValue[2][$i] >= $iHiValue Then ExitLoop
    Next
    If $i < 21 Then
        AdlibUnRegister("_Read_NetWork_3")
        MsgBox(0, "Alert", "Network 3 has dropped 30% within 2 secs")
        For $i = 0 To 20
            $aNetWorkValue[2][$i] = 0
        Next
        AdlibRegister("_Read_NetWork_3", 100)
    EndIf
    $aNetWorkValue[2][0] += 1
    If $aNetWorkValue[2][0] = 21 Then $aNetWorkValue[2][0] = 1

EndFunc

Func _Read_Network_4()

    Local $iNetWorkInput = "Your_DLL_Call_to_Network_4_code_here"
    Local $iCurrValue = $iNetWorkInput
    $aNetWorkValue[3][$aNetWorkValue[3][0]] = $iNetWorkInput
    $iHiValue = $iCurrValue * 10 / 7
    For $i = 1 To 20
        If $aNetWorkValue[3][$i] >= $iHiValue Then ExitLoop
    Next
    If $i < 21 Then
        AdlibUnRegister("_Read_NetWork_4")
        MsgBox(0, "Alert", "Network 4 has dropped 30% within 2 secs")
        For $i = 0 To 2
            $aNetWorkValue[3][$i] = 0
        Next
        AdlibRegister("_Read_NetWork_4", 100)
    EndIf
    $aNetWorkValue[3][0] += 1
    If $aNetWorkValue[3][0] = 21 Then $aNetWorkValue[3][0] = 1

EndFunc

Func On_Exit()
    Exit
EndFunc

Put your DLL code in the places shown and run it.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

ericnail,

Like this: :(

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

; Set up a 2D array to hold the detected values from the 4 networks - dimensions = [network][reading]
Global $aNetWorkValue[4][21]

; Now set the [][0] elements as indices
For $i = 0 To 3
    $aNetWorkValue[$i][0] = 1
Next




; Still assuming we read each dll every 100 ms start reading the values
; We spread them out a bit so they (hopefully) do not interfere too much
AdlibRegister("_Read_NetWork_1", 100)
Sleep(20)
AdlibRegister("_Read_NetWork_2", 100)
Sleep(20)
AdlibRegister("_Read_NetWork_3", 100)
Sleep(20)
AdlibRegister("_Read_NetWork_4", 100)

; Keep the script active
While 1
    Sleep(10)
WEnd

Func _Read_Network_1()

    Local $iNetWorkInput = "Your_DLL_Call_to_Network_1_code_here"
    Local $iCurrValue = $iNetWorkInput
    $aNetWorkValue[0][$aNetWorkValue[0][0]] = $iNetWorkInput
    $iHiValue = $iCurrValue * 10 / 7
    For $i = 1 To 20
        If $aNetWorkValue[0][$i] >= $iHiValue Then ExitLoop
    Next
    If $i < 21 Then
        AdlibUnRegister("_Read_NetWork_1")
        MsgBox(0, "Alert", "Network 1 has dropped 30% within 2 secs")
        For $i = 0 To 20
            $aNetWorkValue[0][$i] = 0
        Next
        AdlibRegister("_Read_NetWork_1", 100)
    EndIf
    $aNetWorkValue[0][0] += 1
    If $aNetWorkValue[0][0] = 21 Then $aNetWorkValue[0][0] = 1

EndFunc

Func _Read_Network_2()

    Local $iNetWorkInput = "Your_DLL_Call_to_Network_2_code_here"
    Local $iCurrValue = $iNetWorkInput
    $aNetWorkValue[1][$aNetWorkValue[1][0]] = $iNetWorkInput
    $iHiValue = $iCurrValue * 10 / 7
    For $i = 1 To 20
        If $aNetWorkValue[1][$i] >= $iHiValue Then ExitLoop
    Next
    If $i < 21 Then
        AdlibUnRegister("_Read_NetWork_2")
        MsgBox(0, "Alert", "Network 2 has dropped 30% within 2 secs")
        For $i = 0 To 20
            $aNetWorkValue[1][$i] = 0
        Next
        AdlibRegister("_Read_NetWork_2", 100)
    EndIf
    $aNetWorkValue[1][0] += 1
    If $aNetWorkValue[1][0] = 21 Then $aNetWorkValue[1][0] = 1

EndFunc

Func _Read_Network_3()

    Local $iNetWorkInput = "Your_DLL_Call_to_Network_3_code_here"
    Local $iCurrValue = $iNetWorkInput
    $aNetWorkValue[2][$aNetWorkValue[2][0]] = $iNetWorkInput
    $iHiValue = $iCurrValue * 10 / 7
    For $i = 1 To 20
        If $aNetWorkValue[2][$i] >= $iHiValue Then ExitLoop
    Next
    If $i < 21 Then
        AdlibUnRegister("_Read_NetWork_3")
        MsgBox(0, "Alert", "Network 3 has dropped 30% within 2 secs")
        For $i = 0 To 20
            $aNetWorkValue[2][$i] = 0
        Next
        AdlibRegister("_Read_NetWork_3", 100)
    EndIf
    $aNetWorkValue[2][0] += 1
    If $aNetWorkValue[2][0] = 21 Then $aNetWorkValue[2][0] = 1

EndFunc

Func _Read_Network_4()

    Local $iNetWorkInput = "Your_DLL_Call_to_Network_4_code_here"
    Local $iCurrValue = $iNetWorkInput
    $aNetWorkValue[3][$aNetWorkValue[3][0]] = $iNetWorkInput
    $iHiValue = $iCurrValue * 10 / 7
    For $i = 1 To 20
        If $aNetWorkValue[3][$i] >= $iHiValue Then ExitLoop
    Next
    If $i < 21 Then
        AdlibUnRegister("_Read_NetWork_4")
        MsgBox(0, "Alert", "Network 4 has dropped 30% within 2 secs")
        For $i = 0 To 2
            $aNetWorkValue[3][$i] = 0
        Next
        AdlibRegister("_Read_NetWork_4", 100)
    EndIf
    $aNetWorkValue[3][0] += 1
    If $aNetWorkValue[3][0] = 21 Then $aNetWorkValue[3][0] = 1

EndFunc

Func On_Exit()
    Exit
EndFunc

Put your DLL code in the places shown and run it.

M23

WOW! I Freaking Love You!

You have NO idea how long I've been trying to get this to work.

Seriously, you just made my day! :)

Edited by ericnail

Share this post


Link to post
Share on other sites

ericnail,

My pleasure. :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  
Followers 0