automater

No preview image

1 collaborator

Army_coat_pix R. Wade Schuette (Author)

Tags

automation 

Tagged by R. Wade Schuette almost 5 years ago

regression-testing 

"this model show how to re-use control scripts"

Tagged by R. Wade Schuette almost 5 years ago

utility 

Tagged by R. Wade Schuette almost 5 years ago

validation 

Tagged by R. Wade Schuette almost 5 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 6.1.1 • Viewed 175 times • Downloaded 22 times • Run 0 times
Download the 'automater' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

This won't run over the web

This model uses File I/O which means you cannot run it over the web. If you download it, it should run just fine

Posted almost 5 years ago

Help! The command file is missing!

You can generate your own command file, such as the one called test-01-input.txt in the model. Three sample lines are shown at the top of the code in the notes. Just copy and paste those lines into a new text file, remove the semicolons, and save the file.

Posted almost 5 years ago

Click to Run Model

;; Please read HOW TO USE IT in the INFO tab!

;; the sample command file is called test-01-input.txt and contains the following lines, without the
;; semicolons
;;
;;  print "This is just a test command file"
;;  repeat 4 [go]
;;  clean-up-files  stop
;;
;; this code will generate such a file if you want it to, over-writing any old one of that name



globals [
  working-directory   ;; the operating system working directory
  command-file        ;; where the commands will be read from
  output-file         ;; optional, where output from the go step can be written
  log-file            ;; a log of what commands were executed
  run-title           ;; whatever you want to name this run
  show-commands-as-run?        ;; controls whether you want to see commands as they are run
  use-sample-input-file?       ;; if true, generates a file called test-01-input.txt to use
                               ;; as input for this model.
                               ;; This will destroy an existing file of that name!
]

to setup
  clear-all

  set run-title "Automated validation example"
  print (word run-title "\n"  "at " date-and-time "\n" )

  set show-commands-as-run? false  ;; shows each command as it is read in from the command file
  set-up-files
  init-log
  reset-ticks
  automate-run
end 

to automate-run

  if not file-exists? command-file  [ type "Can't find the command file: " print  command-file stop]
  print " "
  print (word ".....show-commands-as-run? is set to " show-commands-as-run? )
  print ".....Reading command input now..."

  repeat 10000  ;;  reads this many lines from the command-file, if available.
  [
    ;; read the next command from the command file
    file-open command-file
    if  file-at-end? [ clean-up-files stop]
    let line file-read-line

    ;; track progress in the log file
    file-open log-file

    ;; ok to comment out the next line
    file-print (word "Executing: " line)

    ;; track the upcoming command in the Command Center if you want to
    ;; ok to comment out the next line
    if show-commands-as-run? = true [print (word "..................................Executing: " line) ]

    ;; execute that command
    run line

    ;; track completion of the command in the Command Center if you want to
    ;; print (word "...............................Executed: " line)
  ]
end 

to go
  create-turtles 1 [ set size 3 setxy random-xcor random-ycor]

  ;; your code may produce output.  Here's how to do that
  file-open output-file
  file-print "executed the go command once"

  tick
end 

to set-up-files
  file-close-all

  ;; replace these with the path name and file-names of your own files

  set working-directory "C:\\Users\\condor\\Google Drive\\ABModels\\models\\netlogo\\caveman\\versions\\automater"

  if (working-directory = "C:\\Users\\condor\\Google Drive\\ABModels\\models\\netlogo\\caveman\\versions\\automater")
  [ user-message "You MUST set your own working directory in the set-up-files section!"]

  ;; possibly
  ;; set working-directory ""  ;; use the directory containing the model engine itself

  set command-file "test-01-input.txt"   ;; this file should exist
  set output-file "test-01-output.txt"   ;; this can be missing. If it exists it will be replaced.
  set log-file "test-01-log.txt"         ;; this can be missing. If it exists it will be replaced.

  print ("Using these files defined in set-up-files ")
  print (word "working directory: " working-directory)
  print (word "commands : "  command-file )
  print (word "output   : "  output-file)
  print (word "log      : "  log-file   )

  set-current-directory working-directory  ;; has to be done where file-at-end? is trested

  ;; open files for writing

  if  file-exists?   log-file  [ file-delete log-file  ]
  file-open log-file
  file-print run-title
  file-print date-and-time
  file-print "  "

  if  file-exists?   output-file [ file-delete output-file  ]
  file-open output-file
  file-print run-title
  file-print date-and-time
  file-print " "
end 

to init-log
  file-open log-file
  file-print (word "current directory: " working-directory)
  file-print (word "commands : "  command-file)
  file-print (word "output   :"  output-file)
  file-print (word "log      :"  log-file)
  file-print " "
end 

to clean-up-files
   file-close-all
   print ".....Finished reading control input"
   print ".....Cleaning up"
end 

;; Written by R. Wade Schuette 10-November-2019
;; no copyright is claimed.

There is only one version of this model, created almost 5 years ago by R. Wade Schuette.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.