Trying to return time left

HI all,

i was wondering if anyone could help.

I am writing an application that copies large amounts of data (200gb +). In my app i have a percentage and a progress bar. These work great to demonstrate progress, but i really want to give a time.

My app returns throughput speed (real time) The value is updated on my app and shown to the user every 3 seconds. and the app also states the size of the folder being copied, and how much has been copied (updated every 3 seconds).

I was wondering if i could write the time est in applescript?

i was working on the following theory:

throughput / whats left * 60 (seconds) . But i have no idea how i would convert that into hrs and mins.

32 MB sec | 40000MB Size 32/40000*60 = 48Mins…

Any help would be greatly appreciated

Hi.


set seconds_left to MB_left / MB_per_second

set hours_part to seconds_left div hours
set minutes_part to seconds_left mod hours div minutes
set seconds_part to seconds_left mod minutes as integer

Hey Nigel This is GREAT!

set seconds_left to 400 / 32

set hours_part to seconds_left div hours
set minutes_part to seconds_left mod hours div minutes
set seconds_part to seconds_left mod minutes

400MB Left / 32MB a second

Is there any way to return the above in a sting like:

0hrs 10Mins 12seconds

0r

0Hrs 10mins

Of course:

set seconds_left to MB_left / MB_per_second

set hours_part to seconds_left div hours
set minutes_part to seconds_left mod hours div minutes
set seconds_part to seconds_left mod minutes as integer

set time_left_string to (hours_part as text) & " hr " & minutes_part & " min " & seconds_part & " seconds left"

It would be a good idea to put the entire code for calculating and displaying the time left in a ‘try’ statement, in case the throughput stalls and the initial division turns out to be by 0.

Thanks Nigel!

Hi Nigel,

I seem to have an issue:

Total Size : 47270 MB (47gb)
Remaining : 46002MB (46GB)
Complete : 1269MB (1.2gb)

Throughput: 33MB a second

The time returned is 1min 3 seconds to complete the copy… (its about 21 mins to do 50gb on my mac if i do a drag and drop to external drive).

Here is my code in my app:

//CODE//

dim speed as Integer
dim math2 as Integer

speed = m.Status.Throughput
math2 = m.Status.BytesRemaining

dim MBLeftToDo as integer

dim MBSpeed as integer

MBLeftToDo = math2
MBSpeed = speed

MainWindow.Label1.text = Speedy (MBLeftToDo, MBSpeed) // Passing varible to applescript (Speedy)

MainWindow.Label1.Refresh

it looks like its my code :frowning: Please ignore the above

Ok Found the issue. The MB that is being passed to Applescript is adding a space with MB after it

47270 MB

Is there any way to trim this off the _MB from the number in the apple script?

Sorry to be a pain

There are a few ways to do this. It’s difficult to recommend a best one without knowing the circumstances. Is there some way to prevent the " MB" being passed to the script in the first place? More importantly, is the figure always in megabytes? If not, the script will not only have to trim the trailing letters but analyse what’s being trimmed and do any necessary maths with the number.