Skip to content

Commit

Permalink
✨ readd Attribute.msg
Browse files Browse the repository at this point in the history
  • Loading branch information
Rezenders committed Apr 26, 2024
1 parent 6b33386 commit e076a96
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
10 changes: 6 additions & 4 deletions ros_typedb/ros_typedb/ros_typedb_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import ros_typedb_msgs

from rcl_interfaces.msg import ParameterValue
from rcl_interfaces.msg import Parameter
from rclpy.callback_groups import MutuallyExclusiveCallbackGroup
from rclpy.callback_groups import ReentrantCallbackGroup
from rclpy.lifecycle import Node
Expand All @@ -26,6 +25,7 @@

from ros_typedb.typedb_interface import MatchResultDict
from ros_typedb.typedb_interface import TypeDBInterface
from ros_typedb_msgs.msg import Attribute
from ros_typedb_msgs.msg import QueryResult
from ros_typedb_msgs.srv import Query

Expand Down Expand Up @@ -85,8 +85,9 @@ def fetch_query_result_to_ros_msg(
for result in query_result:
_result = QueryResult()
for key, value_dict in result.items():
_attr = Parameter()
_attr = Attribute()
_attr.name = key
_attr.label = value_dict.get('type').get('label')
if 'value' in value_dict:
_attr.value = set_query_result_value(
value_dict.get('value'),
Expand All @@ -112,8 +113,9 @@ def get_query_result_to_ros_msg(
for variable in _variables:
if result.get(variable).is_attribute():
_typedb_attr = result.get(variable).as_attribute()
_attr = Parameter()
_attr = Attribute()
_attr.name = variable
_attr.label = _typedb_attr.get_type().get_label().name
_attr.value = set_query_result_value(
_typedb_attr.get_value(),
str(_typedb_attr.get_type().get_value_type()))
Expand All @@ -132,7 +134,7 @@ def get_aggregate_query_result_to_ros_msg(
:return: converted query response.
"""
response = Query.Response()
_attr = Parameter()
_attr = Attribute()
_attr.value = set_query_result_value(
query_result,
type(query_result).__name__)
Expand Down
18 changes: 11 additions & 7 deletions ros_typedb/test/test_ros_typedb_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,19 @@ def test_ros_typedb_fetch_query_attribute(insert_query):
correct_date = False
for result in query_res.results:
for r in result.attributes:
if r.name == 'nick' and r.value.string_value == 'test':
if r.name == 'nick' and r.label == 'nickname' and \
r.value.string_value == 'test':
correct_nick = True
if r.name == 'age' and r.value.integer_value == 33:
if r.name == 'age' and r.label == 'age' and \
r.value.integer_value == 33:
correct_age = True
if r.name == 'height' and r.value.double_value == 1.75:
if r.name == 'height' and r.label == 'height' and \
r.value.double_value == 1.75:
correct_height = True
if r.name == 'alive' and \
if r.name == 'alive' and r.label == 'alive' and \
r.value.bool_value is True:
correct_alive = True
if r.name == 'date' and \
if r.name == 'date' and r.label == 'birth-date' and \
r.value.string_value == '1990-06-01T00:00:00.000':
correct_date = True

Expand Down Expand Up @@ -285,9 +288,10 @@ def test_ros_typedb_get_query(insert_query):
correct_name = False
correct_email = False
for r in query_res.results[0].attributes:
if r.name == 'name' and r.value.string_value == 'Ahmed Frazier':
if r.name == 'name' and r.label == 'full-name' \
and r.value.string_value == 'Ahmed Frazier':
correct_name = True
if r.name == 'email' and \
if r.name == 'email' and r.label == 'email' and \
r.value.string_value == 'ahmed.frazier@gmail.com':
correct_email = True

Expand Down
1 change: 1 addition & 0 deletions ros_typedb_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ find_package(rcl_interfaces REQUIRED)
find_package(std_msgs REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
"msg/Attribute.msg"
"msg/QueryResult.msg"
"srv/Query.srv"
DEPENDENCIES std_msgs rcl_interfaces
Expand Down
2 changes: 1 addition & 1 deletion ros_typedb_msgs/msg/QueryResult.msg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rcl_interfaces/Parameter[] attributes
ros_typedb_msgs/Attribute[] attributes

0 comments on commit e076a96

Please sign in to comment.