Skip to content

Instantly share code, notes, and snippets.

@etihwnad
Created December 6, 2019 22:18
Show Gist options
  • Save etihwnad/835b6950bb184479b934eb3656346655 to your computer and use it in GitHub Desktop.
Save etihwnad/835b6950bb184479b934eb3656346655 to your computer and use it in GitHub Desktop.
Give stats about how long a tedious task is taking and an estimate of when it will be finished.
#! /usr/bin/env python3
# MIT license
# Copyright 2019 Dan White
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# runs under Python 2.7+
from __future__ import print_function
import datetime
import sys
import time
from datetime import datetime, timedelta
if sys.version[0] < '3':
input = raw_input
usage = """usage:
python whendone.py 45
press enter after finishing each paper
# last, avg, n, done time
1 02:08, 02:08, 44, 12:25 AM
2 01:03, 01:36, 43, 12:01 AM
3 10:42, 04:38, 42, 02:12 AM
4 06:33, 05:07, 41, 02:32 AM
5 03:51, 04:51, 40, 02:22 AM
6 05:57, 05:02, 39, 02:29 AM
7 03:07, 04:46, 38, 02:18 AM
8 07:01, 05:03, 37, 02:30 AM
"""
def mean(x):
s = 0.0
for i in x:
s += i
return s/len(x)
if len(sys.argv) < 2:
print(usage)
sys.exit()
else:
N = int(sys.argv[1])
top = " # last, avg, total, n, left, done time"
fmt = "%3i %5s, %5s, %5s, %3i, %5s, %s"
durations = []
tstart = datetime.now()
t0 = time.time()
for i in range(N):
input()
t1 = time.time()
duration = t1 - t0
durations.append(duration)
lasttime = timedelta(seconds=duration)
avgtime = timedelta(seconds=mean(durations))
esttime = avgtime * N
estdone = tstart + esttime
togo = esttime - (avgtime * i)
if i==0: print(top)
print(fmt % (i+1,
time.strftime('%M:%S', time.gmtime(lasttime.total_seconds())),
time.strftime('%M:%S', time.gmtime(avgtime.total_seconds())),
time.strftime('%M:%S', time.gmtime(i*avgtime.total_seconds())),
N - (i + 1),
time.strftime('%H:%M', time.gmtime(togo.total_seconds())),
estdone.strftime('%I:%M %p')),
end='', flush=True) #input() already adds a newline
t0 = t1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment