Beispiel #1
0
        def process(building_map: Optional[BuildingMap]):
            """
            1. Converts a `BuildingMap` message to an ordered dict.
            2. Saves the images into `{static_directory}/{map_name}/`.
            3. Change the `AffineImage` `data` field to the url of the image.
            """
            if not building_map:
                return {}
            self.logger.info("got new building map")
            processed_map = message_to_ordereddict(building_map)

            for i in range(len(building_map.levels)):
                level: Level = building_map.levels[i]
                for j in range(len(level.images)):
                    image: AffineImage = level.images[j]
                    # look at non-crypto hashes if we need more performance
                    sha1_hash = hashlib.sha1()
                    sha1_hash.update(image.data)
                    fingerprint = base64.b32encode(
                        sha1_hash.digest()).lower().decode()
                    relpath = f"{building_map.name}/{level.name}-{image.name}.{fingerprint}.{image.encoding}"  # pylint: disable=line-too-long
                    urlpath = self.static_files.add_file(image.data, relpath)
                    processed_map["levels"][i]["images"][j]["data"] = urlpath
            self.rmf_gateway.building_map.on_next(processed_map)
            return {building_map.name: processed_map}
Beispiel #2
0
    def _init_task_summary(self):
        topic = topics.task_summaries

        self.room_records[topic] = lambda: {
            x.task_id: message_to_ordereddict(x)
            for x in self.rmf_gateway.current_task_summaries.values()
        }

        def on_next(task: TaskSummary):
            async def emit_task():
                await self.sio.emit(topic,
                                    message_to_ordereddict(task),
                                    to=topic)
                self.logger.debug(f'emitted message to room "{topic}"')

            self.loop.create_task(emit_task())

        self._subscriptions.append(
            self.rmf_gateway.task_summaries.subscribe(on_next))
Beispiel #3
0
 def update_from_rmf(self, rmf_msg: RmfMessage):
     self.id_ = key_mapper(rmf_msg)
     self.data = message_to_ordereddict(rmf_msg)
     return self
Beispiel #4
0
 def update_or_create_from_rmf(cls, rmf_msg: RmfMessage):
     id_ = key_mapper(rmf_msg)
     data = message_to_ordereddict(rmf_msg)
     return cls.update_or_create({"data": data}, id_=id_)
Beispiel #5
0
 def _tunnel_state_callback(self, msg):
     if self.save_data:
         msg_dict = convert.message_to_ordereddict(msg)
         self.data_writer.writerow(msg_dict)
Beispiel #6
0
 def _init_door_state(self):
     self._init_room(
         topics.door_states,
         self.rmf_gateway.door_states.pipe(
             rx_map(lambda x: {x.door_name: message_to_ordereddict(x)})),
     )
Beispiel #7
0
 async def emit_task():
     await self.sio.emit(topic,
                         message_to_ordereddict(task),
                         to=topic)
     self.logger.debug(f'emitted message to room "{topic}"')
Beispiel #8
0
 def update_or_create_from_rmf(cls, rmf_msg: RmfTaskSummary):
     id_ = rmf_msg.task_id
     data = message_to_ordereddict(rmf_msg)
     state = rmf_msg.state
     return cls.update_or_create({"data": data, "state": state}, id_=id_)
Beispiel #9
0
 def _init_ingestor_state(self):
     self._init_room(
         topics.ingestor_states,
         self.rmf_gateway.ingestor_states.pipe(
             rx_map(lambda x: {x.guid: message_to_ordereddict(x)})),
     )
Beispiel #10
0
 async def update(task: TaskSummary):
     await ttm.TaskSummary.update_or_create_from_rmf(task)
     self._loggers.task_summary.info(
         json.dumps(message_to_ordereddict(task)))
Beispiel #11
0
 async def update(fleet_state: FleetState):
     await ttm.FleetState.update_or_create_from_rmf(fleet_state)
     self._loggers.fleet_state.info(
         json.dumps(message_to_ordereddict(fleet_state)))
Beispiel #12
0
 async def update(ingestor_state: IngestorState):
     await ttm.IngestorState.update_or_create_from_rmf(ingestor_state)
     self._loggers.ingestor_state.info(
         json.dumps(message_to_ordereddict(ingestor_state)))
Beispiel #13
0
 async def update(dispenser_state: DispenserState):
     await ttm.DispenserState.update_or_create_from_rmf(dispenser_state)
     self._loggers.dispenser_state.info(
         json.dumps(message_to_ordereddict(dispenser_state)))
Beispiel #14
0
 async def update(lift_state: LiftState):
     await ttm.LiftState.update_or_create_from_rmf(lift_state)
     self._loggers.lift_state.info(
         json.dumps(message_to_ordereddict(lift_state)))