-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery Starbot ⭐ refactored ClaasRostock/stgem #1
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to GitHub API limits, only the first 60 comments can be shown.
l = " " + l.lstrip() | ||
l = f" {l.lstrip()}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _normalize_docstring_lines
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
raise Exception("No path '{}'.".format(path)) | ||
raise Exception(f"No path '{path}'.") | ||
|
||
results = [] | ||
for dir, subdirs, files in os.walk(path): | ||
for file in files: | ||
if file.startswith(prefix): | ||
results.append(os.path.join(dir, file)) | ||
|
||
results.extend( | ||
os.path.join(dir, file) | ||
for file in files | ||
if file.startswith(prefix) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function collect_replica_files
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
) - Replace a for append loop with list extend (
for-append-to-extend
)
results = [] | ||
for file in files: | ||
results.append(STGEMResult.restore_from_file(file)) | ||
|
||
results = [STGEMResult.restore_from_file(file) for file in files] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function load_results
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
)
raise Exception("Empty experiment for prefix '{}' for benchmark '{}'.".format(prefix, benchmark)) | ||
raise Exception( | ||
f"Empty experiment for prefix '{prefix}' for benchmark '{benchmark}'." | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function loadExperiments
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
c = 0 | ||
for result in experiment: | ||
c += 1 if any(step.success for step in result.step_results) else 0 | ||
|
||
c = sum( | ||
1 if any(step.success for step in result.step_results) else 0 | ||
for result in experiment | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function falsification_rate
refactored with the following changes:
- Convert for loop into call to sum() (
sum-comprehension
)
) | ||
) | ||
step_2 = Search(mode=mode, | ||
budget_threshold={"executions": 300}, | ||
algorithm=OGAN(model_factory=(lambda: OGAN_Model(ogan_model_parameters["convolution"])), parameters=ogan_parameters) | ||
#algorithm=WOGAN(model_factory=(lambda: WOGAN_Model()) | ||
) | ||
#steps = [step_1] | ||
steps = [step_1, step_2] | ||
return steps | ||
return [step_1, step_2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function step_factory
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
#steps = [step_1]
) | ||
) | ||
step_2 = Search(mode=mode, | ||
budget_threshold={"executions": 300}, | ||
algorithm=OGAN(model_factory=(lambda: OGAN_Model(ogan_model_parameters["convolution"])), parameters=ogan_parameters), | ||
#algorithm=WOGAN(model_factory=(lambda: WOGAN_Model())), | ||
results_include_models=False | ||
) | ||
#steps = [step_1] | ||
steps = [step_1, step_2] | ||
return steps | ||
return [step_1, step_2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function step_factory
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
#steps = [step_1]
) | ||
) | ||
step_2 = Search(mode=mode, | ||
budget_threshold={"executions": 300}, | ||
algorithm=OGAN(model_factory=(lambda: OGAN_Model(ogan_model_parameters["convolution"])), parameters=ogan_parameters), | ||
#algorithm=WOGAN(model_factory=(lambda: WOGAN_Model())), | ||
results_include_models=False | ||
) | ||
#steps = [step_1] | ||
steps = [step_1, step_2] | ||
return steps | ||
return [step_1, step_2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function step_factory
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
#steps = [step_1]
# Notice that here the input is a vector. | ||
if selected_specification == "F16": | ||
specification = "always[0,15] ALTITUDE > 0" | ||
|
||
specifications = [specification] | ||
strict_horizon_check = True | ||
else: | ||
raise Exception("Unknown specification '{}'.".format(selected_specification)) | ||
if selected_specification != "F16": | ||
raise Exception(f"Unknown specification '{selected_specification}'.") | ||
|
||
specifications = ["always[0,15] ALTITUDE > 0"] | ||
strict_horizon_check = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function build_specification
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Inline variable that is only used once (
inline-variable
) - Replace call to format with f-string (
use-fstring-for-formatting
)
This removes the following comments ( why? ):
# Notice that here the input is a vector.
) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function step_factory
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
#steps = [step_1]
if not "initial_altitude" in self.parameters: | ||
if "initial_altitude" not in self.parameters: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function F16GCAS_PYTHON2.__init__
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
if not "initial_altitude" in self.parameters: | ||
if "initial_altitude" not in self.parameters: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function F16GCAS_PYTHON3.__init__
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
assert Nz <= self.ctrlLimits.NzMax, "autopilot commanded too low Nz ({})".format(Nz) | ||
assert Nz >= self.ctrlLimits.NzMin, "autopilot commanded too high Nz ({})".format(Nz) | ||
assert Nz <= self.ctrlLimits.NzMax, f"autopilot commanded too low Nz ({Nz})" | ||
assert Nz >= self.ctrlLimits.NzMin, f"autopilot commanded too high Nz ({Nz})" | ||
|
||
u_ref = np.array([Nz, ps, Ny_r, throttle], dtype=float) | ||
|
||
return u_ref | ||
return np.array([Nz, ps, Ny_r, throttle], dtype=float) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Autopilot.get_u_ref
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
man_start = 2 # maneuver starts after 2 seconds | ||
|
||
if self.state == GcasAutopilot.STATE_START: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function GcasAutopilot.advance_discrete_state
refactored with the following changes:
- Move assignments closer to their usage (
move-assign
)
vals = [] | ||
|
||
for col in cols: | ||
vals.append(mat[row, col]) | ||
|
||
vals = [mat[row, col] for col in cols] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function subindex_mat
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
)
num_plots = sum([len(var_data) for _, var_data in plot_data_list]) | ||
num_plots = sum(len(var_data) for _, var_data in plot_data_list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function plot2d
refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator
)
rt = 1.0 | ||
return 1.0 | ||
elif dp >= 50: | ||
rt = .1 | ||
return .1 | ||
else: | ||
rt = 1.9 - .036 * dp | ||
|
||
return rt | ||
return 1.9 - .036 * dp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function rtau
refactored with the following changes:
- Lift return into if (
lift-return-into-if
)
if thtl <= .77: | ||
tg = 64.94 * thtl | ||
else: | ||
tg = 217.38 * thtl - 117.38 | ||
|
||
return tg | ||
return 64.94 * thtl if thtl <= .77 else 217.38 * thtl - 117.38 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function tgear
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
thrst = tidl + (tmil - tidl) * power * .02 | ||
return tidl + (tmil - tidl) * power * .02 | ||
else: | ||
s = c[i, m] * cdh + c[i + 1, m] * dh | ||
t = c[i, m + 1] * cdh + c[i + 1, m + 1] * dh | ||
tmax = s + (t - s) * dm | ||
thrst = tmil + (tmax - tmil) * (power - 50) * .02 | ||
|
||
return thrst | ||
return tmil + (tmax - tmil) * (power - 50) * .02 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function thrust
refactored with the following changes:
- Lift return into if (
lift-return-into-if
)
raise TypeError("{} does not contain attribute '{}' (object was frozen)".format(self, key)) | ||
raise TypeError( | ||
f"{self} does not contain attribute '{key}' (object was frozen)" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Freezable.__setattr__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
if ele > 0: | ||
rv = int(floor(ele)) | ||
else: | ||
rv = int(ceil(ele)) | ||
|
||
return rv | ||
return int(floor(ele)) if ele > 0 else int(ceil(ele)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function fix
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
rv = -1 | ||
return -1 | ||
elif ele == 0: | ||
rv = 0 | ||
return 0 | ||
else: | ||
rv = 1 | ||
|
||
return rv | ||
return 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function sign
refactored with the following changes:
- Lift return into if (
lift-return-into-if
)
res = {} | ||
res['status'] = integrator.status | ||
res['times'] = times | ||
res['states'] = np.array(states, dtype=float) | ||
res['modes'] = modes | ||
|
||
res = { | ||
'status': integrator.status, | ||
'times': times, | ||
'states': np.array(states, dtype=float), | ||
'modes': modes, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function run_f16_sim
refactored with the following changes:
- Merge dictionary assignment with declaration [×4] (
merge-dict-assign
)
raise TypeError("{} does not contain attribute '{}' (object was frozen)".format(self, key)) | ||
raise TypeError( | ||
f"{self} does not contain attribute '{key}' (object was frozen)" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Freezable.__setattr__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
width = max(width, max([len(l) for l in col_labels])) | ||
width = max(width, max(len(l) for l in col_labels)) | ||
|
||
if row_labels is not None: | ||
width = max(width, max([len(l) for l in row_labels])) | ||
width = max(width, max(len(l) for l in row_labels)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function printmat
refactored with the following changes:
- Replace unneeded comprehension with generator [×2] (
comprehension-to-generator
) - Replace call to format with f-string (
use-fstring-for-formatting
)
rv = self.waypoint_index >= len(self.waypoints) and self.done_time + 5.0 < t | ||
|
||
return rv | ||
return self.waypoint_index >= len(self.waypoints) and self.done_time + 5.0 < t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function WaypointAutopilot.is_finished
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
horiz_range = np.linalg.norm(delta[0:2]) | ||
horiz_range = np.linalg.norm(delta[:2]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function WaypointAutopilot.get_waypoint_data
refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index
)
if abs(phi): # if cos(phi) ~= 0, basically | ||
nz = 1 / cos(phi) - 1 # Keeps plane at altitude | ||
else: | ||
nz = 0 | ||
|
||
return nz | ||
return 1 / cos(phi) - 1 if abs(phi) else 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_nz_for_level_turn_ol
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
# Keeps plane at altitude
# if cos(phi) ~= 0, basically
gamma = asin((cos(alpha)*sin(theta)- \ | ||
sin(alpha)*cos(theta)*cos(phi))*cos(beta) - \ | ||
(cos(theta)*sin(phi))*sin(beta)) | ||
|
||
return gamma | ||
return asin( | ||
(cos(alpha) * sin(theta) - sin(alpha) * cos(theta) * cos(phi)) | ||
* cos(beta) | ||
- (cos(theta) * sin(phi)) * sin(beta) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_path_angle
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
assert f16_model in ['stevens', 'morelli'], 'Unknown F16_model: {}'.format(f16_model) | ||
assert f16_model in ['stevens', 'morelli'], f'Unknown F16_model: {f16_model}' | ||
|
||
x_ctrl, u_deg = llc.get_u_deg(u_ref, x_f16) | ||
|
||
# Note: Control vector (u) for subF16 is in units of degrees | ||
xd_model, Nz, Ny, _, _ = subf16_model(x_f16[0:13], u_deg, f16_model) | ||
xd_model, Nz, Ny, _, _ = subf16_model(x_f16[:13], u_deg, f16_model) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function controlled_f16
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] [×2] (
remove-redundant-slice-index
)
This removes the following comments ( why? ):
# inner-loop commands are 4-7
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
main
branch, then run: