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

Compute can load (Sourcery refactored) #14

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

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Oct 29, 2022

Pull Request #13 refactored by Sourcery.

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

NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.

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 compute_can_load branch, then run:

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

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from AlejoPm03 October 29, 2022 19:55
Comment on lines -18 to +29
def convert_string(string: str) -> str:
if not isinstance(string, str):
def convert_string(self) -> str:
if not isinstance(self, str):
raise TypeError("`string` needs to be an integer type!")

string = string.upper()
string = string.replace(' ', '_')
string = normalize('NFKD', string)
string = string.encode('ASCII', 'ignore')
string = string.decode('ASCII')
string = re.sub('[^A-Z0-9_]+', '', string)
self = self.upper()
self = self.replace(' ', '_')
self = normalize('NFKD', self)
self = self.encode('ASCII', 'ignore')
self = self.decode('ASCII')
self = re.sub('[^A-Z0-9_]+', '', self)

return string
return self
Copy link
Author

Choose a reason for hiding this comment

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

Function Can.convert_string refactored with the following changes:

Comment on lines -31 to +32
def validate_byte(byte: int) -> bool:
if (byte < 0) | (byte > 8):
def validate_byte(self) -> bool:
if (self < 0) | (self > 8):
Copy link
Author

Choose a reason for hiding this comment

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

Function Can.validate_byte refactored with the following changes:

Comment on lines -37 to +38
def validate_bit(bit: int) -> bool:
if (bit < 0) | (bit > 8):
def validate_bit(self) -> bool:
if (self < 0) | (self > 8):
Copy link
Author

Choose a reason for hiding this comment

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

Function Can.validate_bit refactored with the following changes:

load = 0
for topic in self.topics:
load += topic.get_load(bitrate)
return load
return sum(topic.get_load(bitrate) for topic in self.topics)
Copy link
Author

Choose a reason for hiding this comment

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

Function Can.module.get_total_load refactored with the following changes:

Comment on lines -256 to +253

Copy link
Author

Choose a reason for hiding this comment

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

Found the following improvement in Function Can.export_csv:

Comment on lines -295 to +292
if not topic["id"] in load.keys():
if topic["id"] not in load:
Copy link
Author

Choose a reason for hiding this comment

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

Function Can.get_can_load_by_topic refactored with the following changes:

Comment on lines -326 to +330
if not topic["id"] in ids.keys():
if topic["id"] not in ids:
ids[topic["id"]] = 0
ids[topic["id"]] += self.get_topic_load(topic)

id = list(ids.keys())
id.sort()

load = []
for i in id:
load.append(ids[i])

axes[0][0].bar(range(0, len(id)), load, align='center', color='royalblue')
axes[0][0].set_xticks(range(0, len(id)))
id = sorted(ids.keys())
load = [ids[i] for i in id]
axes[0][0].bar(range(len(id)), load, align='center', color='royalblue')
axes[0][0].set_xticks(range(len(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 Can.plot_load refactored with the following changes:

ids = list(loads.keys())
ids.sort()
ids = sorted(loads.keys())
Copy link
Author

Choose a reason for hiding this comment

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

Lines 11-12 refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Oct 29, 2022

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 4.14 ⭐ 3.90 ⭐ -0.24 👍
Method Length 58.78 ⭐ 57.83 ⭐ -0.95 👍
Working memory 7.08 🙂 7.07 🙂 -0.01 👍
Quality 72.31% 🙂 72.70% 🙂 0.39% 👍
Other metrics Before After Change
Lines 369 360 -9
Changed files Quality Before Quality After Quality Change
can.py 71.68% 🙂 72.09% 🙂 0.41% 👍
main.py 86.69% ⭐ 87.45% ⭐ 0.76% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
can.py Can.plot_load 12 🙂 460 ⛔ 11 😞 37.06% 😞 Try splitting into smaller methods. Extract out complex expressions
can.py Can.export_csv 3 ⭐ 148 😞 14 😞 53.53% 🙂 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!

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.

0 participants