def _createAndAssignFilamentModel(self, printJob, payload):
        filemanentModel = FilamentModel()

        fileData = self._file_manager.get_metadata(payload["origin"],
                                                   payload["path"])

        filamentLength = None
        if "analysis" in fileData:
            if "filament" in fileData["analysis"]:
                if "tool0" in fileData["analysis"]["filament"]:
                    filamentLength = fileData["analysis"]["filament"]["tool0"][
                        'length']

        filemanentModel.calculatedLength = filamentLength

        if self._filamentManagerPluginImplementation != None:

            filemanentModel.usedLength = self._filamentManagerPluginImplementation.filamentOdometer.totalExtrusion[
                0]
            selectedSpool = self._filamentManagerPluginImplementation.filamentManager.get_all_selections(
                self._filamentManagerPluginImplementation.client_id)
            if selectedSpool != None and len(selectedSpool) > 0:
                spoolData = selectedSpool[0]["spool"]
                spoolName = spoolData["name"]
                spoolCost = spoolData["cost"]
                spoolCostUnit = self._filamentManagerPluginImplementation._settings.get(
                    ["currencySymbol"])
                spoolWeight = spoolData["weight"]

                profileData = selectedSpool[0]["spool"]["profile"]
                diameter = profileData["diameter"]
                material = profileData["material"]
                vendor = profileData["vendor"]
                density = profileData["density"]

                filemanentModel.spoolName = spoolName
                filemanentModel.spoolCost = spoolCost
                filemanentModel.spoolCostUnit = spoolCostUnit
                filemanentModel.spoolWeight = spoolWeight

                filemanentModel.profileVendor = vendor
                filemanentModel.diameter = diameter
                filemanentModel.density = density
                filemanentModel.material = material

                radius = diameter / 2
                volume = filemanentModel.usedLength * math.pi * radius * radius / 1000
                usedWeight = volume * density

                filemanentModel.usedWeight = usedWeight
                filemanentModel.usedCost = spoolCost / spoolWeight * usedWeight

        printJob.addFilamentModel(filemanentModel)
        pass
    def _createAndAssignFilamentModel(self, printJob, payload):
        filemanentModel = FilamentModel()
        filePath = payload["path"]
        fileData = self._file_manager.get_metadata(payload["origin"], filePath)

        toolId = self._settings.get(
            [SettingsKeys.SETTINGS_KEY_DEFAULT_TOOL_ID])  # "tool0"
        filamentLength = None
        if "analysis" in fileData:
            if "filament" in fileData["analysis"]:
                if toolId in fileData["analysis"]["filament"]:
                    filamentLength = fileData["analysis"]["filament"][toolId][
                        'length']
                else:
                    self._logger.error(
                        "MetaFile Filamentlength not found for toolId '" +
                        str(toolId) + "'")
            else:
                self._logger.error("MetaFile of '" + str(filePath) +
                                   "' doesnt include 'filament'")
        else:
            self._logger.error("MetaFile of '" + str(filePath) +
                               "' doesnt include 'analysis'")

        if (filamentLength == None):
            self._logger.error("Filamentlength not found for toolId '" +
                               str(toolId) + "'")
        filemanentModel.calculatedLength = filamentLength

        if self._filamentManagerPluginImplementation != None and self._filamentManagerPluginImplementationState == "enabled":

            filemanentModel.usedLength = self._filamentManagerPluginImplementation.filamentOdometer.totalExtrusion[
                0]
            selectedSpools = self._filamentManagerPluginImplementation.filamentManager.get_all_selections(
                self._filamentManagerPluginImplementation.client_id)
            if selectedSpools != None and len(selectedSpools) > 0:
                spoolData = None
                defaultToolNumber = toolId[-1]
                for currentSpoolData in selectedSpools:
                    toolNumber = str(currentSpoolData["tool"])
                    if (defaultToolNumber == toolNumber):
                        spoolData = currentSpoolData["spool"]
                        break

                if (spoolData == None):
                    self._logger.error(
                        "Filamentmanager Spooldata could not be found for toolId '"
                        + toolId + "'")
                else:
                    spoolName = spoolData["name"]
                    spoolCost = spoolData["cost"]
                    spoolCostUnit = self._filamentManagerPluginImplementation._settings.get(
                        ["currencySymbol"])
                    spoolWeight = spoolData["weight"]

                    profileData = spoolData["profile"]
                    diameter = profileData["diameter"]
                    material = profileData["material"]
                    vendor = profileData["vendor"]
                    density = profileData["density"]

                    filemanentModel.spoolName = spoolName
                    filemanentModel.spoolCost = spoolCost
                    filemanentModel.spoolCostUnit = spoolCostUnit
                    filemanentModel.spoolWeight = spoolWeight

                    filemanentModel.profileVendor = vendor
                    filemanentModel.diameter = diameter
                    filemanentModel.density = density
                    filemanentModel.material = material

                    radius = diameter / 2.0
                    volume = filemanentModel.usedLength * math.pi * radius * radius / 1000.0
                    usedWeight = volume * density

                    filemanentModel.usedWeight = usedWeight
                    filemanentModel.usedCost = spoolCost / spoolWeight * usedWeight
        else:
            self._logger.info(
                "Empty filamentModel, because Filamentmanager not installed!")

        printJob.addFilamentModel(filemanentModel)
        pass