Ejemplo n.º 1
0
def _get_temperature_data(preprocessor):
    if not printer.is_operational():
        abort(409, description="Printer is not operational")

    tempData = printer.get_current_temperatures()

    if "history" in request.values and request.values["history"] in valid_boolean_trues:
        history = printer.get_temperature_history()

        limit = 300
        if "limit" in request.values and str(request.values["limit"]).isnumeric():
            limit = int(request.values["limit"])

        limit = min(limit, len(history))

        tempData.update(
            {"history": list(map(lambda x: preprocessor(x), history[-limit:]))}
        )

    return preprocessor(tempData)
Ejemplo n.º 2
0
def _getTemperatureData(filter):
	if not printer.is_operational():
		return make_response("Printer is not operational", 409)

	tempData = printer.get_current_temperatures()

	if "history" in request.values.keys() and request.values["history"] in valid_boolean_trues:
		tempHistory = printer.get_temperature_history()

		limit = 300
		if "limit" in request.values.keys() and unicode(request.values["limit"]).isnumeric():
			limit = int(request.values["limit"])

		history = list(tempHistory)
		limit = min(limit, len(history))

		tempData.update({
			"history": map(lambda x: filter(x), history[-limit:])
		})

	return filter(tempData)
Ejemplo n.º 3
0
def _get_temperature_data(preprocessor):
    if not printer.is_operational():
        return make_response("Printer is not operational", 409)

    tempData = printer.get_current_temperatures()

    if "history" in list(request.values.keys(
    )) and request.values["history"] in valid_boolean_trues:
        tempHistory = printer.get_temperature_history()

        limit = 300
        if "limit" in list(request.values.keys()) and str(
                request.values["limit"]).isnumeric():
            limit = int(request.values["limit"])

        history = list(tempHistory)
        limit = min(limit, len(history))

        tempData.update(
            {"history": [preprocessor(x) for x in history[-limit:]]})

    return preprocessor(tempData)
Ejemplo n.º 4
0
    def on_event(self, event, payload):
        """
        Callback for general OctoPrint events.
        """
        sql = ""
        if event == octoprint.events.Events.CONNECTED:
            port = payload["port"]
            baudrate = payload["baudrate"]
            sql = "INSERT INTO connected (event_time, port, baudrate) VALUES ('%s', '%s', '%s')" % (datetime.datetime.today(), port, baudrate)

        if event == octoprint.events.Events.DISCONNECTED:
            sql = "INSERT INTO disconnected (event_time) VALUES ('%s')" % (datetime.datetime.today())

        if event == octoprint.events.Events.UPLOAD:
            file = os.path.basename(payload["file"])
            target = payload["target"]
            sql = "INSERT INTO upload (event_time, file, target) VALUES ('%s', '%s', '%s')" % (datetime.datetime.today(), file, target)

        if event == octoprint.events.Events.PRINT_STARTED:
            file = os.path.basename(payload["file"])
            origin = payload["origin"]
            bed_target = 0
            tool0_target = 0
            tool1_target = 0

            from octoprint.server import printer
            if printer is not None:
                temps = printer.get_current_temperatures()
                if "bed" in temps:
                    bed_target = temps["bed"]["target"]
                if "tool0" in temps:
                    tool0_target = temps["tool0"]["target"]
                if "tool1" in temps:
                    tool1_target = temps["tool1"]["target"]

            sql = "INSERT INTO print_started (event_time, file, origin, bed_target, tool0_target, tool1_target) VALUES ('%s', '%s', '%s', %f, %f, %f)" % (datetime.datetime.today(), file, origin, bed_target, tool0_target, tool1_target)

        if event == octoprint.events.Events.PRINT_DONE:
            file = os.path.basename(payload["file"])
            ptime = payload["time"]
            origin = payload["origin"]
            bed_actual = 0
            tool0_actual = 0
            tool1_actual = 0
            tool0_volume = 0
            tool1_volume = 0
            tool0_length = 0
            tool1_length = 0

            from octoprint.server import printer
            if printer is not None:
                temps = printer.get_current_temperatures()
                if "bed" in temps:
                    bed_actual = temps["bed"]["actual"]
                if "tool0" in temps:
                    tool0_actual = temps["tool0"]["actual"]
                if "tool1" in temps:
                    tool1_actual = temps["tool1"]["actual"]

            try:
                printData = self._file_manager.get_metadata(origin, file)
            except:
                printData = None

            if printData is not None:
                if "analysis" in printData:
                    if "filament" in printData["analysis"] and "tool0" in printData["analysis"]["filament"]:
                        tool0_volume = printData["analysis"]["filament"]["tool0"]["volume"]
                        tool0_length = printData["analysis"]["filament"]["tool0"]['length']
                    if "filament" in printData["analysis"] and "tool1" in printData["analysis"]["filament"]:
                        tool1_volume = printData["analysis"]["filament"]["tool1"]["volume"]
                        tool1_length = printData["analysis"]["filament"]["tool1"]['length']

            sql = "INSERT INTO print_done (event_time, file, ptime, origin, bed_actual, tool0_actual, tool1_actual, tool0_volume, tool1_volume, tool0_length, tool1_length) VALUES ('%s', '%s', '%s', '%s', %f, %f, %f, %f, %f, %f, %f)" % (datetime.datetime.today(), file, ptime, origin, bed_actual, tool0_actual, tool1_actual, tool0_volume, tool1_volume, tool0_length, tool1_length)

        if event == octoprint.events.Events.PRINT_FAILED:
            file = os.path.basename(payload["file"])
            origin = payload["origin"]
            sql = "INSERT INTO print_failed (event_time, file, origin) VALUES ('%s', '%s', '%s')" % (datetime.datetime.today(), file, origin)

        if event == octoprint.events.Events.PRINT_CANCELLED:
            file = os.path.basename(payload["file"])
            origin = payload["origin"]
            sql = "INSERT INTO print_cancelled (event_time, file, origin) VALUES ('%s', '%s', '%s')" % (datetime.datetime.today(), file, origin)

        if event == octoprint.events.Events.PRINT_PAUSED:
            file = os.path.basename(payload["file"])
            origin = payload["origin"]
            sql = "INSERT INTO print_paused (event_time, file, origin) VALUES ('%s', '%s', '%s')" % (datetime.datetime.today(), file, origin)

        if event == octoprint.events.Events.PRINT_RESUMED:
            file = os.path.basename(payload["file"])
            origin = payload["origin"]
            sql = "INSERT INTO print_resumed (event_time, file, origin) VALUES ('%s', '%s', '%s')" % (datetime.datetime.today(), file, origin)

        if event == octoprint.events.Events.ERROR:
            perror = payload["error"]
            sql = "INSERT INTO error (event_time, perror) VALUES ('%s', '%s')" % (datetime.datetime.today(), perror)

        if sql != '':
            self.statDB.execute(sql)
            self.refreshFull()
            self.refreshHour()
            self.refreshPrint()
            self.refreshWatts()
Ejemplo n.º 5
0
    def on_event(self, event, payload):
        """
        Callback for general OctoPrint events.
        """
        sql = ""
        if event == octoprint.events.Events.CONNECTED:
            port = payload["port"]
            baudrate = payload["baudrate"]
            sql = "INSERT INTO connected (event_time, port, baudrate) VALUES ('%s', '%s', '%s')" % (
                datetime.datetime.today(), port, baudrate)

        if event == octoprint.events.Events.DISCONNECTED:
            sql = "INSERT INTO disconnected (event_time) VALUES ('%s')" % (
                datetime.datetime.today())

        if event == octoprint.events.Events.UPLOAD:
            file = os.path.basename(payload["file"])
            target = payload["target"]
            sql = "INSERT INTO upload (event_time, file, target) VALUES ('%s', '%s', '%s')" % (
                datetime.datetime.today(), file, target)

        if event == octoprint.events.Events.PRINT_STARTED:
            file = os.path.basename(payload["file"])
            origin = payload["origin"]
            bed_target = 0
            tool0_target = 0
            tool1_target = 0

            from octoprint.server import printer
            if printer is not None:
                temps = printer.get_current_temperatures()
                if "bed" in temps:
                    bed_target = temps["bed"]["target"]
                if "tool0" in temps:
                    tool0_target = temps["tool0"]["target"]
                if "tool1" in temps:
                    tool1_target = temps["tool1"]["target"]

            sql = "INSERT INTO print_started (event_time, file, origin, bed_target, tool0_target, tool1_target) VALUES ('%s', '%s', '%s', %f, %f, %f)" % (
                datetime.datetime.today(), file, origin, bed_target,
                tool0_target, tool1_target)

        if event == octoprint.events.Events.PRINT_DONE:
            file = os.path.basename(payload["file"])
            ptime = payload["time"]
            origin = payload["origin"]
            bed_actual = 0
            tool0_actual = 0
            tool1_actual = 0
            tool0_volume = 0
            tool1_volume = 0
            tool0_length = 0
            tool1_length = 0

            from octoprint.server import printer
            if printer is not None:
                temps = printer.get_current_temperatures()
                if "bed" in temps:
                    bed_actual = temps["bed"]["actual"]
                if "tool0" in temps:
                    tool0_actual = temps["tool0"]["actual"]
                if "tool1" in temps:
                    tool1_actual = temps["tool1"]["actual"]

            try:
                printData = self._file_manager.get_metadata(origin, file)
            except:
                printData = None

            if printData is not None:
                if "analysis" in printData:
                    if "filament" in printData[
                            "analysis"] and "tool0" in printData["analysis"][
                                "filament"]:
                        tool0_volume = printData["analysis"]["filament"][
                            "tool0"]["volume"]
                        tool0_length = printData["analysis"]["filament"][
                            "tool0"]['length']
                    if "filament" in printData[
                            "analysis"] and "tool1" in printData["analysis"][
                                "filament"]:
                        tool1_volume = printData["analysis"]["filament"][
                            "tool1"]["volume"]
                        tool1_length = printData["analysis"]["filament"][
                            "tool1"]['length']

            sql = "INSERT INTO print_done (event_time, file, ptime, origin, bed_actual, tool0_actual, tool1_actual, tool0_volume, tool1_volume, tool0_length, tool1_length) VALUES ('%s', '%s', '%s', '%s', %f, %f, %f, %f, %f, %f, %f)" % (
                datetime.datetime.today(), file, ptime, origin, bed_actual,
                tool0_actual, tool1_actual, tool0_volume, tool1_volume,
                tool0_length, tool1_length)

        if event == octoprint.events.Events.PRINT_FAILED:
            file = os.path.basename(payload["file"])
            origin = payload["origin"]
            sql = "INSERT INTO print_failed (event_time, file, origin) VALUES ('%s', '%s', '%s')" % (
                datetime.datetime.today(), file, origin)

        if event == octoprint.events.Events.PRINT_CANCELLED:
            file = os.path.basename(payload["file"])
            origin = payload["origin"]
            sql = "INSERT INTO print_cancelled (event_time, file, origin) VALUES ('%s', '%s', '%s')" % (
                datetime.datetime.today(), file, origin)

        if event == octoprint.events.Events.PRINT_PAUSED:
            file = os.path.basename(payload["file"])
            origin = payload["origin"]
            sql = "INSERT INTO print_paused (event_time, file, origin) VALUES ('%s', '%s', '%s')" % (
                datetime.datetime.today(), file, origin)

        if event == octoprint.events.Events.PRINT_RESUMED:
            file = os.path.basename(payload["file"])
            origin = payload["origin"]
            sql = "INSERT INTO print_resumed (event_time, file, origin) VALUES ('%s', '%s', '%s')" % (
                datetime.datetime.today(), file, origin)

        if event == octoprint.events.Events.ERROR:
            perror = payload["error"]
            sql = "INSERT INTO error (event_time, perror) VALUES ('%s', '%s')" % (
                datetime.datetime.today(), perror)

        if sql != '':
            self.statDB.execute(sql)
            self.refreshFull()
            self.refreshHour()
            self.refreshPrint()
            self.refreshWatts()