Skip to content
Snippets Groups Projects

print gaps info when click

Merged Lan Dam requested to merge i241-print-gaps-information-when-click into develop
1 unresolved thread
Files
2
@@ -422,3 +422,43 @@ def get_valid_file_count(list_of_dir: Path) -> int:
total += len([f for f in files
if validate_file(Path(path).joinpath(f), f)])
return total
def _format_time_item(
unit: str, value: Union[int, float], time_list: List[str]):
"""
Append the format string of time item to time_list if not zero
:param unit: a time unit (day/hour/minute/second)
:param value: value of the time item
:param time_list: list of different formatted time item
"""
if value == 0:
return
else:
formatted = f"{value} {unit}"
if value > 1:
formatted += 's'
time_list.append(formatted)
def get_formatted_time_delta(time_delta: float) -> str:
"""
Convert time_delta in seconds into formatted string of
(days, hours, minutes, seconds)
:param time_delta: length of time delta in seconds
:return formatted string of time delta
"""
time_list = []
days = int(time_delta // 86400)
_format_time_item('day', days, time_list)
hours = int((time_delta - days * 86400) // 3600)
_format_time_item('hour', hours, time_list)
minutes = int((time_delta - days * 86400 - hours * 3600) // 60)
_format_time_item('minute', minutes, time_list)
seconds = time_delta - days * 86400 - hours * 3600 - minutes * 60
_format_time_item('second', seconds, time_list)
if not time_list:
return "0.0 seconds"
else:
return " ".join(time_list)
Loading