Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SourceryAI
Copy link

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:

git fetch https://github.com/sourcery-ai-bot/stgem main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Copy link
Author

@SourceryAI SourceryAI left a 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()}"
Copy link
Author

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:

Comment on lines -22 to +30
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)
)
Copy link
Author

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:

Comment on lines -33 to +34
results = []
for file in files:
results.append(STGEMResult.restore_from_file(file))

results = [STGEMResult.restore_from_file(file) for file in files]
Copy link
Author

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:

raise Exception("Empty experiment for prefix '{}' for benchmark '{}'.".format(prefix, benchmark))
raise Exception(
f"Empty experiment for prefix '{prefix}' for benchmark '{benchmark}'."
)
Copy link
Author

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:

Comment on lines -60 to +63
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
)
Copy link
Author

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:

Comment on lines -105 to +113
)
)
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]
Copy link
Author

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:

This removes the following comments ( why? ):

#steps = [step_1]

Comment on lines -162 to +169
)
)
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]
Copy link
Author

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:

This removes the following comments ( why? ):

#steps = [step_1]

Comment on lines -131 to +138
)
)
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]
Copy link
Author

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:

This removes the following comments ( why? ):

#steps = [step_1]

Comment on lines -79 to +83
# 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
Copy link
Author

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:

This removes the following comments ( why? ):

# Notice that here the input is a vector.

Comment on lines -102 to +98
)
)
Copy link
Author

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:

This removes the following comments ( why? ):

#steps = [step_1]

if not "initial_altitude" in self.parameters:
if "initial_altitude" not in self.parameters:
Copy link
Author

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:
Copy link
Author

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)

Comment on lines -57 to +60
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)
Copy link
Author

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:

Comment on lines -103 to 105
man_start = 2 # maneuver starts after 2 seconds

if self.state == GcasAutopilot.STATE_START:
Copy link
Author

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:

vals = []

for col in cols:
vals.append(mat[row, col])

vals = [mat[row, col] for col in cols]
Copy link
Author

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:

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)
Copy link
Author

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:

Comment on lines -12 to +16
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
Copy link
Author

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:

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
Copy link
Author

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:

Comment on lines -69 to +74
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
Copy link
Author

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:

Comment on lines -19 to +21
raise TypeError("{} does not contain attribute '{}' (object was frozen)".format(self, key))
raise TypeError(
f"{self} does not contain attribute '{key}' (object was frozen)"
)
Copy link
Author

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:

Comment on lines -92 to +94
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))
Copy link
Author

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:

Comment on lines -103 to +104
rv = -1
return -1
elif ele == 0:
rv = 0
return 0
else:
rv = 1

return rv
return 1
Copy link
Author

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:

Comment on lines -123 to +128
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,
}
Copy link
Author

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:

Comment on lines -46 to +48
raise TypeError("{} does not contain attribute '{}' (object was frozen)".format(self, key))
raise TypeError(
f"{self} does not contain attribute '{key}' (object was frozen)"
)
Copy link
Author

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:

Comment on lines -138 to +143
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))
Copy link
Author

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:

Comment on lines -185 to +171
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
Copy link
Author

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:

Comment on lines -242 to +226
horiz_range = np.linalg.norm(delta[0:2])
horiz_range = np.linalg.norm(delta[:2])
Copy link
Author

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:

Comment on lines -255 to +239
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
Copy link
Author

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:

This removes the following comments ( why? ):

# Keeps plane at altitude
# if cos(phi) ~= 0, basically

Comment on lines -270 to +253
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)
)
Copy link
Author

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:

Comment on lines -22 to +27
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)
Copy link
Author

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:

This removes the following comments ( why? ):

# inner-loop commands are 4-7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant