def check_logs(config_params, test_duration, print_output=False): """Check the logs in mongodb and print the status. :config_params: black_box.config.ConfigParams :test_duration: float :print_output: bool :returns: None """ db_name = config_params.default.db_name collection_names = DBUtils.get_data_collection_names(db_name) # check if all topics are present in db fail = False size_status = [] if config_params.ros: for topic_params in config_params.ros.topic: topic_name = ConfigUtils.get_full_variable_name( "ros", topic_params.name) if topic_name not in collection_names: fail = True print(colored(topic_name + " not present in mongoDB", "red")) size_status.append({ 'collection': topic_name, 'expected_size': topic_params.max_frequency * test_duration, 'collection_size': 0 }) continue collection_size = len(DBUtils.get_all_docs(db_name, topic_name)) size_status.append({ 'collection': topic_name, 'expected_size': topic_params.max_frequency * test_duration, 'collection_size': collection_size }) if config_params.zyre: expected_size = test_duration * config_params.default.max_frequency for message_type in config_params.zyre.message_types: topic_name = ConfigUtils.get_full_variable_name( "zyre", message_type) if topic_name not in collection_names: fail = True print(colored(topic_name + " not present in mongoDB", "red")) size_status.append({ 'collection': topic_name, 'expected_size': expected_size, 'collection_size': 0 }) continue collection_size = len(DBUtils.get_all_docs(db_name, topic_name)) size_status.append({ 'collection': topic_name, 'expected_size': expected_size, 'collection_size': collection_size }) if not fail and print_output: print( colored("All topics have their respective collection in mongoDB", "green")) for comparison in size_status: color = "green" if comparison['expected_size'] == comparison[ 'collection_size'] else "red" string = comparison['collection'] + ': ' + str(comparison['collection_size']) \ + '/' + str(comparison['expected_size']) if print_output: print(colored(string, color)) return size_status
def test_get_all_docs(self): docs = DBUtils.get_all_docs(db_name=self.test_db_name, collection_name='ros_ropod_cmd_vel') self.assertEqual(len(docs), 149)
stdscr.refresh() if __name__ == '__main__': # rospy.init_node('rosbag_play') config_param = get_config_param() run_events = False parser = argparse.ArgumentParser(description="Play rosbag from mongo db") parser.add_argument('-db', help='name of the mongo db', default=config_param['db_name']) parser.add_argument('-e', '--events', action='store_true', help='Enable events playback') args = parser.parse_args() db_name = args.db if args.events and 'ros_ropod_event' in DBUtils.get_data_collection_names(db_name) \ and len(DBUtils.get_all_docs(db_name, 'ros_ropod_event')) > 0: events = DBUtils.get_all_docs(db_name, 'ros_ropod_event') chosen_event_index = choose_event(events, 1) while chosen_event_index != 0 : chosen_event = events[chosen_event_index-1] event_time = chosen_event['timestamp'] play_rosbag(event_time-config_param['event_playback_duration'], event_time+config_param['event_playback_duration']) chosen_event_index = choose_event(events, chosen_event_index) else : start_time = DBUtils.get_db_oldest_timestamp(db_name) stop_time = DBUtils.get_db_newest_timestamp(db_name) start_time, stop_time = get_desired_duration(start_time, stop_time) play_rosbag(start_time, stop_time)
return duration_doc['data'] def get_label(event_start, event_end): if event_start and event_end: if event_start == 'success': return 1 else: return 0 return 0 if __name__ == '__main__': log_db_name = 'pull_logs' event_docs = DBUtils.get_all_docs(log_db_name, 'ros_event') event_timestamps = DataUtils.get_all_measurements(event_docs, 'timestamp') event_descriptions = DataUtils.get_all_measurements( event_docs, 'description') data_point_count = len(event_timestamps) // 2 object_positions = np.zeros((data_point_count, 3)) goal_positions = np.zeros((data_point_count, 3)) distances_from_edge = np.zeros((data_point_count, 1)) motion_durations = np.zeros((data_point_count, 1)) labels = np.zeros(data_point_count, dtype=int) data_idx = 0 for i in range(0, data_point_count * 2, 2): object_positions[data_idx], _ = get_object_pose( log_db_name, event_timestamps[i])
return 1 else: return 0 return 0 def state_update_fn(state_update, pose, b_box): p_copy = deepcopy(pose) p_copy.position.x += state_update[0] p_copy.position.y += state_update[1] p_copy.position.z += state_update[2] return {'pose': p_copy, 'b_box': b_box} if __name__ == '__main__': log_db_name = 'drawer_handle_grasping_failures' event_docs = DBUtils.get_all_docs(log_db_name, 'ros_event') event_timestamps = DataUtils.get_all_measurements(event_docs, 'timestamp') event_descriptions = DataUtils.get_all_measurements(event_docs, 'description') ground_truth_diagnoses = DBUtils.get_all_docs(log_db_name, 'fault_diagnoses_ground_truth') data_point_count = len(event_timestamps) // 2 handle_positions = np.zeros((data_point_count, 3)) handle_bb_mins = np.zeros((data_point_count, 3)) handle_bb_maxs = np.zeros((data_point_count, 3)) goal_positions = np.zeros((data_point_count, 3)) goal_orientations = np.zeros((data_point_count, 3)) labels = np.zeros(data_point_count, dtype=int) data_idx = 0 print('Extracting data...')