?
Solved

Predict programme finish time

Posted on 2011-02-14
7
Medium Priority
?
441 Views
Last Modified: 2012-08-13
Hi *,

I have some programs which run for a long time; sometimes they run for days/weeks. I can calculate how far through a programme is in percent. What I would like to do is predict (roughly, assuming the programme speed is linear) when a programme should finish.

I have thought that this should be possible by recording the date and time when the programme starts, and then using the current percentage to predict forwards. What I would like is to be able to display a string, containing an estimated time left; perhaps like this:
w0 d13 h17 m22

One thing is that, I currently (due to computer setup) I have another programme displaying the current progress of a programme. Therefore, I have a programme (which I want to monitor and predict finish time for) saving the current progress to a file. This file is then read by the other programme and displays the progress to the user. Therefore, the start time would need to be saved to this same text file and read by the other programme.

Any suggestions? Thoughts?

Cheers,
James
0
Comment
Question by:James_h1023
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 2000 total points
ID: 34888027
If you have the start time, and the percentage of progress, then you can calculate the end time :

        end_time = start_time + ((current_time - start_time) / percentage)

where all times are in seconds since the epoch (or something similar), and percentage is a value between 0 and 1.
0
 
LVL 4

Author Comment

by:James_h1023
ID: 34888189
Thanks for your response.

This is true, I had completely forgotton that one can get the seconds since the epoch in Unix.

Very simply question!

Thanks,
James
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 34888381
Btw, be careful for division by 0 ;)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Author Comment

by:James_h1023
ID: 34888462
In fact, I say it was simple, but I am having a nightmare implementing it!

I am getting all stuck up in variables types.

I have the attached.

I'm looking at the lines with lots of 'X's. I think I currently have problems with casting between floats and ints, as end up with -2010200302 or something similar for predTime.

Also, how could I convert from int (assuming it is calcaulted properly, i.e., predTime) back to time_t which ctime() needs so I can output the time as a nice string.

Sorry, I close the question too early. Nevermind, if it is too late.

Cheers,
James
// Get the current progress
float progress=0.23;

// Get the start time in seconds
char *progressC[100];
int  progressD=0;
FILE *f1;
f1 = fopen("progress.dat", "rt");
fgets(progressC, 100, f1);
progressD = atoi(progressC);
fclose(f1);

// Get the current time in seconds
time_t tim=time(NULL);

// Predict end time in seconds
int predTime = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
char *predTimeC[100] = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
printf("%s\n", predTimeC);

Open in new window

0
 
LVL 53

Expert Comment

by:Infinity08
ID: 34888784
>> Sorry, I close the question too early. Nevermind, if it is too late.

It's certainly not too late. As long as it has to do with the original question (which is definitely the case here), I'm always ready to provide additional support.


>> char *progressC[100];

You probably want :

        char progressC[100] = "";

(similarly for predTimeC further in the code)


>> progressD = atoi(progressC);

Representating the time in seconds since the epoch, can be a large value that might not fit in a (signed) int.
It's probably best to use a time_t, and to store it in binary form in the file.


predTime could then be calculated something like this (assuming that time_t is an integer value that represents the number of seconds since the epoch on your specific platform - which is the case for the large majority of platforms these days) :

        time_t predTime = progressD + ((tim - progressD) / progress);

(I would pick more meaningful/consistent variable names though - see my first post eg.)

Note that this will NOT work on platforms where time_t is NOT an integer value that represents the number of seconds since the epoch on your specific platform. But as said : that is quite unlikely.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 34888794
Oh, and you can format a time_t as a string using strftime :

        http://www.cplusplus.com/reference/clibrary/ctime/strftime/

(see the code example at the bottom of that reference page)
0
 
LVL 4

Author Comment

by:James_h1023
ID: 34889959
Wonderful, that's got my silly questions answered.

Many thanks,
James
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question