Merge pull request #3978 from eumiro/py2numbers
🦕 Remove the redundant Python2 float conversion relics
This commit is contained in:
14 files changed
+44
-43
No files matched your search
@@ -136,6 +136,7 @@ date of first contribution):
|
||||
* ["shadycuz"](https://github.com/shadycuz)
|
||||
* [David Rifkind](https://github.com/drifkind)
|
||||
* [Nils Hofmann](https://github.com/Master92)
|
||||
* [Miroslav Šedivý](https://github.com/eumiro)
|
||||
|
||||
OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by
|
||||
[Daid Braam](https://github.com/daid). Parts of its communication layer and
|
||||
|
||||
@@ -1358,7 +1358,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]:
|
||||
|
||||
@@ -809,7 +809,7 @@ class VirtualPrinter(object):
|
||||
# noinspection PyUnusedLocal
|
||||
def _gcode_G20(self, data):
|
||||
# type: (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:
|
||||
@@ -866,7 +866,7 @@ class VirtualPrinter(object):
|
||||
|
||||
_timeout = 0
|
||||
if matchP:
|
||||
_timeout = float(matchP.group(1)) / 1000.0
|
||||
_timeout = float(matchP.group(1)) / 1000
|
||||
elif matchS:
|
||||
_timeout = float(matchS.group(1))
|
||||
|
||||
@@ -1639,8 +1639,8 @@ class VirtualPrinter(object):
|
||||
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:
|
||||
@@ -1653,10 +1653,10 @@ class VirtualPrinter(object):
|
||||
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:
|
||||
@@ -1670,10 +1670,10 @@ class VirtualPrinter(object):
|
||||
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:
|
||||
@@ -1687,10 +1687,10 @@ class VirtualPrinter(object):
|
||||
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:
|
||||
@@ -1705,10 +1705,10 @@ class VirtualPrinter(object):
|
||||
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:
|
||||
@@ -2295,7 +2295,7 @@ class CharCountingQueue(queue.Queue):
|
||||
endtime = monotonic_time() + timeout
|
||||
while not self._will_it_fit(item):
|
||||
remaining = endtime - monotonic_time()
|
||||
if remaining <= 0.0:
|
||||
if remaining <= 0:
|
||||
raise queue.Full
|
||||
self.not_full.wait(remaining)
|
||||
|
||||
|
||||
@@ -796,8 +796,8 @@ class PrinterProfileManager(object):
|
||||
@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,
|
||||
|
||||
@@ -634,7 +634,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))
|
||||
@@ -1138,7 +1138,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:
|
||||
@@ -1184,7 +1184,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):
|
||||
|
||||
@@ -814,7 +814,7 @@ class WsgiInputContainer(object):
|
||||
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)
|
||||
|
||||
|
||||
@@ -1097,7 +1097,7 @@ class TimelapseRenderJob(object):
|
||||
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:
|
||||
|
||||
@@ -347,9 +347,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")
|
||||
|
||||
|
||||
@@ -1779,7 +1779,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)
|
||||
@@ -1908,7 +1908,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
|
||||
|
||||
@@ -667,7 +667,7 @@ class MachineCom(object):
|
||||
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
|
||||
|
||||
@@ -4750,7 +4750,7 @@ class MachineCom(object):
|
||||
# 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
|
||||
|
||||
@@ -5169,7 +5169,7 @@ class MachineCom(object):
|
||||
|
||||
_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"))
|
||||
|
||||
@@ -5400,7 +5400,7 @@ class PrintingFileInformation(object):
|
||||
"""
|
||||
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):
|
||||
"""
|
||||
@@ -5609,8 +5609,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(
|
||||
|
||||
@@ -282,9 +282,9 @@ class gcode(object):
|
||||
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
|
||||
|
||||
@@ -387,7 +387,7 @@ class gcode(object):
|
||||
e -= currentE[currentExtruder]
|
||||
|
||||
# If move with extrusion, calculate new min/max coordinates of model
|
||||
if e > 0.0 and move:
|
||||
if e > 0 and move:
|
||||
# extrusion and move -> oldPos & pos relevant for print area & dimensions
|
||||
self._minMax.record(oldPos)
|
||||
self._minMax.record(pos)
|
||||
@@ -405,7 +405,7 @@ class gcode(object):
|
||||
currentE[i] += e
|
||||
maxExtrusion[i] = max(maxExtrusion[i], totalExtrusion[i])
|
||||
else:
|
||||
e = 0.0
|
||||
e = 0
|
||||
|
||||
# move time in x, y, z, will be 0 if no movement happened
|
||||
moveTimeXYZ = abs((oldPos - pos).length / feedrate)
|
||||
@@ -419,10 +419,10 @@ class gcode(object):
|
||||
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
|
||||
|
||||
+1
-1
@@ -37,7 +37,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):
|
||||
|
||||
Vendored
+2
-2
@@ -453,7 +453,7 @@ class DNSRecord(DNSEntry):
|
||||
|
||||
def get_remaining_ttl(self, now):
|
||||
"""Returns the remaining TTL in seconds."""
|
||||
return max(0, (self._expiration_time - now) / 1000.0)
|
||||
return max(0, (self._expiration_time - now) / 1000)
|
||||
|
||||
def is_expired(self, now):
|
||||
"""Returns true if this record has expired."""
|
||||
@@ -1820,7 +1820,7 @@ class Zeroconf(QuietLogger):
|
||||
"""Calling thread waits for a given number of milliseconds or
|
||||
until notified."""
|
||||
with self.condition:
|
||||
self.condition.wait(timeout / 1000.0)
|
||||
self.condition.wait(timeout / 1000)
|
||||
|
||||
def notify_all(self):
|
||||
"""Notifies all waiting threads"""
|
||||
|
||||
@@ -233,9 +233,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