def _createSamplePrintModel(self):
		p1 = PrintJobModel()
		p1.userName = "******"
		p1.printStatusResult = "success"
		p1.printStartDateTime = datetime.now()
		p1.printEndDateTime = datetime.now() + timedelta(minutes=123)
		p1.duration = (p1.printEndDateTime - p1.printStartDateTime).total_seconds()
		p1.fileName = "OllisBenchy.gcode"
		p1.filePathName = "/_archive/OllisBenchy.gcode"
		p1.fileSize = 123456
		p1.printedLayers = "45 / 45"
		p1.noteText = "Geiles Teil!!"

		t1 = TemperatureModel()
		t1.sensorName = "bed"
		t1.sensorValue = "53"
		p1.addTemperatureModel(t1)
		t2 = TemperatureModel()
		t2.sensorName = "tool0"
		t2.sensorValue = "210"
		p1.addTemperatureModel(t2)

		f1 = FilamentModel()
		f1.spoolName = "My best spool"
		f1.material = "PLA"
		f1.diameter = 1.75
		f1.density = 1.24
		f1.usedLength = 1345.0
		f1.calculatedLength = 1456.0
		f1.usedWeight = 321.0
		f1.usedCost = 1.34
		f1.spoolCostUnit = "€"
		p1.addFilamentModel(f1)

		return p1
Exemplo n.º 2
0
    def _createSamplePrintModel(self, fileName="OllisBenchy.gcode"):
        p1 = PrintJobModel()
        p1.userName = "******"
        p1.printStatusResult = "success"
        p1.printStartDateTime = datetime.now()
        p1.printEndDateTime = datetime.now() + timedelta(minutes=123)
        p1.duration = (p1.printEndDateTime -
                       p1.printStartDateTime).total_seconds()
        p1.fileName = fileName
        p1.filePathName = "/_archive/OllisBenchy.gcode"
        p1.fileSize = 123456
        p1.printedLayers = "45 / 45"
        p1.printedHeight = "0.4 / 23.8"
        p1.noteText = "Geiles Teil!!"

        t1 = TemperatureModel()
        t1.sensorName = "bed"
        t1.sensorValue = "53"
        p1.addTemperatureModel(t1)
        t2 = TemperatureModel()
        t2.sensorName = "tool0"
        t2.sensorValue = "210"
        p1.addTemperatureModel(t2)

        f1 = FilamentModel()
        f1.toolId = "tool0"
        f1.vendor = "Ollis-Factory"
        f1.spoolName = "My best spool"
        f1.material = "PLA"
        f1.diameter = 1.75
        f1.density = 1.24
        f1.usedLength = 1345.0
        f1.calculatedLength = 1456.0
        f1.usedWeight = 321.0
        f1.usedCost = 1.34
        p1.addFilamentModel(f1)

        f2 = FilamentModel()
        f2.toolId = "total"
        f2.vendor = "Ollis-Factory"
        f2.spoolName = "My best spool"
        f2.material = "PLA"
        f2.diameter = 1.75
        f2.density = 1.24
        f2.usedLength = 1345.0
        f2.calculatedLength = 1456.0
        f2.usedWeight = 321.0
        f2.usedCost = 1.34
        p1.addFilamentModel(f2)

        c1 = CostModel()
        c1.filamentCost = 3.123
        c1.electricityCost = 0.89
        c1.printerCost = 1.234
        c1.otherCostLabel = "Delivery"
        c1.otherCost = 22.67
        c1.withDefaultSpoolValues = True
        p1.setCosts(c1)

        return p1
Exemplo n.º 3
0
    def put_printjob(self, databaseId):
        jsonData = request.json

        printJobModel = None
        oldStartDateTimeIfChanged = None
        newStartDateTime = None
        if (databaseId == 'null'):
            printJobModel = PrintJobModel()

            filemanentModel = FilamentModel()
            filemanentModel.toolId = "total"
            printJobModel.addFilamentModel(filemanentModel)

            tempModel = TemperatureModel()
            tempModel.sensorName = "bed"
            printJobModel.addTemperatureModel(tempModel)

            tempModel = TemperatureModel()
            tempModel.sensorName = self._settings.get(
                [SettingsKeys.SETTINGS_KEY_DEFAULT_TOOL_ID])
            printJobModel.addTemperatureModel(tempModel)

        else:
            printJobModel = self._databaseManager.loadPrintJob(databaseId)
            # check if the startDate is changed, if true -> change snapshot image as well
            currentStartDateTime = printJobModel.printStartDateTime
            newStartDateTime = StringUtils.transformToDateTimeOrNone(
                self._getValueFromJSONOrNone("printStartDateTimeFormatted",
                                             jsonData))
            changed = currentStartDateTime != newStartDateTime
            if (changed):
                oldStartDateTimeIfChanged = currentStartDateTime
                try:
                    self._cameraManager.renameSnapshotFilename(
                        oldStartDateTimeIfChanged, newStartDateTime)
                except (Exception) as error:
                    self._logger.error(error)
                    message = errorMessage = str(error)
                    self._sendDataToClient(
                        dict(
                            action="errorPopUp",
                            title=
                            "could not rename snapshot image to new startdatetime",
                            message=message))

        def imageRollbackHandler():
            if (oldStartDateTimeIfChanged != None):
                # do rollback on snapshotimage filename
                try:
                    self._cameraManager.renameSnapshotFilename(
                        newStartDateTime, oldStartDateTimeIfChanged)
                except (Exception) as error:
                    self._logger.error(error)
                    message = errorMessage = str(error)
                    self._sendDataToClient(
                        dict(
                            action="errorPopUp",
                            title=
                            "could not rename snapshot image to new startdatetime",
                            message=message))
                pass
            pass

        # transfer values from ui to the model
        self._updatePrintJobFromJson(printJobModel, jsonData)

        if (databaseId == 'null'):
            self._databaseManager.insertPrintJob(printJobModel)
        else:

            self._databaseManager.updatePrintJob(printJobModel,
                                                 imageRollbackHandler)

        return flask.jsonify()
    def _test_createPrintJob(self):
        self.databaseManager.deletePrintJob(1011)

        newPrintJob = self.printJobService.createWithDefaults()
        # check
        # - databaseId
        # - filament total
        self.assertEqual(newPrintJob.databaseId, None,
                         "Model already persistence!")
        totalFilament = newPrintJob.getFilamentModelByToolId("total")
        self.assertEqual(totalFilament.toolId, "total")

        # create data
        newPrintJob.userName = "******"
        newPrintJob.fileOrigin = "local"
        newPrintJob.fileName = "OllisBenchy.gcode"
        newPrintJob.filePathName = "archive/OllisBenchy.gcode"
        newPrintJob.fileSize = 1234
        newPrintJob.printStartDateTime = StringUtils.transformToDateTimeOrNone(
            "12.03.2013 14:45")
        newPrintJob.printEndDateTime = StringUtils.transformToDateTimeOrNone(
            "12.03.2013 16:45")
        newPrintJob.duration = DateTimeUtils.calcDurationInSeconds(
            newPrintJob.printEndDateTime, newPrintJob.printStartDateTime)
        newPrintJob.printStatusResult = "failed"
        newPrintJob.noteText = "Hello World"
        newPrintJob.noteDeltaFormat = "Something"
        newPrintJob.noteHtml = "<p>Hello World</p>"
        newPrintJob.printedLayers = "10 / 133"
        newPrintJob.printedHeight = "1.3 / 143.3"
        newPrintJob.slicerSettingsAsText = "dummy slicer settings"

        newFilamentModel = FilamentModel()
        newFilamentModel.toolId = "tool0"
        newPrintJob.addFilamentModel(newFilamentModel)

        newTemperatureModel = TemperatureModel()
        newTemperatureModel.sensorName = "tool0"
        newTemperatureModel.sensorValue = "123C"
        newPrintJob.addTemperatureModel(newTemperatureModel)

        # store
        self.printJobService.savePrintJob(newPrintJob)
        databaseId = newPrintJob.databaseId
        self.rollBackPrintJobs.append(databaseId)

        # load again and check if everything is in
        loadedPrintJobModel = self.printJobService.loadPrintJob(databaseId)
        self.assertEqual(loadedPrintJobModel.databaseId,
                         newPrintJob.databaseId)
        self.assertEqual(loadedPrintJobModel.userName, newPrintJob.userName)
        self.assertEqual(loadedPrintJobModel.fileOrigin,
                         newPrintJob.fileOrigin)
        self.assertEqual(loadedPrintJobModel.fileName, newPrintJob.fileName)
        self.assertEqual(loadedPrintJobModel.filePathName,
                         newPrintJob.filePathName)
        self.assertEqual(loadedPrintJobModel.fileSize, newPrintJob.fileSize)
        self.assertEqual(loadedPrintJobModel.printStartDateTime,
                         newPrintJob.printStartDateTime)
        self.assertEqual(loadedPrintJobModel.printEndDateTime,
                         newPrintJob.printEndDateTime)
        self.assertEqual(loadedPrintJobModel.duration, newPrintJob.duration)
        self.assertEqual(loadedPrintJobModel.printStatusResult,
                         newPrintJob.printStatusResult)
        self.assertEqual(loadedPrintJobModel.noteText, newPrintJob.noteText)
        self.assertEqual(loadedPrintJobModel.noteDeltaFormat,
                         newPrintJob.noteDeltaFormat)
        self.assertEqual(loadedPrintJobModel.noteHtml, newPrintJob.noteHtml)
        self.assertEqual(loadedPrintJobModel.printedLayers,
                         newPrintJob.printedLayers)
        self.assertEqual(loadedPrintJobModel.slicerSettingsAsText,
                         newPrintJob.slicerSettingsAsText)
        # check-assos
        # - allFilaments
        allFilamentModels = loadedPrintJobModel.getFilamentModels()
        self.assertEqual(len(allFilamentModels), 2,
                         "'total' and 'tool0' filamentModel expected")
        # - allTemperatures
        allTemperatureModels = loadedPrintJobModel.getTemperatureModels()
        self.assertEqual(len(allTemperatureModels), 1,
                         "temperatureModels expected")

        #  - allTemperatures

        # do test-cleanup
        for printJobDatabaseId in self.rollBackPrintJobs:
            self.databaseManager.deletePrintJob(printJobDatabaseId)