Database Solutions - Hints & Tips

Current Tip:
current tip | tips archive

Estimating time remaining when processing large amounts of data

Problem

There are occasions when an online, interactive process has to loop through a substantial number of rows (occurrences) of data. It is good design practice to give a visual indication to the end user that the process is active and an estimation of how much time is left until completion.

Solution

The following UNIFACE proc code will indicate to the end user the number of the occurrence currently being processed, the total number of occurrences to process and an estimation of the time required to process the remaining occurrences. This information is displayed in the message area and in particular the information is only refreshed every 25 occurrences.

variables
    numeric E_HITS ;total number of occurrences to process
    numeric E_INDEX ;number of the occurrence currently being processed
    numeric E_LEFT ;number of occurrences left to process
    time T_START ;time the processing started
    time T_CURRENT ;current time
    time T_LEFT ;estimated time left
endvariables

;initialise the variables
T_START = $clock
E_HITS = $hits(MY_ENTITY)
E_INDEX = 1

;point to the first occurrence
setocc "MY_ENTITY", 1
if ($status < 0)
    message "%%$componentname: setocc MY_ENTITY,1 failed, $status = %%$status"
    return($status)
endif

;loop through the occurrences
while ($status > 0)
    if ((E_INDEX % 25) = 0)
        ;we only want to update the message area every 25 occurrences
        T_CURRENT = $clock
        E_LEFT = (E_HITS – E_INDEX)
        T_LEFT = (((T_CURRENT – T_START) / E_INDEX) * E_LEFT)
        message "Processing occurrence %%E_INDEX of %%E_HITS, estimated time remaining = %%T_LEFT"
    endif
    ……………………
    …………………… the processing to be carried out on each occurrence would be here
    ……………………
    E_INDEX = (E_INDEX + 1)
    setocc "MY_ENTITY",E_INDEX
endwhile

compuware_01.gif (3977 bytes)


Copyright ©2000 OCS Consulting plc

dbs_block_logo.gif (2150 bytes)
Refresh Frames