def test_csvExportPrinjob(self):

		# selectedDatabaseIds = flask.request.values["databaseIds"]
		# allJobsModels = self._databaseManager.loadSelectedPrintJobs(selectedDatabaseIds)
		allJobsModels = self.databaseManager.loadAllPrintJobs()

		for csvLine in CSVExportImporter.transform2CSV(allJobsModels):
			print(csvLine)
示例#2
0
    def exportPrintJobHistoryData(self, exportType):

        if exportType == "CSV":
            allJobsModels = self._databaseManager.loadAllPrintJobs()

            return Response(
                CSVExportImporter.transform2CSV(allJobsModels),
                mimetype='text/csv',
                headers={
                    'Content-Disposition':
                    'attachment; filename=OctoprintPrintJobHistory.csv'
                })  # TODO add timestamp

        else:
            print("BOOOMM not supported type")
        pass
	def get_sampleCSV(self):

		allJobsModels = list()

		printModel = self._createSamplePrintModel()
		allJobsModels.append(printModel)

		# allJobsModels = self._databaseManager.loadAllPrintJobs()
		# allJobsDict = TransformPrintJob2JSON.transformAllPrintJobModels(allJobsModels)
		# csvContent = Transform2CSV.transform2CSV(allJobsDict)
		# csvContent = CSVExportImporter.transform2CSV(allJobsModels)



		return Response(CSVExportImporter.transform2CSV(allJobsModels),
						mimetype='text/csv',
						headers={'Content-Disposition': 'attachment; filename=PrintJobHistory-SAMPLE.csv'})
	def exportPrintJobHistoryData(self, exportType):

		if exportType == "CSV":
			if "databaseIds" in flask.request.values:
				selectedDatabaseIds = flask.request.values["databaseIds"]
				allJobsModels = self._databaseManager.loadSelectedPrintJobs(selectedDatabaseIds)
			else:
				allJobsModels = self._databaseManager.loadAllPrintJobs()

			return Response(CSVExportImporter.transform2CSV(allJobsModels),
							mimetype='text/csv',
							headers={'Content-Disposition': 'attachment; filename=OctoprintPrintJobHistory.csv'}) # TODO add timestamp

		else:
			if (exportType == "legacyPrintHistory"):
				return self.exportPrintHistoryData()

			print("BOOOMM not supported type")
		pass
	def exportPrintJobHistoryData(self, exportType):

		if exportType == "CSV":
			allJobsModels = self._databaseManager.loadAllPrintJobs()
			# allJobsDict = self._convertPrintJobHistoryEntitiesToDict(allJobsEntities)
			# allJobsDict = TransformPrintJob2JSON.transformAllPrintJobModels(allJobsModels)

			# csvContent = Transform2CSV.transform2CSV(allJobsDict)
			# csvContent = CSVExportImporter.transform2CSV(allJobsDict)
			# response = flask.make_response(csvContent)

			# response.headers["Content-type"] = "text/csv"
			# response.headers["Content-Disposition"] = "attachment; filename=OctoprintPrintJobHistory.csv" # TODO add timestamp
			# return response

			return Response(CSVExportImporter.transform2CSV(allJobsModels),
							mimetype='text/csv',
							headers={'Content-Disposition': 'attachment; filename=OctoprintPrintJobHistory.csv'}) # TODO add timestamp

		else:
			print("BOOOMM not supported type")

		pass
	def get_sampleCSV(self):

		allJobsModels = list()

		printModel = self._createSamplePrintModel()
		allJobsModels.append(printModel)

		# allJobsModels = self._databaseManager.loadAllPrintJobs()
		# allJobsDict = TransformPrintJob2JSON.transformAllPrintJobModels(allJobsModels)
		# csvContent = Transform2CSV.transform2CSV(allJobsDict)
		# csvContent = CSVExportImporter.transform2CSV(allJobsModels)

		#filename = "PrintJobHistory-SAMPLE.csv"

		# response = flask.make_response(CSVExportImporter.transform2CSV(allJobsModels))
		# response.headers["Content-type"] = "text/csv"
		# response.headers[
		# 	"Content-Disposition"] = "attachment; filename=PrintJobHistory-SAMPLE.csv"  # TODO add timestamp
		#
		# return response

		return Response(CSVExportImporter.transform2CSV(allJobsModels),
						mimetype='text/csv',
						headers={'Content-Disposition': 'attachment; filename=PrintJobHistory-SAMPLE.csv'})
    def exportPrintHistoryData(self):

        allJobsModels = list()

        history_db_path = self.get_plugin_data_folder(
        ) + "/../printhistory/history.db"

        conn = sqlite3.connect(history_db_path)
        cur = conn.cursor()
        cur.execute("SELECT * FROM print_history ORDER BY timestamp")

        for row in cur.fetchall():
            printJob = PrintJobModel()
            filamentModel = FilamentModel()
            isFilamentValuesPresent = False
            for i, value in enumerate(row):
                # id, fileName, note, spool, filamentVolume (float), filamentLength (float), printTime (float), success (int), timestamp (float), user (unicode), parameters (json-string)
                fieldName = cur.description[i][0]
                if (fieldName == "fileName"):
                    printJob.fileName = value
                    continue
                if (fieldName == "note"):
                    printJob.noteText = value
                    continue
                if (fieldName == "spool"):
                    isFilamentValuesPresent = True
                    filamentModel.spoolName = value
                    continue
                if (fieldName == "filamentVolume"):
                    # isFilamentValuesPresent = True
                    # filamentModel.spoolName = value
                    continue  # just ignore
                if (fieldName == "filamentLength"):
                    isFilamentValuesPresent = True
                    filamentModel.usedLength = value
                    filamentModel.calculatedLength = value
                    continue
                if (fieldName == "printTime"):
                    printJob.duration = int(value)
                    continue
                if (fieldName == "success"):
                    if (value == 1):
                        printJob.printStatusResult = "success"
                    else:
                        printJob.printStatusResult = "failed"
                    continue
                if (fieldName == "timestamp"):
                    startPrintDataTime = datetime.fromtimestamp(value)
                    printJob.printStartDateTime = startPrintDataTime
                    continue
                if (fieldName == "user"):
                    printJob.userName = value
                    continue

                if (fieldName == "parameters"):
                    continue  # just ignore
                pass

            if (isFilamentValuesPresent == True):
                printJob.addFilamentModel(filamentModel)

            # Calculate endtime
            endDateTime = printJob.printStartDateTime + timedelta(
                seconds=printJob.duration)
            printJob.printEndDateTime = endDateTime

            allJobsModels.append(printJob)
        # history_dict = [dict(
        # 						(cur.description[i][0], value) \
        # 					 for i, value in enumerate(row)
        # 					) for row in cur.fetchall()]

        conn.close()

        return Response(CSVExportImporter.transform2CSV(allJobsModels),
                        mimetype='text/csv',
                        headers={
                            'Content-Disposition':
                            'attachment; filename=PrintHistory.csv'
                        })