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 refactored master branch #86

Closed
wants to merge 1 commit into from
Closed

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jul 28, 2021

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jul 28, 2021

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.44%.

Quality metrics Before After Change
Complexity 8.48 ⭐ 7.95 ⭐ -0.53 👍
Method Length 70.67 🙂 70.06 🙂 -0.61 👍
Working memory 9.81 🙂 9.75 🙂 -0.06 👍
Quality 62.04% 🙂 62.48% 🙂 0.44% 👍
Other metrics Before After Change
Lines 3254 3211 -43
Changed files Quality Before Quality After Quality Change
benchmark/benchmark_dev_team.py 48.16% 😞 48.16% 😞 0.00%
benchmark/benchmark_mixed.py 38.18% 😞 40.42% 😞 2.24% 👍
processscheduler/base.py 86.75% ⭐ 87.70% ⭐ 0.95% 👍
processscheduler/cost.py 83.67% ⭐ 85.13% ⭐ 1.46% 👍
processscheduler/jupyter_ui.py 71.52% 🙂 71.89% 🙂 0.37% 👍
processscheduler/problem.py 71.32% 🙂 72.23% 🙂 0.91% 👍
processscheduler/solution.py 41.45% 😞 40.10% 😞 -1.35% 👎
processscheduler/solver.py 40.92% 😞 41.78% 😞 0.86% 👍
processscheduler/task_constraint.py 72.68% 🙂 73.24% 🙂 0.56% 👍
test/test_indicator.py 74.01% 🙂 74.01% 🙂 0.00%
test/test_solver.py 75.22% ⭐ 75.16% ⭐ -0.06% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
processscheduler/solution.py SchedulingSolution.render_gantt_matplotlib 42 ⛔ 544 ⛔ 20 ⛔ 9.40% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
processscheduler/solver.py SchedulingSolver.build_solution 41 ⛔ 371 ⛔ 12 😞 19.77% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
processscheduler/solver.py SchedulingSolver.solve_optimize_incremental 29 😞 290 ⛔ 15 😞 22.30% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
processscheduler/solution.py SchedulingSolution.render_gantt_plotly 22 😞 283 ⛔ 16 ⛔ 25.54% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
processscheduler/solver.py SchedulingSolver.__init__ 19 😞 290 ⛔ 12 😞 32.75% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Comment on lines +88 to -93
# Teams and Resources
num_resource_a = 2
num_resource_b = 2

for num_dev_teams in N:
print("-> Num dev teams:", num_dev_teams)
# Teams and Resources
num_resource_a = 2
num_resource_b = 2

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 90-93 refactored with the following changes:

Comment on lines +88 to -92
MAX_TASKS_PER_PERIOD = 2
MAX_TASKS_IN_PROBLEM = 4
NB_WORKERS = 10
NB_TASKS_PER_WORKER = 10
for horizon in range(20, n, step):
MAX_TASKS_PER_PERIOD = 2
MAX_TASKS_IN_PROBLEM = 4
NB_WORKERS = 10
NB_TASKS_PER_WORKER = 10
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 89-122 refactored with the following changes:

assertions_str = "".join(["%s" % ass for ass in self.assertions])
assertions_str = "".join("%s" % ass for ass in self.assertions)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _NamedUIDObject.__repr__ refactored with the following changes:

Comment on lines -152 to +154
applied_vars = []
for constraint in list_of_optional_constraints:
applied_vars.append(constraint.applied)
applied_vars = [
constraint.applied for constraint in list_of_optional_constraints
]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ForceApplyNOptionalConstraints.__init__ refactored with the following changes:

y = []
for x_ in x:
y.append(self.f(x_))

y = [self.f(x_) for x_ in x]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _Cost.plot refactored with the following changes:

Comment on lines -92 to +96
tasks_to_return = {}
for task in tasks_not_unavailable:
if tasks_not_unavailable[task].scheduled:
tasks_to_return[task] = tasks_not_unavailable[task]
return tasks_to_return
return {
task: tasks_not_unavailable[task]
for task in tasks_not_unavailable
if tasks_not_unavailable[task].scheduled
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SchedulingSolution.get_scheduled_tasks refactored with the following changes:

Comment on lines -106 to +118
if self.problem.delta_time is not None:
if self.problem.start_time is not None:
problem_properties["problem_start_time"] = self.problem.start_time
problem_properties["problem_end_time"] = (
self.problem.start_time + self.horizon * self.problem.delta_time
)
else:
problem_properties["problem_start_time"] = time(0)
problem_properties["problem_end_time"] = (
self.horizon * self.problem.delta_time
)
else:
if self.problem.delta_time is None:
problem_properties["problem_start_time"] = None
problem_properties["problem_end_time"] = None
elif self.problem.start_time is not None:
problem_properties["problem_start_time"] = self.problem.start_time
problem_properties["problem_end_time"] = (
self.problem.start_time + self.horizon * self.problem.delta_time
)
else:
problem_properties["problem_start_time"] = time(0)
problem_properties["problem_end_time"] = (
self.horizon * self.problem.delta_time
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SchedulingSolution.to_json_string refactored with the following changes:

Comment on lines -192 to +191
colors = []
for _ in range(len(df)):
colors.append("#%02X%02X%02X" % (r(), r(), r()))

colors = ["#%02X%02X%02X" % (r(), r(), r()) for _ in df]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SchedulingSolution.render_gantt_plotly refactored with the following changes:

Comment on lines -336 to +332
if length == 0: # zero duration tasks, to be visible
bar_dimension = (start - 0.05, 0.1)
else:
bar_dimension = (start, length)
bar_dimension = (start - 0.05, 0.1) if length == 0 else (start, length)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SchedulingSolution.render_gantt_matplotlib.draw_broken_barh_with_text refactored with the following changes:

This removes the following comments ( why? ):

# zero duration tasks, to be visible

Comment on lines -267 to +273
new_task_solution.end_time = (
new_task_solution.start_time + new_task_solution.duration_time
)
else:
new_task_solution.start_time = (
new_task_solution.start * self._problem.delta_time
)
new_task_solution.end_time = (
new_task_solution.start_time + new_task_solution.duration_time
)

new_task_solution.end_time = (
new_task_solution.start_time + new_task_solution.duration_time
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SchedulingSolver.build_solution refactored with the following changes:

This removes the following comments ( why? ):

# should not be scheduled
# if will be set to False if the resource is an alternative worker
# by default, resource_should_be_assigned is set to True

Comment on lines -436 to +431
if max_recursion_depth is not None:
if depth > max_recursion_depth:
warnings.warn(
"maximum recursion depth exceeded. There might be a better solution."
)
break
if max_recursion_depth is not None and depth > max_recursion_depth:
warnings.warn(
"maximum recursion depth exceeded. There might be a better solution."
)
break
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SchedulingSolver.solve_optimize_incremental refactored with the following changes:

if offset > 0:
lower = task_before.end + offset
else:
lower = task_before.end
lower = task_before.end + offset if offset > 0 else task_before.end
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TaskPrecedence.__init__ refactored with the following changes:

  • Simplify conditional into switch-like form (switch)
  • Replace if statement with if expression (assign-if-exp)

Comment on lines -283 to +280
sched_vars = []
for task in list_of_optional_tasks:
sched_vars.append(task.scheduled)

sched_vars = [task.scheduled for task in list_of_optional_tasks]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ForceScheduleNOptionalTasks.__init__ refactored with the following changes:

Comment on lines -303 to +305
[
solution.indicators[indicator_id]
for indicator_id in solution.indicators
if "FlowTime" in indicator_id
]
solution.indicators[indicator_id]
for indicator_id in solution.indicators
if "FlowTime" in indicator_id
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestIndicator.get_sum_flowtime refactored with the following changes:

solution = solver.solve()
return solution
return solver.solve()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _solve_problem refactored with the following changes:

@codecov-commenter
Copy link

codecov-commenter commented Jul 28, 2021

Codecov Report

Merging #86 (053b4c9) into master (e0e3a01) will increase coverage by 0.15%.
The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #86      +/-   ##
==========================================
+ Coverage   94.96%   95.11%   +0.15%     
==========================================
  Files          30       30              
  Lines        3417     3380      -37     
==========================================
- Hits         3245     3215      -30     
+ Misses        172      165       -7     
Impacted Files Coverage Δ
processscheduler/jupyter_ui.py 44.50% <0.00%> (+1.42%) ⬆️
test/test_indicator.py 99.52% <ø> (ø)
processscheduler/solver.py 96.32% <66.66%> (+0.30%) ⬆️
processscheduler/base.py 94.54% <100.00%> (-0.20%) ⬇️
processscheduler/cost.py 85.36% <100.00%> (-0.69%) ⬇️
processscheduler/problem.py 97.12% <100.00%> (-0.12%) ⬇️
processscheduler/solution.py 94.59% <100.00%> (-0.33%) ⬇️
processscheduler/task_constraint.py 100.00% <100.00%> (ø)
test/test_solver.py 99.64% <100.00%> (-0.01%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e0e3a01...053b4c9. Read the comment docs.

@tpaviot tpaviot closed this Jul 29, 2021
@tpaviot tpaviot deleted the sourcery/master branch July 29, 2021 14:10
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.

None yet

2 participants