Skip to content

Commit

Permalink
New Version 1.2.0
Browse files Browse the repository at this point in the history
- B #55 bed temperature could be stored
- E #52 added PLA+
- E #29, #30, #32,#35, #53  more Attributes

Some preparations for external Database
  • Loading branch information
OllisGit committed Sep 3, 2020
1 parent 85002f2 commit 4b7154d
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 58 deletions.
34 changes: 33 additions & 1 deletion octoprint_SpoolManager/DatabaseManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

FORCE_CREATE_TABLES = False

CURRENT_DATABASE_SCHEME_VERSION = 2
CURRENT_DATABASE_SCHEME_VERSION = 3

# List all Models
MODELS = [PluginMetaDataModel, SpoolModel]
Expand Down Expand Up @@ -118,6 +118,38 @@ def _upgradeFrom3To4(self):

def _upgradeFrom2To3(self):
self._logger.info(" Starting 2 -> 3")
# What is changed:
# - version = IntegerField(null=True) # since V3
# - diameterTolerance = FloatField(null=True) # since V3
# - flowRateCompensation = IntegerField(null=True) # since V3
# - bedTemperature = IntegerField(null=True) # since V3
# - encloserTemperature = IntegerField(null=True) # since V3

connection = sqlite3.connect(self._databaseFileLocation)
cursor = connection.cursor()

sql = """
PRAGMA foreign_keys=off;
BEGIN TRANSACTION;
ALTER TABLE 'spo_spoolmodel' ADD 'version' INTEGER;
ALTER TABLE 'spo_spoolmodel' ADD 'diameterTolerance' REAL;
ALTER TABLE 'spo_spoolmodel' ADD 'spoolWeight' REAL;
ALTER TABLE 'spo_spoolmodel' ADD 'flowRateCompensation' INTEGER;
ALTER TABLE 'spo_spoolmodel' ADD 'bedTemperature' INTEGER;
ALTER TABLE 'spo_spoolmodel' ADD 'encloserTemperature' INTEGER;
ALTER TABLE 'spo_spoolmodel' ADD 'totalLength' INTEGER;
UPDATE 'spo_spoolmodel' SET version=1;
UPDATE 'spo_pluginmetadatamodel' SET value=3 WHERE key='databaseSchemeVersion';
COMMIT;
PRAGMA foreign_keys=on;
"""
cursor.executescript(sql)

connection.close()

self._logger.info(" Successfully 2 -> 3")
pass

Expand Down
15 changes: 14 additions & 1 deletion octoprint_SpoolManager/api/SpoolManagerAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,25 @@ def _sendCSVUploadStatusToClient(self, importStatus, currenLineNumber, backupFil

def _updateSpoolModelFromJSONData(self, spoolModel, jsonData):

spoolModel.version = self._getValueFromJSONOrNone("version", jsonData)
spoolModel.databaseId = self._getValueFromJSONOrNone("databaseId", jsonData)
spoolModel.isTemplate = self._getValueFromJSONOrNone("isTemplate", jsonData)
spoolModel.displayName = self._getValueFromJSONOrNone("displayName", jsonData)
spoolModel.vendor = self._getValueFromJSONOrNone("vendor", jsonData)
spoolModel.material = self._getValueFromJSONOrNone("material", jsonData)
spoolModel.density = self._getValueFromJSONOrNone("density", jsonData)
spoolModel.diameter = self._getValueFromJSONOrNone("diameter", jsonData)
spoolModel.diameterTolerance = self._getValueFromJSONOrNone("diameterTolerance", jsonData)
spoolModel.colorName = self._getValueFromJSONOrNone("colorName", jsonData)
spoolModel.color = self._getValueFromJSONOrNone("color", jsonData)
spoolModel.flowRateCompensation = self._getValueFromJSONOrNone("flowRateCompensation", jsonData)
spoolModel.temperature = self._getValueFromJSONOrNone("temperature", jsonData)
spoolModel.bedTemperature = self._getValueFromJSONOrNone("bedTemperature", jsonData)
spoolModel.encloserTemperature = self._getValueFromJSONOrNone("encloserTemperature", jsonData)
spoolModel.totalWeight = self._getValueFromJSONOrNone("totalWeight", jsonData)
spoolModel.spoolWeight = self._getValueFromJSONOrNone("spoolWeight", jsonData)
spoolModel.remainingWeight = self._getValueFromJSONOrNone("remainingWeight", jsonData)
spoolModel.totalLength = self._getValueFromJSONOrNone("totalLength", jsonData)
spoolModel.usedLength = self._getValueFromJSONOrNone("usedLength", jsonData)
spoolModel.usedWeight = self._getValueFromJSONOrNone("usedWeight", jsonData)
spoolModel.code = self._getValueFromJSONOrNone("code", jsonData)
Expand Down Expand Up @@ -100,11 +107,17 @@ def _createSampleSpoolModel(self):
s1.vendor = "The Spool Company"
s1.material = "PETG"
s1.diameter = 1.75
s1.diameterTolerance = 0.2
s1.density = 1.27
s1.flowRateCompensation = 110
s1.temperature = 182
s1.bedtemperature = 52
s1.encloserTemperature = 23
s1.totalWeight = 1000.0
s1.spoolWeight = 12.3
s1.usedWeight = 123.4
s1.usedLength = 234.5
s1.totalLength = 1321
s1.usedLength = 234
s1.lastUse = datetime.datetime.now()

s1.firstUse = datetime.datetime.strptime("2020-03-02 10:33", '%Y-%m-%d %H:%M')
Expand Down
19 changes: 17 additions & 2 deletions octoprint_SpoolManager/api/Transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def _calculateRemainingPercentage(remainingWeight, totalWeight):
return None

if ( (type(remainingWeight) == int or type(remainingWeight) == float) and
(type(totalWeight) == int or type(totalWeight) == float) ):
(type(totalWeight) == int or type(totalWeight) == float) and
(totalWeight > 0) ):
result = remainingWeight / (totalWeight / 100.0)
return result

Expand All @@ -31,7 +32,8 @@ def _calculateUsedPercentage(usedWeight, totalWeight):
return None

if ( (type(usedWeight) == int or type(usedWeight) == float) and
(type(totalWeight) == int or type(totalWeight) == float) ):
(type(totalWeight) == int or type(totalWeight) == float) and
(totalWeight > 0) ):
result = usedWeight / (totalWeight / 100.0)
return result

Expand Down Expand Up @@ -62,8 +64,21 @@ def transformSpoolModelToDict(spoolModel):

# Decimal and date time needs to be converted. ATTENTION orgiginal fields will be modified
spoolAsDict["totalWeight"] = StringUtils.formatFloat(spoolModel.totalWeight)
spoolAsDict["spoolWeight"] = StringUtils.formatFloat(spoolModel.spoolWeight)
spoolAsDict["usedWeight"] = StringUtils.formatFloat(spoolModel.usedWeight)

usedLength = spoolModel.usedLength
totalLength = spoolModel.totalLength
remainingLength = calculateRemainingWeight(usedLength, totalLength)
remainingLengthPercentage = _calculateUsedPercentage(remainingLength, totalLength)
usedLengthPercentage = _calculateUsedPercentage(usedLength, totalLength)

spoolAsDict["remainingLength"] = StringUtils.formatInt(remainingLength)
spoolAsDict["remainingLengthPercentage"] = StringUtils.formatInt(remainingLengthPercentage)
spoolAsDict["usedLengthPercentage"] = StringUtils.formatInt(usedLengthPercentage)




# spoolAsDict["temperature"] = StringUtils.formatSave("{:.02f}", spoolAsDict["temperature"], "")
# spoolAsDict["weight"] = StringUtils.formatSave("{:.02f}", spoolAsDict["weight"], "")
Expand Down
36 changes: 33 additions & 3 deletions octoprint_SpoolManager/common/CSVExportImporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@
COLUMN_MATERIAL = "Material"
COLUMN_DENSITY = "Density [g/cm3]"
COLUMN_DIAMETER = "Diameter [mm]"
COLUMN_TEMPERTURE = "Temperature [C]"
COLUMN_DIAMETER_TOLERANCE = "Diameter Tolerance[mm]"
COLUMN_FLOWRATECOMPENSATION = "Flow rate compensation [%]"
COLUMN_TEMPERATURE = "Temperature [C]"
COLUMN_TEMPERATURE_BED = "Bed Temperature [C]"
COLUMN_TEMPERATURE_ENCLOSER = "Encloser Temperature [C]"
COLUMN_TOTAL_WEIGHT = "Total weight [g]"
COLUMN_SPOOL_WEIGHT = "Spool weight [g]"
COLUMN_USED_WEIGHT = "Used weight [g]"
COLUMN_TOTAL_LENGTH = "Total length [mm]"
COLUMN_USED_LENGTH = "Used length [mm]"
COLUMN_FIST_USE_DATETIME = "First use [dd.mm.yyyy hh:mm]"
COLUMN_LAST_USE_DATETIME = "Last use [dd.mm.yyyy hh:mm]"
Expand Down Expand Up @@ -135,12 +141,24 @@ def parseAndAssignFieldValue(self, fieldLabel, fieldName, fieldValue, spoolModel
fieldValue = float(fieldValue)
if ("diameter" == fieldName):
fieldValue = float(fieldValue)
if ("diameterTolerance" == fieldName):
fieldValue = float(fieldValue)
if ("flowRateCompensation" == fieldName):
fieldValue = int(fieldValue)
if ("temperature" == fieldName):
fieldValue = int(fieldValue)
if ("bedTemperature" == fieldName):
fieldValue = int(fieldValue)
if ("encloserTemperature" == fieldName):
fieldValue = int(fieldValue)
if ("totalWeight" == fieldName):
fieldValue = float(fieldValue)
if ("spoolWeight" == fieldName):
fieldValue = float(fieldValue)
if ("usedWeight" == fieldName):
fieldValue = float(fieldValue)
if ("totalLength" == fieldName):
fieldValue = int(fieldValue)
if ("usedLength" == fieldName):
fieldValue = int(fieldValue)
if ("cost" == fieldName):
Expand All @@ -158,9 +176,15 @@ def parseAndAssignFieldValue(self, fieldLabel, fieldName, fieldValue, spoolModel
COLUMN_MATERIAL,
COLUMN_DENSITY,
COLUMN_DIAMETER,
COLUMN_TEMPERTURE,
COLUMN_DIAMETER_TOLERANCE,
COLUMN_FLOWRATECOMPENSATION,
COLUMN_TEMPERATURE,
COLUMN_TEMPERATURE_BED,
COLUMN_TEMPERATURE_ENCLOSER,
COLUMN_TOTAL_WEIGHT,
COLUMN_SPOOL_WEIGHT,
COLUMN_USED_WEIGHT,
COLUMN_TOTAL_LENGTH,
COLUMN_USED_LENGTH,
COLUMN_FIST_USE_DATETIME,
COLUMN_LAST_USE_DATETIME,
Expand All @@ -180,9 +204,15 @@ def parseAndAssignFieldValue(self, fieldLabel, fieldName, fieldValue, spoolModel
COLUMN_MATERIAL: CSVColumn("material", COLUMN_MATERIAL, "", DefaultCSVFormattorParser()),
COLUMN_DENSITY: CSVColumn("density", COLUMN_DENSITY, "", NumberCSVFormattorParser()),
COLUMN_DIAMETER: CSVColumn("diameter", COLUMN_DIAMETER, "", NumberCSVFormattorParser()),
COLUMN_TEMPERTURE: CSVColumn("temperature", COLUMN_TEMPERTURE, "", NumberCSVFormattorParser()),
COLUMN_DIAMETER_TOLERANCE: CSVColumn("diameterTolerance", COLUMN_DIAMETER_TOLERANCE, "", NumberCSVFormattorParser()),
COLUMN_FLOWRATECOMPENSATION: CSVColumn("flowRateCompensation", COLUMN_FLOWRATECOMPENSATION, "", NumberCSVFormattorParser()),
COLUMN_TEMPERATURE: CSVColumn("temperature", COLUMN_TEMPERATURE, "", NumberCSVFormattorParser()),
COLUMN_TEMPERATURE_BED: CSVColumn("bedTemperature", COLUMN_TEMPERATURE_BED, "", NumberCSVFormattorParser()),
COLUMN_TEMPERATURE_ENCLOSER: CSVColumn("encloserTemperature", COLUMN_TEMPERATURE_ENCLOSER, "", NumberCSVFormattorParser()),
COLUMN_TOTAL_WEIGHT: CSVColumn("totalWeight", COLUMN_TOTAL_WEIGHT, "", NumberCSVFormattorParser()),
COLUMN_SPOOL_WEIGHT: CSVColumn("spoolWeight", COLUMN_SPOOL_WEIGHT, "", NumberCSVFormattorParser()),
COLUMN_USED_WEIGHT: CSVColumn("usedWeight", COLUMN_USED_WEIGHT, "", NumberCSVFormattorParser()),
COLUMN_TOTAL_LENGTH: CSVColumn("totalLength", COLUMN_TOTAL_LENGTH, "", NumberCSVFormattorParser()),
COLUMN_USED_LENGTH: CSVColumn("usedLength", COLUMN_USED_LENGTH, "", NumberCSVFormattorParser()),
COLUMN_FIST_USE_DATETIME: CSVColumn("firstUse", COLUMN_FIST_USE_DATETIME, "", DateTimeCSVFormattorParser()),
COLUMN_LAST_USE_DATETIME: CSVColumn("lastUse", COLUMN_LAST_USE_DATETIME, "", DateTimeCSVFormattorParser()),
Expand Down
9 changes: 9 additions & 0 deletions octoprint_SpoolManager/common/StringUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ def formatFloat(floatValue):
pass # do nothing
return result

def formatInt(intValue):
result = ""
if (intValue != None ):
try:
result = "{:.0f}".format(float(intValue))
except ValueError:
pass # do nothing
return result

def transformToDateTimeOrNone(dateTimeString):
if dateTimeString != None and len(dateTimeString) != 0:
index = dateTimeString.find(" ")
Expand Down
9 changes: 8 additions & 1 deletion octoprint_SpoolManager/models/SpoolModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,31 @@

class SpoolModel(BaseModel):

version = IntegerField(null=True) # since V3
isTemplate = BooleanField(null=True)
displayName = CharField(null=True)
vendor = CharField(null=True)
material = CharField(null=True)
density = FloatField(null=True)
diameter = FloatField(null=True)
diameterTolerance = FloatField(null=True) # since V3
colorName = CharField(null=True)
color = CharField(null=True)
# Grad
flowRateCompensation = IntegerField(null=True) #since V3
# Temperature
temperature = IntegerField(null=True)
bedTemperature = IntegerField(null=True) # since V3
encloserTemperature = IntegerField(null=True) # since V3
# in g
totalWeight = FloatField(null=True)
spoolWeight = FloatField(null=True) # since V3
# in g
usedWeight = FloatField(null=True)
# in g
remainingWeight = FloatField(null=True)

# in mm
totalLength = IntegerField(null=True) # since V3
usedLength = IntegerField(null=True)
# Bar or QR Code
code = CharField(null=True)
Expand Down
Loading

0 comments on commit 4b7154d

Please sign in to comment.