diff --git a/README.md b/README.md index 1626960..416858e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # OctoPrint-CostEstimation -This OctoPrint plugin displays the estimated print cost for the loaded model. The print cost includes the price for the used filament and the operating cost for the printer. - -**Note:** This Plugin requires the [Filament Manager Plugin](https://github.com/malnvenshorn/OctoPrint-FilamentManager) to work. Make sure it is installed. +This OctoPrint plugin displays the estimated print cost for the loaded model. The print cost includes the price for the used filament the maintenance and operating cost for the printer as well as the depreciation of the printer. ## Features - Calculation based on the provided filament length diff --git a/octoprint_costestimation/__init__.py b/octoprint_costestimation/__init__.py index 35cdc2e..a9c3b12 100644 --- a/octoprint_costestimation/__init__.py +++ b/octoprint_costestimation/__init__.py @@ -16,11 +16,19 @@ class CostEstimationPlugin(octoprint.plugin.SettingsPlugin, def get_settings_defaults(self): return dict( - powerConsumption=0.2, # kWh - costOfElectricity=0.25, # €/kWh + weightOfFilament=1000, # g + costOfFilament=20, # € + densityOfFilament=1.32, # g/cm³ + diameterOfFilament=1.75, # mm + powerConsumption=0.2, # kWh + costOfElectricity=0.25, # €/kWh currency="€", - currencyFormat="%v %s", # %v - value, %s - currency symbol - requiresLogin=False + currencyFormat="%v %s", # %v - value, %s - currency symbol + requiresLogin=False, + useFilamentManager=True, + priceOfPrinter=0, # € + lifespanOfPrinter=0, # h + maintenanceCosts=0, # €/h ) def get_settings_version(self): @@ -49,7 +57,7 @@ def on_settings_migrate(self, target, current=None): def get_template_configs(self): return [ - dict(type="settings", custom_bindings=False) + dict(type="settings") ] # AssetPlugin diff --git a/octoprint_costestimation/static/js/costestimation.js b/octoprint_costestimation/static/js/costestimation.js index c1c2963..aa7c7b9 100644 --- a/octoprint_costestimation/static/js/costestimation.js +++ b/octoprint_costestimation/static/js/costestimation.js @@ -20,6 +20,10 @@ $(function() { self.loginState.isUser() : true; }); + self.showFilamentGroup = ko.pureComputed(function() { + return self.filamentManager === null || !self.settings.settings.plugins.costestimation.useFilamentManager(); + }) + self.estimatedCostString = ko.pureComputed(function() { if (!self.showEstimatedCost()) return "-"; if (self.printerState.filename() === undefined) return "-"; @@ -27,7 +31,11 @@ $(function() { var pluginSettings = self.settings.settings.plugins.costestimation; var jobFilament = self.printerState.filament(); - var spoolData = self.filamentManager.selectedSpools(); + var spoolData = null; + + if (self.filamentManager !== null && pluginSettings.useFilamentManager()) { + spoolData = self.filamentManager.selectedSpools(); + } // calculating filament cost var filamentCost = 0; @@ -35,13 +43,23 @@ $(function() { var result = /(\d+)/.exec(jobFilament[i].name()); // extract tool id from name var tool = result === null ? 0 : result[1]; - if (spoolData[tool] === undefined) continue; // skip tools with no selected spool + if (spoolData !== null && spoolData[tool] === undefined) continue; // skip tools with no selected spool - var costOfFilament = spoolData[tool].cost; - var weightOfFilament = spoolData[tool].weight; - var densityOfFilament = spoolData[tool].profile.density; - var diameterOfFilament = spoolData[tool].profile.diameter; - var costPerWeight = costOfFilament / weightOfFilament; + var costOfFilament, weightOfFilament, densityOfFilament, diameterOfFilament; + + if (spoolData !== null) { + costOfFilament = spoolData[tool].cost; + weightOfFilament = spoolData[tool].weight; + densityOfFilament = spoolData[tool].profile.density; + diameterOfFilament = spoolData[tool].profile.diameter; + } else { + costOfFilament = parseFloat(pluginSettings.costOfFilament()); + weightOfFilament = parseFloat(pluginSettings.weightOfFilament()); + densityOfFilament = parseFloat(pluginSettings.densityOfFilament()); + diameterOfFilament = parseFloat(pluginSettings.diameterOfFilament()); + } + + var costPerWeight = weightOfFilament > 0 ? costOfFilament / weightOfFilament : 0; var filamentLength = jobFilament[i].data().length; var filamentVolume = self.calculateVolume(filamentLength, diameterOfFilament) / 1000; @@ -49,14 +67,21 @@ $(function() { } // calculating electricity cost - var powerConsumption = pluginSettings.powerConsumption(); - var costOfElectricity = pluginSettings.costOfElectricity(); + var powerConsumption = parseFloat(pluginSettings.powerConsumption()); + var costOfElectricity = parseFloat(pluginSettings.costOfElectricity()); var costPerHour = powerConsumption * costOfElectricity; var estimatedPrintTime = self.printerState.estimatedPrintTime() / 3600; // h var electricityCost = costPerHour * estimatedPrintTime; + // calculating printer cost + var purchasePrice = parseFloat(pluginSettings.priceOfPrinter()); + var lifespan = parseFloat(pluginSettings.lifespanOfPrinter()); + var depreciationPerHour = lifespan > 0 ? purchasePrice / lifespan : 0; + var maintenancePerHour = parseFloat(pluginSettings.maintenanceCosts()); + var printerCost = (depreciationPerHour + maintenancePerHour) * estimatedPrintTime; + // assembling string - var estimatedCost = filamentCost + electricityCost; + var estimatedCost = filamentCost + electricityCost + printerCost; var currencySymbol = pluginSettings.currency(); var currencyFormat = pluginSettings.currencyFormat(); return currencyFormat.replace("%v", estimatedCost.toFixed(2)).replace("%s", currencySymbol); @@ -81,6 +106,7 @@ $(function() { construct: CostEstimationViewModel, dependencies: ["printerStateViewModel", "settingsViewModel", "loginStateViewModel", "filamentManagerViewModel"], - elements: ["#costestimation_string"] + optional: ["filamentManagerViewModel"], + elements: ["#costestimation_string", "#settings_plugin_costestimation"] }); }); diff --git a/octoprint_costestimation/templates/costestimation_settings.jinja2 b/octoprint_costestimation/templates/costestimation_settings.jinja2 index 6635d47..2b17bea 100644 --- a/octoprint_costestimation/templates/costestimation_settings.jinja2 +++ b/octoprint_costestimation/templates/costestimation_settings.jinja2 @@ -2,7 +2,66 @@

{{ _("Filament") }}

- {{ _("The settings can be found in the") }} Filament Manager +
+
+ +
+
+ +
+
+ +
+
+ + +
+
+
+ +
+ +
+
+ + g +
+
+
+ +
+ +
+
+ + g/cm3 +
+
+
+ +
+ +
+
+ + mm +
+
+
+

{{ _("Operating Cost") }}

@@ -10,7 +69,7 @@
- + kW
@@ -20,8 +79,40 @@
- - /kWh + + /kWh +
+
+ + +

{{ _("Printer Cost") }}

+ +
+ +
+
+ + +
+
+
+ +
+ +
+
+ + h +
+
+
+ +
+ +
+
+ + /h
@@ -31,21 +122,21 @@
- +
- +
diff --git a/octoprint_costestimation/translations/de/LC_MESSAGES/messages.mo b/octoprint_costestimation/translations/de/LC_MESSAGES/messages.mo index 440ba65..6a95857 100644 Binary files a/octoprint_costestimation/translations/de/LC_MESSAGES/messages.mo and b/octoprint_costestimation/translations/de/LC_MESSAGES/messages.mo differ diff --git a/octoprint_costestimation/translations/de/LC_MESSAGES/messages.po b/octoprint_costestimation/translations/de/LC_MESSAGES/messages.po index f6cda4a..f125d64 100644 --- a/octoprint_costestimation/translations/de/LC_MESSAGES/messages.po +++ b/octoprint_costestimation/translations/de/LC_MESSAGES/messages.po @@ -8,8 +8,8 @@ msgid "" msgstr "" "Project-Id-Version: OctoPrint-CostEstimation 0.1.0\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2017-08-19 11:51+0200\n" -"PO-Revision-Date: 2017-08-19 11:51+0200\n" +"POT-Creation-Date: 2018-01-14 19:43+0100\n" +"PO-Revision-Date: 2018-01-14 19:49+0100\n" "Last-Translator: Sven Lohrmann \n" "Language: de\n" "Language-Team: de \n" @@ -18,13 +18,13 @@ msgstr "" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.4.0\n" -"X-Generator: Poedit 2.0.3\n" +"X-Generator: Poedit 2.0.5\n" -#: octoprint_costestimation/static/js/costestimation.js:70 +#: octoprint_costestimation/static/js/costestimation.js:98 msgid "Cost" msgstr "Kosten" -#: octoprint_costestimation/static/js/costestimation.js:71 +#: octoprint_costestimation/static/js/costestimation.js:99 msgid "Estimated print cost based on required quantity of filament and print time" msgstr "" "Geschätzte Druckkosten basierend auf der benötigten Menge an Filamant und der " @@ -34,31 +34,75 @@ msgstr "" msgid "Filament" msgstr "Filament" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:5 -msgid "The settings can be found in the" -msgstr "Die Einstellungen befinden sich im" +#: octoprint_costestimation/templates/costestimation_settings.jinja2:9 +msgid "" +"Use Filament Manager Plugin" +msgstr "" +"Verwende Filament Manager Plugin" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:11 +msgid "(installed)" +msgstr "(installiert)" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:14 +msgid "(not installed)" +msgstr "(nicht installiert)" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:22 +msgid "Price" +msgstr "Preis" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:33 +msgid "Weight" +msgstr "Gewicht" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:44 +msgid "Density" +msgstr "Dichte" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:7 +#: octoprint_costestimation/templates/costestimation_settings.jinja2:55 +msgid "Diameter" +msgstr "Durchmesser" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:66 msgid "Operating Cost" msgstr "Betriebskosten" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:10 +#: octoprint_costestimation/templates/costestimation_settings.jinja2:69 msgid "Power consumption" msgstr "Stromverbrauch" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:20 +#: octoprint_costestimation/templates/costestimation_settings.jinja2:79 msgid "Electricity cost" msgstr "Stromkosten" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:29 +#: octoprint_costestimation/templates/costestimation_settings.jinja2:88 +msgid "Printer Cost" +msgstr "Druckerkosten" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:91 +msgid "Purchase price" +msgstr "Einkaufspreis" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:101 +msgid "Estimated lifespan" +msgstr "Ungefähre Lebensdauer" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:111 +msgid "Maintenance costs" +msgstr "Wartungskosten" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:120 msgid "Appearance" msgstr "Aussehen" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:32 +#: octoprint_costestimation/templates/costestimation_settings.jinja2:123 msgid "Currency symbol" msgstr "Währungssymbol" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:38 +#: octoprint_costestimation/templates/costestimation_settings.jinja2:129 #, python-format msgid "" "Format string that allows control of symbol position (%%v = value, %%s = symbol)" @@ -66,49 +110,10 @@ msgstr "" "Formatierungsstring zum festlegen der Position des Währungssymbols (%%v = Wert, " "%%s = Symbol)" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:39 +#: octoprint_costestimation/templates/costestimation_settings.jinja2:130 msgid "String format" msgstr "Stringformat" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:48 +#: octoprint_costestimation/templates/costestimation_settings.jinja2:139 msgid "Show estimated cost only if logged in" msgstr "Zeige Kosten nur wenn eingeloggt" - -#~ msgid "Misc" -#~ msgstr "Sonstiges" - -#~ msgid "Symbol" -#~ msgstr "Symbol" - -#~ msgid "Format" -#~ msgstr "Format" - -#~ msgid "Manage Filament" -#~ msgstr "Filament verwalten" - -#~ msgid "New" -#~ msgstr "Neu" - -#~ msgid "Delete" -#~ msgstr "Löschen" - -#~ msgid "Name" -#~ msgstr "Name" - -#~ msgid "Price" -#~ msgstr "Preis" - -#~ msgid "Weight" -#~ msgstr "Gewicht" - -#~ msgid "Density" -#~ msgstr "Dichte" - -#~ msgid "Diameter" -#~ msgstr "Durchmesser" - -#~ msgid "Close" -#~ msgstr "Schließen" - -#~ msgid "Tool" -#~ msgstr "Werkzeug" diff --git a/screenshots/costestimation_settings.png b/screenshots/costestimation_settings.png index 9e245c0..e7998b8 100644 Binary files a/screenshots/costestimation_settings.png and b/screenshots/costestimation_settings.png differ diff --git a/setup.py b/setup.py index 82c9d18..5e74a6b 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ plugin_identifier = "costestimation" plugin_package = "octoprint_costestimation" plugin_name = "OctoPrint-CostEstimation" -plugin_version = "2.0.1" +plugin_version = "2.1.0" plugin_description = "Displays the estimated print cost for the loaded model" plugin_author = "Sven Lohrmann" plugin_author_email = "malnvenshorn@gmail.com" diff --git a/translations/de/LC_MESSAGES/messages.mo b/translations/de/LC_MESSAGES/messages.mo new file mode 100644 index 0000000..6a95857 Binary files /dev/null and b/translations/de/LC_MESSAGES/messages.mo differ diff --git a/translations/de/LC_MESSAGES/messages.po b/translations/de/LC_MESSAGES/messages.po new file mode 100644 index 0000000..f125d64 --- /dev/null +++ b/translations/de/LC_MESSAGES/messages.po @@ -0,0 +1,119 @@ +# German translations for OctoPrint-CostEstimation. +# Copyright (C) 2017 ORGANIZATION +# This file is distributed under the same license as the +# OctoPrint-CostEstimation project. +# FIRST AUTHOR , 2017. +# +msgid "" +msgstr "" +"Project-Id-Version: OctoPrint-CostEstimation 0.1.0\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2018-01-14 19:43+0100\n" +"PO-Revision-Date: 2018-01-14 19:49+0100\n" +"Last-Translator: Sven Lohrmann \n" +"Language: de\n" +"Language-Team: de \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.4.0\n" +"X-Generator: Poedit 2.0.5\n" + +#: octoprint_costestimation/static/js/costestimation.js:98 +msgid "Cost" +msgstr "Kosten" + +#: octoprint_costestimation/static/js/costestimation.js:99 +msgid "Estimated print cost based on required quantity of filament and print time" +msgstr "" +"Geschätzte Druckkosten basierend auf der benötigten Menge an Filamant und der " +"Druckzeit" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:3 +msgid "Filament" +msgstr "Filament" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:9 +msgid "" +"Use Filament Manager Plugin" +msgstr "" +"Verwende Filament Manager Plugin" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:11 +msgid "(installed)" +msgstr "(installiert)" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:14 +msgid "(not installed)" +msgstr "(nicht installiert)" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:22 +msgid "Price" +msgstr "Preis" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:33 +msgid "Weight" +msgstr "Gewicht" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:44 +msgid "Density" +msgstr "Dichte" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:55 +msgid "Diameter" +msgstr "Durchmesser" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:66 +msgid "Operating Cost" +msgstr "Betriebskosten" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:69 +msgid "Power consumption" +msgstr "Stromverbrauch" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:79 +msgid "Electricity cost" +msgstr "Stromkosten" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:88 +msgid "Printer Cost" +msgstr "Druckerkosten" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:91 +msgid "Purchase price" +msgstr "Einkaufspreis" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:101 +msgid "Estimated lifespan" +msgstr "Ungefähre Lebensdauer" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:111 +msgid "Maintenance costs" +msgstr "Wartungskosten" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:120 +msgid "Appearance" +msgstr "Aussehen" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:123 +msgid "Currency symbol" +msgstr "Währungssymbol" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:129 +#, python-format +msgid "" +"Format string that allows control of symbol position (%%v = value, %%s = symbol)" +msgstr "" +"Formatierungsstring zum festlegen der Position des Währungssymbols (%%v = Wert, " +"%%s = Symbol)" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:130 +msgid "String format" +msgstr "Stringformat" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:139 +msgid "Show estimated cost only if logged in" +msgstr "Zeige Kosten nur wenn eingeloggt" diff --git a/octoprint_costestimation/translations/messages.pot b/translations/messages.pot similarity index 50% rename from octoprint_costestimation/translations/messages.pot rename to translations/messages.pot index 62fbc10..91bd3ff 100644 --- a/octoprint_costestimation/translations/messages.pot +++ b/translations/messages.pot @@ -1,15 +1,15 @@ # Translations template for OctoPrint-CostEstimation. -# Copyright (C) 2017 ORGANIZATION +# Copyright (C) 2018 The OctoPrint Project # This file is distributed under the same license as the # OctoPrint-CostEstimation project. -# FIRST AUTHOR , 2017. +# FIRST AUTHOR , 2018. # #, fuzzy msgid "" msgstr "" -"Project-Id-Version: OctoPrint-CostEstimation 1.1.0\n" -"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2017-08-19 11:51+0200\n" +"Project-Id-Version: OctoPrint-CostEstimation 2.0.1\n" +"Report-Msgid-Bugs-To: i18n@octoprint.org\n" +"POT-Creation-Date: 2018-01-14 19:43+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -18,11 +18,11 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.4.0\n" -#: octoprint_costestimation/static/js/costestimation.js:70 +#: octoprint_costestimation/static/js/costestimation.js:98 msgid "Cost" msgstr "" -#: octoprint_costestimation/static/js/costestimation.js:71 +#: octoprint_costestimation/static/js/costestimation.js:99 msgid "Estimated print cost based on required quantity of filament and print time" msgstr "" @@ -30,42 +30,84 @@ msgstr "" msgid "Filament" msgstr "" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:5 -msgid "The settings can be found in the" +#: octoprint_costestimation/templates/costestimation_settings.jinja2:9 +msgid "" +"Use Filament Manager Plugin" +msgstr "" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:11 +msgid "(installed)" +msgstr "" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:14 +msgid "(not installed)" +msgstr "" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:22 +msgid "Price" +msgstr "" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:33 +msgid "Weight" +msgstr "" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:44 +msgid "Density" msgstr "" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:7 +#: octoprint_costestimation/templates/costestimation_settings.jinja2:55 +msgid "Diameter" +msgstr "" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:66 msgid "Operating Cost" msgstr "" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:10 +#: octoprint_costestimation/templates/costestimation_settings.jinja2:69 msgid "Power consumption" msgstr "" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:20 +#: octoprint_costestimation/templates/costestimation_settings.jinja2:79 msgid "Electricity cost" msgstr "" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:29 +#: octoprint_costestimation/templates/costestimation_settings.jinja2:88 +msgid "Printer Cost" +msgstr "" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:91 +msgid "Purchase price" +msgstr "" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:101 +msgid "Estimated lifespan" +msgstr "" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:111 +msgid "Maintenance costs" +msgstr "" + +#: octoprint_costestimation/templates/costestimation_settings.jinja2:120 msgid "Appearance" msgstr "" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:32 +#: octoprint_costestimation/templates/costestimation_settings.jinja2:123 msgid "Currency symbol" msgstr "" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:38 +#: octoprint_costestimation/templates/costestimation_settings.jinja2:129 #, python-format msgid "" "Format string that allows control of symbol position (%%v = value, %%s = " "symbol)" msgstr "" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:39 +#: octoprint_costestimation/templates/costestimation_settings.jinja2:130 msgid "String format" msgstr "" -#: octoprint_costestimation/templates/costestimation_settings.jinja2:48 +#: octoprint_costestimation/templates/costestimation_settings.jinja2:139 msgid "Show estimated cost only if logged in" msgstr ""