def _test_something(self): db = peewee.SqliteDatabase(self.databaselocation+'/printJobHistory.db') singlePrintJob = PrintJobModel.select().join(FilamentModel).where(PrintJobModel.databaseId == 109).get() print(singlePrintJob) print(singlePrintJob.fileName) singlePrintJob.printFila() # for fila in singlePrintJob.filaments: # print(fila) newFilaModel = FilamentModel() newFilaModel.material = "MeinMaterial" newFilaModel = FilamentModel.create(printJob = singlePrintJob) # singlePrintJob.filaments.append(newFilaModel) # singlePrintJob.save() pass
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 == databaseIdAsInt).execute() n = TemperatureModel.delete().where( TemperatureModel.printJob == databaseIdAsInt).execute() n = CostModel.delete().where( CostModel.printJob == databaseIdAsInt).execute() 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 # to rollback(). transaction.rollback() self._logger.exception( "Could not delete printJob from database:" + str(e)) self.sendErrorMessageToClient( "PJH-DatabaseManager", "Could not delete the printjob ('" + str(databaseId) + "') from the database. See OctoPrint.log for details!") pass
def deletePrintJob(self, databaseId): 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() PrintJobModel.delete_by_id(databaseId) except Exception as e: # Because this block of code is wrapped with "atomic", a # new transaction will begin automatically after the call # to rollback(). transaction.rollback() self._logger.exception("Could not delete printJob from database:" + str(e)) self.sendErrorMessageToClient("PJH-DatabaseManager", "Could not delete the printjob ('"+ str(databaseId) +"') from the database. See OctoPrint.log for details!") pass
def parseAndAssignFieldValue(self, fieldLabel, fieldName, fieldValue, printJobModel, errorCollection, lineNumber): if ("" == fieldValue or "-" == fieldValue or fieldValue == None): # check if mandatory return filemanentModel = None allFilemanentModel = printJobModel.getFilamentModels() if (allFilemanentModel != None and len(allFilemanentModel) > 0): filemanentModel = allFilemanentModel[0] else: filemanentModel = FilamentModel() printJobModel.addFilamentModel(filemanentModel) if (COLUMN_SPOOL_VENDOR == fieldLabel): filemanentModel.profileVendor = fieldValue pass elif (COLUMN_SPOOL_NAME == fieldLabel): filemanentModel.spoolName = fieldValue pass elif (COLUMN_MATERIAL == fieldLabel): filemanentModel.material = fieldValue pass elif (COLUMN_DIAMETER == fieldLabel): filemanentModel.diameter = float(fieldValue) pass elif (COLUMN_DENSITY == fieldLabel): filemanentModel.density = float(fieldValue) pass elif (COLUMN_USED_LENGTH == fieldLabel): filemanentModel.usedLength = float(fieldValue) pass elif (COLUMN_CALCULATED_LENGTH == fieldLabel): filemanentModel.calculatedLength = float(fieldValue) pass elif (COLUMN_USED_WEIGHT == fieldLabel): filemanentModel.usedWeight = float(fieldValue) pass elif (COLUMN_USED_FILAMENT_COSTS == fieldLabel): costUnit = fieldValue[-1] if (costUnit.isdigit()): filemanentModel.spoolCost = float(fieldValue) else: costValue = fieldValue[:-1] filemanentModel.spoolCost = float(costValue) filemanentModel.spoolCostUnit = costUnit pass pass
def _createAndAssignFilamentModel(self, printJob, payload): filemanentModel = FilamentModel() filePath = payload["path"] fileData = self._file_manager.get_metadata(payload["origin"], filePath) toolId = self._settings.get( [SettingsKeys.SETTINGS_KEY_DEFAULT_TOOL_ID]) # "tool0" filamentLength = None if "analysis" in fileData: if "filament" in fileData["analysis"]: if toolId in fileData["analysis"]["filament"]: filamentLength = fileData["analysis"]["filament"][toolId][ 'length'] else: self._logger.error( "MetaFile Filamentlength not found for toolId '" + str(toolId) + "'") else: self._logger.error("MetaFile of '" + str(filePath) + "' doesnt include 'filament'") else: self._logger.error("MetaFile of '" + str(filePath) + "' doesnt include 'analysis'") if (filamentLength == None): self._logger.error("Filamentlength not found for toolId '" + str(toolId) + "'") filemanentModel.calculatedLength = filamentLength if self._filamentManagerPluginImplementation != None and self._filamentManagerPluginImplementationState == "enabled": filemanentModel.usedLength = self._filamentManagerPluginImplementation.filamentOdometer.totalExtrusion[ 0] selectedSpools = self._filamentManagerPluginImplementation.filamentManager.get_all_selections( self._filamentManagerPluginImplementation.client_id) if selectedSpools != None and len(selectedSpools) > 0: spoolData = None defaultToolNumber = toolId[-1] for currentSpoolData in selectedSpools: toolNumber = str(currentSpoolData["tool"]) if (defaultToolNumber == toolNumber): spoolData = currentSpoolData["spool"] break if (spoolData == None): self._logger.error( "Filamentmanager Spooldata could not be found for toolId '" + toolId + "'") else: spoolName = spoolData["name"] spoolCost = spoolData["cost"] spoolCostUnit = self._filamentManagerPluginImplementation._settings.get( ["currencySymbol"]) spoolWeight = spoolData["weight"] profileData = spoolData["profile"] diameter = profileData["diameter"] material = profileData["material"] vendor = profileData["vendor"] density = profileData["density"] filemanentModel.spoolName = spoolName filemanentModel.spoolCost = spoolCost filemanentModel.spoolCostUnit = spoolCostUnit filemanentModel.spoolWeight = spoolWeight filemanentModel.profileVendor = vendor filemanentModel.diameter = diameter filemanentModel.density = density filemanentModel.material = material radius = diameter / 2.0 volume = filemanentModel.usedLength * math.pi * radius * radius / 1000.0 usedWeight = volume * density filemanentModel.usedWeight = usedWeight filemanentModel.usedCost = spoolCost / spoolWeight * usedWeight else: self._logger.info( "Empty filamentModel, because Filamentmanager not installed!") printJob.addFilamentModel(filemanentModel) pass
def _createAndAssignFilamentModel(self, printJob, payload): filemanentModel = FilamentModel() fileData = self._file_manager.get_metadata(payload["origin"], payload["path"]) filamentLength = None if "analysis" in fileData: if "filament" in fileData["analysis"]: if "tool0" in fileData["analysis"]["filament"]: filamentLength = fileData["analysis"]["filament"]["tool0"][ 'length'] filemanentModel.calculatedLength = filamentLength if self._filamentManagerPluginImplementation != None: filemanentModel.usedLength = self._filamentManagerPluginImplementation.filamentOdometer.totalExtrusion[ 0] selectedSpool = self._filamentManagerPluginImplementation.filamentManager.get_all_selections( self._filamentManagerPluginImplementation.client_id) if selectedSpool != None and len(selectedSpool) > 0: spoolData = selectedSpool[0]["spool"] spoolName = spoolData["name"] spoolCost = spoolData["cost"] spoolCostUnit = self._filamentManagerPluginImplementation._settings.get( ["currencySymbol"]) spoolWeight = spoolData["weight"] profileData = selectedSpool[0]["spool"]["profile"] diameter = profileData["diameter"] material = profileData["material"] vendor = profileData["vendor"] density = profileData["density"] filemanentModel.spoolName = spoolName filemanentModel.spoolCost = spoolCost filemanentModel.spoolCostUnit = spoolCostUnit filemanentModel.spoolWeight = spoolWeight filemanentModel.profileVendor = vendor filemanentModel.diameter = diameter filemanentModel.density = density filemanentModel.material = material radius = diameter / 2 volume = filemanentModel.usedLength * math.pi * radius * radius / 1000 usedWeight = volume * density filemanentModel.usedWeight = usedWeight filemanentModel.usedCost = spoolCost / spoolWeight * usedWeight printJob.addFilamentModel(filemanentModel) pass
def createWithDefaults(self): newPrintJobModel = PrintJobModel() totalFilament = FilamentModel() totalFilament.toolId = "total" newPrintJobModel.addFilamentModel(totalFilament) return newPrintJobModel
def parseAndAssignFieldValue(self, fieldLabel, fieldName, fieldValue, printJobModel, errorCollection, lineNumber): if ("" == fieldValue or "-" == fieldValue or fieldValue == None): # check if mandatory return # allFilemanentModel = printJobModel.getFilamentModels() filamanentModel = printJobModel.getFilamentModelByToolId("total") if (filamanentModel == None): filamanentModel = FilamentModel() filamanentModel.toolId = "total" printJobModel.addFilamentModel(filamanentModel) if (COLUMN_SPOOL_VENDOR == fieldLabel): filamanentModel.vendor = fieldValue pass elif (COLUMN_SPOOL_NAME == fieldLabel): filamanentModel.spoolName = fieldValue pass elif (COLUMN_MATERIAL == fieldLabel): filamanentModel.material = fieldValue pass elif (COLUMN_DIAMETER == fieldLabel): filamanentModel.diameter = float(fieldValue) pass elif (COLUMN_DENSITY == fieldLabel): filamanentModel.density = float(fieldValue) pass elif (COLUMN_USED_LENGTH == fieldLabel): filamanentModel.usedLength = float(fieldValue) pass elif (COLUMN_CALCULATED_LENGTH == fieldLabel): filamanentModel.calculatedLength = float(fieldValue) pass elif (COLUMN_USED_WEIGHT == fieldLabel): filamanentModel.usedWeight = float(fieldValue) pass pass
def parseAndAssignFieldValue(self, fieldLabel, fieldName, fieldValue, printJobModel, errorCollection, lineNumber): if ("" == fieldValue or "-" == fieldValue or fieldValue == None): # check if mandatory return # allFilemanentModel = printJobModel.getFilamentModels() filamanentModel = printJobModel.getFilamentModelByToolId("total") if (filamanentModel == None): filamanentModel = FilamentModel() filamanentModel.toolId = "total" printJobModel.addFilamentModel(filamanentModel) if (COLUMN_SPOOL_VENDOR == fieldLabel): filamanentModel.vendor = fieldValue pass elif (COLUMN_SPOOL_NAME == fieldLabel): filamanentModel.spoolName = fieldValue pass elif (COLUMN_MATERIAL == fieldLabel): filamanentModel.material = fieldValue pass elif (COLUMN_DIAMETER == fieldLabel): filamanentModel.diameter = float(fieldValue) pass elif (COLUMN_DENSITY == fieldLabel): filamanentModel.density = float(fieldValue) pass elif (COLUMN_USED_LENGTH == fieldLabel): filamanentModel.usedLength = float(fieldValue) pass elif (COLUMN_CALCULATED_LENGTH == fieldLabel): filamanentModel.calculatedLength = float(fieldValue) pass elif (COLUMN_USED_WEIGHT == fieldLabel): filamanentModel.usedWeight = float(fieldValue) pass elif (COLUMN_USED_FILAMENT_COSTS == fieldLabel): costUnit = fieldValue[-1] if (costUnit.isdigit()): # no unit present filamanentModel.usedCost = float(fieldValue) else: # Split between cost and unit costValue = "" for i in range(len(fieldValue)): c = fieldValue[i] if (c.isdigit() or c == "."): costValue += c else: costUnit = fieldValue[i:] break filamanentModel.usedCost = float(costValue) filamanentModel.spoolCostUnit = costUnit pass pass