better time formatting and ETA
This commit is contained in:
@@ -130,6 +130,14 @@ def format_size(size_bytes):
|
||||
size_bytes /= 1024.0
|
||||
return f"{size_bytes:.2f} TB"
|
||||
|
||||
def format_time(seconds):
|
||||
"""Format time as HH:MM:SS:MsMs (hours:minutes:seconds:centiseconds)."""
|
||||
hours = int(seconds // 3600)
|
||||
minutes = int((seconds % 3600) // 60)
|
||||
secs = int(seconds % 60)
|
||||
centiseconds = int((seconds % 1) * 100)
|
||||
return f"{hours:02d}:{minutes:02d}:{secs:02d}:{centiseconds:02d}"
|
||||
|
||||
def main():
|
||||
input_dir = Path('input')
|
||||
output_dir = Path('output')
|
||||
@@ -200,17 +208,19 @@ def main():
|
||||
if processed == 1 or time_since_update >= 0.5:
|
||||
rate = processed / elapsed if elapsed > 0 else 0
|
||||
remaining = len(png_files) - processed
|
||||
eta = remaining / rate if rate > 0 else 0
|
||||
eta_seconds = remaining / rate if rate > 0 and remaining > 0 else 0
|
||||
|
||||
total_savings = total_original_size - total_new_size
|
||||
total_savings_pct = (total_savings / total_original_size * 100) if total_original_size > 0 else 0
|
||||
|
||||
eta_str = format_time(eta_seconds) if eta_seconds > 0 else "calculating..."
|
||||
elapsed_str = format_time(elapsed)
|
||||
|
||||
print(f"[{processed:5d}/{len(png_files)}] "
|
||||
f"Compressed: {compressed} | Skipped: {skipped} | "
|
||||
f"Speed: {rate:.1f} files/sec | "
|
||||
f"ETA: {eta:.1f}s | "
|
||||
f"Saved: {format_size(total_savings)} ({total_savings_pct:.1f}%) | "
|
||||
f"Elapsed: {elapsed:.1f}s", end='\r')
|
||||
f"Elapsed: {elapsed_str} | ETA: {eta_str} | "
|
||||
f"Saved: {format_size(total_savings)} ({total_savings_pct:.1f}%)", end='\r')
|
||||
last_update_time = current_time
|
||||
else:
|
||||
failed += 1
|
||||
@@ -229,7 +239,7 @@ def main():
|
||||
if jpg_files:
|
||||
print(f"Ignored (JPG/JPEG): {len(jpg_files)} files")
|
||||
print(f"Failed: {failed} files")
|
||||
print(f"Total time: {total_time:.2f} seconds")
|
||||
print(f"Total time: {format_time(total_time)}")
|
||||
print(f"Average speed: {avg_rate:.2f} files/second")
|
||||
print(f"Original size: {format_size(total_original_size)}")
|
||||
print(f"Compressed size: {format_size(total_new_size)}")
|
||||
|
||||
Reference in New Issue
Block a user