Skip to content

Commit

Permalink
New Version 1.15.0
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
OllisGit committed Nov 13, 2021
1 parent 93b2fb4 commit 946623c
Show file tree
Hide file tree
Showing 24 changed files with 1,285 additions and 276 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ If you like it, I would be thankful about a cup of coffee :)

- [PreHeat](https://plugins.octoprint.org/plugins/preheat/)
- Starting Temperature
- [CostEstimation](https://plugins.octoprint.org/plugins/costestimation/)
- Added the estimated costs to a print job
- [SpoolManager](https://plugins.octoprint.org/plugins/SpoolManager/)
- Spool Management
- [FillamentManager](https://plugins.octoprint.org/plugins/filamentmanager/)
Expand Down
9 changes: 7 additions & 2 deletions octoprint_PrintJobHistory/CameraManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,13 @@ def takePluginThumbnail(self, snapshotFilename, thumbnailLocation, storeImage =
if (storeImage):
self._logger.info("Try converting thumbnail '" + thumbnailLocation + "' to '" + snapshotFilename + "'")
im = Image.open(thumbnailLocation)
rgb_im = im.convert('RGB')
rgb_im.save(snapshotFilename)
# fill_color = (120, 8, 220)
# bg = Image.new("RGB", im.size, fill_color) see https://github.com/OllisGit/OctoPrint-PrintJobHistory/issues/160
bg = Image.new("RGB", im.size, (255, 255, 255))
bg.paste(im, im)
bg.save(snapshotFilename, 'JPEG')
# rgb_im = im.convert('RGB')
# rgb_im.save(snapshotFilename, 'JPEG')
self._logger.info("Converting successfull!")
else:
self._logger.info("Thumbnail is present")
Expand Down
71 changes: 61 additions & 10 deletions octoprint_PrintJobHistory/DatabaseManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from octoprint_PrintJobHistory.WrappedLoggingHandler import WrappedLoggingHandler
from octoprint_PrintJobHistory.api import TransformPrintJob2JSON
from octoprint_PrintJobHistory.common import StringUtils
from octoprint_PrintJobHistory.models.CostModel import CostModel
from octoprint_PrintJobHistory.models.FilamentModel import FilamentModel
from octoprint_PrintJobHistory.models.PrintJobModel import PrintJobModel
from octoprint_PrintJobHistory.models.PluginMetaDataModel import PluginMetaDataModel
Expand All @@ -21,10 +22,10 @@
FORCE_CREATE_TABLES = False
SQL_LOGGING = True

CURRENT_DATABASE_SCHEME_VERSION = 6
CURRENT_DATABASE_SCHEME_VERSION = 7

# List all Models
MODELS = [PluginMetaDataModel, PrintJobModel, FilamentModel, TemperatureModel]
MODELS = [PluginMetaDataModel, PrintJobModel, FilamentModel, TemperatureModel, CostModel]


class DatabaseManager(object):
Expand Down Expand Up @@ -107,6 +108,40 @@ def _upgradeFrom7To8(self):

def _upgradeFrom6To7(self):
self._logger.info(" Starting 6 -> 7")

connection = sqlite3.connect(self._databaseFileLocation)
cursor = connection.cursor()

## Changeset
# - NEW CostModel
# - Droping costUnit, because now there is a general plugin-setting

sql = """
PRAGMA foreign_keys=off;
BEGIN TRANSACTION;
CREATE TABLE "pjh_costmodel" ("databaseId" INTEGER NOT NULL PRIMARY KEY,
"created" DATETIME NOT NULL,
"printJob_id" INTEGER NOT NULL,
"totalCosts" REAL,
"filamentCost" REAL,
"electricityCost" REAL,
"printerCost" REAL,
"otherCostLabel" VARCHAR(255),
"otherCost" REAL,
"withDefaultSpoolValues" INTEGER,
FOREIGN KEY ("printJob_id") REFERENCES "pjh_printjobmodel" ("databaseId") ON DELETE CASCADE);
ALTER TABLE "pjh_filamentmodel" DROP COLUMN "spoolCostUnit";
UPDATE 'pjh_pluginmetadatamodel' SET value=7 WHERE key='databaseSchemeVersion';
COMMIT;
PRAGMA foreign_keys=on;
"""
cursor.executescript(sql)

connection.close()

self._logger.info(" Successfully 6 -> 7")
pass

Expand Down Expand Up @@ -139,7 +174,6 @@ def _upgradeFrom5To6(self):
self._logger.info(" Successfully 5 -> 6")
pass


def _upgradeFrom4To5(self):
self._logger.info(" Starting 4 -> 5")
# What is changed:
Expand Down Expand Up @@ -426,7 +460,7 @@ def backupDatabaseFile(self, backupFolder):
currentSchemeVersion = str(currentSchemeVersion.value)
except Exception as e:
self._logger.exception("Could not read databasescheme version:" + str(e))
backupDatabaseFileName = "printJobHistory-backup-V"+currentSchemeVersion +"-"+currentDate+".db"
backupDatabaseFileName = "printJobHistory-backup-"+currentDate+"-V"+currentSchemeVersion +".db"
backupDatabaseFilePath = os.path.join(backupFolder, backupDatabaseFileName)
if not os.path.exists(backupDatabaseFilePath):
shutil.copy(self._databaseFileLocation, backupDatabaseFilePath)
Expand Down Expand Up @@ -473,6 +507,10 @@ def insertPrintJob(self, printJobModel):
for temperatureModel in printJobModel.getTemperatureModels():
temperatureModel.printJob = printJobModel
temperatureModel.save()
# - Costs
if (printJobModel.getCosts() != None):
printJobModel.getCosts().save()

# do expicit commit
transaction.commit()
except Exception as e:
Expand All @@ -498,10 +536,14 @@ def updatePrintJob(self, printJobModel, rollbackHandler = None):
for filamentModel in printJobModel.getFilamentModels():
filamentModel.save()

# # - Temperature
# # - Temperature not needed for an update
# for temperatureModel in printJobModel.getTemperatureModels():
# temperatureModel.printJob = printJobModel
# temperatureModel.save()

# - Costs
if (printJobModel.getCosts() != None):
printJobModel.getCosts().save()
except Exception as e:
# Because this block of code is wrapped with "atomic", a
# new transaction will begin automatically after the call
Expand Down Expand Up @@ -558,7 +600,6 @@ def calculatePrintJobsStatisticByQuery(self, tableQuery):
if filla.toolId == "total":
# exclude totals, otherwise everything is counted twice
continue

if (StringUtils.isEmpty(filla.usedLength) == False):
length = length + filla.usedLength
if (StringUtils.isEmpty(filla.usedWeight) == False):
Expand Down Expand Up @@ -797,16 +838,26 @@ def loadAllPrintJobs(self):
# return allDict

def loadPrintJob(self, databaseId):
return PrintJobModel.get_by_id(databaseId)
databaseIdAsInt = StringUtils.transformToIntOrNone(databaseId)
if (databaseIdAsInt == None):
self._logger.error("Could not load PrintJob, because not a valid databaseId '"+str(databaseId)+"' maybe not a number")
return None
return PrintJobModel.get_or_none(databaseIdAsInt)

def deletePrintJob(self, databaseId):
databaseIdAsInt = StringUtils.transformToIntOrNone(databaseId)
if (databaseIdAsInt == None):
self._logger.error("Could not delete PrintJob, because not a valid databaseId '"+str(databaseId)+"' maybe not a number")
return None

with self._database.atomic() as transaction: # Opens new transaction.
try:
# first delete relations
n = FilamentModel.delete().where(FilamentModel.printJob == databaseId).execute()
n = TemperatureModel.delete().where(TemperatureModel.printJob == databaseId).execute()
n = FilamentModel.delete().where(FilamentModel.printJob == databaseIdAsInt).execute()
n = TemperatureModel.delete().where(TemperatureModel.printJob == databaseIdAsInt).execute()
n = CostModel.delete().where(CostModel.printJob == databaseIdAsInt).execute()

PrintJobModel.delete_by_id(databaseId)
PrintJobModel.delete_by_id(databaseIdAsInt)
except Exception as e:
# Because this block of code is wrapped with "atomic", a
# new transaction will begin automatically after the call
Expand Down
Loading

0 comments on commit 946623c

Please sign in to comment.