Beispiel #1
0
def transformPrintJobModel(job, fileManager, deleteDateTimeFromDict=True):
    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

    fileSize = job.fileSize
    fileSizeFormatted = StringUtils.get_formatted_size(fileSize)
    jobAsDict["fileSizeFormatted"] = fileSizeFormatted
    # -- filament
    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
            if (deleteDateTimeFromDict):
                del filamentDict["created"]
            # put to overall model
            allFilamentDict[filamentDict["toolId"]] = filamentDict

        jobAsDict['filamentModels'] = allFilamentDict
    # -- temperatures
    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
    # -- costs
    isCostsAvailable = False
    costs = job.getCosts()
    if (costs != None):
        costsAsDict = costs.__data__
        del costsAsDict["created"]
        jobAsDict["costs"] = costsAsDict
        isCostsAvailable = True
    jobAsDict["isCostsAvailable"] = isCostsAvailable
    # -- images
    jobAsDict["snapshotFilename"] = CameraManager.buildSnapshotFilename(
        job.printStartDateTime)
    # remove timedelta object, because could not transfered to client
    if (deleteDateTimeFromDict):
        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
	def calculatePrintJobsStatisticByQuery(self, tableQuery):

		duration = 0
		length = 0.0
		weight = 0.0
		fileSize = 0
		statusDict = dict()
		materialDict = dict()
		spoolDict = dict()
		firstDate = None
		lastDate = None
		newTableQuery = tableQuery.copy()
		newTableQuery["sortColumn"] = "printStartDateTime"
		newTableQuery["sortOrder"] = "asc"
		allJobModels = self.loadPrintJobsByQuery(newTableQuery)

		for job in allJobModels:
			if (firstDate == None):
				firstDate = job.printStartDateTime
			lastDate = job.printEndDateTime
			fileSize = fileSize + job.fileSize
			duration = duration + job.duration
			statusResult = job.printStatusResult

			if (statusResult in statusDict):
				currentCount = statusDict[statusResult]
				currentCount = currentCount + 1
				statusDict[statusResult] = currentCount
			else:
				statusDict[statusResult] = 1

			job.loadFilamentFromAssoziation()
			allFilaments = job.allFilaments
			if allFilaments != None:
				for filla in allFilaments:
					if (StringUtils.isEmpty(filla.usedLength) == False):
						length = length + filla.usedLength
					if (StringUtils.isEmpty(filla.usedWeight) == False):
						weight = weight + filla.usedWeight

					if (StringUtils.isEmpty(filla.spoolName) == False):
						# spoolsSet.add(filla.spoolName)
						if (filla.spoolName in spoolDict):
							currentCount = spoolDict[filla.spoolName]
							currentCount = currentCount + 1
							spoolDict[filla.spoolName] = currentCount
						else:
							spoolDict[filla.spoolName] = 1

					if (StringUtils.isEmpty(filla.material) == False):
						# materialsSet.add(filla.material)
						if (filla.material in materialDict):
							currentCount = materialDict[filla.material]
							currentCount = currentCount + 1
							materialDict[filla.material] = currentCount
						else:
							materialDict[filla.material] = 1



		# do formatting
		queryString = self._buildQueryString(tableQuery)
		fromToString = firstDate.strftime('%d.%m.%Y %H:%M') + " - " + lastDate.strftime('%d.%m.%Y %H:%M')
		durationString = StringUtils.secondsToText(duration)
		lengthString = self._buildLengthString(length)
		weightString = self._buildWeightString(weight)
		statusString = self._buildStatusString(statusDict)
		materialString = self._buildDictlString(materialDict)
		spoolString = self._buildDictlString(spoolDict)
		fileSizeString = StringUtils.get_formatted_size(fileSize)
		return {
			"query": queryString,
			"fromToDate": fromToString,
			"duration": durationString,
			"usedLength": lengthString,
			"usedWeight": weightString,
			"fileSize": fileSizeString,
			"printStatus": statusString,
		    "material": materialString,
			"spools": spoolString
		}
    def calculatePrintJobsStatisticByQuery(self, tableQuery):

        printJobCount = 0
        duration = 0
        length = 0.0
        weight = 0.0
        fileSize = 0
        statusDict = dict()
        materialDict = dict()
        spoolDict = dict()
        firstDate = None
        lastDate = None
        newTableQuery = tableQuery.copy()
        newTableQuery["sortColumn"] = "printStartDateTime"
        newTableQuery["sortOrder"] = "asc"
        newTableQuery["from"] = 0
        newTableQuery["to"] = 999999
        allJobModels = self.loadPrintJobsByQuery(newTableQuery)

        for job in allJobModels:
            printJobCount = printJobCount + 1
            if (firstDate == None):
                firstDate = job.printStartDateTime
            if (job.printEndDateTime != None):
                lastDate = job.printEndDateTime
            tempJobFileSize = job.fileSize
            if (tempJobFileSize == None):
                tempJobFileSize = 0
            fileSize = fileSize + tempJobFileSize
            duration = duration + job.duration
            statusResult = job.printStatusResult

            if (statusResult in statusDict):
                currentCount = statusDict[statusResult]
                currentCount = currentCount + 1
                statusDict[statusResult] = currentCount
            else:
                statusDict[statusResult] = 1

            allFilaments = job.getFilamentModels()
            if allFilaments != None:
                for filla in allFilaments:
                    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):
                        weight = weight + filla.usedWeight

                    if (StringUtils.isEmpty(filla.spoolName) == False):
                        # spoolsSet.add(filla.spoolName)
                        if (filla.spoolName in spoolDict):
                            currentCount = spoolDict[filla.spoolName]
                            currentCount = currentCount + 1
                            spoolDict[filla.spoolName] = currentCount
                        else:
                            spoolDict[filla.spoolName] = 1

                    if (StringUtils.isEmpty(filla.material) == False):
                        # materialsSet.add(filla.material)
                        if (filla.material in materialDict):
                            currentCount = materialDict[filla.material]
                            currentCount = currentCount + 1
                            materialDict[filla.material] = currentCount
                        else:
                            materialDict[filla.material] = 1

        # do formatting
        queryString = self._buildQueryString(tableQuery)
        lastDateString = ""
        if (lastDate != None):
            lastDateString = lastDate.strftime('%d.%m.%Y %H:%M')
        fromToString = firstDate.strftime(
            '%d.%m.%Y %H:%M') + " - " + lastDateString
        durationString = StringUtils.secondsToText(duration)
        lengthString = self._buildLengthString(length)
        weightString = self._buildWeightString(weight)
        statusString = self._buildStatusString(statusDict)
        materialString = self._buildDictlString(materialDict)
        spoolString = self._buildDictlString(spoolDict)
        fileSizeString = StringUtils.get_formatted_size(fileSize)
        return {
            "printJobCount": printJobCount,
            "query": queryString,
            "fromToDate": fromToString,
            "duration": durationString,
            "usedLength": lengthString,
            "usedWeight": weightString,
            "fileSize": fileSizeString,
            "printStatus": statusString,
            "material": materialString,
            "spools": spoolString
        }