fixed items from code review

This commit is contained in:
Félix Boisselier
2024-06-11 21:26:15 +02:00
parent 6d1e53d4d1
commit ecd57ea3dc
21 changed files with 52 additions and 122 deletions

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# Common functions for the Shake&Tune package
# Written by Frix_x#0161 #
@@ -35,9 +33,9 @@ def parse_log(logname):
# Check for a PSD file generated by Klipper and raise a warning
if cleaned_line.startswith('#freq,psd_x,psd_y,psd_z,psd_xyz'):
ConsoleOutput.print(
'Warning: %s does not contain raw accelerometer data. '
f'Warning: {logname} does not contain raw accelerometer data. '
'Please use the official Klipper script to process it instead. '
'It will be ignored by Shake&Tune!' % (logname,)
'It will be ignored by Shake&Tune!'
)
return None
@@ -48,8 +46,8 @@ def parse_log(logname):
if not header:
ConsoleOutput.print(
'Warning: file %s has an incorrect header and will be ignored by Shake&Tune!\n'
"Expected '#time,accel_x,accel_y,accel_z', but got '%s'." % (logname, header.strip())
f'Warning: file {logname} has an incorrect header and will be ignored by Shake&Tune!\n'
f"Expected '#time,accel_x,accel_y,accel_z', but got '{header.strip()}'."
)
return None
@@ -57,8 +55,8 @@ def parse_log(logname):
data = np.loadtxt(logname, comments='#', delimiter=',', skiprows=1)
if data.ndim == 1 or data.shape[1] != 4:
ConsoleOutput.print(
'Warning: %s does not have the correct data format; expected 4 columns. '
'It will be ignored by Shake&Tune!' % (logname,)
f'Warning: {logname} does not have the correct data format; expected 4 columns. '
'It will be ignored by Shake&Tune!'
)
return None

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# Classes to retrieve a couple of motors infos and extract the relevant information
# from the Klipper configuration and the TMC registers
# Written by Frix_x#0161 #
@@ -41,7 +39,7 @@ class Motor:
value_dict = new_value_dict
# Then gets merged all the thresholds into the same THRS virtual register
if register in ['TPWMTHRS', 'TCOOLTHRS']:
if register in {'TPWMTHRS', 'TCOOLTHRS'}:
existing_thrs = self._registers.get('THRS', {})
merged_values = {**existing_thrs, **value_dict}
self._registers['THRS'] = merged_values
@@ -97,10 +95,7 @@ class Motor:
if not differences['registers']:
del differences['registers']
if not differences:
return None
return differences
return None if not differences else differences
class MotorsConfigParser:
@@ -180,10 +175,7 @@ class MotorsConfigParser:
# Find and return the motor by its name
def get_motor(self, motor_name: str) -> Optional[Motor]:
for motor in self._motors:
if motor.name == motor_name:
return motor
return None
return next((motor for motor in self._motors if motor.name == motor_name), None)
# Get all the motor list at once
def get_motors(self) -> List[Motor]:

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# The logic in this file was "extracted" from Klipper's orignal resonance_tester.py file
# Courtesy of Dmitry Butyugin <dmbutyugin@google.com> for the original implementation