def give_zones_handler(robo_id): """ Service for giving cleaning zones to smallvot amd distrivuting IDs to new smallvots :param robo_id: ID of the small rovot requesting a clean Task :return: fields for a clean Task """ latestTask = Task(3) latestTask.workerID = robo_id.workerID start = Pose() start.position.x = 30 # ['isActive', 'isComplete', 'workerID', 'type', 'zone', 'startingPoint'] return [True, False, latestTask.workerID, "clean", 123, start]
def basic_test_with_camera(): emptyRobotList = [] taskID = 0 CM = CleaningManager(emptyRobotList) timer = 0 print("Getting Frames...") while timer < 500: CM.mapManager.mapMaker.update_map_async() if CM.mapManager.mapMaker.get_frame() == sl.ERROR_CODE.SUCCESS: # When grab() = SUCCESS, a new image, depth and pose is available. # Spatial mapping automatically ingests the new data to build the mesh. timer += 1 CM.mapManager.update_OG() timer = 0 cleaningTask1 = Task(Zone([Pose(), Pose(), Pose(), Pose()], taskID)) CM.cleaningTasks.append(cleaningTask1) CM.mapManager.get_visible_zones() while 1: if CM.mapManager.mapMaker.get_frame() == sl.ERROR_CODE.SUCCESS: timer += 1 if timer == 50: "updating OG..." CM.mapManager.mapMaker.update_pose_z() CM.mapManager.mapMaker.update_map_async() CM.mapManager.update_OG() CM.robotManager.director.publish_og() timer = 0 if len(CM.cleaningTasks) < 1: taskID = taskID + 1 corners = CM.mapManager.get_corners_from_center( CM.mapManager.get_center_from_zone_index(taskID)) tl = Pose() tl.position.x = corners[0][0] tl.position.y = corners[0][1] tr = Pose() tr.position.x = corners[1][0] tr.position.y = corners[1][1] br = Pose() br.position.x = corners[2][0] br.position.y = corners[2][1] bl = Pose() bl.position.x = corners[3][0] bl.position.y = corners[3][1] cleaningTask = Task(Zone([tl, tr, br, bl], taskID)) #cleaningTask = Task(Zone([Pose(), Pose(), Pose(), Pose()], taskID)) CM.cleaningTasks.append(cleaningTask) print("added new cleaning task with ID:") print(taskID) time.sleep(.5)
def basic_test(): emptyRobotList = [] taskID = 0 CM = CleaningManager(emptyRobotList) cleaningTask1 = Task(Zone([Pose(), Pose(), Pose(), Pose()], taskID)) CM.cleaningTasks.append(cleaningTask1) while 1: if len(CM.cleaningTasks) < 1: taskID = taskID + 1 cleaningTask = Task(Zone([Pose(), Pose(), Pose(), Pose()], taskID)) CM.cleaningTasks.append(cleaningTask) print("added new cleaning task with ID:") print(taskID) time.sleep(.5)
def give_cleaning_task(self, robot_request): if len(self.cleaningManager.cleaningTasks) > 0: print("giving cleaning task") task = self.cleaningManager.cleaningTasks.pop() self.cleaningManager.completed_tasks.append(task) print("task is " + str(task.zone.id)) print("tasks remaining: " + str(len(self.cleaningManager.cleaningTasks))) task.workerID = robot_request.workerID return task.to_service_format() else: print("no cleaning Task") task = Task() task.make_safe_task(robot_request.workerID) return task.to_service_format()
def __init__(self): self.robotList = [] self.Tasks = [] self.latestTask = Task(0) self.ros_node() rospy.sleep(8) self.order_avoid(2, 360) self.order_dump(1, 123) self.order_dump(2, 456)
def give_avoid_status(self, robot_request): task = Task() if self.robotManager.should_robot_avoid(robot_request.workerID): if DEBUG: print("sending avoid task to robot with ID:") print(robot_request.workerID) task.make_avoid_task(Pose(), robot_request.workerID) return task.to_service_format() else: if DEBUG: print("sending safe task to robot with ID:") print(robot_request.workerID) task.make_safe_task(robot_request.workerID) return task.to_service_format()
def create_cleaning_tasks(self): for zone in self.mapManager.zones: exists = False for task in self.cleaningTasks: if task.zone.id == zone.id: exists = True break for task in self.completed_tasks: if task.zone.id == zone.id: exists = True break if not exists: self.cleaningTasks.append(Task(zone=zone))
def test_extract_paragraphs_when_no_pdf_file(self): tenant = "test_extract_paragraphs_when_no_pdf_file" shutil.rmtree(f"{DOCKER_VOLUME_PATH}/to_extract/{tenant}", ignore_errors=True) os.makedirs(f"{DOCKER_VOLUME_PATH}/to_extract/{tenant}") task = Task(tenant=tenant, task="segmentation", params=Params(filename="no_file")) extraction_data = extract_paragraphs(task) self.assertIsNone(extraction_data)
def give_zones_handler(self, robo_id): """ Service for giving cleaning zones to smallvot amd distrivuting IDs to new smallvots :param robo_id: ID of the small rovot requesting a clean Task :return: fields for a clean Task """ self.latestTask = Task(3) if robo_id.workerID is -1: self.Tasks.append("Robot") self.latestTask.workerID = len(self.Tasks) else: self.latestTask.workerID = robo_id.workerID # [isActive, isComplete, WorkerID, Zone, Task type] return [True, False, self.latestTask.workerID, 123, "clean"]
def parse_task(self, taskResponse): """ Takes a service response and combines all the fields into a Task :param taskResponse: response received from a service :return: a Task """ zone = Zone(taskResponse.zoneCorners, taskResponse.zoneID) task = Task(zone, taskResponse.type) task.isActive = taskResponse.isActive task.isComplete = taskResponse.isComplete task.workerID = taskResponse.workerID task.start_point = taskResponse.startingPoint return task
def process(self, id, message, rc, ts): try: task = Task(**message) except ValidationError: self.logger.error(f"Not a valid message: {message}") return True self.logger.info(f"Valid message: {message}") try: extraction_data = extract_paragraphs(task) if not extraction_data: extraction_message = ExtractionMessage( tenant=task.tenant, task=task.task, params=task.params, success=False, error_message="Error getting the xml from the pdf", ) self.results_queue.sendMessage().message(extraction_message.dict()).execute() self.logger.error(extraction_message.json()) return True results_url = f"{self.config.service_url}/get_paragraphs/{task.tenant}/{task.params.filename}" file_results_url = f"{self.config.service_url}/get_xml/{task.tenant}/{task.params.filename}" extraction_message = ExtractionMessage( tenant=extraction_data.tenant, task=task.task, params=task.params, success=True, data_url=results_url, file_url=file_results_url, ) self.pdf_paragraph_db.paragraphs.insert_one(extraction_data.dict()) self.logger.info(extraction_message.json()) self.results_queue.sendMessage(delay=3).message(extraction_message.dict()).execute() return True except Exception: self.logger.error("error", exc_info=1) return True
def test_extract_paragraphs(self): # setup tenant = "tenant_async" pdf_file_name = "test.pdf" xml_file_name = "test.xml" shutil.rmtree(f"{DOCKER_VOLUME_PATH}/to_extract/{tenant}", ignore_errors=True) shutil.rmtree(f"{DOCKER_VOLUME_PATH}/xml/{tenant}", ignore_errors=True) os.makedirs(f"{DOCKER_VOLUME_PATH}/to_extract/{tenant}") print(f"{ROOT_FOLDER}/extract_pdf_paragraph/test_files/test.pdf") shutil.copyfile( f"{ROOT_FOLDER}/src/test_files/test.pdf", f"{DOCKER_VOLUME_PATH}/to_extract/{tenant}/{pdf_file_name}", ) # act task = Task(tenant=tenant, task="segmentation", params=Params(filename=pdf_file_name)) extraction_data = extract_paragraphs(task) # assert self.assertIsNotNone(extraction_data) self.assertEqual(tenant, extraction_data.tenant) self.assertEqual(pdf_file_name, extraction_data.file_name) self.assertEqual(612, extraction_data.page_width) self.assertEqual(792, extraction_data.page_height) self.assertLess(15, len(extraction_data.paragraphs)) self.assertEqual("A/INF/76/1", extraction_data.paragraphs[0].text) self.assertEqual({1, 2}, {x.page_number for x in extraction_data.paragraphs}) self.assertTrue( os.path.exists( f"{DOCKER_VOLUME_PATH}/xml/{tenant}/{xml_file_name}")) self.assertFalse( os.path.exists( f"{DOCKER_VOLUME_PATH}/to_extract/{tenant}/{pdf_file_name}")) shutil.rmtree(f"{DOCKER_VOLUME_PATH}/xml/{tenant}", ignore_errors=True)
def test_extract_paragraphs_when_pdf_error(self): mongo_client = pymongo.MongoClient("mongodb://localhost:27017") tenant = "tenant_async" pdf_file_name = "test.pdf" shutil.rmtree(f"{DOCKER_VOLUME_PATH}/to_extract/{tenant}", ignore_errors=True) shutil.rmtree(f"{DOCKER_VOLUME_PATH}/failed_pdf/{tenant}", ignore_errors=True) shutil.rmtree(f"{DOCKER_VOLUME_PATH}/xml/{tenant}", ignore_errors=True) os.makedirs(f"{DOCKER_VOLUME_PATH}/to_extract/{tenant}") shutil.copyfile( f"{ROOT_FOLDER}/README.md", f"{DOCKER_VOLUME_PATH}/to_extract/{tenant}/{pdf_file_name}", ) task = Task(tenant=tenant, task="segmentation", params=Params(filename=pdf_file_name)) extract_paragraphs(task) self.assertIsNone(mongo_client.pdf_paragraph.paragraphs.find_one()) self.assertFalse( os.path.exists( f"{DOCKER_VOLUME_PATH}/to_extract/{tenant}/{pdf_file_name}")) self.assertFalse( os.path.exists( f"{DOCKER_VOLUME_PATH}/xml/{tenant}/{pdf_file_name}")) self.assertTrue( os.path.exists( f"{DOCKER_VOLUME_PATH}/failed_pdf/{tenant}/{pdf_file_name}")) shutil.rmtree(f"{DOCKER_VOLUME_PATH}/to_extract/{tenant}", ignore_errors=True) shutil.rmtree(f"{DOCKER_VOLUME_PATH}/failed_pdf/{tenant}", ignore_errors=True) shutil.rmtree(f"{DOCKER_VOLUME_PATH}/xml/{tenant}", ignore_errors=True)
def play_possum(self, workerID): task = Task() pass
def avoid_to_direction(self, direction, workerID): task = Task() pass
def go_back_to_zone(self, workerID): task = Task() robot = self.robotManager.get_robot(workerID) zone = robot.task.zone pass