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 #13

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Compute can load #13

wants to merge 8 commits into from

Conversation

AlejoPm03
Copy link
Member

Compute bus load with the size of the frame, message frequency, and bit rate
And implement figures to better analyzes

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 29, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.59%.

Quality metrics Before After Change
Complexity 1.73 ⭐ 2.51 ⭐ 0.78 👎
Method Length 183.82 😞 179.62 😞 -4.20 👍
Working memory 8.86 🙂 8.92 🙂 0.06 👎
Quality 60.12% 🙂 59.53% 🙂 -0.59% 👎
Other metrics Before After Change
Lines 2743 2959 216
Changed files Quality Before Quality After Quality Change
can.py 84.26% ⭐ 71.68% 🙂 -12.58% 👎
can_ids_generator.py 45.84% 😞 45.84% 😞 0.00%
main.py 97.34% ⭐ 86.69% ⭐ -10.65% 👎
test/test_can.py 85.80% ⭐ 85.17% ⭐ -0.63% 👎

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 13 🙂 482 ⛔ 11 😞 36.05% 😞 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
test/test_can.py test_can_topic.test_describe_bit 0 ⭐ 125 😞 7 🙂 72.38% 🙂 Try splitting into smaller methods

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!

@@ -53,6 +54,10 @@ def __init__(self, msg: str, id: int, description: str):

self.bytes = [None] * 8

self.frequency = frequency

self.frame_length = 47
Copy link
Member

Choose a reason for hiding this comment

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

why 47? Can you add a comment pointing to a source or explaining it.

return len(list(filter(lambda x: x is not None, self.bytes)))

def get_frame_length(self):
return 44 + 8 * self.get_length()
Copy link
Member

Choose a reason for hiding this comment

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

why 44 and 8? Can you add a comment pointing to a source or explaining it.

Comment on lines +10 to +15
loads = can.get_can_load_by_topic()
ids = list(loads.keys())
ids.sort()
for id in ids:
print("Id: ", id, "load:", loads[id])
print("Total load:", round(can.get_can_load(),3), "%")
Copy link
Member

Choose a reason for hiding this comment

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

Can you extract out these lines into a helper function?

Comment on lines +257 to +286
modules = []
signature = []
ids = []
names = []
frequency = []
load = []
frame_length = []
description = []

for module in self.modules:
for topic in module["topics"]:
modules.append(module["name"])
signature.append(module["signature"])
ids.append(topic["id"])
names.append(topic["name"])
frequency.append(round(topic["frequency"],3))
load.append(round(self.get_topic_load(topic),3))
frame_length.append(topic["frame_length"])
description.append(topic["description"])

df = pd.DataFrame({
"modules":modules,
"signature": signature,
"name": names,
"ids": ids,
"frequency": frequency,
"load": load,
"frame_length": frame_length,
"description": description,
})
Copy link
Member

@joaoantoniocardoso joaoantoniocardoso Oct 29, 2022

Choose a reason for hiding this comment

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

Since this data is small it is okay doing it this way, but note that for bigger data, possibly it would be better convert it to a DataFrame first, then group / add / remove columns as you need.

Comment on lines +312 to +314
# load = period for 1 msg * frequency * 100%
# Reference:
# https://support.vector.com/kb?id=kb_article_view&sysparm_article=KB0012332&sys_kb_id=99354e281b2614148e9a535c2e4bcb6d&spa=1
Copy link
Member

Choose a reason for hiding this comment

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

Always great to have references, move it on the beginning of the function

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.

2 participants