Skip to content

Commit

Permalink
feat: new time str format
Browse files Browse the repository at this point in the history
  • Loading branch information
isHarryh authored and Samueli924 committed Sep 21, 2024
1 parent 60ba3a5 commit a686eaa
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions api/process.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import time
from api.config import GlobalConst as gc

def sec2time(sec):
ret = ""
if sec // 3600 > 0:
ret += f"{sec // 3600}h "
sec = sec - sec // 3600 * 3600
if sec // 60 > 0:
ret += f"{sec // 60}min "
sec = sec - sec // 60 * 60
if sec:
ret += f"{sec}s"
if not ret:
ret = "0s"
return ret
def sec2time(sec: int):
h = int(sec / 3600)
m = int(sec % 3600 / 60)
s = int(sec % 60)
if h != 0:
return f'{h}:{m:02}:{s:02}'
if sec != 0:
return f'{m:02}:{s:02}'
return '--:--'


def show_progress(name, start: int, span: int, total: int, _speed: float):
def show_progress(name: str, start: int, span: int, total: int, _speed: float):
start_time = time.time()
while int(time.time() - start_time) < int(span // _speed):
while int(time.time() - start_time) < int(span / _speed):
current = start + int((time.time() - start_time) * _speed)
percent = int(current / total * 100)
length = int(percent * 40 // 100)
Expand Down

0 comments on commit a686eaa

Please sign in to comment.