bug in eta
This commit is contained in:
@@ -10,52 +10,44 @@ TOKEN="{{ token }}"
|
|||||||
class ETA():
|
class ETA():
|
||||||
def __init__(self,total):
|
def __init__(self,total):
|
||||||
self.total = total
|
self.total = total
|
||||||
self.memory = 360 # seconds
|
self.memory_length = 360 # seconds
|
||||||
self.counts = []
|
self.timestamps = [] # (time, count)
|
||||||
self.timestamps = []
|
|
||||||
self.started = time.time()
|
self.started = time.time()
|
||||||
|
|
||||||
def update(self,count):
|
def update(self,count):
|
||||||
|
|
||||||
self.counts.append(count)
|
self.timestamps.append((time.time(), count))
|
||||||
self.timestamps.append(time.time())
|
newest = self.timestamps[-1][0]
|
||||||
|
self.timestamps = [x for x in self.timestamps if newest - x[0] < self.memory_length]
|
||||||
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]
|
|
||||||
|
|
||||||
def get_seconds(self):
|
def get_seconds(self):
|
||||||
if len(self.timestamps)<2:
|
if len(self.timestamps)<2:
|
||||||
return None
|
return None
|
||||||
diff_stamp = self.timestamps[-1] - self.timestamps[0]
|
diff_stamp = self.timestamps[-1][0] - self.timestamps[0][0]
|
||||||
diff_count = self.counts[-1] - self.counts[0]
|
diff_count = self.timestamps[-1][1] - self.timestamps[0][1]
|
||||||
eps = diff_count / diff_stamp
|
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
|
return time_left
|
||||||
|
|
||||||
def get_eta(self):
|
def get_eta(self):
|
||||||
return time.strftime(
|
return self.format(
|
||||||
'%H:%M:%S',
|
self.get_seconds()
|
||||||
time.gmtime(
|
|
||||||
self.get_seconds()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_finished(self):
|
def get_finished(self):
|
||||||
|
return self.format(
|
||||||
|
time.time() - self.started
|
||||||
|
)
|
||||||
|
|
||||||
|
def format(self, seconds):
|
||||||
return time.strftime(
|
return time.strftime(
|
||||||
'%H:%M:%S',
|
'%H:%M:%S',
|
||||||
time.gmtime(
|
time.gmtime(
|
||||||
time.time() - self.started
|
seconds
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def split_upload(path, opts):
|
def split_upload(path, opts):
|
||||||
try:
|
try:
|
||||||
size = int(subprocess.check_output(['du','-b',path]).split("\t")[0])
|
size = int(subprocess.check_output(['du','-b',path]).split("\t")[0])
|
||||||
|
|||||||
Reference in New Issue
Block a user