-
Notifications
You must be signed in to change notification settings - Fork 110
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
Remove all instances of MessageToDict #3405
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -3,8 +3,6 @@ | |||
|
||||
import textwrap | ||||
|
||||
from google.protobuf.json_format import MessageToDict | ||||
|
||||
from proto.import_all_protos import * | ||||
from software.py_constants import * | ||||
from software.thunderscope.constants import Colors, DepthValues | ||||
|
@@ -38,20 +36,17 @@ def __init__(self, name: str, buffer_size: int = 5) -> None: | |||
def refresh_graphics(self) -> None: | ||||
"""Update graphics in this layer""" | ||||
self.cached_world = self.world_buffer.get(block=False) | ||||
play_info = self.play_info_buffer.get(block=False) | ||||
play_info_dict = MessageToDict(play_info) | ||||
play_info = self.play_info_buffer.get(block=False).GetOptions() | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need to call Software/src/proto/parameters.proto Line 61 in 10bded3
|
||||
|
||||
self.__update_tactic_name_graphics( | ||||
self.cached_world.friendly_team, play_info_dict | ||||
) | ||||
self.__update_tactic_name_graphics(self.cached_world.friendly_team, play_info) | ||||
|
||||
def __update_tactic_name_graphics(self, team: Team, play_info_dict) -> None: | ||||
def __update_tactic_name_graphics(self, team: Team, play_info) -> None: | ||||
"""Update the GLGraphicsItems that display tactic data | ||||
|
||||
:param team: The team proto | ||||
:param play_info_dict: The dictionary containing play/tactic info | ||||
:param play_info: The dictionary containing play/tactic info | ||||
""" | ||||
tactic_assignments = play_info_dict["robotTacticAssignment"] | ||||
tactic_assignments = play_info.robotTacticAssignment() | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this doesn't quite work. The correct way access the robot tactic assignment field is: This will return a The function call will match the field from the definition of the proto parameters: Software/src/proto/play_info_msg.proto Line 18 in 10bded3
|
||||
|
||||
# Ensure we have the same number of graphics as robots | ||||
self.tactic_fsm_info_graphics.resize( | ||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,4 @@ | ||||||||||||||
from proto.play_info_msg_pb2 import PlayInfo | ||||||||||||||
from google.protobuf.json_format import MessageToDict | ||||||||||||||
from pyqtgraph.Qt.QtWidgets import * | ||||||||||||||
from proto.import_all_protos import * | ||||||||||||||
from software.thunderscope.common.common_widgets import set_table_data | ||||||||||||||
|
@@ -35,42 +34,42 @@ def __init__(self, buffer_size: int = 1) -> None: | |||||||||||||
|
||||||||||||||
def refresh(self) -> None: | ||||||||||||||
"""Update the play info widget with new play information""" | ||||||||||||||
playinfo = self.playinfo_buffer.get(block=False, return_cached=False) | ||||||||||||||
playinfo = self.playinfo_buffer.get( | ||||||||||||||
block=False, return_cached=False | ||||||||||||||
).GetOptions() | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need to call |
||||||||||||||
|
||||||||||||||
# Updating QTableWidget could be expensive, so we only update if there is new data | ||||||||||||||
if playinfo is None or playinfo == self.last_playinfo: | ||||||||||||||
return | ||||||||||||||
|
||||||||||||||
self.last_playinfo = playinfo | ||||||||||||||
|
||||||||||||||
play_info_dict = MessageToDict(playinfo) | ||||||||||||||
|
||||||||||||||
robot_ids = [] | ||||||||||||||
tactic_fsm_states = [] | ||||||||||||||
tactic_names = [] | ||||||||||||||
play_name = [] | ||||||||||||||
|
||||||||||||||
if "robotTacticAssignment" not in play_info_dict: | ||||||||||||||
if "robotTacticAssignment" not in playinfo: | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you can do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe try |
||||||||||||||
return | ||||||||||||||
|
||||||||||||||
num_rows = max( | ||||||||||||||
len(play_info_dict["robotTacticAssignment"]), | ||||||||||||||
len(play_info_dict["play"]["playState"]), | ||||||||||||||
len(playinfo.robotTacticAssignment()), | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you meant |
||||||||||||||
len(playinfo.play.playState()), | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be |
||||||||||||||
) | ||||||||||||||
|
||||||||||||||
# setting table size dynamically | ||||||||||||||
self.play_table.setRowCount(num_rows) | ||||||||||||||
|
||||||||||||||
for state in play_info_dict["play"]["playState"]: | ||||||||||||||
for state in playinfo.play().playstate(): | ||||||||||||||
play_name.append(state) | ||||||||||||||
|
||||||||||||||
for robot_id in sorted(play_info_dict["robotTacticAssignment"]): | ||||||||||||||
for robot_id in sorted(playinfo.robotTacticAssignment()): | ||||||||||||||
robot_ids.append(robot_id) | ||||||||||||||
tactic_fsm_states.append( | ||||||||||||||
play_info_dict["robotTacticAssignment"][robot_id]["tacticFsmState"] | ||||||||||||||
playinfo.robotTacticAssignment().robot_id().tacticFsmState() | ||||||||||||||
) | ||||||||||||||
tactic_names.append( | ||||||||||||||
play_info_dict["robotTacticAssignment"][robot_id]["tacticName"] | ||||||||||||||
playinfo.robotTacticAssignment().robot_id().tacticName() | ||||||||||||||
Comment on lines
+56
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these function calls should be updated. The field names should match the proto field names. You should take a look at the proto definition:
And take a look at the Python generated code reference guide: https://protobuf.dev/reference/python/python-generated/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for your reference, it should be something like this:
Software/src/proto/play_info_msg.proto Lines 12 to 16 in 10bded3
To get the tactic_name we do |
||||||||||||||
) | ||||||||||||||
|
||||||||||||||
set_table_data( | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
from google.protobuf.json_format import MessageToDict | ||
from pyqtgraph.Qt.QtWidgets import * | ||
from proto.import_all_protos import * | ||
from software.py_constants import SECONDS_PER_MICROSECOND, SECONDS_PER_MINUTE | ||
|
@@ -36,15 +35,13 @@ def __init__(self, buffer_size: int = 1) -> None: | |
|
||
def refresh(self) -> None: | ||
"""Update the referee info widget with new referee information""" | ||
referee = self.referee_buffer.get(block=False, return_cached=False) | ||
referee = self.referee_buffer.get(block=False, return_cached=False).GetOptions() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need to call |
||
# Updating QTableWidget could be expensive, so we only update if there is new data | ||
if referee is None: | ||
return | ||
|
||
referee_msg_dict = MessageToDict(referee) | ||
|
||
if not referee_msg_dict: | ||
if not referee: | ||
return | ||
|
||
Comment on lines
-46
to
45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this check is duplicated above, you can delete this now |
||
stage_time_left_s = ( | ||
|
@@ -54,27 +51,27 @@ def refresh(self) -> None: | |
f"Packet Timestamp: {round(float(referee_msg_dict['packetTimestamp']) * SECONDS_PER_MICROSECOND, 3)}\n" | ||
+ f"Stage Time Left: {int(stage_time_left_s / SECONDS_PER_MINUTE):02d}" | ||
+ f":{int(stage_time_left_s % SECONDS_PER_MINUTE):02d}\n" | ||
+ f"Stage: {referee_msg_dict['stage']}\n" | ||
+ f"Stage: {referee.stage()}\n" | ||
+ "Command: " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need a |
||
+ referee_msg_dict["command"] | ||
+ referee.command() | ||
+ "\n" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
+ f"Blue Team on Positive Half: {referee_msg_dict['blueTeamOnPositiveHalf']}\n" | ||
+ f"Blue Team on Positive Half: {referee.blueTeamOnPositiveHalf()}\n" | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here as well |
||
self.referee_info.setText(p) | ||
|
||
team_info = [] | ||
blue = [] | ||
yellow = [] | ||
|
||
for team_info_name in referee_msg_dict["blue"]: | ||
for team_info_name in referee.blue(): | ||
if team_info_name == "timeouts": | ||
team_info.append("remainingTimeouts") | ||
elif team_info_name == "goalkeeper": | ||
team_info.append("goalkeeperID") | ||
else: | ||
team_info.append(team_info_name) | ||
|
||
for team_info_name in referee_msg_dict["yellow"]: | ||
for team_info_name in referee.yellow(): | ||
if team_info_name in team_info: | ||
continue | ||
|
||
|
@@ -87,17 +84,17 @@ def refresh(self) -> None: | |
|
||
for info in team_info: | ||
if info == "yellowCardTimes": | ||
blue.append(self.parse_yellow_card_times(referee_msg_dict["blue"])) | ||
yellow.append(self.parse_yellow_card_times(referee_msg_dict["yellow"])) | ||
blue.append(self.parse_yellow_card_times(referee.blue())) | ||
yellow.append(self.parse_yellow_card_times(referee.yellow())) | ||
elif info == "remainingTimeouts": | ||
blue.append(referee_msg_dict["blue"]["timeouts"]) | ||
yellow.append(referee_msg_dict["yellow"]["timeouts"]) | ||
blue.append(referee.blue().timeouts()) | ||
yellow.append(referee.yellow().timeouts()) | ||
elif info == "goalkeeperID": | ||
blue.append(referee_msg_dict["blue"]["goalkeeper"]) | ||
yellow.append(referee_msg_dict["yellow"]["goalkeeper"]) | ||
blue.append(referee.blue().goalkeepers()) | ||
yellow.append(referee.yellow().goalkeeper()) | ||
else: | ||
blue.append(referee_msg_dict["blue"][info]) | ||
yellow.append(referee_msg_dict["yellow"][info]) | ||
blue.append(referee.blue().info()) | ||
yellow.append(referee.yellow().info()) | ||
|
||
Comment on lines
86
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you actually don't need the |
||
set_table_data( | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be nice to add type annotation
def __create_int_parameter_writable(key, value, descriptor):
todef __create_int_parameter_writable(key:str, value:int, descriptor:FieldDescriptor):
Also,
FieldDescriptor
could be found here:from google.protobuf.descriptor import FieldDescriptor