From 136f47f31856b6a8ad5312d4974f9dab9fca4e59 Mon Sep 17 00:00:00 2001 From: Martin Muehlhaeuser Date: Sat, 18 Aug 2018 12:44:11 +0000 Subject: [PATCH] [fix] File listing not working --- .../modules/KlipperLogAnalyzer.py | 12 +++---- octoprint_klipper/static/js/klipper.js | 10 +++--- octoprint_klipper/static/js/klipper_graph.js | 32 +++++++------------ .../static/js/klipper_leveling.js | 24 ++++++++------ .../templates/klipper_graph_dialog.jinja2 | 10 +++--- .../templates/klipper_leveling_dialog.jinja2 | 5 +-- 6 files changed, 45 insertions(+), 48 deletions(-) diff --git a/octoprint_klipper/modules/KlipperLogAnalyzer.py b/octoprint_klipper/modules/KlipperLogAnalyzer.py index 9613ab6..62cf520 100644 --- a/octoprint_klipper/modules/KlipperLogAnalyzer.py +++ b/octoprint_klipper/modules/KlipperLogAnalyzer.py @@ -17,12 +17,9 @@ class KlipperLogAnalyzer(): def analyze(self): data = self.parse_log(self.log_file, None) if not data: - result = dict(error= "Couldn't parse \"{}\"".format(self.log_file)) + result = dict(error= "No relevant data available in \"{}\"".format(self.log_file)) else: result = self.plot_mcu(data, self.MAXBANDWIDTH) - #if options.frequency: - # plot_frequency(data, outname, options.mcu) - # return return result def parse_log(self, logname, mcu): @@ -119,14 +116,13 @@ class KlipperLogAnalyzer(): else: hb = 100. * (self.MAXBUFFER - hb) / self.MAXBUFFER hostbuffers.append(hb) - #times.append(datetime.datetime.utcfromtimestamp(st)) times.append(st) bwdeltas.append(100. * (bw - lastbw) / (maxbw * timedelta)) loads.append(100. * load / self.TASK_MAX) awake.append(100. * float(d.get('mcu_awake', 0.)) / self.STATS_INTERVAL) lasttime = st lastbw = bw - + result = dict( times= times, bwdeltas= bwdeltas, @@ -151,4 +147,6 @@ class KlipperLogAnalyzer(): val = d.get(key) if val not in (None, '0', '1'): times.append(st) - values.append(float(val)) + values.append(float(val)/1000000.0) + + return values diff --git a/octoprint_klipper/static/js/klipper.js b/octoprint_klipper/static/js/klipper.js index 83bb983..e976dc6 100644 --- a/octoprint_klipper/static/js/klipper.js +++ b/octoprint_klipper/static/js/klipper.js @@ -5,17 +5,19 @@ $(function() { self.settings = parameters[0]; self.loginState = parameters[1]; self.connectionState = parameters[2]; - + self.levelingViewModel = parameters[3]; + self.shortStatus = ko.observable(); self.logMessages = ko.observableArray(); - + self.showLevelingDialog = function() { var dialog = $("#klipper_leveling_dialog"); dialog.modal({ show: 'true', backdrop: 'static', keyboard: false - }); + }); + self.levelingViewModel.initView(); } self.showPidTuningDialog = function() { @@ -89,7 +91,7 @@ $(function() { OCTOPRINT_VIEWMODELS.push({ construct: KlipperViewModel, - dependencies: ["settingsViewModel", "loginStateViewModel", "connectionViewModel"], + dependencies: ["settingsViewModel", "loginStateViewModel", "connectionViewModel", "klipperLevelingViewModel"], elements: ["#tab_plugin_klipper_main", "#sidebar_plugin_klipper", "#navbar_plugin_klipper"] }); }); \ No newline at end of file diff --git a/octoprint_klipper/static/js/klipper_graph.js b/octoprint_klipper/static/js/klipper_graph.js index b56c9ce..82bea2e 100644 --- a/octoprint_klipper/static/js/klipper_graph.js +++ b/octoprint_klipper/static/js/klipper_graph.js @@ -2,11 +2,13 @@ $(function() { function KlipperGraphViewModel(parameters) { var self = this; - + self.loginState = parameters[0]; + self.header = OctoPrint.getRequestHeaders({ "content-type": "application/json", "cache-control": "no-cache" }); + self.apiUrl = OctoPrint.getSimpleApiUrl("klipper"); self.availableLogFiles = ko.observableArray(); @@ -18,7 +20,7 @@ function KlipperGraphViewModel(parameters) { self.canvasContext; self.chart; self.spinnerDialog; - + self.onStartup = function() { self.canvas = $("#klipper_graph_canvas")[0] self.canvasContext = self.canvas.getContext("2d"); @@ -31,6 +33,13 @@ function KlipperGraphViewModel(parameters) { var myChart = new Chart(self.canvas, { type: "line" }); + + if(self.loginState.loggedIn()) { + self.listLogFiles(); + } + } + + self.onUserLoggedIn = function(user) { self.listLogFiles(); } @@ -147,15 +156,6 @@ function KlipperGraphViewModel(parameters) { data: response.awake }); -// self.datasets.push( -// { -// label: "Frequency", -// backgroundColor: "rgba(33, 64, 95, 0.5)", -// borderColor: "rgb(33, 64, 95)", -// yAxisID: 'y-axis-2', -// data: response.frequency -// }); - self.chart = new Chart(self.canvas, { type: "line", data: { @@ -193,14 +193,6 @@ function KlipperGraphViewModel(parameters) { position: 'left', id: 'y-axis-1' } -// { -// scaleLabel: { -// display: true, -// labelString: 'MHz' -// }, -// position: 'right', -// id: 'y-axis-2' -// } ] }, legend: { @@ -215,7 +207,7 @@ function KlipperGraphViewModel(parameters) { OCTOPRINT_VIEWMODELS.push({ construct: KlipperGraphViewModel, - dependencies: [], + dependencies: ["loginStateViewModel"], elements: ["#klipper_graph_dialog"] }); }); diff --git a/octoprint_klipper/static/js/klipper_leveling.js b/octoprint_klipper/static/js/klipper_leveling.js index 7b56fe0..c0fd3d2 100644 --- a/octoprint_klipper/static/js/klipper_leveling.js +++ b/octoprint_klipper/static/js/klipper_leveling.js @@ -3,14 +3,18 @@ $(function() { var self = this; self.settings = parameters[0]; self.loginState = parameters[1]; - self.connectionState = parameters[2]; - self.activePoint = ko.observable(); + self.activePoint = ko.observable(-1); + self.pointCount = ko.observable(); + self.points = ko.observableArray(); - self.onStartup = function() { - self.activePoint(-1); + self.initView = function() { + self.points(self.settings.settings.plugins.klipper.probe.points()); + self.pointCount( + self.points().length + ); } - + self.startLeveling = function() { OctoPrint.control.sendGcode("G28") self.moveToPoint(0); @@ -39,14 +43,14 @@ $(function() { self.jumpToPoint = function(item) { self.moveToPoint( - self.settings.settings.plugins.klipper.probe.points().indexOf(item) + self.points().indexOf(item) ); } - + /* self.pointCount = function() { return self.settings.settings.plugins.klipper.probe.points().length; } - + */ self.moveToPosition = function(x, y) { OctoPrint.control.sendGcode( "G1 Z" + (self.settings.settings.plugins.klipper.probe.height() * 1 + @@ -64,7 +68,7 @@ $(function() { } self.moveToPoint = function(index) { - var point = self.settings.settings.plugins.klipper.probe.points()[index]; + var point = self.points()[index]; self.moveToPosition(point.x(), point.y()); self.activePoint(index); @@ -73,7 +77,7 @@ $(function() { OCTOPRINT_VIEWMODELS.push({ construct: KlipperLevelingViewModel, - dependencies: ["settingsViewModel", "loginStateViewModel", "connectionViewModel"], + dependencies: ["settingsViewModel", "loginStateViewModel"], elements: ["#klipper_leveling_dialog"] }); }); \ No newline at end of file diff --git a/octoprint_klipper/templates/klipper_graph_dialog.jinja2 b/octoprint_klipper/templates/klipper_graph_dialog.jinja2 index 1b373af..3bfc47a 100644 --- a/octoprint_klipper/templates/klipper_graph_dialog.jinja2 +++ b/octoprint_klipper/templates/klipper_graph_dialog.jinja2 @@ -9,15 +9,15 @@ Click labels to hide/show dataset +
 
-
+
@@ -41,11 +41,12 @@
- +
+
\ No newline at end of file