class ProgressReport – the code

class ProgressReport{
  int startTime,lastTime,end;
  String message;
  
  ProgressReport(int e,String m){    // task goes from 0 to e, m is a message
  end=e;
  message=m;
  }
  
  void reset(){
    startTime=millis();
    lastTime=startTime;
  }
  
  void report(int j){
    int time=millis();
    if(time-lastTime>2000){                // progress report every 2 seconds
      float progress=(j+0.1)/end;
      float restTime=(1.-progress)/progress*(time-startTime)*0.001;
      lastTime=time;
      println(message+" done: "+(100*progress)+" %, remaining time: "+restTime+" seconds");
    }
  }  
}
This entry was posted in programming and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s