Commit 8245f90e authored by Guillaume Seguin's avatar Guillaume Seguin

Factorize ETA computation

parent 5c5e41f5
......@@ -1430,12 +1430,28 @@ class pronsole(cmd.Cmd):
secondselapsed = int(time.time() - self.starttime + self.extra_print_time)
self.compute_eta.update_layer(newlayer, secondselapsed)
def get_eta(self):
if self.sdprinting or self.uploading:
if self.uploading:
fractioncomplete = float(self.p.queueindex) / len(self.p.mainqueue)
else:
fractioncomplete = float(self.percentdone / 100.0)
secondselapsed = int(time.time() - self.starttime + self.extra_print_time)
# Prevent division by zero
secondsestimate = secondselapsed / max(fractioncomplete, 0.000001)
secondsremain = secondsestimate - secondselapsed
progress = fractioncomplete
else:
secondselapsed = int(time.time() - self.starttime + self.extra_print_time)
secondsremain, secondsestimate = self.compute_eta(self.p.queueindex, secondselapsed)
progress = self.p.queueindex
return secondsremain, secondsestimate, progress
def do_eta(self, l):
if not self.p.printing:
self.logError(_("Printer is not currently printing. No ETA available."))
else:
secondselapsed = int(time.time() - self.starttime + self.extra_print_time)
secondsremain, secondsestimate = self.compute_eta(self.p.queueindex, secondselapsed)
secondsremain, secondsestimate, progress = self.get_eta()
eta = _("Est: %s of %s remaining") % (format_duration(secondsremain),
format_duration(secondsestimate))
self.log(eta.strip())
......
......@@ -909,29 +909,18 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
def statuschecker(self):
while self.statuscheck:
string = ""
fractioncomplete = 0.0
if self.sdprinting or self.uploading:
if self.uploading:
fractioncomplete = float(self.p.queueindex) / len(self.p.mainqueue)
string += _("SD upload: %04.2f%% |") % (100 * fractioncomplete,)
if self.sdprinting or self.uploading or self.p.printing:
secondsremain, secondsestimate, progress = self.get_eta()
if self.sdprinting or self.uploading:
if self.uploading:
string += _("SD upload: %04.2f%% |") % (100 * progress,)
string += _(" Line# %d of %d lines |") % (self.p.queueindex, len(self.p.mainqueue))
else:
string += _("SD printing: %04.2f%% |") % (self.percentdone,)
elif self.p.printing:
string += _("Printing: %04.2f%% |") % (100 * float(self.p.queueindex) / len(self.p.mainqueue),)
string += _(" Line# %d of %d lines |") % (self.p.queueindex, len(self.p.mainqueue))
else:
fractioncomplete = float(self.percentdone / 100.0)
string += _("SD printing: %04.2f%% |") % (self.percentdone,)
if fractioncomplete > 0.0:
secondselapsed = int(time.time() - self.starttime + self.extra_print_time)
secondsestimate = secondselapsed / fractioncomplete
secondsremain = secondsestimate - secondselapsed
string += _(" Est: %s of %s remaining | ") % (format_duration(secondsremain),
format_duration(secondsestimate))
string += _(" Z: %.3f mm") % self.curlayer
elif self.p.printing:
fractioncomplete = float(self.p.queueindex) / len(self.p.mainqueue)
string += _("Printing: %04.2f%% |") % (100 * float(self.p.queueindex) / len(self.p.mainqueue),)
string += _(" Line# %d of %d lines |") % (self.p.queueindex, len(self.p.mainqueue))
if self.p.queueindex > 0:
secondselapsed = int(time.time() - self.starttime + self.extra_print_time)
secondsremain, secondsestimate = self.compute_eta(self.p.queueindex, secondselapsed)
if progress > 0:
string += _(" Est: %s of %s remaining | ") % (format_duration(secondsremain),
format_duration(secondsestimate))
string += _(" Z: %.3f mm") % self.curlayer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment