def open(self):
        scheduler = AsyncIOScheduler()

        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()

        # 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):
            self.write_message(x.body)

        def on_error(ex):
            print(ex)

        searcher.subscribe(send_response, on_error, scheduler=scheduler)
Beispiel #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()

        # 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):
            self.write_message(x.body)

        def on_error(ex):
            print(ex)

        searcher.subscribe(send_response, on_error, scheduler=scheduler)
    def open(self):
        print("WebSocket opened")

        self.stream = Subject()

        searcher = self.stream.pipe(ops.map(lambda x: x["term"]),
                                    ops.filter(lambda text: len(text) > 2),
                                    ops.debounce(0.750),
                                    ops.distinct_until_changed(),
                                    ops.flat_map_latest(search_wikipedia))

        def send_response(x):
            self.write_message(x.body)

        def on_error(ex):
            print(ex)

        searcher.subscribe(send_response, on_error, scheduler=scheduler)
Beispiel #4
0
async def main(loop):
    scheduler = AsyncIOScheduler(loop)
    finder = WikipediaFinder(loop)
    stream = Subject()

    def task(term):
        t = loop.create_task(finder.search(term))
        return rx.from_future(t)

    def pretty(result):
        parsed = json.loads(result)
        print(json.dumps(parsed, sort_keys=True, indent=2))

    stream.pipe(
        ops.debounce(0.750),
        ops.distinct(),
        ops.flat_map_latest(task)
    ).subscribe(pretty, scheduler=scheduler)

    def reader():
        line = sys.stdin.readline().strip()
        stream.on_next(line)

    loop.add_reader(sys.stdin.fileno(), reader)
 def pipe_predict_one(self, obs):
     return obs.pipe(ops.flat_map_latest(lambda x: self.predict_one_obs),
                     async_switch_map(self.predict))
 def pipe_train_2(self, obs):
     return obs.pipe(ops.flat_map_latest(lambda x: self.trainUnfreezed),
                     async_switch_map(self.train_stage_2))
 def get_trained_obs(self):
     return self.dataSetFolderSubject.pipe(
         async_switch_map(self.handleFolder),
         ops.do_action(self.set_learner),
         ops.flat_map_latest(lambda event: self.trainFirstStage),
         async_switch_map(self.train_stage_1), ops.share())
def async_switch_map(corutin, *args, **kwargs):
    return ops.flat_map_latest(
        lambda event: to_observable(corutin(event, *args, **kwargs)))
Beispiel #9
0
import rx
import rx.operators as ops
from time import sleep


NUM_TESTRUNS_PER_CATEGORY = 3

source = rx.timer(0, 7).pipe(
    ops.map(lambda i: i + 1),
    ops.take(2),
)

testresultStream = source.pipe(
    ops.flat_map_latest(
        lambda selectedJobId: getCategoryAndDependencies(selectedJobId)
    ),
)


def getCategoryAndDependencies(selectedJobId):
    return rx.of(selectedJobId).pipe(
        ops.flat_map(
            lambda selectedJobId: getCategory(selectedJobId)
        ),
        ops.flat_map(
            lambda category: getTestruns(category)
        ),
        ops.flat_map(
            lambda testruns: rx.from_(testruns)
        ),
        ops.map(