The Unofficial Macro Scheduler Puzzler #13

Anything Really. Just keep it clean!

Moderators: Dorian (MJT support), JRL

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

The Unofficial Macro Scheduler Puzzler #13

Post by JRL » Fri Apr 15, 2022 6:38 pm

Its been more than 4 years since Puzzler #12. Hopefully I've been forgiven.

The game this time is to use the DateStamp> function to produce a nice clean result. something that looks like this:

2022-04-15:12:14:00:000 - result

Such that when DateStamp> writes it's data, it writes it within a millisecond, exactly on the minute, every minute for at least 1000 minutes.

The only rule(s) I can think of is that you must use the DateStamp> function to write the results file and the file isn't to be modified after writing. Coerce DateStamp to write the time on the minute. I'd also like you to have at least 1000 minutes / lines of results before you think you have good code. No need to paste your results file, there's no way to test whether it's been modified. Just submit your code and we'll see how well it does on my computer(s). This implies it needs to work well on any computer.

So that we're all on the same page, we'll start with this template. Modifications are allowed but you must use DateStamp> to create the results file.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  BorderIcons = [biSystemMenu, biMinimize]
  Caption = 'Puzzler #13 DateStamp> Cycle 0'
  ClientHeight = 100
  ClientWidth = 380
  Color = clBlue
  OnTaskBar = True
  PixelsPerInch = 96
  Position = poScreenCenter
  object Label1: TLabel
    Left = 45
    Top = 32
    Width = 128
    Height = 24
    Caption = 'Please Wait...'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clYellow
    Font.Height = -19
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
  end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,,OnClose,Quit
Let>vCycle=0
SRT>Quit
  ExecuteFile>%Temp_dir%DateStampPuzzlerTrial.txt
  Exit>0
END>Quit
Show>Dialog1
Let>RP_Wait=1
Let>RP_Windowmode=0
Label>Start
Add>vCycle,1
RunProgram>cmd /c wmic cpu get loadpercentage > %temp_dir%PuzzlerCPULoad.txt
ReadLn>%temp_dir%PuzzlerCPULoad.txt,2,vData
Trim>vData,vData
DateStamp>%Temp_dir%DateStampPuzzlerTrial.txt,vData
SetDialogProperty>Dialog1,Label1,Caption,Last Checked CPU Load = %vData%
SetDialogProperty>Dialog1,,Caption,Puzzler #13 DateStamp> Cycle %vCycle%
Wait>60
Goto>Start
I have a script that works sort of. I'm hitting 00:000 a little better than 10% of the time. Hitting 00:001 almost 60% of the time and the other 30% varies but not by much. I have an idea to use AI to improve it but I'll work on it and let you know. I really have no idea whether hitting 100% is possible so the "winner" (there are no winnings) may be the code that hits the highest percentage of ...00:000 results.

I'll post my code when there has either been a clear winner or when I get tired of waiting.

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: The Unofficial Macro Scheduler Puzzler #13

Post by hagchr » Sat Apr 23, 2022 5:54 pm

Hi, I just saw this post yesterday, many thanks for posting, always inspiring and eye-opening. I thought I had the solution and tested with 500 runs last night and realized why you need the 1000 runs, things happen...

Time to get the load% seems to vary on my machine so I run it slightly before the end of each minute to have a small buffer. Currently (testing with 500 runs) 29% is spot on and 70% is at time 999, all in all 0 +/-1 ms in 99.4% cases.

I will adjust the script to improve the numbers, and then run tonight. Unless problems I will post the code tomorrow...

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

Re: The Unofficial Macro Scheduler Puzzler #13

Post by JRL » Sun Apr 24, 2022 4:46 pm

hagchr,
Thanks for playing...
I now have 5 versions. I just keep making it worse. The first version where I got about 10% is my best attempt. I actually have one version that in several hundred datestamp writes only hit 00:000 twice. I'm thinking your 29% is really excellent.
hagchr wrote:things happen...
There's an understatement!

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: The Unofficial Macro Scheduler Puzzler #13

Post by hagchr » Mon Apr 25, 2022 8:57 pm

JRL,

Thought I had it, then tried running a compiled version... and got worse numbers. Adjusted now, and doing the check run. I note that (at least for my solution) it is Load% dependent. Checking different loads and the spot-on-hit-rate I note:

Load(%) HitRate
0-9 84%
10-19 79%
20-29 69%
30-39 63%
40-49 34%
50-59 32%
60-69 17%
70-79 10%

One can use it to compensate and improve the overall accuracy but not sure if one can improve hitting zero. So (in my case) the lower the load the better the numbers...

Hope to land at an average of 60-70%, will see tomorrow.

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

Re: The Unofficial Macro Scheduler Puzzler #13

Post by JRL » Mon Apr 25, 2022 10:11 pm

I have not tried doing anything to analyse load. Having enough trouble just finding a reliable method for timing. Then again maybe load is the problem. :?

Here's a tool for parsing out percentages.

Code: Select all

Let>Msg_width=500
Let>msg_Height=900
ReadFile>%temp_dir%DateStampPuzzlerTrial.txt,vData
Separate>vData,crlf,vLine
Sub>vLine_Count,1

Let>vOutput=
Let>kk=10960
Repeat>kk
  Add>kk,1
  Midstr>kk,3,3,vRes
  Let>vSep=:%vRes%
  Separate>vData,vSep,vList
  If>vList_Count<2
    Let>vQty=0
    Let>lastPer=0
  Else
    Let>vQty={%vList_Count%-1}
    Let>Per%vRes%=%vQty%/%vLine_Count%
    Let>lastPer=Per%vRes%
  EndIf
  Let>vOutput=%vOutput%%vres% = %vQty% = %lastPer%%crlf%
Until>kk=11040

MDL>vOutPut

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: The Unofficial Macro Scheduler Puzzler #13

Post by Grovkillen » Tue Apr 26, 2022 8:03 am

Write to file could maybe be done once every X minutes instead of every iteration? The file will be bigger and bigger (more rows to parse through) and maybe write to the known row is better?
Let>ME=%Script%

Running: 15.0.27
version history

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: The Unofficial Macro Scheduler Puzzler #13

Post by hagchr » Fri Apr 29, 2022 8:23 pm

Hi, Dear Taskmaster! I have adjusted your script and run it on my machine, with results like:

995 = 0 = 0
996 = 0 = 0
997 = 0 = 0
998 = 0 = 0
999 = 188 = 0.152597402597403
000 = 823 = 0.668019480519481
001 = 172 = 0.13961038961039
002 = 4 = 0.00324675324675325
003 = 6 = 0.00487012987012987
004 = 8 = 0.00649350649350649
005 = 16 = 0.012987012987013
006 = 3 = 0.00243506493506494
007 = 2 = 0.00162337662337662
008 = 0 = 0
009 = 1 = 0.000811688311688312
010 = 2 = 0.00162337662337662

Quite steady at around 80% for the first 500 cycles and then slowly moving down . Full of confidence I then ran it on an older/slower/cheaper/ laptop and got ...

987 = 0 = 0
988 = 0 = 0
989 = 6 = 0.00510204081632653
990 = 29 = 0.0246598639455782
991 = 59 = 0.0501700680272109
992 = 44 = 0.0374149659863946
993 = 60 = 0.0510204081632653
994 = 56 = 0.0476190476190476
995 = 55 = 0.0467687074829932
996 = 56 = 0.0476190476190476
997 = 63 = 0.0535714285714286
998 = 57 = 0.048469387755102
999 = 64 = 0.054421768707483
000 = 65 = 0.0552721088435374
001 = 61 = 0.0518707482993197
002 = 67 = 0.0569727891156463
003 = 54 = 0.0459183673469388
004 = 58 = 0.0493197278911565
005 = 111 = 0.0943877551020408
006 = 76 = 0.0646258503401361
007 = 42 = 0.0357142857142857
008 = 34 = 0.0289115646258503
009 = 19 = 0.016156462585034
010 = 18 = 0.0153061224489796
011 = 10 = 0.00850340136054422
012 = 7 = 0.00595238095238095
013 = 1 = 0.000850340136054422
014 = 0 = 0
015 = 2 = 0.00170068027210884

Completely spread out, sigh! I have tried to modify it but still get seemingly random behavior - at least I can get it to fluctuate around 000.

Not sure how to explain it - quality of processors, components? Did you try your version on different machines?

Given the number of submissions, I still think I have a shot at top three so here is my script below. Maybe you can try it on your machine to see if it works (it needs at least 10-15 minutes to get calibrated). If it does not work then maybe time to look for new computer? Joke aside, I'd be happy to try your version on my machine for comparison.

If it was mission critical then I guess one can do what some photographers do - shoot x frames per second and pick the best picture, ie just do a few relevant DateStamps into temp file(s) and then pick the one at 000 and append to the official file.

Again, thanks for the challenge, I learn a lot every time.


NOTE: I delete any previous copies of %Temp_dir%DateStampPuzzlerTrial.txt

Code: Select all

Let>resFile=%Temp_dir%DateStampPuzzlerTrial.txt

// Delete old versions of result file
IfFileExists>resFile
  DeleteFile>resFile
EndIf

// Dialog
  Dialog>Dialog1
object Dialog1: TForm
  BorderIcons = [biSystemMenu, biMinimize]
  Caption = 'Puzzler #13 DateStamp> Cycle 0'
  ClientHeight = 100
  ClientWidth = 380
  Color = clBlue
  OnTaskBar = True
  PixelsPerInch = 96
  Position = poScreenCenter
  object Label1: TLabel
    Left = 45
    Top = 32
    Width = 128
    Height = 24
    Caption = 'Please Wait...'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clYellow
    Font.Height = -19
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
  end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,,OnClose,Quit
Let>vCycle=0

// SRT to handle Quit
SRT>Quit
   ExecuteFile>resFile
  Exit>0
END>Quit

Show>Dialog1
Let>RP_Wait=1
Let>RP_Windowmode=0


// Initialize, in particular determine the time (in ms) from start of macro
// to the next change in minute.
GoSub>Initialize


// Start of cycle
Label>Start
  
  Add>vCycle,1

  // Run 2 sec early to give enough time to clear everything before writeout to file at time 60
  Wait>58

  // Get the load%. Check time taken to allow for case if it were to take longer than 2 sec
  CODEBLOCK
    Timer>chk1
      RunProgram>cmd /c wmic cpu get loadpercentage > %temp_dir%PuzzlerCPULoad.txt
      ReadLn>%temp_dir%PuzzlerCPULoad.txt,2,vData
      Trim>vData,vData
    Timer>chk2

    // If it took longer than 2 sec to get load% then do a manual DateStamp
    Let>timecheck={%chk2%-%chk1%}
    If>timecheck>2000
      DateStamp>resFile,vData
    EndIf
  ENDCODEBLOCK

  // SRT Check_Trigger will just wait until the DateStamp is due
  GoSub>Check_Trigger
  DateStamp>resFile,vData

  SetDialogProperty>Dialog1,Label1,Caption,Last Checked CPU Load = %vData%
  SetDialogProperty>Dialog1,,Caption,Puzzler #13 DateStamp> Cycle %vCycle%

  // Correction will check if correction is needed due to drift etc.
  GoSub>Correction
  
Goto>Start


// SRT Initialize - To initialize
SRT>Initialize

  // Determine time in ms from start of script to the next change in minute
  Min>minute0
  Let>minute1=minute0

  While>minute1=minute0
    Min>minute1
  EndWhile

  //Var refTime gives the time increment to the start time of cycle 1.
  //comp is a compensation variable intialized to 0
  Timer>refTime
  Let>comp=0

END>Initialize

// SRT Check-Trigger - To manage the scheduling of DateStamp
SRT>Check_Trigger

    // Loop will run until next min starts
    // comp is an adjustment variable that can shift +/- when it should trigger

    Let>ref=1000
    While>ref>=1000
      Timer>currTime
      Let>ref={(%currTime%-%refTime%+%comp%) MOD 60000}
    EndWhile

END>Check_Trigger

// SRT Correction - To adjust timing
SRT>Correction

// Analyze first 5 cycles for overall difference from zero
// and adjust the timing by setting the comp variable.
If>vCycle=5
  ReadFile>resFile,strFile

  // Extract the times into array m_k
  Let>tmp0=\d{3}(?= -)
  RegEx>tmp0,strFile,0,m,nm,0

  // Check how many of the 5 values are >0 (and < 25 to exclue any outliers)
  Let>ctpos=0
  Let>ctr=0
  Let>k=0

  While>k<5
    Add>k,1
    Let>tmpVal=m_%k%
    If>%tmpVal%>0
      If>%tmpVal%<25
          Add>ctpos,tmpVal
          Add>ctr,1
      EndIF
    EndIf
  EndWhile

  // Make a correction if at least 4 of the five values are >0
  // Correction is the average value of the positive numbers
  If>ctr<4
    Let>comp=0
  EndIf

  If>ctr>3
    Let>xRes={%ctpos%/%ctr%}
    Let>xRes={Round(%xRes%)}
    Let>comp=xRes
  EndIf

EndIf

// After first 5 cycles check every 5 cycles for drift etc
If>vCycle>5

  Let>refCheck={%vCycle% mod 5}
  If>refCheck=0

    // Read file and extract array m_k with all times
    ReadFile>resFile,strFile
    Let>tmp0=\d{3}(?= -)
    RegEx>tmp0,strFile,0,m,nm,0

    // ctpos and ctneg counts number of pos and neg numbers 
    Let>ctpos=0
    Let>ctneg=0
    Let>k={%nm%-5}

    // Count number of pos and neg numbers. Note eg 999 is neg vs 000.
    While>k<nm
      Add>k,1
      Let>tmpVal=m_%k%
      If>%tmpVal%>0
        If>%tmpVal%<500
          Add>ctpos,1
        EndIF
      EndIf

      If>%tmpVal%>900
        Add>ctneg,1
      EndIf

    EndWhile

    // If neg difference (at least 4 of 5 numbers)
    If>ctneg>3
      Add>comp,-1
    EndIf

    // If pos difference (at least 4 of 5 numbers)
    If>ctpos>3
      Add>comp,1
    EndIf

  EndIf

EndIf

END>Correction

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

Re: The Unofficial Macro Scheduler Puzzler #13

Post by JRL » Fri Apr 29, 2022 9:40 pm

Taskmaster?
Who knew? moving up in the world...

I've been running mine on 4 machines and only able to get 12% max on one of them. I finally wrote a script that pauses until 59 seconds into the minute, does a standard wait for 0.98 seconds, then runs 30 consecutive lines of datestamp. Not a loop, 30 lines. I get three different results. The computer I have the best results with gives thirty consecutive millisecond datestamp lines. The computer I have the worst results with gives three lines at 00:997 then four lines at 00:112 then four lines at 00:127. Basically only printing at 15.625 millisecond intervals (1/64 of a second). The other two vacillate between 5, 6 or 7 milliseconds between writes and rarely land on zero..
one can do what some photographers do - shoot x frames per second and pick the best picture, ie just do a few relevant DateStamps into temp file(s) and then pick the one at 000 and append to the official file
That was my thought until I tried the 30 lines of datestamp.

As for pc quality. There may be something to what CPU you have that but it isn't "Quality". My best results are on a Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz with 8 gig of RAM. My 1/64 of a second writes result is on a quadcore Xeon with 3.4 Ghz and 32 gig of RAM.

I plan to wait a bit yet before posting my embarrassing code. Here is the thirty line test script. I'll take a look at yours and get back with comments. All positive I'm sure.

Code: Select all

Message>
DeleteFile>%temp_Dir%TimerTest.txt

  Label>PreTime
  Wait>0.01
  vbeval>Timer,vt
  Separate>%vt%,.,elem
  Let>ll={%elem_1% mod 60}
  If>ll=59
  Wait>0.93
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
    DateStamp>%temp_Dir%TimerTest.txt,
  Else
    GetTime>TT
    SetControlText>Macro Scheduler Message,TMemo,1,tt
    Goto>PreTime
  EndIf
  
ExecuteFile>%temp_Dir%TimerTest.txt

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: The Unofficial Macro Scheduler Puzzler #13

Post by Grovkillen » Sat Apr 30, 2022 10:21 am

Maybe use the Timer command and look how much time has passed from the last time you had an exact match in the time stamp?
Let>ME=%Script%

Running: 15.0.27
version history

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: The Unofficial Macro Scheduler Puzzler #13

Post by hagchr » Mon May 02, 2022 7:49 pm

Hi, based on your last "TimerTest" script, I created a small "spray and pray" function that I added to my original script. In stead of 30 DateStamps, I think 10 will work fine in my case. After 500 runs it shows around 89%. Will see how it moves as time progresses.

I also tried on my other machine and there it does not work at all, it is like an animal that cannot be tamed. I can center the results but there is too much variability.

The machine that works well is a (well-behaved) 10-year old i7-3520 (2.9GHz, 2-Cores, 16G RAM)
The other one (problem child) i3-3110M (2.4GHz 2-Cores 16GB RAM)

Both running Win 10.

No other heavy load or VM etc, running on the machine at the present.

UPDATE: After around 2400 cycles the hit rate was around 89%. Then for some reason when MS did a DateStamp , the file was overwritten with the new post, ie it replaced everything in stead of appending it. Not sure how that could happen. I have restarted the script just to see if it happens again.
Last edited by hagchr on Sun May 08, 2022 8:27 am, edited 1 time in total.

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: The Unofficial Macro Scheduler Puzzler #13

Post by hagchr » Thu May 05, 2022 9:37 am

It just struck me that the computer working well is writing to an internal SSD drive vs the other laptop that is writing to a standard spinning drive. Could that cause the difference in performance?

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

Re: The Unofficial Macro Scheduler Puzzler #13

Post by JRL » Thu May 05, 2022 7:56 pm

SSD vs conventional hard drive... I suppose that could be possible. The only SSD I have is my personal computer and that is the one that gives me some of the worst results. Writes multiples at the same millisecond then skips to the next 1/64th and writes more multiples

I have run your script twice on my "best" computer for this task. Had a run of 500 minutes that gave you 82% zeros. Then ran it overnight on the same computer and a run of 1400 minutes only produced 91 zeros total.

I have no explanation. Here's a slice of the 1400 min. result. I did not save the 500 min. result. I didn't think it was needed.


991 = 18 = 0.012847965738758
992 = 65 = 0.046395431834404
993 = 72 = 0.0513918629550321
994 = 68 = 0.0485367594575303
995 = 84 = 0.0599571734475375
996 = 89 = 0.0635260528194147
997 = 80 = 0.0571020699500357
998 = 77 = 0.0549607423269094
999 = 89 = 0.0635260528194147
000 = 91 = 0.0649536045681656
001 = 76 = 0.0542469664525339
002 = 93 = 0.0663811563169165
003 = 75 = 0.0535331905781585
004 = 82 = 0.0585296216987866
005 = 72 = 0.0513918629550321
006 = 85 = 0.0606709493219129
007 = 58 = 0.0413990007137759
008 = 32 = 0.0228408279800143
009 = 11 = 0.00785153461812991
010 = 2 = 0.00142755174875089
011 = 7 = 0.00499643112062812
012 = 5 = 0.00356887937187723
013 = 2 = 0.00142755174875089
014 = 0 = 0
015 = 2 = 0.00142755174875089
016 = 1 = 0.000713775874375446
017 = 3 = 0.00214132762312634
018 = 3 = 0.00214132762312634
019 = 2 = 0.00142755174875089
020 = 1 = 0.000713775874375446
021 = 3 = 0.00214132762312634
022 = 1 = 0.000713775874375446



Further reading

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

Re: The Unofficial Macro Scheduler Puzzler #13

Post by JRL » Fri May 27, 2022 9:11 pm

Working on ideas. I'm getting a sense that millisecond timing on PCs is a major issue.

Discovered that a script that gives 90s% 000:00 hits running in native Macro Scheduler might only give two hits in a thousand cycles running as an executable. Also for some reason remarks, even when they are outside the process area of the script cause DateStamp>timing to run amok. For example the remark created on the first line when a script is compiled can cause timing to go haywire... Might explain why compiled scripts DateStamp> inconsistently.

Discovered that VBEval>Timer produces results that vary from DateStamp> but Macro Scheduler's Timer> function follows pretty close to DateStamp results. I wanted to use VB Timer because it is real time and MS Timer> is Script time. So in the script below the first process is an attempt to acquire the milliseconds offset between MS Timer and real time then use that offset to run DateStamp>. Also only using a positive offset. Could not make a negative offset run consistently.

Another discovery is the speed at which lines of Macro Scheduler code process. If I run this:

Code: Select all

Let>kk=0
Let>res=0
Timer>Start
Repeat>res
  Add>kk,1
  Timer>End
  Let>res={%End%-%Start%}
Until>res>1000

MDL>kk
I see results around 8000. That's 8000 cycles of three lines of code or roughly 24,000 lines per second. I realize these three lines of code are fairly simple but I'm impressed nonetheless.

This script is the best luck I've had thus far. I've only run it on one PC and that PC has the latest Macro Scheduler installed on it. Any other PC I have access to only has Version 14 which is not a bad thing. Version 14 is awesome. I'm just anticipating there might be different results when using a different version.

Also, When this script is closed it will automatically run the script I posted above to parse out percentages. I named the script Analyze_timestamp_Output.scp and it resides in the same folder as this script.

Code: Select all

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

Dialog>Dialog1
object Dialog1: TForm
  Left = 590
  Top = 128
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Timing Test'
  ClientHeight = 106
  ClientWidth = 180
  Color = clBtnFace
  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 = 52
    Height = 13
    Caption = 'Cycle Time'
  end
  object Label2: TLabel
    Left = 56
    Top = 40
    Width = 48
    Height = 13
    Caption = 'Real Time'
  end
  object MSButton1: tMSButton
    Left = 50
    Top = 65
    Width = 75
    Height = 25
    Caption = 'Close'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

GetTime>vPreTime
SetDialogProperty>Dialog1,,Caption,vPreTime
AddDialogHandler>Dialog1,MSButton1,OnClick,Quit
AddDialogHandler>Dialog1,,OnClose,Quit
Show>Dialog1
Let>ResetFlag=0
Let>vMod=5
Let>vCycleCount=0
Wait>2

Label>PreTime
If>ResetFlag>%vMod%
  Let>ResetFlag=0
EndIf
timer>aTime
VBEval>right("%aTime%",3),vDigits

  VBEval>Timer,vNow
  Separate>vNow,.,vMil
  VBEval>Left("%vMil_2%",3),vNowSec
  
If>{%vDigits%>%vNowSec%}
  Length>vNowSec,vNowLen
  If>vNowLen<>3
    Goto>PreTime
  EndIf
  Length>vDigits,vDigLen
  If>vDigLen<>3
    Goto>PreTime
  EndIf
  Let>vOffset={%vDigits%-%vNowSec%}
Else
  Goto>PreTime
  Let>vPreset={%vNowSec%-%vDigits%}
  Let>vOffset={%vDigits%-%vPreset%}
EndIf


Label>ReTime
vbeval>Timer,vt
Separate>%vt%,.,elem
Let>gg={%elem_1% mod 60}
If>gg=0
Else
  GetTime>vPostTime
  SetDialogProperty>Dialog1,Label2,Caption,vPostTime
  Goto>ReTime
EndIF

timer>aTime
VBEval>right("%aTime%",3),digits
If>digits=%vOffset%
  add>vCycleCount,1
  SetDialogProperty>Dialog1,,Caption,%vPreTime% - %vCycleCount%
  SetDialogProperty>Dialog1,Label1,Caption,vPostTime
  SetDialogProperty>Dialog1,Label2,Caption,vPostTime
Else
  GetTime>vPostTime
  Goto>ReTime
EndIf
DateStamp>%temp_dir%DateStampPuzzlerTrial.txt, %vOffSet% - %ResetFlag%
  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
If>{(%vMill%<>000)and(%vMill%<500)}
  If>ResetFlag=%vMod%
    Sub>vOffset,1
  Else
    Add>ResetFlag,1
  EndIf
EndIF
If>{%vMill%>500}
  If>ResetFlag=%vMod%
    Add>vOffset,1
  Else
    Add>ResetFlag,1
  EndIf
EndIf
If>{%vMill%=000}
  Let>ResetFlag=1
EndIf
Wait>1
Goto>ReTime

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

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: The Unofficial Macro Scheduler Puzzler #13

Post by hagchr » Sat May 28, 2022 7:09 pm

Hi, I have tried your script during some 1100 minutes (exe based on MS 15) and get:

998 = 0 = 0
999 = 8 = 0.00721370604147881
000 = 979 = 0.882777276825969
001 = 94 = 0.084761045987376
002 = 12 = 0.0108205590622182
003 = 8 = 0.00721370604147881
004 = 2 = 0.0018034265103697
005 = 0 = 0
006 = 2 = 0.0018034265103697
007 = 1 = 0.000901713255184851
008 = 1 = 0.000901713255184851
009 = 1 = 0.000901713255184851
010 = 0 = 0
ie around 88.3% spot-on, which is a good number.

Since that just gives the overall picture, I looked at the individual data and plotted them as 15-minute average values (ie sum 15 data points and average...) Then I note that, when the machine is "idle" the average hit rate is 80%-93% ie 12, 13, 14 correct DateStamps> out of 15. When the machine is loaded with other things, then the hit rate drops, in some cases to 30%. So on the plot I can clearly see the hit-rate go up when some nightly tasks finished, and stay high, to drop temporarily when I had to do some things mid-day. So very much load dependent (in my case).

Looking at the DateStamps>, there were 62 instances (5.6%) where data is missing, in two cases with as much as 5 minutes. Maybe the machine had a coffee break? Drops also seems to be correlated with machine load.

Overall a good challenge, which also highlights that you need to have in mind, not only the problem at hand, but also the environment, pc, load, ... etc, where a script is going to run.

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

Re: The Unofficial Macro Scheduler Puzzler #13

Post by JRL » Wed Jun 01, 2022 1:53 pm

hagchr,
Challenge? That's putting it mildly. However, I get obsessed by the seemingly impossible. I spent a couple of years trying to draw a rubber band selection box. I have no doubt there is a solution for performing a DateStamp on a given millisecond but I don't think we're there yet.

You show that you got 88% using my last script in an executable. I've been hitting in the 60% to 70% range pretty consistently running the script as a script. So I compiled it. Best I can get with the compiled script is 30%. Moved it to a different computer yesterday and got the unusual result that intermittently, it does not datestamp at all. Is that what you were calling a "coffee break"?

I've only been running the script overnight for any length of time and have no processes running on the test computer that should create any load. In my case minor load on the computer does not seem to be the issue.

I'll keep trying.

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