def from_dict(request_dict): id = request_dict.get('id', generate_uuid()) request = TaskRequest(id=id) request.load_type = request_dict["loadType"] request.load_id = request_dict["loadId"] request.user_id = request_dict["userId"] request.earliest_pickup_time = TimeStamp.from_str( request_dict["earliestPickupTime"]) request.latest_pickup_time = TimeStamp.from_str( request_dict["latestPickupTime"]) pickup_area_dict = request_dict.get('pickup_pose', None) if pickup_area_dict: request.pickup_pose = Area.from_dict(pickup_area_dict) else: # when the provided dict is from json schema request.pickup_pose = Area() request.pickup_pose.name = request_dict.get("pickupLocation", '') request.pickup_pose.floor_number = request_dict.get( "pickupLocationLevel", 0) delivery_area_dict = request_dict.get('delivery_pose', None) if delivery_area_dict: request.delivery_pose = Area.from_dict(delivery_area_dict) else: # when the provided dict is from json schema request.delivery_pose = Area() request.delivery_pose.name = request_dict.get( "deliveryLocation", '') request.delivery_pose.floor_number = request_dict.get( "deliveryLocationLevel", 0) request.priority = request_dict["priority"] return request
def from_dict(sub_area_reservation_dict): sub_area_reservation = SubAreaReservation() sub_area_reservation.sub_area_id = sub_area_reservation_dict[ 'subAreaId'] sub_area_reservation.task_id = sub_area_reservation_dict['taskId'] sub_area_reservation.robot_id = sub_area_reservation_dict['robotId'] sub_area_reservation.start_time = TimeStamp.from_str( sub_area_reservation_dict['startTime']) sub_area_reservation.end_time = TimeStamp.from_str( sub_area_reservation_dict['endTime']) sub_area_reservation.status = sub_area_reservation_dict['status'] sub_area_reservation.required_capacity = sub_area_reservation_dict[ 'requiredCapacity'] return sub_area_reservation
def task_status_cb(self, msg): payload = msg['payload'] timestamp = TimeStamp.from_str( msg["header"]["timestamp"]).to_datetime() task_status = TaskStatus.from_payload(payload) if self.robot_id == task_status.robot_id: task = Task.get_task(task_status.task_id) self.logger.debug("Received task status %s for task %s", task_status.task_status, task.task_id) self.logger.debug("Sending task status %s for task %s", task_status.task_status, task.task_id) self.api.publish(msg, groups=["TASK-ALLOCATION"]) if task_status.task_status == TaskStatusConst.ONGOING: self.update_timetable(task, task_status.task_progress, timestamp) elif task_status.task_status == TaskStatusConst.COMPLETED: self.logger.debug("Completing execution of task %s", task.task_id) self.task = None task.update_status(task_status.task_status)
def from_dict(timetable_dict, stp): robot_id = timetable_dict['robot_id'] timetable = Timetable(robot_id, stp) stn_cls = timetable.initialize_stn() zero_timepoint = timetable_dict.get('zero_timepoint') if zero_timepoint: timetable.zero_timepoint = TimeStamp.from_str(zero_timepoint) else: timetable.zero_timepoint = zero_timepoint timetable.risk_metric = timetable_dict['risk_metric'] timetable.temporal_metric = timetable_dict['temporal_metric'] stn = timetable_dict.get('stn') if stn: timetable.stn = stn_cls.from_dict(stn) else: timetable.stn = stn dispatchable_graph = timetable_dict.get('dispatchable_graph') if dispatchable_graph: timetable.dispatchable_graph = stn_cls.from_dict(dispatchable_graph) else: timetable.dispatchable_graph = dispatchable_graph schedule = timetable_dict.get('schedule') if schedule: timetable.schedule = stn_cls.from_dict(schedule) else: timetable.schedule = schedule return timetable
def _get_value(cls, key, value): if key in ['task_id', 'round_id', 'action_id']: return from_str(value) elif key in ['ztp', 'earliest_admissible_time', 'earliest_start_time']: return TimeStamp.from_str(value) else: return value
def from_dict(timetable_dict): robot_id = timetable_dict['robot_id'] stp_solver = STP(timetable_dict['solver_name']) timetable = Timetable(robot_id, stp_solver) stn_cls = timetable.stp_solver.get_stn() ztp = timetable_dict.get('ztp') timetable.ztp = TimeStamp.from_str(ztp) timetable.stn = stn_cls.from_dict(timetable_dict['stn']) timetable.dispatchable_graph = stn_cls.from_dict(timetable_dict['dispatchable_graph']) timetable.stn_tasks = timetable_dict['stn_tasks'] return timetable
def from_payload(payload): round_id = from_str(payload['roundId']) zero_timepoint = TimeStamp.from_str(payload['zeroTimepoint']) tasks_dict = payload['tasksLots'] tasks_lots = list() for task_id, task_dict in tasks_dict.items(): Task.create_new(task_id=task_id) tasks_lots.append(TaskLot.from_payload(task_dict)) task_announcement = TaskAnnouncement(tasks_lots, round_id, zero_timepoint) return task_announcement
def task_status_cb(self, msg): payload = msg['payload'] timestamp = TimeStamp.from_str( msg["header"]["timestamp"]).to_datetime() task_status = TaskStatus.from_payload(payload) if self.robot_id == task_status.robot_id: task = Task.get_task(task_status.task_id) self.logger.debug("Received task status %s for task %s", task_status.task_status, task.task_id) if task_status.task_status == TaskStatusConst.ONGOING: self._update_timetable(task, task_status.task_progress, timestamp) task.update_status(task_status.task_status)
def task_status_cb(self, msg): while self.deleting_task: time.sleep(0.1) self.processing_task = True payload = msg['payload'] timestamp = TimeStamp.from_str( msg["header"]["timestamp"]).to_datetime() task_status = TaskStatus.from_payload(payload) task_progress = task_status.task_progress task = Task.get_task(task_status.task_id) self.logger.debug("Received task status %s for task %s by %s", task_status.task_status, task_status.task_id, task_status.robot_id) if task_status.task_status == TaskStatusConst.ONGOING: self._update_progress(task, task_progress, timestamp) self.update_timetable(task, task_status.robot_id, task_progress, timestamp) self._update_task_schedule(task, task_progress, timestamp) task.update_status(task_status.task_status) elif task_status.task_status == TaskStatusConst.COMPLETED: self.logger.debug("Adding task %s to tasks to remove", task.task_id) self.tasks_to_remove.append((task, task_status.task_status)) elif task_status.task_status == TaskStatusConst.UNALLOCATED: self.re_allocate(task) elif task_status.task_status == TaskStatusConst.PREEMPTED: if task.status.status == TaskStatusConst.PREEMPTED: self.logger.warning("Task %s is already preempted", task_status.task_id) return try: self._remove_task(task, task_status.task_status) except TaskNotFound: return self.processing_task = False
def from_dict(task_dict): task = Task() task.id = task_dict['id'] task.loadType = task_dict['loadType'] task.loadId = task_dict['loadId'] task.team_robot_ids = task_dict['team_robot_ids'] task.earliest_start_time = TimeStamp.from_str( task_dict['earliest_start_time']) task.latest_start_time = TimeStamp.from_str( task_dict['latest_start_time']) task.estimated_duration = datetime.timedelta( minutes=task_dict['estimated_duration']) task.earliest_finish_time = TimeStamp.from_str( task_dict['earliest_finish_time']) task.latest_finish_time = TimeStamp.from_str( task_dict['latest_finish_time']) start_time = task_dict.get('start_time', None) if start_time: task.start_time = TimeStamp.from_str(start_time) else: task.start_time = start_time finish_time = task_dict.get('finish_time', None) if finish_time: task.finish_time = TimeStamp.from_str(finish_time) else: task.finish_time = finish_time task.pickup_pose = Area.from_dict(task_dict['pickup_pose']) task.delivery_pose = Area.from_dict(task_dict['delivery_pose']) task.priority = task_dict['priority'] task.status = TaskStatus.from_dict(task_dict['status']) task.hard_constraints = task_dict['hard_constraints'] for robot_id, actions in task_dict['robot_actions'].items(): task.robot_actions[robot_id] = list() for action_dict in actions: action = Action.from_dict(action_dict) task.robot_actions[robot_id].append(action) return task