Skip to content

Commit 8c20dd1

Browse files
AmyKawapre-commit-ci-lite[bot]williamckha
authored
Remove all instances of MessageToDict (UBC-Thunderbots#3405)
* Removed all instances of messagetodict * [pre-commit.ci lite] apply automatic fixes * Changes made before updated branch * applied suggestions * [pre-commit.ci lite] apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: williamckha <williamha@outlook.com>
1 parent dd34bc9 commit 8c20dd1

4 files changed

Lines changed: 27 additions & 31 deletions

File tree

src/software/thunderscope/common/proto_parameter_tree_util.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pyqtgraph.Qt.QtWidgets import *
22
from pyqtgraph import parametertree
3-
from google.protobuf.json_format import MessageToDict
43
from thefuzz import fuzz
4+
from proto.import_all_protos import *
55
import netifaces
66

77

@@ -33,10 +33,13 @@ def __create_int_parameter_writable(key, value, descriptor):
3333
"""
3434
# Extract the options from the descriptor, and store it
3535
# in the dictionary.
36-
options = MessageToDict(descriptor.GetOptions(), preserving_proto_field_name=True)
36+
options = descriptor.GetOptions()
3737

3838
try:
39-
min_max = options["[TbotsProto.bounds]"]
39+
minimum, maximum = (
40+
options.Extensions[bounds].min_double_value,
41+
options.Extensions[bounds].max_double_value,
42+
)
4043
except KeyError:
4144
raise KeyError("{} missing ParameterRangeOptions".format(key))
4245

@@ -45,7 +48,7 @@ def __create_int_parameter_writable(key, value, descriptor):
4548
"type": "int",
4649
"value": value,
4750
"default": value,
48-
"limits": (int(min_max["min_int_value"]), int(min_max["max_int_value"])),
51+
"limits": (int(minimum), int(maximum)),
4952
"step": 1,
5053
}
5154

@@ -61,10 +64,13 @@ def __create_double_parameter_writable(key, value, descriptor):
6164
"""
6265
# Extract the options from the descriptor, and store it
6366
# in the dictionary.
64-
options = MessageToDict(descriptor.GetOptions(), preserving_proto_field_name=True)
67+
options = descriptor.GetOptions()
6568

6669
try:
67-
min_max = options["[TbotsProto.bounds]"]
70+
minimum, maximum = (
71+
options.Extensions[bounds].min_double_value,
72+
options.Extensions[bounds].max_double_value,
73+
)
6874
except KeyError:
6975
raise KeyError("{} missing ParameterRangeOptions".format(key))
7076

@@ -74,8 +80,8 @@ def __create_double_parameter_writable(key, value, descriptor):
7480
"value": value,
7581
"default": value,
7682
"limits": (
77-
min_max["min_double_value"],
78-
min_max["max_double_value"],
83+
minimum,
84+
maximum,
7985
),
8086
"step": 0.01,
8187
}

src/software/thunderscope/gl/layers/gl_tactic_layer.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
import textwrap
55

6-
from google.protobuf.json_format import MessageToDict
7-
86
from proto.import_all_protos import *
97
from software.py_constants import *
108
from software.thunderscope.constants import (
@@ -42,20 +40,17 @@ def __init__(self, name: str, buffer_size: int = 5) -> None:
4240
def refresh_graphics(self) -> None:
4341
"""Update graphics in this layer"""
4442
self.cached_world = self.world_buffer.get(block=False)
45-
play_info = self.play_info_buffer.get(block=False)
46-
play_info_dict = MessageToDict(play_info)
43+
play_info = self.play_info_buffer.get(block=False).bounds()
4744

48-
self.__update_tactic_name_graphics(
49-
self.cached_world.friendly_team, play_info_dict
50-
)
45+
self.__update_tactic_name_graphics(self.cached_world.friendly_team, play_info)
5146

52-
def __update_tactic_name_graphics(self, team: Team, play_info_dict) -> None:
47+
def __update_tactic_name_graphics(self, team: Team, play_info) -> None:
5348
"""Update the GLGraphicsItems that display tactic data
5449
5550
:param team: The team proto
56-
:param play_info_dict: The dictionary containing play/tactic info
51+
:param play_info: The dictionary containing play/tactic info
5752
"""
58-
tactic_assignments = play_info_dict["robotTacticAssignment"]
53+
tactic_assignments = play_info.robot_tactic_assignment()
5954

6055
# Ensure we have the same number of graphics as robots
6156
self.tactic_fsm_info_graphics.resize(

src/software/thunderscope/play/playinfo_widget.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from proto.play_info_msg_pb2 import PlayInfo
2-
from google.protobuf.json_format import MessageToDict
32
from pyqtgraph.Qt.QtWidgets import *
43
from proto.import_all_protos import *
54
from software.thunderscope.common.common_widgets import set_table_data
@@ -43,36 +42,32 @@ def refresh(self) -> None:
4342

4443
self.last_playinfo = playinfo
4544

46-
play_info_dict = MessageToDict(playinfo)
47-
4845
robot_ids = []
4946
tactic_fsm_states = []
5047
tactic_names = []
5148
play_name = []
5249

53-
if "robotTacticAssignment" not in play_info_dict:
50+
if not playinfo.robot_tactic_assignment:
5451
return
5552

5653
num_rows = max(
57-
len(play_info_dict["robotTacticAssignment"]),
58-
len(play_info_dict["play"]["playState"]),
54+
len(playinfo.robot_tactic_assignment),
55+
len(playinfo.play.play_state),
5956
)
6057

6158
# setting table size dynamically
6259
self.play_table.setRowCount(num_rows)
6360

64-
for state in play_info_dict["play"]["playState"]:
61+
for state in playinfo.play.play_state:
6562
play_name.append(state)
6663

67-
for robot_id in sorted(play_info_dict["robotTacticAssignment"]):
64+
for robot_id in sorted(playinfo.robot_tactic_assignment):
6865
robot_ids.append(robot_id)
6966
tactic_fsm_states.append(
70-
play_info_dict["robotTacticAssignment"][robot_id]["tacticFsmState"]
71-
)
72-
tactic_names.append(
73-
play_info_dict["robotTacticAssignment"][robot_id]["tacticName"]
67+
playinfo.robot_tactic_assignment[robot_id].tactic_fsm_state
7468
)
7569

70+
tactic_names.append(playinfo.robot_tactic_assignment[robot_id].tactic_name)
7671
set_table_data(
7772
{
7873
"Play": play_name,

src/software/thunderscope/play/refereeinfo_widget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from google.protobuf.json_format import MessageToDict
21
from pyqtgraph.Qt.QtWidgets import *
32
from proto.import_all_protos import *
43
from software.py_constants import SECONDS_PER_MICROSECOND, SECONDS_PER_MINUTE
54
from software.thunderscope.common.common_widgets import set_table_data
65
from software.thunderscope.thread_safe_buffer import ThreadSafeBuffer
6+
from google.protobuf.json_format import MessageToDict
77

88

99
class RefereeInfoWidget(QWidget):

0 commit comments

Comments
 (0)