Пример #1
0
 def on_mouse_up(self) -> Observable[MouseButtonEvent]:
     return self.on_state_change.pipe(
         ops.map(lambda s: s.buttons),
         ops.distinct_until_changed(),
         ops.pairwise(),
         ops.flat_map(lambda b: b[0] - b[1]),
         ops.map(lambda b: MouseUpEvent(self, self.state.unwrap(), b)))
Пример #2
0
    def open(self):
        scheduler = AsyncIOScheduler(asyncio.get_event_loop())

        print("WebSocket opened")

        # A Subject is both an observable and observer, so we can both subscribe
        # to it and also feed (send) it with new values
        self.subject: Subject[Dict[str, str]] = Subject()

        # Get all distinct key up events from the input and only fire if long enough and distinct
        searcher = self.subject.pipe(
            ops.map(lambda x: x["term"]),
            ops.filter(lambda text: len(text) > 2
                       ),  # Only if the text is longer than 2 characters
            ops.debounce(0.750),  # Pause for 750ms
            ops.distinct_until_changed(),  # Only if the value has changed
            ops.flat_map_latest(search_wikipedia),
        )

        def send_response(x: HTTPResponse) -> None:
            self.write_message(x.body)

        def on_error(ex: Exception):
            print(ex)

        searcher.subscribe(on_next=send_response,
                           on_error=on_error,
                           scheduler=scheduler)
    :param temperature: the sensor temperature
    :return: Line protocol to write into InfluxDB
    """

    import socket
    return 'iot_sensor,hostname={},type=temperature value={}'.format(
        socket.gethostname(), temperature)


"""
Read temperature every minute; distinct_until_changed - produce only if temperature change
"""
data = rx \
    .interval(period=timedelta(seconds=60)) \
    .pipe(ops.map(lambda t: sensor_temperature()),
          ops.distinct_until_changed(),
          ops.map(lambda temperature: line_protocol(temperature)))

_db_client = InfluxDBClient(url="http://localhost:8086",
                            token="my-token",
                            org="my-org",
                            debug=True)
"""
Create client that writes data into InfluxDB
"""
_write_api = _db_client.write_api(write_options=WriteOptions(batch_size=1))
_write_api.write(bucket="my-bucket", record=data)
"""
Call after terminate a script
"""
atexit.register(on_exit, _db_client, _write_api)
Пример #4
0
 def on_state_change(self) -> Observable[TState]:
     return self._state_subject.pipe(ops.distinct_until_changed())
Пример #5
0
 def create():
     return xs.pipe(ops.distinct_until_changed())
Пример #6
0
 def on_mouse_move(self) -> Observable[MouseMoveEvent]:
     return self.on_state_change.pipe(
         ops.map(partial(MouseMoveEvent, self)),
         ops.distinct_until_changed())
Пример #7
0
 def create():
     return reactivex.never().pipe(ops.distinct_until_changed())
Пример #8
0
 def create():
     return xs.pipe(
         ops.distinct_until_changed(comparer=lambda x, y: _raise(ex)), )
Пример #9
0
 def create():
     return xs.pipe(ops.distinct_until_changed(lambda x: _raise(ex)))
Пример #10
0
 def create():
     return xs.pipe(ops.distinct_until_changed(lambda x: x % 2))
Пример #11
0
 def create():
     return xs.pipe(
         ops.distinct_until_changed(comparer=lambda x, y: False))