Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

spektrum-scanner: fix plot_rssi.py script #49

Merged
merged 1 commit into from
Oct 8, 2018

Conversation

smlng
Copy link
Member

@smlng smlng commented Oct 4, 2018

Adapt python script to comply with python coding conventions, i.e.
fixing error reported by flake8.

@smlng smlng requested a review from jnohlgard October 4, 2018 15:27
@smlng smlng mentioned this pull request Oct 4, 2018
Copy link
Member

@jnohlgard jnohlgard left a comment

Choose a reason for hiding this comment

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

See inline question

@@ -65,7 +66,7 @@ def plot_rssi(self, port):
tidx = int(timestamp / (self.dt * 1000000)) % (Z.shape[1])
except ValueError:
continue
logging.debug("data: tidx=%d if=%d t=%d", tidx, iface_id, timestamp)
logging.debug("data: tidx={} if={} cnt={} t={}".format(tidx, iface_id, count, timestamp))
Copy link
Member

Choose a reason for hiding this comment

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

Why is this change necessary?
The original statement avoids evaluating the format when logging is disabled, an insignificant performance difference here, but in other situations the impact can be noticeable.

Copy link
Member Author

Choose a reason for hiding this comment

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

mhm, I read/heard that the {} + format() notation is the more (?) pythonic way to do string formatting nowadays. And I added count so its used, otherwise flake8 complains about an unused variable - though we could also completely omit that.

Also, you really think performance is (that) critical? I mean this python typically runs on standard desktop PCs, right?�

Copy link
Member

Choose a reason for hiding this comment

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

Like I wrote, it does not make any difference here, but in general, it would be undesirable to evaluate the format string at all if it is going to be discarded anyway because of loglevel < LOG_DEBUG. To reduce the developer confusion and to adhere to best practices, I would prefer to stay with the recommended style of pushing the variables as arguments instead of preformatting the message.

Some relevant articles:
https://reinout.vanrees.org/weblog/2015/06/05/logging-formatting.html
https://www.reddit.com/r/Python/comments/387oog/when_will_logging_use_newstyle_string_formatting/
https://realpython.com/python-logging/#logging-variable-data

Copy link
Member Author

Choose a reason for hiding this comment

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

mhm, I see ...

@smlng smlng added the NEEDS SQUASHING Please squash before merge label Oct 5, 2018
@smlng
Copy link
Member Author

smlng commented Oct 5, 2018

@gebart addressed comments

Copy link
Member

@jnohlgard jnohlgard left a comment

Choose a reason for hiding this comment

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

Looks fine, untested ACK

@smlng
Copy link
Member Author

smlng commented Oct 8, 2018

I tested 😉

Adapt python script to comply with python coding conventions, i.e.
fixing error reported by flake8.
@smlng smlng force-pushed the pr/fix/plot_rssi branch from 08a30fb to 4998410 Compare October 8, 2018 14:30
@smlng smlng removed the NEEDS SQUASHING Please squash before merge label Oct 8, 2018
@smlng smlng merged commit 2abd9f3 into RIOT-OS:master Oct 8, 2018
@smlng smlng deleted the pr/fix/plot_rssi branch October 8, 2018 15:15
chrysn pushed a commit to chrysn-pull-requests/RIOT that referenced this pull request Sep 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants