tebelorg / RPA-Python

Python package for doing RPA
Apache License 2.0
4.87k stars 663 forks source link

Correct estimation of the operation execution time - known issue design choice #514

Closed debugger1979 closed 1 month ago

debugger1979 commented 8 months ago

Hello! Please help me with the following question. You have described the r.timer() function. According to the description, it measures the execution time of the previous operation. My task is to measure the execution time of the document saving operation. I'm doing the following steps: r.click("Save.png") save_time = r.timer() What does save_time contain? Variants:

  1. The search time for the "Save button" + clicking on the button area
  2. Item 1 + the time of the save operation

How can I evaluate the effective execution time of operations?

I checked the options with turbo = true and without.

The script:

`r.init(visual_automation=True, chrome_browser=False, turbo_mode=True)

start = r.timer() r.click('folder.png')

fin_folder = r.timer() r.click('downloads.png') fin_downlds = r.timer() r.dclick('excel-file.png') fin_dclk = r.timer() r.click('r7_trial_ok.png') fin_trial = r.timer() r.rclick('r7-row2.png') fin_rclick = r.timer() r.click('r7-insert-string.png') fin_click = r.timer() r.keyboard('kljsdhcvfkesdbvfkdjhb[tab]wleqjfcbewkljbhfkewb[tab]qwefdjewabrkgvberkbver[tab]sdfklvjnbsedkfvb[tab]edrfg;vkertmlgnrlnb[tab]wfv,jerbkvfberkbe[tab]weflkjerwkfbekb') fin_write_text = r.timer() r.click('r7-save.png') fin_save = r.timer()

print('start = ' + str(start)) print('folder = ' + str(fin_folder)) print('downloads = ' + str(fin_downlds)) print('dclick = ' + str(fin_dclk)) print('trial = ' + str(fin_trial)) print('rclick = ' + str(fin_rclick)) print('click = ' + str(fin_click)) print('write text = ' + str(fin_write_text)) print('save file = ' + str(fin_save)) print('all = ' + str(start + fin_folder + fin_downlds + fin_dclk + fin_trial + fin_rclick + fin_click + fin_write_text + fin_save))`

turbo = False

start = 0.07 folder = 7.011 downloads = 2.006 dclick = 2.006 trial = 4.117 rclick = 2.013 click = 2.004 writetext = 11.004 save file = 2.006 all = 32.237

turbo = True

start = 0.072 folder = 5.089 downloads = 0.558 dclick = 0.806 trial = 1.88 rclick = 4.192 click = 0.51 write text = 11.306 save file = 0.406 all = 24.819

Do I understand correctly that in turbo mode, manipulations are performed immediately with the found area (button), without the side costs of "moving the mouse"? In general, is it possible to track the execution time of the operation by the application?

debugger1979 commented 8 months ago

Example of a script:

r.click('Start_menu.png') r.click('Open_file.png')

How can I determine that the first line of the script has already been executed? Do I understand correctly that a screenshot of the screen is compared before the operation and after the operation? If the screenshots do not match, then there is some result after the click and you can set the result of the function to True? Do I understand the logic correctly?

debugger1979 commented 8 months ago

Hello! Conducted the following research on measuring the execution time of a test script: Source data: A qemu/kvm-based virtual machine. AlmaLinux OS 9, office suite R7-Office

The script uses the following algorithm (turbo_mode = True):

  1. Open the home folder [r.click()]
  2. Select the Download folder [r.click()]
  3. Open the Excel file [r.dclick()]
  4. Confirm the message about the trial version office suite [r.click()]
  5. Open the drop-down menu in the row numbers field of the table [r.click()]
  6. Select "Add line" [r.click()]
  7. In the added line, fill in all the fields [r.keyboard() + modifier [tab]]
  8. Click the "Save document" icon [r.click()]
  9. Exit from the Office programm [r.click()]

Time measurements were performed in 3 ways:

  1. r.timer() after each command was executed, then the sum of the time values of all points was completed
  2. datetime.datetime.now(), the start time before point 1 and the finish time after point 9, then the difference between them is calculated
  3. Manual measurement + manual execution of all stages - stopwatch on a smartphone

The values obtained:

  1. sum_rtimer = 44.39
  2. delta_datetime = 32.64
  3. Stopwatch = 34.90 (human factor)

The analysis of the timer() function showed that no measurements are made inside rpa-python, but simply the contents of the file are read rpa_python.txt , which creates an external tagui component, which presumably contains the execution time of the next request (operation). Logically, it is fair to take time costs directly from the query executor. But it is unclear why the results are so big? Or does it imply other information?

kensoh commented 1 month ago

Hi @debugger1979, thanks for raising this! What you said is all correct and valid, I appreciate very much that you shared these replication details.

There was a design choice made to use the timer that is already embedded within the JavaScript engine in TagUI, vs loading the time module in Python to do the same thing. I agree with you the accurate way to measure will be to do it in Python.

I'll watch out to see if anyone else raises this issue, then I'll change the calculation method to use Python. I am hesitant to change for now because it could break backward compatibility for some users because the timings will be different if I push out this change to the new rpa package version.

In the meantime, in addition to using timer() you can also use time module below to calculate the time delta.

import time
start = time.time()
print("hello")
end = time.time()
print(end - start)

I'll close issue for now but will look out if this feature is desired by other users.