-1

My AutoIt script should predict when a process will complete by saying The process will be complete at 3:18:24 PM. But that is not happening. It takes these input values:

  1. Starting time
  2. Starting percentage
  3. Current time
  4. Current percentage

It displays:

"The extraction will be complete at 0".

I isolated the problem to _DateDiff(). I thought the first parameter was n for difference in minutes. But it returns 0 when I pass the next two parameters (date values spaced sixty minutes apart). Here's the code:

GUICreate("Completion Time Predictor", 300, 300)
;Here I enter the starting time and percentage
GUICtrlCreateLabel("Enter the start time:", 10, 10, 270, 29)
$StartTime = GUICtrlCreateDate("", 10, 40, 270, 21, $DTS_TIMEFORMAT)
GUICtrlCreateLabel("Enter the start percentage:", 10, 70, 270, 29)
Local $StartPercent = GUICtrlCreateInput("", 10, 100, 270, 21)
;Here I enter the current time and percentage
GUICtrlCreateLabel("Enter the current time:", 10, 130, 270, 29)
$CurrentTime = GUICtrlCreateDate("", 10, 160, 270, 21, $DTS_TIMEFORMAT)
GUICtrlCreateLabel("Enter the current percentage:", 10, 190, 270, 29)
Local $CurrentPercent = GUICtrlCreateInput("", 10, 220, 270, 21)
Local $CTRL_a = GUICtrlCreateButton("Calculate", 10, 260, 280, 21)
GUISetState()
Local $msg
Do
    $msg = GUIGetMsg()
    Select
        Case $msg = $CTRL_a
            $PercentChange = GUICtrlRead($CurrentPercent) - GUICtrlRead($StartPercent)
            ;This seems to be where everything is going wrong
            $ChangePerMinute = $PercentChange / _DateDiff('n', GUICtrlRead($StartTime), GUICtrlRead($CurrentTime))
            $MinutesRemaining = (100 - GUICtrlRead($CurrentPercent)) / $ChangePerMinute
            $EndTime = _DateAdd('n', $MinutesRemaining, GUICtrlRead($CurrentTime))
            MsgBox($MB_OK, "Predicted Completion Time:", "The extraction will be complete at  " & $EndTime)
    EndSelect
Until $msg = $GUI_EVENT_CLOSE
user4157124
  • 2,809
  • 13
  • 27
  • 42
DED1
  • 43
  • 6
  • [Related](https://stackoverflow.com/a/30426814/4157124). – user4157124 Jan 08 '18 at 20:08
  • 1
    According to the [documentation for _DateDiff()](https://www.autoitscript.com/autoit3/docs/libfunctions/_DateDiff.htm) the $sStartDate and $sEndDate parameters need to be in the form "YYYY/MM/DD[ HH:MM:SS]" which means that they need to be a date in the form "YYYY/MM/DD" or a date and a time in the form "YYYY/MM/DD HH:MM:SS", but you are using only a time. – garbb Jan 08 '18 at 20:46
  • So I need to add a date in the YYYY/MM/DD form. Can you give me some advice as to how I can do that? I tried concatenating the current system date with the time value, and that did not work. – DED1 Jan 08 '18 at 21:01
  • by substracting the current percentage with old percentage, you get what it's call percentage speed, it could be like 1%/Sec or anything else and with this value you can determine how long does it takes to reach 100% eg. 1%/Sec means it will be completed in 100 Seconds or 00:01:40. – endrik exe Jan 09 '18 at 01:23

1 Answers1

0

I have no idea what you are doing, but maybe this helps you finding the problem

#include <Date.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
GUICreate("Completion Time Predictor", 300, 300)
;Here I enter the starting time and percentage
GUICtrlCreateLabel("Enter the start time:", 10, 10, 270, 29)
$StartTime = GUICtrlCreateDate("", 10, 40, 270, 21, $DTS_TIMEFORMAT)
GUICtrlCreateLabel("Enter the start percentage:", 10, 70, 270, 29)
Local $StartPercent = GUICtrlCreateInput("0", 10, 100, 270, 21)
;Here I enter the current time and percentage
GUICtrlCreateLabel("Enter the current time:", 10, 130, 270, 29)
$CurrentTime = GUICtrlCreateDate("", 10, 160, 270, 21, $DTS_TIMEFORMAT)
GUICtrlSetData(-1, _NowCalcDate() & ' ' & @HOUR + 1 & ":" & @MIN & ':' & @SEC)
GUICtrlCreateLabel("Enter the current percentage:", 10, 190, 270, 29)
Local $CurrentPercent = GUICtrlCreateInput("10", 10, 220, 270, 21)
Local $CTRL_a = GUICtrlCreateButton("Calculate", 10, 260, 280, 21)
GUISetState()
Local $msg

Do
    $msg = GUIGetMsg()
    Select
        Case $msg = $CTRL_a
            ConsoleWrite(_NowCalcDate() & ' ' & GUICtrlRead($StartTime) & " " & _NowCalcDate() & ' ' & GUICtrlRead($CurrentTime) & @CRLF)
            $PercentChange = GUICtrlRead($CurrentPercent) - GUICtrlRead($StartPercent)
            ConsoleWrite("% Change: " & $PercentChange & @CRLF)
            ;This seems to be where everything is going wrong
            $diff_min = _DateDiff('n', _NowCalcDate() & ' ' & GUICtrlRead($StartTime), _NowCalcDate() & ' ' & GUICtrlRead($CurrentTime))
            ConsoleWrite("Diff in Min: " & $diff_min & @CRLF)
            $ChangePerMinute = $PercentChange / $diff_min
            ConsoleWrite("Change / min : " & $ChangePerMinute & @CRLF)
            $MinutesRemaining = (100 - GUICtrlRead($CurrentPercent)) / $ChangePerMinute
            ConsoleWrite("MinutesRemaining : " & " " & $MinutesRemaining & @CRLF)
            $EndTime = _DateAdd('n', $MinutesRemaining, _NowCalcDate() & ' ' & GUICtrlRead($CurrentTime))
            MsgBox($MB_OK, "Predicted Completion Time:", "The extraction will be complete at  " & $EndTime)
    EndSelect
Until $msg = $GUI_EVENT_CLOSE
Xenobiologist
  • 2,091
  • 1
  • 12
  • 16