def addFilamentModel(self, filamentModel): # check preconditions if (filamentModel == None): return if (StringUtils.isEmpty(filamentModel.toolId)): raise AttributeError( "You can only add a FilamentModel with an toolId") filamentModel.printJob = self if (self.filamentModelsByToolId == None or len(self.filamentModelsByToolId) == 0): self._loadFilamentModels() self.filamentModelsByToolId[filamentModel.toolId] = filamentModel pass
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 }