Merge pull request #3980 from eumiro/numbers
🦕 Remove the redundant Python2 float conversion relics from the `devel` branch
This commit is contained in:
14 files changed
+52
-52
No files matched your search
@@ -1348,7 +1348,7 @@ class LocalFileStorage(StorageInterface):
|
||||
continue
|
||||
statistics["averagePrintTime"][printer_profile] = sum(
|
||||
former_print_times[printer_profile]
|
||||
) / float(len(former_print_times[printer_profile]))
|
||||
) / len(former_print_times[printer_profile])
|
||||
|
||||
for printer_profile in last_print:
|
||||
if not last_print[printer_profile]:
|
||||
|
||||
@@ -757,7 +757,7 @@ class VirtualPrinter:
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
def _gcode_G20(self, data: str) -> None:
|
||||
self._unitModifier = 1.0 / 2.54
|
||||
self._unitModifier = 1 / 2.54
|
||||
if self._lastX is not None:
|
||||
self._lastX *= 2.54
|
||||
if self._lastY is not None:
|
||||
@@ -807,9 +807,9 @@ class VirtualPrinter:
|
||||
|
||||
_timeout = 0
|
||||
if matchP:
|
||||
_timeout = float(matchP.group(1)) / 1000.0
|
||||
_timeout = int(matchP.group(1)) / 1000
|
||||
elif matchS:
|
||||
_timeout = float(matchS.group(1))
|
||||
_timeout = int(matchS.group(1))
|
||||
|
||||
if self._sendBusy and self._busyInterval > 0:
|
||||
until = time.monotonic() + _timeout
|
||||
@@ -1510,11 +1510,11 @@ class VirtualPrinter:
|
||||
return
|
||||
|
||||
try:
|
||||
self.targetTemp[tool] = float(re.search(r"S([0-9]+)", line).group(1))
|
||||
self.targetTemp[tool] = int(re.search(r"S([0-9]+)", line).group(1))
|
||||
except Exception:
|
||||
if support_r:
|
||||
try:
|
||||
self.targetTemp[tool] = float(re.search(r"R([0-9]+)", line).group(1))
|
||||
self.targetTemp[tool] = int(re.search(r"R([0-9]+)", line).group(1))
|
||||
only_wait_if_higher = False
|
||||
except Exception:
|
||||
pass
|
||||
@@ -1531,11 +1531,11 @@ class VirtualPrinter:
|
||||
|
||||
only_wait_if_higher = True
|
||||
try:
|
||||
self.bedTargetTemp = float(re.search(r"S([0-9]+)", line).group(1))
|
||||
self.bedTargetTemp = int(re.search(r"S([0-9]+)", line).group(1))
|
||||
except Exception:
|
||||
if support_r:
|
||||
try:
|
||||
self.bedTargetTemp = float(re.search(r"R([0-9]+)", line).group(1))
|
||||
self.bedTargetTemp = int(re.search(r"R([0-9]+)", line).group(1))
|
||||
only_wait_if_higher = False
|
||||
except Exception:
|
||||
pass
|
||||
@@ -1551,11 +1551,11 @@ class VirtualPrinter:
|
||||
|
||||
only_wait_if_higher = True
|
||||
try:
|
||||
self.chamberTargetTemp = float(re.search("S([0-9]+)", line).group(1))
|
||||
self.chamberTargetTemp = int(re.search("S([0-9]+)", line).group(1))
|
||||
except Exception:
|
||||
if support_r:
|
||||
try:
|
||||
self.chamberTargetTemp = float(re.search("R([0-9]+)", line).group(1))
|
||||
self.chamberTargetTemp = int(re.search("R([0-9]+)", line).group(1))
|
||||
only_wait_if_higher = False
|
||||
except Exception:
|
||||
pass
|
||||
@@ -1577,8 +1577,8 @@ class VirtualPrinter:
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
speedXYZ = self._lastF * (self._feedrate_multiplier / 100.0)
|
||||
speedE = self._lastF * (self._flowrate_multiplier / 100.0)
|
||||
speedXYZ = self._lastF * (self._feedrate_multiplier / 100)
|
||||
speedE = self._lastF * (self._flowrate_multiplier / 100)
|
||||
if speedXYZ == 0:
|
||||
speedXYZ = 999999999999
|
||||
if speedE == 0:
|
||||
@@ -1591,10 +1591,10 @@ class VirtualPrinter:
|
||||
pass
|
||||
else:
|
||||
if self._relative or self._lastX is None:
|
||||
duration = max(duration, x * self._unitModifier / speedXYZ * 60.0)
|
||||
duration = max(duration, x * self._unitModifier / speedXYZ * 60)
|
||||
else:
|
||||
duration = max(
|
||||
duration, (x - self._lastX) * self._unitModifier / speedXYZ * 60.0
|
||||
duration, (x - self._lastX) * self._unitModifier / speedXYZ * 60
|
||||
)
|
||||
|
||||
if self._relative and self._lastX is not None:
|
||||
@@ -1608,10 +1608,10 @@ class VirtualPrinter:
|
||||
pass
|
||||
else:
|
||||
if self._relative or self._lastY is None:
|
||||
duration = max(duration, y * self._unitModifier / speedXYZ * 60.0)
|
||||
duration = max(duration, y * self._unitModifier / speedXYZ * 60)
|
||||
else:
|
||||
duration = max(
|
||||
duration, (y - self._lastY) * self._unitModifier / speedXYZ * 60.0
|
||||
duration, (y - self._lastY) * self._unitModifier / speedXYZ * 60
|
||||
)
|
||||
|
||||
if self._relative and self._lastY is not None:
|
||||
@@ -1625,10 +1625,10 @@ class VirtualPrinter:
|
||||
pass
|
||||
else:
|
||||
if self._relative or self._lastZ is None:
|
||||
duration = max(duration, z * self._unitModifier / speedXYZ * 60.0)
|
||||
duration = max(duration, z * self._unitModifier / speedXYZ * 60)
|
||||
else:
|
||||
duration = max(
|
||||
duration, (z - self._lastZ) * self._unitModifier / speedXYZ * 60.0
|
||||
duration, (z - self._lastZ) * self._unitModifier / speedXYZ * 60
|
||||
)
|
||||
|
||||
if self._relative and self._lastZ is not None:
|
||||
@@ -1643,10 +1643,10 @@ class VirtualPrinter:
|
||||
else:
|
||||
lastE = self._lastE[self.currentExtruder]
|
||||
if self._relative or lastE is None:
|
||||
duration = max(duration, e * self._unitModifier / speedE * 60.0)
|
||||
duration = max(duration, e * self._unitModifier / speedE * 60)
|
||||
else:
|
||||
duration = max(
|
||||
duration, (e - lastE) * self._unitModifier / speedE * 60.0
|
||||
duration, (e - lastE) * self._unitModifier / speedE * 60
|
||||
)
|
||||
|
||||
if self._relative and lastE is not None:
|
||||
@@ -2228,7 +2228,7 @@ class CharCountingQueue(queue.Queue):
|
||||
endtime = time.monotonic() + timeout
|
||||
while not self._will_it_fit(item):
|
||||
remaining = endtime - time.monotonic()
|
||||
if remaining <= 0.0:
|
||||
if remaining <= 0:
|
||||
raise queue.Full
|
||||
self.not_full.wait(remaining)
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class PrintTimeEstimator:
|
||||
# by that divided by the sd status polling interval
|
||||
interval = settings().getFloat(["serial", "timeout", "sdStatus"])
|
||||
if interval <= 0:
|
||||
interval = 1.0
|
||||
interval = 1
|
||||
rolling_window = int(15 // interval)
|
||||
if rolling_window < 1:
|
||||
rolling_window = 1
|
||||
|
||||
@@ -789,8 +789,8 @@ class PrinterProfileManager:
|
||||
@staticmethod
|
||||
def _default_box_for_volume(volume):
|
||||
if volume["origin"] == BedOrigin.CENTER:
|
||||
half_width = volume["width"] / 2.0
|
||||
half_depth = volume["depth"] / 2.0
|
||||
half_width = volume["width"] / 2
|
||||
half_depth = volume["depth"] / 2
|
||||
return {
|
||||
"x_min": -half_width,
|
||||
"x_max": half_width,
|
||||
|
||||
@@ -630,7 +630,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
raise ValueError("factor is not a number")
|
||||
|
||||
if isinstance(factor, float):
|
||||
factor = int(factor * 100.0)
|
||||
factor = int(factor * 100)
|
||||
|
||||
if min_val and factor < min_val:
|
||||
raise ValueError("factor must be a value >={}".format(min_val))
|
||||
@@ -1134,7 +1134,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
if progress == 0:
|
||||
printTimeLeft = None
|
||||
printTimeLeftOrigin = None
|
||||
elif progress == 1.0:
|
||||
elif progress == 1:
|
||||
printTimeLeft = 0
|
||||
printTimeLeftOrigin = None
|
||||
elif estimator is not None:
|
||||
@@ -1180,7 +1180,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
return self._dict(
|
||||
count=self._comm.received_resends,
|
||||
transmitted=self._comm.transmitted_lines,
|
||||
ratio=int(self._comm.resend_ratio * 100.0),
|
||||
ratio=int(self._comm.resend_ratio * 100),
|
||||
)
|
||||
|
||||
def _addTemperatureData(self, tools=None, bed=None, chamber=None, custom=None):
|
||||
|
||||
@@ -797,7 +797,7 @@ class WsgiInputContainer:
|
||||
log_method = access_log.warning
|
||||
else:
|
||||
log_method = access_log.error
|
||||
request_time = 1000.0 * request.request_time()
|
||||
request_time = 1000 * request.request_time()
|
||||
summary = request.method + " " + request.uri + " (" + request.remote_ip + ")"
|
||||
log_method("%d %s %.2fms", status_code, summary, request_time)
|
||||
|
||||
|
||||
@@ -843,9 +843,9 @@ class ZTimelapse(Timelapse):
|
||||
and payload["old"] is not None
|
||||
and payload["new"] is not None
|
||||
):
|
||||
diff = round(abs(payload["new"] - payload["old"]), 3)
|
||||
zhop = round(self._retraction_zhop, 3)
|
||||
if diff == zhop:
|
||||
diff = abs(payload["new"] - payload["old"])
|
||||
zhop = self._retraction_zhop
|
||||
if abs(diff - zhop) < 0.001:
|
||||
return
|
||||
|
||||
# check if last picture has been less than min_delay ago, if so don't take a picture (anti vase mode...)
|
||||
@@ -1085,7 +1085,7 @@ class TimelapseRenderJob:
|
||||
current_time = _ffmpeg_current_regex.search(line)
|
||||
if current_time is not None and self._parsed_duration != 0:
|
||||
current_s = self._convert_time(*current_time.groups())
|
||||
progress = current_s / float(self._parsed_duration) * 100
|
||||
progress = current_s / self._parsed_duration * 100
|
||||
|
||||
# Update progress bar
|
||||
for callback in _update_callbacks:
|
||||
|
||||
@@ -333,9 +333,9 @@ def get_formatted_size(num):
|
||||
"""
|
||||
|
||||
for x in ["B", "KB", "MB", "GB"]:
|
||||
if num < 1024.0:
|
||||
if num < 1024:
|
||||
return "%3.1f%s" % (num, x)
|
||||
num /= 1024.0
|
||||
num /= 1024
|
||||
return "%3.1f%s" % (num, "TB")
|
||||
|
||||
|
||||
@@ -1732,7 +1732,7 @@ class PrependableQueue(queue.Queue):
|
||||
endtime = _time() + timeout
|
||||
while self._qsize() == self.maxsize:
|
||||
remaining = endtime - _time()
|
||||
if remaining <= 0.0:
|
||||
if remaining <= 0:
|
||||
raise queue.Full
|
||||
self.not_full.wait(remaining)
|
||||
self._prepend(item)
|
||||
@@ -1859,7 +1859,7 @@ def time_this(
|
||||
try:
|
||||
return f(*args, **kwargs)
|
||||
finally:
|
||||
timing = (time.time() - start) * 1000.0
|
||||
timing = (time.time() - start) * 1000
|
||||
func = fqfn(f)
|
||||
|
||||
lt = logtarget
|
||||
|
||||
@@ -654,7 +654,7 @@ class MachineCom:
|
||||
self._received_resend_requests = 0
|
||||
self._resend_ratio_start = settings().getInt(["serial", "resendRatioStart"])
|
||||
self._resend_ratio_threshold = (
|
||||
settings().getInt(["serial", "resendRatioThreshold"]) / 100.0
|
||||
settings().getInt(["serial", "resendRatioThreshold"]) / 100
|
||||
)
|
||||
self._resend_ratio_reported = False
|
||||
|
||||
@@ -4734,7 +4734,7 @@ class MachineCom:
|
||||
# may be busy, so give things a little time before we try again. Extend this
|
||||
# period each time we fail until either we write the data or run out of retry attempts.
|
||||
if passes > 1:
|
||||
time.sleep((passes - 1) / 10.0)
|
||||
time.sleep((passes - 1) / 10)
|
||||
|
||||
self._transmitted_lines += 1
|
||||
|
||||
@@ -5152,7 +5152,7 @@ class MachineCom:
|
||||
|
||||
_timeout = 0
|
||||
if p_match:
|
||||
_timeout = float(p_match.group("value")) / 1000.0
|
||||
_timeout = float(p_match.group("value")) / 1000
|
||||
elif s_match:
|
||||
_timeout = float(s_match.group("value"))
|
||||
|
||||
@@ -5383,7 +5383,7 @@ class PrintingFileInformation:
|
||||
"""
|
||||
if self._size is None or not self._size > 0:
|
||||
return -1
|
||||
return float(self._pos) / float(self._size)
|
||||
return self._pos / self._size
|
||||
|
||||
def reset(self):
|
||||
"""
|
||||
@@ -5592,8 +5592,8 @@ class StreamingGcodeFileInformation(PrintingGcodeFileInformation):
|
||||
if duration > 0 and read_lines > 0:
|
||||
stats = {
|
||||
"lines": read_lines,
|
||||
"rate": float(read_lines) / duration,
|
||||
"time_per_line": duration * 1000.0 / float(read_lines),
|
||||
"rate": read_lines / duration,
|
||||
"time_per_line": duration * 1000 / read_lines,
|
||||
"duration": duration,
|
||||
}
|
||||
self._logger.info(
|
||||
|
||||
@@ -279,9 +279,9 @@ class gcode:
|
||||
readBytes += len(line.encode("utf-8"))
|
||||
|
||||
if isinstance(gcodeFile, (io.IOBase, codecs.StreamReaderWriter)):
|
||||
percentage = float(readBytes) / float(self._fileSize)
|
||||
percentage = readBytes / self._fileSize
|
||||
elif isinstance(gcodeFile, (list)):
|
||||
percentage = float(lineNo) / float(len(gcodeFile))
|
||||
percentage = lineNo / len(gcodeFile)
|
||||
else:
|
||||
percentage = None
|
||||
|
||||
@@ -416,10 +416,10 @@ class gcode:
|
||||
elif G == 4: # Delay
|
||||
S = getCodeFloat(line, "S")
|
||||
if S is not None:
|
||||
totalMoveTimeMinute += S / 60.0
|
||||
totalMoveTimeMinute += S / 60
|
||||
P = getCodeFloat(line, "P")
|
||||
if P is not None:
|
||||
totalMoveTimeMinute += P / 60.0 / 1000.0
|
||||
totalMoveTimeMinute += P / 60 / 1000
|
||||
elif G == 10: # Firmware retract
|
||||
totalMoveTimeMinute += fwretractTime
|
||||
elif G == 11: # Firmware retract recover
|
||||
@@ -427,7 +427,7 @@ class gcode:
|
||||
elif G == 20: # Units are inches
|
||||
scale = 25.4
|
||||
elif G == 21: # Units are mm
|
||||
scale = 1.0
|
||||
scale = 1
|
||||
elif G == 28: # Home
|
||||
x = getCodeFloat(line, "X")
|
||||
y = getCodeFloat(line, "Y")
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ class Callback(object):
|
||||
|
||||
def calculate_next_run(self):
|
||||
"""Caltulate next scheduled run"""
|
||||
return time.time() + self.callback_time / 1000.0
|
||||
return time.time() + self.callback_time / 1000
|
||||
|
||||
def start(self, timeout=None):
|
||||
"""Start callbacks"""
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ class MovingAverage(object):
|
||||
if streamlen == 0:
|
||||
self.last_average = 0
|
||||
else:
|
||||
self.last_average = self.sum / float(streamlen)
|
||||
self.last_average = self.sum / streamlen
|
||||
|
||||
|
||||
class StatsCollector(object):
|
||||
|
||||
@@ -253,7 +253,7 @@ class TestSettings(unittest.TestCase):
|
||||
|
||||
def test_get_float(self):
|
||||
with self.mocked_config():
|
||||
expected_serial_timeout = 1.0
|
||||
expected_serial_timeout = 1
|
||||
|
||||
settings = octoprint.settings.Settings()
|
||||
|
||||
|
||||
@@ -225,9 +225,9 @@ class TimelapseTest(unittest.TestCase):
|
||||
"0: Video: mpeg2video, yuv420p, 640x480, q=2-31, 10000 kb/s, 90k tbn, 25 tbc"
|
||||
)
|
||||
progress1Str = "frame= 134 fps=0.0 q=1.6 size= 1528kB time=00:00:05.28 bitrate=2370.7kbits/s dup=80 drop=0 " # 5s elapsed
|
||||
expectedProgress1 = 5.0 / 18.0 * 100.0
|
||||
expectedProgress1 = 5 / 18 * 100
|
||||
progress2Str = "frame= 274 fps=270 q=2.0 size= 2748kB time=00:00:10.88 bitrate=2069.1kbits/s dup=164 drop=0 " # 10s elapsed
|
||||
expectedProgress2 = 10.0 / 18.0 * 100.0
|
||||
expectedProgress2 = 10 / 18 * 100
|
||||
|
||||
# Callback mock
|
||||
callback = mock.MagicMock()
|
||||
|
||||
Reference in new issue
Block a user