diff --git a/docs/api/datamodel.rst b/docs/api/datamodel.rst index 76fc003c..7511332d 100644 --- a/docs/api/datamodel.rst +++ b/docs/api/datamodel.rst @@ -164,6 +164,10 @@ Job information - 0..1 - Integer - The estimated print time for the file, in seconds. + * - ``lastPrintTime`` + - 0..1 + - Integer + - The print time of the last print of the file, in seconds. * - ``filament`` - 0..1 - Object diff --git a/src/octoprint/printer.py b/src/octoprint/printer.py index ee96fc94..875af19c 100644 --- a/src/octoprint/printer.py +++ b/src/octoprint/printer.py @@ -95,6 +95,7 @@ class Printer(): "date": None }, "estimatedPrintTime": None, + "lastPrintTime": None, "filament": { "length": None, "volume": None @@ -389,6 +390,7 @@ class Printer(): self._selectedFile = None estimatedPrintTime = None + lastPrintTime = None date = None filament = None if filename: @@ -398,11 +400,14 @@ class Printer(): date = int(os.stat(filename).st_ctime) fileData = self._gcodeManager.getFileData(filename) - if fileData is not None and "gcodeAnalysis" in fileData.keys(): - if "estimatedPrintTime" in fileData["gcodeAnalysis"].keys(): - estimatedPrintTime = fileData["gcodeAnalysis"]["estimatedPrintTime"] - if "filament" in fileData["gcodeAnalysis"].keys(): - filament = fileData["gcodeAnalysis"]["filament"] + if fileData is not None: + if "gcodeAnalysis" in fileData: + if estimatedPrintTime is None and "estimatedPrintTime" in fileData["gcodeAnalysis"]: + estimatedPrintTime = fileData["gcodeAnalysis"]["estimatedPrintTime"] + if "filament" in fileData["gcodeAnalysis"].keys(): + filament = fileData["gcodeAnalysis"]["filament"] + if "prints" in fileData and "last" in fileData["prints"] and "lastPrintTime" in fileData["prints"]["last"]: + lastPrintTime = fileData["prints"]["last"]["lastPrintTime"] self._stateMonitor.setJobData({ "file": { @@ -412,6 +417,7 @@ class Printer(): "date": date }, "estimatedPrintTime": estimatedPrintTime, + "lastPrintTime": lastPrintTime, "filament": filament, }) diff --git a/src/octoprint/static/js/app/viewmodels/files.js b/src/octoprint/static/js/app/viewmodels/files.js index 115ea618..e9bc301f 100644 --- a/src/octoprint/static/js/app/viewmodels/files.js +++ b/src/octoprint/static/js/app/viewmodels/files.js @@ -274,12 +274,12 @@ function GcodeFilesViewModel(printerStateViewModel, loginStateViewModel) { } while (filament.hasOwnProperty("tool" + i)); } } - output += "Estimated Print Time: " + formatDuration(data["gcodeAnalysis"]["estimatedPrintTime"]); + output += "Estimated Print Time: " + formatDuration(data["gcodeAnalysis"]["estimatedPrintTime"]) + "
"; } if (data["prints"] && data["prints"]["last"]) { - output += "
Last Printed: " + formatTimeAgo(data["prints"]["last"]["date"]); + output += "Last Printed: " + formatTimeAgo(data["prints"]["last"]["date"]) + "
"; if (data["prints"]["last"]["lastPrintTime"]) { - output += "
Last Print Time: " + formatDuration(data["prints"]["last"]["lastPrintTime"]); + output += "Last Print Time: " + formatDuration(data["prints"]["last"]["lastPrintTime"]); } } return output; diff --git a/src/octoprint/static/js/app/viewmodels/printerstate.js b/src/octoprint/static/js/app/viewmodels/printerstate.js index 2865c387..7dfad297 100644 --- a/src/octoprint/static/js/app/viewmodels/printerstate.js +++ b/src/octoprint/static/js/app/viewmodels/printerstate.js @@ -24,13 +24,16 @@ function PrinterStateViewModel(loginStateViewModel) { self.filament = ko.observableArray([]); self.estimatedPrintTime = ko.observable(undefined); + self.lastPrintTime = ko.observable(undefined); self.currentHeight = ko.observable(undefined); self.estimatedPrintTimeString = ko.computed(function() { - if (!self.estimatedPrintTime()) - return "-"; - return formatDuration(self.estimatedPrintTime()); + if (self.lastPrintTime()) + return formatDuration(self.lastPrintTime()); + if (self.estimatedPrintTime()) + return formatDuration(self.estimatedPrintTime()); + return "-"; }); self.byteString = ko.computed(function() { if (!self.filesize()) @@ -123,6 +126,7 @@ function PrinterStateViewModel(loginStateViewModel) { } self.estimatedPrintTime(data.estimatedPrintTime); + self.lastPrintTime(data.lastPrintTime); var result = []; if (data.filament && typeof(data.filament) == "object" && _.keys(data.filament).length > 0) { diff --git a/src/octoprint/templates/index.jinja2 b/src/octoprint/templates/index.jinja2 index 505655f2..17255f91 100644 --- a/src/octoprint/templates/index.jinja2 +++ b/src/octoprint/templates/index.jinja2 @@ -125,12 +125,11 @@
Machine State:
File:  (SD)
- -
- - Estimated Print Time:
Timelapse:
- Height:
+ +
+ + Approx. Total Print Time:
Print Time:
Print Time Left:
Printed: