예제 #1
0
파일: rmf_io.py 프로젝트: lijian8/rmf-web
    def _init_building_map(self):
        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}

        self._init_room(
            topics.building_map,
            self.rmf_gateway.rmf_building_map.pipe(rx_map(process)),
        )
예제 #2
0
 def sync_stores(self) -> None:
     self.fetch_source().observable().pipe(
         rx_filter(lambda event: event.is_valid()),
         buffer_with_count(200),
         rx_map(self.event_repository.upsert_no_slicing)
     ).subscribe(
         on_next=lambda e: self.logger.info('Upserted %d events for %s', len(e), self.venue.venue_id),
         on_error=self._log_error,
     )
예제 #3
0
def heartbeat(liveliness):
    """
    Projects a source observable sequence to a boolean. The resulting value is True when there
    is an observable emitted within the liveliness factor and False otherwise.
    Args:
        liveliness: The amount of time (in seconds) between each event for the observable to be
        considered alive. Note that an observable may stay alive for up to 2x liveliness between
        each event as this operator checks for items emitted between this window.
    """
    return rx.pipe(
        buffer_with_time_or_count(liveliness, 1),
        rx_map(lambda items: len(items) > 0),
        distinct_until_changed(),
    )
예제 #4
0
파일: rmf_io.py 프로젝트: lijian8/rmf-web
 def _init_door_health(self):
     self._init_room(
         topics.door_health,
         self.rmf_gateway.door_health.pipe(
             rx_map(lambda x: {x.id_: x.to_dict()})),
     )
예제 #5
0
파일: rmf_io.py 프로젝트: lijian8/rmf-web
 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)})),
     )
예제 #6
0
파일: rmf_io.py 프로젝트: lijian8/rmf-web
 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)})),
     )