def formatValue(self, printJob, fieldName): # only support for total model totalFilamentModel = printJob.getFilamentModelByToolId("total") if (totalFilamentModel == None): return "-" if (hasattr(totalFilamentModel, fieldName) == False): return "-" valueToFormat = getattr(totalFilamentModel, fieldName) # append unit to value if ("usedCost" == fieldName and valueToFormat != None and valueToFormat != ""): valueToFormat = StringUtils.formatFloatSave(StringUtils.FLOAT_DEFAULT_FORMAT, valueToFormat, "-") if (hasattr(totalFilamentModel, "spoolCostUnit") == True and totalFilamentModel.spoolCostUnit != None): if (valueToFormat != "-"): if (isinstance(totalFilamentModel.spoolCostUnit, str)): valueToFormat = valueToFormat + totalFilamentModel.spoolCostUnit else: valueToFormat = valueToFormat + totalFilamentModel.spoolCostUnit.encode("utf-8") if ("usedLength" == fieldName or "calculatedLength" == fieldName or "usedWeight" == fieldName): if (valueToFormat != None and valueToFormat != "" and valueToFormat != "-"): valueToFormat = StringUtils.formatFloatSave(StringUtils.FLOAT_DEFAULT_FORMAT, valueToFormat, "-") if valueToFormat is None or "" == valueToFormat: return "-" return valueToFormat
def transformPrintJobModel(job): jobAsDict = job.__data__ jobAsDict["printStartDateTimeFormatted"] = job.printStartDateTime.strftime( '%d.%m.%Y %H:%M') if (job.printEndDateTime): jobAsDict["printEndDateTimeFormatted"] = job.printEndDateTime.strftime( '%d.%m.%Y %H:%M') # # Calculate duration # duration = job.printEndDateTime - job.printStartDateTime duration = job.duration durationFormatted = StringUtils.secondsToText(duration) jobAsDict["durationFormatted"] = durationFormatted allFilaments = job.loadFilamentFromAssoziation() if allFilaments != None: filamentDict = allFilaments.__data__ filamentDict["usedWeight"] = StringUtils.formatFloatSave( "{:.02f}", filamentDict["usedWeight"], "") filamentDict["usedLengthFormatted"] = StringUtils.formatFloatSave( "{:.02f}", convertMM2M(filamentDict["usedLength"]), "") filamentDict[ "calculatedLengthFormatted"] = StringUtils.formatFloatSave( "{:.02f}", convertMM2M(filamentDict["calculatedLength"]), "") filamentDict["usedCost"] = StringUtils.formatFloatSave( "{:.02f}", filamentDict["usedCost"], "") filamentDict["spoolVendor"] = filamentDict["profileVendor"] jobAsDict['filamentModel'] = filamentDict allTemperatures = job.getTemperaturesFromAssoziation() if not allTemperatures == None and len(allTemperatures) > 0: allTempsAsList = list() for temp in allTemperatures: tempAsDict = dict() tempAsDict["sensorName"] = temp.sensorName tempAsDict["sensorValue"] = temp.sensorValue allTempsAsList.append(tempAsDict) jobAsDict["temperatureModels"] = allTempsAsList jobAsDict["snapshotFilename"] = CameraManager.buildSnapshotFilename( job.printStartDateTime) # remove timedelta object, because could not transfered to client del jobAsDict["printStartDateTime"] del jobAsDict["printEndDateTime"] del jobAsDict["created"] del jobAsDict["filamentModel"]["created"] return jobAsDict
def formatValue(self, printJob, fieldName): costModel = printJob.getCosts() if (costModel == None): return "-" if (hasattr(costModel, fieldName) == False): return "-" valueToFormat = getattr(costModel, fieldName) if ("filamentCost" == fieldName or "electricityCost" == fieldName or "printerCost" == fieldName or "otherCost" == fieldName): if (valueToFormat != None and valueToFormat != "" and valueToFormat != "-"): valueToFormat = StringUtils.formatFloatSave( StringUtils.FLOAT_DEFAULT_FORMAT, valueToFormat, "-") if ("otherCost" == fieldName): otherCostLabel = "" if (StringUtils.isNotEmpty(costModel.otherCostLabel)): otherCostLabel = costModel.otherCostLabel valueToFormat = otherCostLabel + ":" + valueToFormat if valueToFormat is None or "" == valueToFormat: return "-" return valueToFormat
def formatValue(self, printJob, fieldNames): if (hasattr(printJob, fieldNames[0]) == False): return "-" allFilamentModels = getattr(printJob, fieldNames[0]) if (allFilamentModels is None): allFilamentModels = printJob.filaments if (allFilamentModels is None or len(allFilamentModels) == 0): return "-" # only support for one model filamentModel = allFilamentModels[0] if (hasattr(filamentModel, fieldNames[1]) == False): return "-" valueToFormat = getattr(filamentModel, fieldNames[1]) # append unit to value if ("usedCost" == fieldNames[1] and valueToFormat != None and valueToFormat != ""): if (hasattr(filamentModel, "spoolCostUnit") == True and filamentModel.spoolCostUnit != None): valueToFormat = StringUtils.formatFloatSave( StringUtils.FLOAT_DEFAULT_FORMAT, valueToFormat, "-") if (valueToFormat != "-"): if (isinstance(filamentModel.spoolCostUnit, str)): valueToFormat = valueToFormat + filamentModel.spoolCostUnit else: valueToFormat = valueToFormat + filamentModel.spoolCostUnit.encode( "utf-8") if ("usedLength" == fieldNames[1] or "calculatedLength" == fieldNames[1] or "usedWeight" == fieldNames[1]): if (valueToFormat != None and valueToFormat != "" and valueToFormat != "-"): valueToFormat = StringUtils.formatFloatSave( StringUtils.FLOAT_DEFAULT_FORMAT, valueToFormat, "-") if valueToFormat is None or "" == valueToFormat: return "-" return valueToFormat
def formatValue(self, printJob, fieldName): # only support for total model totalFilamentModel = printJob.getFilamentModelByToolId("total") if (totalFilamentModel == None): return "-" if (hasattr(totalFilamentModel, fieldName) == False): return "-" valueToFormat = getattr(totalFilamentModel, fieldName) if ("usedLength" == fieldName or "calculatedLength" == fieldName or "usedWeight" == fieldName): if (valueToFormat != None and valueToFormat != "" and valueToFormat != "-"): valueToFormat = StringUtils.formatFloatSave( StringUtils.FLOAT_DEFAULT_FORMAT, valueToFormat, "-") if valueToFormat is None or "" == valueToFormat: return "-" return valueToFormat
def _buildWeightString(self, weight): weightString = StringUtils.formatFloatSave("{:.02f}", weight, "-") if (weightString != "-"): weightString = weightString + "g" return weightString
def _buildLengthString(self, length): lengthString = StringUtils.formatFloatSave("{:.02f}", TransformPrintJob2JSON.convertMM2M(length), "-") if (lengthString != "-"): lengthString = lengthString + "m" return lengthString
def transformPrintJobModel(job, fileManager): jobAsDict = job.__data__ jobAsDict["printStartDateTimeFormatted"] = job.printStartDateTime.strftime( '%d.%m.%Y %H:%M') if (job.printEndDateTime): jobAsDict["printEndDateTimeFormatted"] = job.printEndDateTime.strftime( '%d.%m.%Y %H:%M') # # Calculate duration # duration = job.printEndDateTime - job.printStartDateTime duration = job.duration durationFormatted = StringUtils.secondsToText(duration) jobAsDict["durationFormatted"] = durationFormatted allFilaments = job.getFilamentModels() if allFilaments != None: allFilamentDict = {} for filament in allFilaments: filamentDict = filament.__data__ filamentDict["usedWeight"] = StringUtils.formatFloatSave( "{:.02f}", filamentDict["usedWeight"], "") filamentDict["usedLengthFormatted"] = StringUtils.formatFloatSave( "{:.02f}", convertMM2M(filamentDict["usedLength"]), "") filamentDict[ "calculatedLengthFormatted"] = StringUtils.formatFloatSave( "{:.02f}", convertMM2M(filamentDict["calculatedLength"]), "") filamentDict["usedCost"] = StringUtils.formatFloatSave( "{:.02f}", filamentDict["usedCost"], "") # remove datetime, because not json serializable del filamentDict["created"] # put to overall model allFilamentDict[filamentDict["toolId"]] = filamentDict jobAsDict['filamentModels'] = allFilamentDict allTemperatures = job.getTemperatureModels() if not allTemperatures == None and len(allTemperatures) > 0: allTempsAsList = list() for temp in allTemperatures: tempAsDict = dict() tempAsDict["sensorName"] = temp.sensorName tempAsDict["sensorValue"] = temp.sensorValue allTempsAsList.append(tempAsDict) jobAsDict["temperatureModels"] = allTempsAsList jobAsDict["snapshotFilename"] = CameraManager.buildSnapshotFilename( job.printStartDateTime) # remove timedelta object, because could not transfered to client del jobAsDict["printStartDateTime"] del jobAsDict["printEndDateTime"] del jobAsDict["created"] # not the best approach to check this value here printJobReprintable = PrintJobUtils.isPrintJobReprintable( fileManager, job.fileOrigin, job.filePathName, job.fileName) jobAsDict["isRePrintable"] = printJobReprintable["isRePrintable"] jobAsDict["fullFileLocation"] = printJobReprintable["fullFileLocation"] return jobAsDict