Skip to content

Commit

Permalink
Merge pull request #91 from LazeMSS/develop
Browse files Browse the repository at this point in the history
0.0.2.2 - release
  • Loading branch information
LazeMSS authored Dec 27, 2022
2 parents 851017c + a49d855 commit 684655b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
13 changes: 10 additions & 3 deletions octoprint_toptemp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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] = []
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"

Expand Down
29 changes: 20 additions & 9 deletions octoprint_toptemp/static/js/TopTemp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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){
Expand All @@ -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 = '<div class="pull-left"><small>Current: '+self.formatTempLabel($thisID,actual,iSettings,false)+'</small></div><div class="pull-right"><small>Max: '+self.formatTempLabel($thisID,stats.high,iSettings,false)+' &middot; Min: '+self.formatTempLabel($thisID,stats.low,iSettings,false)+' &middot; Avg: '+self.formatTempLabel($thisID,stats.avg,iSettings,false)+'</small></div>';
$('#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 = '<div class="pull-left"><small>Actual: '+self.formatTempLabel($thisID,actual,iSettings,false)+'</small></div><div class="pull-right"><small>Target: ';
Expand Down Expand Up @@ -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?!
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 684655b

Please sign in to comment.