diff --git a/octoprint_toptemp/__init__.py b/octoprint_toptemp/__init__.py index a5b4b62..3ed74ab 100644 --- a/octoprint_toptemp/__init__.py +++ b/octoprint_toptemp/__init__.py @@ -493,7 +493,7 @@ def checkCpuTempMethods(self): # self._logger.debug("ERROR 1:-------------------------------------------------------------%s %s",err,code) pass else: - if out.replace('.','',1).isdigit(): + if self.checkStringIsVal(out): # self._logger.debug("OK-------------------------------------------------------------%s %s",out,self.tempCmds[key][0]) self.tempCmds[key][2] = float(out) else: @@ -729,7 +729,7 @@ def runPSUtil(self,indx,cmd,returnData = False): def handleCustomData(self,indx,out,time): self.debugOut("Got custom data: " + str(out)) # Check - if isinstance(out,(float, int)) or str(out).replace('.','',1).isdigit(): + if isinstance(out,(float, int)) or self.checkStringIsVal(out): resultData = [time,float(out)] if indx not in self.customHistory: self.customHistory[indx] = [] @@ -834,7 +834,7 @@ def on_api_command(self, command, data): if code or err: repsonse = dict(success=False,error=err,returnCode=code,result=out) else: - if isinstance(out,(float, int)) or str(out).replace('.','',1).lstrip("-").isdigit(): + if isinstance(out,(float, int)) or self.checkStringIsVal(out): repsonse = dict(success=True,error=err,returnCode=code,result=out) else: repsonse = dict(success=False,error="Not an value",returnCode=code,result=out) @@ -947,6 +947,13 @@ def gCodeHandlerSent(self, comm_instance, phase, cmd, cmd_type, gcode, *args, ** self.gcodeQue.put(dataSet) + def checkStringIsVal(self,inputStr): + inputStr = str(inputStr) + if inputStr[0] in ["+", "-"]: + inputStr = inputStr[1:] + return inputStr.replace('.','',1).isdigit() + + __plugin_name__ = "Top Temp" __plugin_pythoncompat__ = ">=2.7,<4" diff --git a/octoprint_toptemp/static/js/TopTemp.js b/octoprint_toptemp/static/js/TopTemp.js index e338ba7..cd19ead 100644 --- a/octoprint_toptemp/static/js/TopTemp.js +++ b/octoprint_toptemp/static/js/TopTemp.js @@ -1225,12 +1225,18 @@ $(function() { }); } - self.findMinMaxAvg = function(data){ - var items = data.length; + self.findMinMaxAvg = function(data,maxHis){ + var items = 0; + var nowTs = Math.round(Date.now() / 1000); var lowValD = null; var highValD = null; var sum = 0; data.map(function(val,i){ + var seconds = val[0]-nowTs; + if (seconds < maxHis){ + return false; + } + items++; sum += val[1]; if (lowValD == null || lowValD > val[1]){ lowValD = val[1]; @@ -1239,7 +1245,11 @@ $(function() { highValD = val[1]; } }); - return {'low':lowValD,'high':highValD,'avg':(sum/items)} + var avg = null; + if (items > 0){ + avg = (sum/items); + } + return {'low':lowValD,'high':highValD,'avg':avg}; } self.updatePopover = function($thisID,$isCustom,iSettings){ @@ -1252,17 +1262,22 @@ $(function() { // update title by calling the original one mainItem.data('popover').tip().find('h3.popover-title').html(mainItem.data('popover').options.title()); + var maxHis = self.popoverGHist; + if (iSettings.gHisSecs() > 0){ + maxHis = 0 - iSettings.gHisSecs(); + } + // Show target/actual if ($('#TopTempPopoverText_'+$thisID).length){ if ($isCustom){ if ($thisID in self.customHistory){ - var stats = self.findMinMaxAvg(self.customHistory[$thisID]); + var stats = self.findMinMaxAvg(self.customHistory[$thisID],maxHis); var actual = self.customHistory[$thisID][self.customHistory[$thisID].length-1][1]; var output = '
Current: '+self.formatTempLabel($thisID,actual,iSettings,false)+'
Max: '+self.formatTempLabel($thisID,stats.high,iSettings,false)+' · Min: '+self.formatTempLabel($thisID,stats.low,iSettings,false)+' · Avg: '+self.formatTempLabel($thisID,stats.avg,iSettings,false)+'
'; $('#TopTempPopoverText_'+$thisID).html(output); } }else{ - var stats = self.findMinMaxAvg(self.tempModel.temperatures[$thisID].actual); + var stats = self.findMinMaxAvg(self.tempModel.temperatures[$thisID].actual,maxHis); var actual = self.tempModel.temperatures[$thisID].actual[self.tempModel.temperatures[$thisID].actual.length-1][1]; var target = self.tempModel.temperatures[$thisID].target[self.tempModel.temperatures[$thisID].target.length-1][1]; var output = '
Actual: '+self.formatTempLabel($thisID,actual,iSettings,false)+'
Target: '; @@ -1300,10 +1315,6 @@ $(function() { } } - var maxHis = self.popoverGHist; - if (iSettings.gHisSecs() > 0){ - maxHis = 0 - iSettings.gHisSecs(); - } // Custom data or not? if ($isCustom){ // No data?! diff --git a/setup.py b/setup.py index 964c762..5fe6459 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "Top Temp" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "0.0.2.1" +plugin_version = "0.0.2.2" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module