-2

So i want to create a simple download eta calculator, and here is my code for it

import PySimpleGUI as sg

layout = [[sg.Text('What is your download speed in MB/s?')],
          [sg.InputText()],
          [sg.Text('What is the size of the file in GB?')],
          [sg.InputText()],
          [sg.Submit(), sg.Cancel()]]

window = sg.Window('Window Title', layout)

event, values = window.read()
window.close()

download_speed = float(values[0])
file_size = float(values[1]) * 1024
file_size_divided = file_size/download_speed
eta_in_minutes = file_size_divided/60
eta_in_hours = eta_in_minutes/60

eta_in_hours_formatted = eta_in_hours

sg.popup('ETA in minutes', round(eta_in_minutes, 2), 'ETA in hours', round(eta_in_hours, 2))

but I want the eta in hours to be displayed in a way where it says Hours and minutes, right now if you use for example 2.2 mb/s and 46 gb, it will give the answer 2.2 hours, I want that to say 2 hours and 12 minutes.

  • Does this answer your question? [Converting a float to hh:mm format](https://stackoverflow.com/questions/27496889/converting-a-float-to-hhmm-format) – Tomerikoo Nov 10 '20 at 15:25

1 Answers1

0

Use a modulo by converting your hours to minutes

from math import floor

eta_in_hours = 2.6
eta_in_hours_and_minutes = (floor(eta_in_hours), eta_in_hours * 60 % 60)
print(eta_in_hours_and_minutes)
>>> (2, 36)

One can also use divmod:

eta_in_hours = 2.6
eta_in_minutes = eta_in_hours * 60
eta_in_hours_and_minutes = divmod(eta_in_minutes, 60)
print(eta_in_hours_and_minutes)
Cyrille Pontvieux
  • 2,356
  • 1
  • 21
  • 29