-1

I have a script which reads data from a .xlsx file and put them in various DB tables. I would like to show the user the percentage of activity in progress. The processing time is variable and the user may get the feeling that something is wrong. I have read several articles in stackoverflow but they all had a definite time or quantity.

It should work inside pyqt5 enviroment.

musicamante
  • 41,230
  • 6
  • 33
  • 58
saceti
  • 11
  • 5
  • If the time required to process the file is completely unknown, then it's logically impossible to show a *progress*. In that case, you can use a QProgressBar with a maximum value set to 0 (which is exactly the case of unknown progress total). **UNLESS** you write a wrapper for the file object, assuming that what actually reads the file does that progressively, and in that case you can estimate the time to completion based on the bytes read and the time elapsed since opening the file. – musicamante Jun 14 '21 at 13:37
  • NOTE: I don't know what you use to read the xls file, but if you have a way to read the size (and count) of the spreadsheet(s) when opening the file, you can do an extimation based on statistics of query completion. – musicamante Jun 14 '21 at 15:02
  • I will calculate the average time necessary to read and elaborate a number of xlsx files, then will use this average to set the 100% time. Thank you for the suggestion, its the easiest way to do the job – saceti Jun 15 '21 at 07:00

1 Answers1

-2

tqdm is the package for you.

from tqdm import tqdm
from time import sleep

for i in tqdm(range(100)):
    sleep(0.2)

To install it, just run pip install tqdm in your active environment.

JacoSolari
  • 1,226
  • 14
  • 28
  • The OP clearly says that: 1. "The processing time is variable", so using a predefined range is not appropriate; 2. "It should work inside pyqt5 enviroment", so we can assume that a UI would be shown, making the output in the terminal/prompt not ideal. – musicamante Jun 14 '21 at 13:30
  • @musicamante 'The processing time is variable' does not mean that you don't NEED a predefined range. If you can explain me how to define a percentage without knowing the 'total' (in this case a predefined range) you deserve a Nobel prize. What variable processing time here mean is that if you have to run 5 SQL queries they might take 1 hour today and 10 hours tomorrow. But you still need to run a defined amount of queries to make a progress bar. In addition, nothing prevents you from running my snippet inside pyqt, so I would suggest you move the -1 to the question and not to my answer? – JacoSolari Jun 14 '21 at 13:59
  • That's exactly my point: there's only one file, with undefined amount of data, hence, unknown processing time for an undefined amount of queries. Even if the OP already knew that, then the 2nd point remains: Qt already provides QProgressBar, using another external module (thus adding another dependency) that also requires having an open terminal or prompt is pointless. Nothing prevents (almost) nothing, the OP could even decide to show the progress in a browser using WebGL through jquery but that's not what has been asked. – musicamante Jun 14 '21 at 15:00