The Unofficial Macro Scheduler Puzzler #13

Anything Really. Just keep it clean!

Moderators: Dorian (MJT support), JRL

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: The Unofficial Macro Scheduler Puzzler #13

Post by JRL » Fri Jul 08, 2022 6:17 pm

Here's another attempt. This is running well for me (qualifiers below) but still not perfect and has a very strange result in the evening. I've been testing for 4 days and I'm consistently hitting the upper 90s% for a few hundred cycles even while using the computer.

This script is not using a "timer" but rather the Min> function. It sets a variable to the current minute then checks for the next minute in a tight loop. The moment the minute updates, Datestamp> is called and the tight loop ends.

Code: Select all

Let>RP_Wait=1
Let>RP_Windowmode=0
DeleteFile>%temp_dir%DateStampPuzzlerTrial.txt
DeleteFile>%temp_dir%PuzzlerCPULoad.txt

Min>vMM

Dialog>Dialog1
object Dialog1: TForm
  BorderIcons = [biSystemMenu]
  Caption = 'Timing Test'
  ClientHeight = 70
  ClientWidth = 180
  Color = 16177200
  Position = poScreenCenter
  object MSButton1: tMSButton
    Left = 50
    Top = 40
    Width = 75
    Height = 25
    Caption = 'Close'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object Label1: TLabel
    Left = 55
    Top = 16
    Width = 52
    Height = 13
    Caption = 'Cycles'
  end
end
EndDialog>Dialog1

GetTime>vPreTime
SetDialogProperty>Dialog1,,Caption,vPreTime
AddDialogHandler>Dialog1,MSButton1,OnClick,Quit
AddDialogHandler>Dialog1,,OnClose,Quit
Show>Dialog1
Let>vCycleCount=0
GoSub>GetCPU

Label>ReTime
  GetTime>vPreTime
  SetDialogProperty>Dialog1,,Caption,vPreTime
  //A second of tight loop
  Sec>vSS
  If>vSS>58
  LibFunc>Winmm,timeBeginPeriod,vResB,1
  Label>NoWait
    Min>vMM2
    If>%vMM%<>%vMM2%
      DateStamp>%temp_dir%DateStampPuzzlerTrial.txt,vData
      Let>vMM=vMM2
      DeleteFile>%temp_dir%PuzzlerCPULoad.txt
      GoSub>GetCPU
      Add>vCycleCount,1
      SetDialogProperty>Dialog1,Label1,Caption,Cycles = %vCycleCount%
      LibFunc>Winmm,timeEndPeriod,vResE,1
      Goto>Control
    EndIf
    Goto>NoWait
  EndIf
  Label>Control
  Wait>0.01
Goto>ReTime

SRT>GetCPU
  RunProgram>cmd /c wmic cpu get loadpercentage > %temp_dir%PuzzlerCPULoad.txt
  ReadLn>%temp_dir%PuzzlerCPULoad.txt,2,vData
  Trim>vData,vData
END>GetCPU

SRT>Quit
  LibFunc>Winmm,timeEndPeriod,vResE,1
  ExecuteFile>%script_Dir%\Analyze_timestamp_Output.scp
  Exit>0
END>Quit
When I try to run this overnight, timing goes completely bonkers during the evening and doesn't seem to recover. Results look like this:

Long stretch of 00:000s
2022-07-07:20:22:00:000 - 29
2022-07-07:20:23:00:000 - 17
2022-07-07:20:24:00:000 - 16
2022-07-07:20:25:00:000 - 29
2022-07-07:20:26:00:000 - 21
2022-07-07:20:27:00:000 - 20
2022-07-07:20:28:00:000 - 22
2022-07-07:20:29:00:000 - 9
2022-07-07:20:30:00:000 - 14
2022-07-07:20:31:00:000 - 18
2022-07-07:20:32:00:000 - 10
2022-07-07:20:33:00:000 - 15
2022-07-07:20:34:00:000 - 28
2022-07-07:20:35:59:037 - 43 < Until here. Note this is almost a 2 minute cycle, minute 34 to minute 36.
2022-07-07:20:36:59:011 - 13
2022-07-07:20:37:59:013 - 17
2022-07-07:20:38:59:015 - 25
2022-07-07:20:39:59:015 - 13
2022-07-07:20:40:59:002 - 11
2022-07-07:20:41:59:013 - 10
2022-07-07:20:42:59:006 - 9
2022-07-07:20:43:59:009 - 25
2022-07-07:20:44:59:010 - 23
2022-07-07:20:45:59:013 - 24
2022-07-07:20:46:59:014 - 19
And it continued like this until I stopped it the next morning.

One time it went very well for 7 hours with nearly no errors until midnight. At the midnight minute DateStamp> stopped for 15 minutes and when it continued it looked very much like the above list except it was not all second 59 and there were other gaps where nothing printed for several minutes.

I've examined the code and can see no reason for this. My suspicion is that virus software is causing the code to stop processing completely for stretches at a time. Maybe someone else can see where I've caused the issue or can confirm that it's an interference issue.

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: The Unofficial Macro Scheduler Puzzler #13

Post by JRL » Mon Jul 11, 2022 3:46 pm

So I ran the code above over the weekend and at 8:15 pm on Sunday the timing went bonkers as I described before. Still have no idea why that happens. Took the results and threw out those roughly 800 consecutive lines (as if I'd stopped the process at 8:14 pm) and then ran the analysis tool on the results file.

000 = 3027 = 0.984710474951204 <---- 98.5% zeros.
001 = 12 = 0.00390370852309694
002 = 19 = 0.00618087182823682
003 = 4 = 0.00130123617436565
004 = 5 = 0.00162654521795706
005 = 1 = 0.000325309043591412
009 = 1 = 0.000325309043591412
024 = 1 = 0.000325309043591412
027 = 2 = 0.000650618087182824
028 = 1 = 0.000325309043591412

This is the best result I've been able to achieve thus far even if I did have to fudge it a little.

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: The Unofficial Macro Scheduler Puzzler #13

Post by JRL » Fri Jul 22, 2022 9:17 pm

This is working well for me. Not perfect but consistently hitting upper 90%. This is actually two scripts. Script1 writes Script2 then runs it once per minute. Script2 is short and has one tight loop waiting for minute two to become different than minute one. when that is detected, DateStamp> is activated.

Script2 uses LibFunc>Winmm,timeBeginPeriod,vResB,1 and LibFunc>Winmm,timeEndPeriod,vResE,1. Without them it does not do well.


Code: Select all

Let>RP_Windowmode=0
StringReplace>Command_Line,",,Command_Line
UpperCase>Command_Line,Command_Line
Uppercase>Script_Dir,Script_Dir
ExtractFileName>Command_Line,vExecutorName
StringReplace>vExecutorName,.EXE ,.EXE,vExecutorName
If>%vExecutorName%=MSCHED.EXE
Else
  StringReplace>Command_Line,%script_Dir%\%vExecutorName%,,Command_Line
EndIf
Let>RP_Windowmode=0
Let>RP_Wait=1

DeleteFile>%temp_dir%DateStampPuzzlerTrial.txt
DeleteFile>%temp_dir%PuzzlerCPULoad.txt

Dialog>Dialog1
object Dialog1: TForm
  Left = 661
  Top = 207
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'P13 Timing Test'
  ClientHeight = 103
  ClientWidth = 180
  Color = 16177200
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 55
    Top = 16
    Width = 31
    Height = 13
    Caption = 'Cycles'
  end
  object Label2: TLabel
    Left = 53
    Top = 40
    Width = 53
    Height = 13
    Caption = 'Last Result'
  end
  object Edit1: TEdit
    Left = -100
    Top = -100
    Width = 10
    Height = 21
    TabOrder = 1
    Text = '999'
    Visible = False
  end
  object MSButton1: tMSButton
    Left = 50
    Top = 64
    Width = 75
    Height = 25
    Caption = 'Close'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

LabelToVar>DateStampScript,vDateStampScript
DeleteFile>%Temp_Dir%\P13 Min Test Called Macro.scp
WriteLn>%Temp_Dir%\P13 Min Test Called Macro.scp,wres,vDateStampScript

GetTime>vPreTime
SetDialogProperty>Dialog1,,Caption,vPreTime
AddDialogHandler>Dialog1,MSButton1,OnClick,Quit
AddDialogHandler>Dialog1,,OnClose,Quit
Show>Dialog1
Let>vCycleCount=0
GoSub>GetCPU

Label>ReTime
  GetTime>vPreTime
  SetDialogProperty>Dialog1,,Caption,vPreTime
  Sec>vSS
  If>vSS>55
      Let>RP_Wait=0
      RunProgram>%command_Line% %Temp_Dir%\P13 Min Test Called Macro.scp /vData=%vData%
      DeleteFile>%temp_dir%PuzzlerCPULoad.txt
      GoSub>GetCPU
      Add>vCycleCount,1
      SetDialogProperty>Dialog1,Label1,Caption,Cycles = %vCycleCount%
  EndIf
  Label>Control
  GetTime>vPreTime
  SetDialogProperty>Dialog1,,Caption,vPreTime
  Sec>vSS
  If>vSS>55
    Wait>0.01
    Goto>Control
  EndIf
  Wait>0.01
  GetDialogProperty>Dialog1,Edit1,Text,vLastMill
  SetDialogProperty>Dialog1,Label2,Caption,Millisec = %vLastMill%
Goto>ReTime

SRT>GetCPU
  Let>RP_Wait=1
  RunProgram>cmd /c wmic cpu get loadpercentage > %temp_dir%PuzzlerCPULoad.txt
  ReadLn>%temp_dir%PuzzlerCPULoad.txt,2,vData
  Trim>vData,vData
END>GetCPU

SRT>Quit
  ExecuteFile>%script_Dir%\Analyze_timestamp_Output.scp
  Exit>0
END>Quit

Exit>0


/*
DateStampScript:
Min>vMM
LibFunc>Winmm,timeBeginPeriod,vResB,1
  Label>NoWait
    Min>vMM2
    If>%vMM%<>%vMM2%
      DateStamp>%temp_dir%DateStampPuzzlerTrial.txt,%vData% - %vMM%
      LibFunc>Winmm,timeEndPeriod,vResE,1
      Let>RP_Windowmode=0
      Let>RP_Wait=1
      RunProgram>cmd /c sort /r %temp_dir%DateStampPuzzlerTrial.txt /o %temp_dir%ssResOut.txt
      ReadLn>%temp_dir%ssResOut.txt,1,vData
      MidStr>vData,21,3,vMill
      Let>WIN_USEHANDLE=1
      SetControlText>%Dialog1.handle%,TEdit,1,vMill
      Goto>Control
    EndIf
  Goto>NoWait
Label>Control
Exit>0
*/

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts