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

PTDM subscribes to relevant events only #590

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

jcapona
Copy link
Contributor

@jcapona jcapona commented Nov 11, 2022

Main changes

Improve PTDMSubscribeClient structure by only subscribing to the events that were marked as relevant according to the dictionary passed to the initialise method. By doing this, overhead is reduced since it's not necessary to filter the received messages once they're received since now when that happens, we're 100% sure it's from an event we're interested in.

Couldn't remove the polling since this is required to stop the PTDMSubscribeClient's internal thread.

Screenshots (feature, test output, profiling, dev tools etc)

[insert screenshots here]

Other notes (e.g. implementation quirks, edge cases, questions / issues)

Manual testing tips

Tag anyone who definitely needs to review or help

@codecov
Copy link

codecov bot commented Nov 11, 2022

Codecov Report

Base: 0.00% // Head: 60.51% // Increases project coverage by +60.51% 🎉

Coverage data is based on head (bd81adb) compared to base (1bf3128).
Patch coverage: 72.00% of modified lines in pull request are covered.

❗ Current head bd81adb differs from pull request most recent head 2873910. Consider uploading reports for the commit 2873910 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           master     #590       +/-   ##
===========================================
+ Coverage        0   60.51%   +60.51%     
===========================================
  Files           0      147      +147     
  Lines           0     7325     +7325     
===========================================
+ Hits            0     4433     +4433     
- Misses          0     2892     +2892     
Flag Coverage Δ
unittests 60.51% <72.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/miniscreen/pitop/miniscreen/miniscreen.py 46.77% <0.00%> (ø)
packages/common/pitop/common/ptdm.py 91.31% <81.81%> (ø)
packages/pma/pitop/pma/imu_controller.py 32.72% <0.00%> (ø)
packages/common/pitop/common/bitwise_ops.py 98.14% <0.00%> (ø)
...ges/robotics/pitop/robotics/pan_tilt_controller.py 81.48% <0.00%> (ø)
...ges/robotics/pitop/robotics/simple_pid/__init__.py 100.00% <0.00%> (ø)
packages/miniscreen/pitop/miniscreen/__init__.py 100.00% <0.00%> (ø)
packages/camera/pitop/camera/core/__init__.py 100.00% <0.00%> (ø)
packages/pma/pitop/pma/servo_motor.py 67.67% <0.00%> (ø)
packages/system/pitop/system/pitop.py 100.00% <0.00%> (ø)
... and 139 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jcapona jcapona marked this pull request as ready for review November 14, 2022 23:22

def invoke_callback_func_if_exists(self, callback, params=list()):
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm not sure but this looks like it would have the same issue as using [] as a default, that the same list is actually reused each time. probably not an issue since you don't mutate it, but I still think it's better practice to use None as the default and then have like params = list() if params is None else params

https://nikos7am.com/posts/mutable-default-arguments/

Copy link
Contributor

Choose a reason for hiding this comment

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

also, not new things but:

  • the naming of this function is confusing me - it doesn't check wether the callback exists it just calls it?
  • below is if params == list() just a weird way to check if the list is empty? usually people check the length?

self._zmq_socket.setsockopt_string(zmq.SUBSCRIBE, "")

for message_id in self._callback_funcs.keys():
self._zmq_socket.setsockopt(zmq.SUBSCRIBE, str(message_id).encode())
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

else:
func(params)
callback(params)
Copy link
Contributor

@angusjfw angusjfw Nov 16, 2022

Choose a reason for hiding this comment

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

codecov seems to say this method isn't tested at all - maybe you could quickly add one where the callback is actually called?

Copy link
Contributor

@angusjfw angusjfw left a comment

Choose a reason for hiding this comment

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

the message filtering thing seems to make sense and be correct to me, but it seems like you have removed parts of the test that actually check the callbacks work

@jcapona jcapona force-pushed the ptdm-subscribes-to-relevant-events branch 2 times, most recently from bc36a83 to 6f30d65 Compare December 7, 2022 13:35
@jcapona jcapona force-pushed the ptdm-subscribes-to-relevant-events branch from 6f30d65 to 2873910 Compare December 7, 2022 13:48
@jcapona jcapona marked this pull request as draft December 20, 2022 12:58
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