Solved

Predict programme finish time

Posted on 2011-02-14
7
435 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
  • 4
  • 3
7 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 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 Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now