Compute can load (Sourcery refactored)#14
Compute can load (Sourcery refactored)#14sourcery-ai[bot] wants to merge 1 commit intocompute_can_loadfrom
Conversation
| 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 |
There was a problem hiding this comment.
Function Can.convert_string refactored with the following changes:
- The first argument to instance methods should be
self(instance-method-first-arg-name)
| def validate_byte(byte: int) -> bool: | ||
| if (byte < 0) | (byte > 8): | ||
| def validate_byte(self) -> bool: | ||
| if (self < 0) | (self > 8): |
There was a problem hiding this comment.
Function Can.validate_byte refactored with the following changes:
- The first argument to instance methods should be
self(instance-method-first-arg-name)
| def validate_bit(bit: int) -> bool: | ||
| if (bit < 0) | (bit > 8): | ||
| def validate_bit(self) -> bool: | ||
| if (self < 0) | (self > 8): |
There was a problem hiding this comment.
Function Can.validate_bit refactored with the following changes:
- The first argument to instance methods should be
self(instance-method-first-arg-name)
| for topic in self.topics: | ||
| load += topic.get_load(bitrate) | ||
| return load | ||
| return sum(topic.get_load(bitrate) for topic in self.topics) |
There was a problem hiding this comment.
Function Can.module.get_total_load refactored with the following changes:
- Convert for loop into call to sum() (
sum-comprehension) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
|
|
There was a problem hiding this comment.
Found the following improvement in Function Can.export_csv:
| if not topic["id"] in load.keys(): | ||
| if topic["id"] not in load: |
There was a problem hiding this comment.
Function Can.get_can_load_by_topic refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan) - Remove unnecessary call to keys() (
remove-dict-keys)
| 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))) |
There was a problem hiding this comment.
Function Can.plot_load refactored with the following changes:
- Remove unnecessary call to keys() [×2] (
remove-dict-keys) - Remove an unnecessary list construction call prior to sorting (
skip-sorted-list-construction) - Replace range(0, x) with range(x) [×4] (
remove-zero-from-range) - Convert for loop into list comprehension (
list-comprehension) - Simplify logical expression using De Morgan identities [×2] (
de-morgan)
| loads = can.get_can_load_by_topic() | ||
| ids = list(loads.keys()) | ||
| ids.sort() | ||
| ids = sorted(loads.keys()) |
There was a problem hiding this comment.
Lines 11-12 refactored with the following changes:
- Remove an unnecessary list construction call prior to sorting (
skip-sorted-list-construction)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.39%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
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! |
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_loadbranch, then run:Help us improve this pull request!