bug in eta

This commit is contained in:
Ville Rantanen
2018-03-20 20:12:29 +02:00
parent 376869f1f3
commit 354393e6f9

View File

@@ -10,52 +10,44 @@ TOKEN="{{ token }}"
class ETA():
def __init__(self,total):
self.total = total
self.memory = 360 # seconds
self.counts = []
self.timestamps = []
self.memory_length = 360 # seconds
self.timestamps = [] # (time, count)
self.started = time.time()
def update(self,count):
self.counts.append(count)
self.timestamps.append(time.time())
newest = self.timestamps[-1]
delete_us = []
for i in range(len(self.timestamps)):
if newest - self.timestamps[i] > self.memory:
delete_us.append(i)
for delete in delete_us:
del self.counts[delete]
del self.timestamps[delete]
self.timestamps.append((time.time(), count))
newest = self.timestamps[-1][0]
self.timestamps = [x for x in self.timestamps if newest - x[0] < self.memory_length]
def get_seconds(self):
if len(self.timestamps)<2:
return None
diff_stamp = self.timestamps[-1] - self.timestamps[0]
diff_count = self.counts[-1] - self.counts[0]
diff_stamp = self.timestamps[-1][0] - self.timestamps[0][0]
diff_count = self.timestamps[-1][1] - self.timestamps[0][1]
eps = diff_count / diff_stamp
time_left = (self.total - self.counts[-1]) / eps
time_left = (self.total - self.timestamps[-1][1]) / eps
return time_left
def get_eta(self):
return time.strftime(
'%H:%M:%S',
time.gmtime(
self.get_seconds()
)
return self.format(
self.get_seconds()
)
def get_finished(self):
return self.format(
time.time() - self.started
)
def format(self, seconds):
return time.strftime(
'%H:%M:%S',
time.gmtime(
time.time() - self.started
seconds
)
)
def split_upload(path, opts):
try:
size = int(subprocess.check_output(['du','-b',path]).split("\t")[0])