From 9e4b9885bac668494e8756c3e1a956ea441a7da8 Mon Sep 17 00:00:00 2001 From: Naoto Tsukamoto Date: Sat, 10 Jun 2023 17:12:24 +0900 Subject: [PATCH] 2023/06/09 change --- database_talker/scripts/hoge.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/database_talker/scripts/hoge.py b/database_talker/scripts/hoge.py index e11b5a962b..34820e01f7 100644 --- a/database_talker/scripts/hoge.py +++ b/database_talker/scripts/hoge.py @@ -111,7 +111,7 @@ def make_reply(self, message, lang="en", startdate=datetime.datetime.now(JST)-da # sort based on similarity with 'query' chat_msgs_sorted = sorted(results, key=lambda x: x['similarity'], reverse=True) - rospy.logerr("chat_msgs_sorted: {}".format(chat_msgs_sorted)) + #rospy.logerr("chat_msgs_sorted: {}".format(chat_msgs_sorted)) if len(chat_msgs_sorted) == 0: rospy.logwarn("no chat message was found") else: @@ -195,6 +195,7 @@ def make_reply(self, message, lang="en", startdate=datetime.datetime.now(JST)-da # make prompt prompt = 'if you are a pet and someone tells you \"' + message + '\" when we went together, ' + \ + 'and ' + 'you remembered that someone said "' + self.translate(text, dest="en").text + '" ' + \ 'and ' + reaction + ' in your memory of that moment, what would you reply? '+ \ 'Show only the reply in {lang}'.format(lang={'en': 'English', 'ja':'Japanese'}[lang]) loop = 0 @@ -251,7 +252,7 @@ def write_image_with_annotation(self, filename, best_result, prompt, smach_state rospy.logwarn("save images to {}".format(filename)) - def query_dialogflow(self, query, start_time, end_time, limit=30, threshold=0.0): + def query_dialogflow(self, query, start_time, end_time, limit=100, threshold=0.0): results = [] for message_type, message_value in [('dialogflow_task_executive/DialogTextActionResult', 'msg.result.response.query'), ('smach_msgs/SmachContainerStatus', 'msg.active_states[0].lower()'), @@ -283,6 +284,8 @@ def query_dialogflow(self, query, start_time, end_time, limit=30, threshold=0.0) msg = deserialise_message(msg) meta = json.loads(meta.pairs[0].second) timestamp = datetime.datetime.fromtimestamp(meta['timestamp']//1000000000, JST) + ### kei okada 2023/06/09 + timestamp = datetime.datetime.fromtimestamp(meta['inserted_at']['$date']//1000, JST) message = eval(message_value) if len(messages) > 0: message_translate = messages.pop(0).strip() @@ -306,14 +309,25 @@ def query_dialogflow(self, query, start_time, end_time, limit=30, threshold=0.0) if msg.result.response.action in ['make_reply', 'input.unknown']: rospy.logwarn("Found dialogflow messages {}({}) at {} but skipping (action:{})".format(result['message'], result['message_translate'], result['timestamp'].strftime('%Y-%m-%d %H:%M:%S'), msg.result.response.action)) else: - rospy.loginfo("Found dialogflow messages {}({}) ({}) at {} ({}:{:.2f})".format(result['message'], result['message_translate'], msg.result.response.action, result['timestamp'].strftime('%Y-%m-%d %H:%M:%S'), query, result['similarity'])) + query_info = "Found dialogflow messages {}({}) ({}) at {} ({}:{:.2f})".format(result['message'], result['message_translate'], msg.result.response.action, result['timestamp'].strftime('%Y-%m-%d %H:%M:%S'), query, result['similarity']) if ( result['similarity'] > threshold): + rospy.loginfo(query_info) results.append(result) else: + rospy.logwarn(query_info) rospy.logwarn(" ... skipping (threshold: {:.2f})".format(threshold)) else: result.update({'action': ''}) - rospy.loginfo("Found {} messages {}({}) at {} ({}:{:.2f})".format(message_type.split('/')[1], result['message'], result['message_translate'], result['timestamp'].strftime('%Y-%m-%d %H:%M:%S'), query, result['similarity'])) + if message_type == 'sound_play/SoundRequestActionGoal': + if any([x in msg.goal_id.id for x in ['/dialogflow_client', 'nav_speak', 'move_base', 'audible_warning', 'tweet_client']]): + # rospy.logwarn("Found {} messages {}({}) at {} ({}:{:.2f})".format(message_type.split('/')[1], result['message'], result['message_translate'], result['timestamp'].strftime('%Y-%m-%d %H:%M:%S'), query, result['similarity'])) + rospy.logwarn(" ... skipping ({})".format(msg.goal_id.id)) + continue + else: + rospy.loginfo("Found {} messages {}({}) at {} ({}:{:.2f}) from {}".format(message_type.split('/')[1], result['message'], result['message_translate'], result['timestamp'].strftime('%Y-%m-%d %H:%M:%S'), query, result['similarity'], msg.goal_id.id)) + + else: + rospy.loginfo("Found {} messages {}({}) at {} ({}:{:.2f})".format(message_type.split('/')[1], result['message'], result['message_translate'], result['timestamp'].strftime('%Y-%m-%d %H:%M:%S'), query, result['similarity'])) results.append(result)