job_status: add eta
This commit is contained in:
parent
cdb40e8ce1
commit
d8b4d2d293
@ -1,5 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import datetime
|
||||||
import gi
|
import gi
|
||||||
|
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
@ -128,7 +128,6 @@ class ScreenPanel:
|
|||||||
def format_time(seconds):
|
def format_time(seconds):
|
||||||
if seconds is None or seconds <= 0:
|
if seconds is None or seconds <= 0:
|
||||||
return "-"
|
return "-"
|
||||||
seconds = int(seconds)
|
|
||||||
days = seconds // 86400
|
days = seconds // 86400
|
||||||
seconds %= 86400
|
seconds %= 86400
|
||||||
hours = seconds // 3600
|
hours = seconds // 3600
|
||||||
@ -140,6 +139,22 @@ class ScreenPanel:
|
|||||||
f"{f'{minutes:2.0f}m ' if minutes > 0 else ''}" \
|
f"{f'{minutes:2.0f}m ' if minutes > 0 else ''}" \
|
||||||
f"{f'{seconds:2.0f}s' if days == 0 and hours == 0 and minutes == 0 else ''}"
|
f"{f'{seconds:2.0f}s' if days == 0 and hours == 0 and minutes == 0 else ''}"
|
||||||
|
|
||||||
|
def format_eta(self, total, elapsed):
|
||||||
|
if total is None:
|
||||||
|
return "-"
|
||||||
|
seconds = total - elapsed
|
||||||
|
if seconds <= 0:
|
||||||
|
return "-"
|
||||||
|
days = seconds // 86400
|
||||||
|
seconds %= 86400
|
||||||
|
hours = seconds // 3600
|
||||||
|
seconds %= 3600
|
||||||
|
minutes = seconds // 60
|
||||||
|
eta = datetime.datetime.now() + datetime.timedelta(days=days, hours=hours, minutes=minutes)
|
||||||
|
if self._config.get_main_config().getboolean("24htime", True):
|
||||||
|
return f"{self.format_time(total - elapsed)} | {eta:%H:%M} {f' +{days:2.0f}d' if days > 0 else ''}"
|
||||||
|
return f"{self.format_time(total - elapsed)} | {eta:%I:%M %p} {f' +{days:2.0f}d' if days > 0 else ''}"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def format_size(size):
|
def format_size(size):
|
||||||
size = float(size)
|
size = float(size)
|
||||||
|
@ -630,6 +630,7 @@ class JobStatusPanel(ScreenPanel):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def update_time_left(self, duration=0, fila_used=0):
|
def update_time_left(self, duration=0, fila_used=0):
|
||||||
|
self.labels["duration"].set_label(self.format_time(duration))
|
||||||
total_duration = None
|
total_duration = None
|
||||||
if self.progress < 1:
|
if self.progress < 1:
|
||||||
slicer_time = filament_time = file_time = None
|
slicer_time = filament_time = file_time = None
|
||||||
@ -641,16 +642,16 @@ class JobStatusPanel(ScreenPanel):
|
|||||||
# speed_factor compensation based on empirical testing
|
# speed_factor compensation based on empirical testing
|
||||||
spdcomp = sqrt(self.speed_factor)
|
spdcomp = sqrt(self.speed_factor)
|
||||||
slicer_time = (self.file_metadata['estimated_time'] * usrcomp) / spdcomp
|
slicer_time = (self.file_metadata['estimated_time'] * usrcomp) / spdcomp
|
||||||
self.labels["slicer_time"].set_label(self.format_time(slicer_time))
|
self.labels["slicer_time"].set_label(self.format_eta(slicer_time, duration))
|
||||||
|
|
||||||
with contextlib.suppress(Exception):
|
with contextlib.suppress(Exception):
|
||||||
if self.file_metadata['filament_total'] > fila_used:
|
if self.file_metadata['filament_total'] > fila_used:
|
||||||
filament_time = duration / (fila_used / self.file_metadata['filament_total'])
|
filament_time = duration / (fila_used / self.file_metadata['filament_total'])
|
||||||
self.labels["filament_time"].set_label(self.format_time(filament_time))
|
self.labels["filament_time"].set_label(self.format_eta(filament_time, duration))
|
||||||
|
|
||||||
with contextlib.suppress(ZeroDivisionError):
|
with contextlib.suppress(ZeroDivisionError):
|
||||||
file_time = duration / self.progress
|
file_time = duration / self.progress
|
||||||
self.labels["file_time"].set_label(self.format_time(file_time))
|
self.labels["file_time"].set_label(self.format_eta(file_time, duration))
|
||||||
|
|
||||||
if timeleft_type == "file":
|
if timeleft_type == "file":
|
||||||
total_duration = file_time
|
total_duration = file_time
|
||||||
@ -670,10 +671,11 @@ class JobStatusPanel(ScreenPanel):
|
|||||||
total_duration = (filament_time + file_time) / 2
|
total_duration = (filament_time + file_time) / 2
|
||||||
else:
|
else:
|
||||||
total_duration = file_time
|
total_duration = file_time
|
||||||
self.labels["duration"].set_label(self.format_time(duration))
|
self.labels["est_time"].set_label(self.format_eta(total_duration, duration))
|
||||||
self.labels["est_time"].set_label(self.format_time(total_duration))
|
self.labels["time_left"].set_label(self.format_eta(total_duration, duration))
|
||||||
if total_duration is not None:
|
else:
|
||||||
self.labels["time_left"].set_label(self.format_time(total_duration - duration))
|
self.labels["est_time"].set_label("-")
|
||||||
|
self.labels["time_left"].set_label("-")
|
||||||
|
|
||||||
def state_check(self):
|
def state_check(self):
|
||||||
ps = self._printer.get_stat("print_stats")
|
ps = self._printer.get_stat("print_stats")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user