package artisynth.models.noor.batchsim;

import java.io.IOException;
import java.io.PrintWriter;
import java.time.Duration;
import java.time.Instant;

import artisynth.models.noor.NoorForwardSimBatchTongue;
import artisynth.tools.batchsim.SimpleTimedBatchWorker;


public class NoorTongueBatchWorker extends SimpleTimedBatchWorker {

   public static final String MODEL_PATH = "models/noor/NoorForwardSimBatchTongue";
   /** Writer for recording simulation results. */
   protected PrintWriter myOutputFileWriter;
   protected NoorForwardSimBatchTongue NoorForwardSimBatchModel;
   Instant lastTime;

   protected double mySettleTime;

   public NoorTongueBatchWorker (String[] args) throws IllegalStateException, IOException {
      super (args);
      myMaxTime = 3.75;
   }

   protected void simpleStartLogSession () {
      /*
       * myLogFileWriter.println ( "Date"+ mySeparator + "Nanoseconds" +
       * mySeparator + "Task Counter Number" + mySeparator +
       * "Did Simulation Succeed" + mySeparator + "Last Step Size Used" +
       * mySeparator + "Number of Simulations Attempted" + mySeparator +
       * "Trial");
       */
   }

   @Override
   protected void preSim () {
      super.preSim ();
      lastTime = Instant.now ();
   }
   /**
    * Adds a log entry to the log file for the current simulation task by
    * following the format of {@link #simpleStartLogSession()}.
    */
   protected void addSimpleLogEntry () {
      StringBuilder builder = new StringBuilder ();
      Instant currentTime = Instant.now ();
      Duration res = Duration.between (lastTime, currentTime);
      builder.append (lastTime + mySeparator);
      builder.append (res.getNano () + mySeparator);
      builder.append (myTaskCounter + mySeparator);
      builder.append (myCurrentTaskSuccessful + mySeparator);
      builder.append (myLastStepSizeUsed + mySeparator);
      builder.append (myNumSimsAttempted + mySeparator);
      for (String[] propValPair : myCurrentTask) {
         builder.append (mySeparator).append (propValPair[1]);
      }
      myLogFileWriter.println (builder);
   }

}

