Skip to content

Commit 946623c

Browse files
committed
New Version 1.15.0
- E #89 support of CostEstimation Plugin - E #154 Report for a printjob - E #160 thumbnail backgroud color is now white - E #162 searching now starts directly after typing(instead of entering 3 letters) - B #165, #158, #156, #155, #149 persist settings of tracking plugin (thx a lot, @ManuelMcLure for the PR) - B #161, #169 statistic popup, double counting (thx a lot, @hvraven for the PR) - B storing note text - #123 changing to octoprint.comm.protocol.gcode.sending for M117 Snapshot trigger
1 parent 93b2fb4 commit 946623c

24 files changed

+1285
-276
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ If you like it, I would be thankful about a cup of coffee :)
5454

5555
- [PreHeat](https://plugins.octoprint.org/plugins/preheat/)
5656
- Starting Temperature
57+
- [CostEstimation](https://plugins.octoprint.org/plugins/costestimation/)
58+
- Added the estimated costs to a print job
5759
- [SpoolManager](https://plugins.octoprint.org/plugins/SpoolManager/)
5860
- Spool Management
5961
- [FillamentManager](https://plugins.octoprint.org/plugins/filamentmanager/)

octoprint_PrintJobHistory/CameraManager.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,13 @@ def takePluginThumbnail(self, snapshotFilename, thumbnailLocation, storeImage =
252252
if (storeImage):
253253
self._logger.info("Try converting thumbnail '" + thumbnailLocation + "' to '" + snapshotFilename + "'")
254254
im = Image.open(thumbnailLocation)
255-
rgb_im = im.convert('RGB')
256-
rgb_im.save(snapshotFilename)
255+
# fill_color = (120, 8, 220)
256+
# bg = Image.new("RGB", im.size, fill_color) see https://github.com/OllisGit/OctoPrint-PrintJobHistory/issues/160
257+
bg = Image.new("RGB", im.size, (255, 255, 255))
258+
bg.paste(im, im)
259+
bg.save(snapshotFilename, 'JPEG')
260+
# rgb_im = im.convert('RGB')
261+
# rgb_im.save(snapshotFilename, 'JPEG')
257262
self._logger.info("Converting successfull!")
258263
else:
259264
self._logger.info("Thumbnail is present")

octoprint_PrintJobHistory/DatabaseManager.py

+61-10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from octoprint_PrintJobHistory.WrappedLoggingHandler import WrappedLoggingHandler
1111
from octoprint_PrintJobHistory.api import TransformPrintJob2JSON
1212
from octoprint_PrintJobHistory.common import StringUtils
13+
from octoprint_PrintJobHistory.models.CostModel import CostModel
1314
from octoprint_PrintJobHistory.models.FilamentModel import FilamentModel
1415
from octoprint_PrintJobHistory.models.PrintJobModel import PrintJobModel
1516
from octoprint_PrintJobHistory.models.PluginMetaDataModel import PluginMetaDataModel
@@ -21,10 +22,10 @@
2122
FORCE_CREATE_TABLES = False
2223
SQL_LOGGING = True
2324

24-
CURRENT_DATABASE_SCHEME_VERSION = 6
25+
CURRENT_DATABASE_SCHEME_VERSION = 7
2526

2627
# List all Models
27-
MODELS = [PluginMetaDataModel, PrintJobModel, FilamentModel, TemperatureModel]
28+
MODELS = [PluginMetaDataModel, PrintJobModel, FilamentModel, TemperatureModel, CostModel]
2829

2930

3031
class DatabaseManager(object):
@@ -107,6 +108,40 @@ def _upgradeFrom7To8(self):
107108

108109
def _upgradeFrom6To7(self):
109110
self._logger.info(" Starting 6 -> 7")
111+
112+
connection = sqlite3.connect(self._databaseFileLocation)
113+
cursor = connection.cursor()
114+
115+
## Changeset
116+
# - NEW CostModel
117+
# - Droping costUnit, because now there is a general plugin-setting
118+
119+
sql = """
120+
PRAGMA foreign_keys=off;
121+
BEGIN TRANSACTION;
122+
123+
CREATE TABLE "pjh_costmodel" ("databaseId" INTEGER NOT NULL PRIMARY KEY,
124+
"created" DATETIME NOT NULL,
125+
"printJob_id" INTEGER NOT NULL,
126+
"totalCosts" REAL,
127+
"filamentCost" REAL,
128+
"electricityCost" REAL,
129+
"printerCost" REAL,
130+
"otherCostLabel" VARCHAR(255),
131+
"otherCost" REAL,
132+
"withDefaultSpoolValues" INTEGER,
133+
FOREIGN KEY ("printJob_id") REFERENCES "pjh_printjobmodel" ("databaseId") ON DELETE CASCADE);
134+
135+
ALTER TABLE "pjh_filamentmodel" DROP COLUMN "spoolCostUnit";
136+
137+
UPDATE 'pjh_pluginmetadatamodel' SET value=7 WHERE key='databaseSchemeVersion';
138+
COMMIT;
139+
PRAGMA foreign_keys=on;
140+
"""
141+
cursor.executescript(sql)
142+
143+
connection.close()
144+
110145
self._logger.info(" Successfully 6 -> 7")
111146
pass
112147

@@ -139,7 +174,6 @@ def _upgradeFrom5To6(self):
139174
self._logger.info(" Successfully 5 -> 6")
140175
pass
141176

142-
143177
def _upgradeFrom4To5(self):
144178
self._logger.info(" Starting 4 -> 5")
145179
# What is changed:
@@ -426,7 +460,7 @@ def backupDatabaseFile(self, backupFolder):
426460
currentSchemeVersion = str(currentSchemeVersion.value)
427461
except Exception as e:
428462
self._logger.exception("Could not read databasescheme version:" + str(e))
429-
backupDatabaseFileName = "printJobHistory-backup-V"+currentSchemeVersion +"-"+currentDate+".db"
463+
backupDatabaseFileName = "printJobHistory-backup-"+currentDate+"-V"+currentSchemeVersion +".db"
430464
backupDatabaseFilePath = os.path.join(backupFolder, backupDatabaseFileName)
431465
if not os.path.exists(backupDatabaseFilePath):
432466
shutil.copy(self._databaseFileLocation, backupDatabaseFilePath)
@@ -473,6 +507,10 @@ def insertPrintJob(self, printJobModel):
473507
for temperatureModel in printJobModel.getTemperatureModels():
474508
temperatureModel.printJob = printJobModel
475509
temperatureModel.save()
510+
# - Costs
511+
if (printJobModel.getCosts() != None):
512+
printJobModel.getCosts().save()
513+
476514
# do expicit commit
477515
transaction.commit()
478516
except Exception as e:
@@ -498,10 +536,14 @@ def updatePrintJob(self, printJobModel, rollbackHandler = None):
498536
for filamentModel in printJobModel.getFilamentModels():
499537
filamentModel.save()
500538

501-
# # - Temperature
539+
# # - Temperature not needed for an update
502540
# for temperatureModel in printJobModel.getTemperatureModels():
503541
# temperatureModel.printJob = printJobModel
504542
# temperatureModel.save()
543+
544+
# - Costs
545+
if (printJobModel.getCosts() != None):
546+
printJobModel.getCosts().save()
505547
except Exception as e:
506548
# Because this block of code is wrapped with "atomic", a
507549
# new transaction will begin automatically after the call
@@ -558,7 +600,6 @@ def calculatePrintJobsStatisticByQuery(self, tableQuery):
558600
if filla.toolId == "total":
559601
# exclude totals, otherwise everything is counted twice
560602
continue
561-
562603
if (StringUtils.isEmpty(filla.usedLength) == False):
563604
length = length + filla.usedLength
564605
if (StringUtils.isEmpty(filla.usedWeight) == False):
@@ -797,16 +838,26 @@ def loadAllPrintJobs(self):
797838
# return allDict
798839

799840
def loadPrintJob(self, databaseId):
800-
return PrintJobModel.get_by_id(databaseId)
841+
databaseIdAsInt = StringUtils.transformToIntOrNone(databaseId)
842+
if (databaseIdAsInt == None):
843+
self._logger.error("Could not load PrintJob, because not a valid databaseId '"+str(databaseId)+"' maybe not a number")
844+
return None
845+
return PrintJobModel.get_or_none(databaseIdAsInt)
801846

802847
def deletePrintJob(self, databaseId):
848+
databaseIdAsInt = StringUtils.transformToIntOrNone(databaseId)
849+
if (databaseIdAsInt == None):
850+
self._logger.error("Could not delete PrintJob, because not a valid databaseId '"+str(databaseId)+"' maybe not a number")
851+
return None
852+
803853
with self._database.atomic() as transaction: # Opens new transaction.
804854
try:
805855
# first delete relations
806-
n = FilamentModel.delete().where(FilamentModel.printJob == databaseId).execute()
807-
n = TemperatureModel.delete().where(TemperatureModel.printJob == databaseId).execute()
856+
n = FilamentModel.delete().where(FilamentModel.printJob == databaseIdAsInt).execute()
857+
n = TemperatureModel.delete().where(TemperatureModel.printJob == databaseIdAsInt).execute()
858+
n = CostModel.delete().where(CostModel.printJob == databaseIdAsInt).execute()
808859

809-
PrintJobModel.delete_by_id(databaseId)
860+
PrintJobModel.delete_by_id(databaseIdAsInt)
810861
except Exception as e:
811862
# Because this block of code is wrapped with "atomic", a
812863
# new transaction will begin automatically after the call

0 commit comments

Comments
 (0)