예제 #1
0
파일: __init__.py 프로젝트: chstan/daquiri
    def __init__(
        self,
        columns,
        add_row=None,
        remove_row=None,
        edit_row_at_index=None,
        clear=None,
        initial_rows=None,
    ):
        self.add_row = Subject() if add_row is None else add_row
        self.remove_row = Subject() if remove_row is None else remove_row
        self.clear = Subject() if clear is None else clear
        self.edit_row_at_index = Subject(
        ) if edit_row_at_index is None else edit_row_at_index

        self.initial_rows = pr.v() if initial_rows is None else initial_rows
        self.initial_columns = pr.v(*columns)

        self.history = rx.merge(self.add_row, self.remove_row, self.clear,
                                self.edit_row_at_index)
        self._values_with_columns = self.history.pipe(
            ops.scan(
                self.reduce_table_state,
                (self.initial_rows, self.initial_columns),
            ))

        self.values = self._values_with_columns.pipe(ops.map(lambda x: x[0]))
        self.columns = self._values_with_columns.pipe(ops.map(lambda x: x[1]))
        self.values_with_history = self.values.pipe(ops.zip(self.history))
예제 #2
0
파일: __init__.py 프로젝트: chstan/daquiri
    def __init__(
        self,
        add=None,
        remove=None,
        reindex=None,
        clear=None,
        edit_at_index=None,
        initial_state=None,
    ):
        self.add = Subject() if add is None else add
        self.remove = Subject() if remove is None else remove
        self.reindex = Subject() if reindex is None else reindex
        self.clear = Subject() if clear is None else clear
        self.edit_at_index = Subject(
        ) if edit_at_index is None else edit_at_index

        self.initial_state = pr.v() if initial_state is None else initial_state

        self.history = rx.merge(self.add, self.remove, self.reindex,
                                self.clear, self.edit_at_index)

        self._values = self.history.pipe(
            ops.scan(self.reduce_list_state, self.initial_state))
        self.values = self._values
        self.values_with_history = self._values.pipe(
            ops.zip(self.history),
            # ops.replay(buffer_size=1)
        )
예제 #3
0
 def __init__(self, inv_chance=0.2):
     super().__init__()
     self.inv_chance = inv_chance
     self.input_danger.pipe(
         ops.zip(self.input_opportunity),
         ops.map(lambda x: self.should_flip(x))).subscribe(
             lambda x: self.output_invert_movement.on_next(x))
예제 #4
0
def demo_zip():

    a = rx.of(1, 2, 3, 4)
    b = rx.of(2, 2, 4, 4)

    a.pipe(
        ops.zip(b), # returns a tuple with the items of a and b
        ops.map(lambda z: operator.mul(z[0], z[1]))
    ).subscribe(print)
예제 #5
0
def demo_starmap():
    '''tuple unpacking'''
    
    a = rx.of(1, 2, 3, 4)
    b = rx.of(2, 2, 4, 4)

    a.pipe(
        ops.zip(b),
        ops.starmap(operator.mul)
    ).subscribe(print)
예제 #6
0
    def __init__(self, scheduler=None):
        self._observerable = rx.interval(
            ObserveConfig.interval,
            scheduler).pipe(ops.map(lambda dummy: get_merge_requests()),
                            ops.retry(), ops.publish(), ops.ref_count())

        self._ready_to_merge = self._observerable.pipe(
            ops.map(lambda requests: next((request for request in requests if
                                           is_ready_to_merge(request)), None)),
            ops.start_with(None), ops.distinct_until_changed())

        self._ready_to_merge.subscribe(lambda ready_to_merge: logging.info(
            'Ready to merge: ' + str(ready_to_merge)))

        voted_merge_requests = self._observerable.pipe(
            ops.map(_to_voted_merge_requests_set))
        self._new_votes_merge_requests = voted_merge_requests.pipe(
            ops.skip(1), ops.zip(voted_merge_requests),
            ops.map(lambda zipped: zipped[0] - zipped[1]), ops.filter(len),
            ops.map(_to_merge_requests))

        self._new_votes_merge_requests.pipe(
            ops.map(lambda diff_set:
                    [merge_request.get_iid() for merge_request in diff_set])
        ).subscribe(
            lambda ids: logging.info(f'New votes for merge requests: {ids}'))

        awards = self._new_votes_merge_requests.pipe(ops.map(_to_awards_set),
                                                     ops.publish(),
                                                     ops.ref_count(),
                                                     ops.start_with(set()))
        self._new_awards = awards.pipe(
            ops.skip(1), ops.zip(awards),
            ops.map(lambda zipped: zipped[0] - zipped[1]), ops.filter(len),
            ops.flat_map(lambda diff_set: rx.from_iterable(diff_set)),
            ops.map(lambda award_key: award_key.award))

        self._new_awards.subscribe(
            lambda new_award: logging.info('New award: ' + str(new_award)))
예제 #7
0
파일: cpg.py 프로젝트: szaruba/ai-toolbox
    def __init__(self):
        super().__init__()

        #  read pre-trained models for predicting two different periodic functions.
        self.forward_model = keras.models.load_model("../model/sine.h5")
        self.backward_model = keras.models.load_model("../model/spiked.h5")

        self.input_danger.pipe(ops.zip(self.input_opportunity, self.input_flip))\
            .subscribe(lambda x: setattr(self, "last_input", x))

        Timer().ticks.pipe(
                ops.filter(lambda x: x % self.muscle_tick_rate == 0),
                ops.map(lambda x: self.input_to_prediction(self.last_input)),
                ops.map(lambda x: self.prediction_to_stimuli(x)))\
            .subscribe(lambda x: self.output_muscle_stimuli.on_next(x))
예제 #8
0
 def mapper(_xs):
     return _xs.pipe(ops.zip(_xs.pipe(ops.skip(1))), ops.map(sum))
import rx
import rx.operators as ops

numbers = rx.from_([1, 2, 3, 4])
characters = rx.from_(['a', 'b', 'c', 'd', 'e'])

characters.pipe(
    ops.zip(numbers),
    ops.map(lambda c: "{}: {}".format(c[0], c[1])),
).subscribe(
    on_next=lambda i: print("on_next {}".format(i)),
    on_error=lambda e: print("on_error: {}".format(e)),
    on_completed=lambda: print("on_completed")
)
예제 #10
0
def test_tuple_with_previous_using_zip():
    from_range = rx.from_iterable(range(10))
    from_range.pipe(
        ops.skip(1),
        ops.zip(from_range),
    ).subscribe(lambda x: print(x))
예제 #11
0
import time

import rx
from rx import operators as ops

t = 0.01

a = rx.interval(t)
b = rx.interval(10 * t)

a.pipe(
    ops.map(lambda x: 1 / 0),
    ops.zip(b),
).subscribe(print)

time.sleep(1000 * t)
예제 #12
0
 def mapper(ys):
     return ys.pipe(
         ops.zip(ys),
         ops.map(sum),
     )
예제 #13
0
파일: starmap.py 프로젝트: oncepy/Packet_rx
import rx
from rx import operators as ops
import operator

a = rx.of(1, 2, 3, 4)
b = rx.of(2, 2, 4, 4)

a.pipe(
    ops.zip(b),  # returns a tuple with the items of a and b
    ops.starmap(operator.mul)
).subscribe(print)

예제 #14
0
파일: zip.py 프로젝트: oncepy/Packet_rx
import rx
from rx import operators as ops

letters = rx.from_(["A", "B", "C", "D", "E", "F"])
numbers = rx.range(1, 5)

letters.pipe(ops.zip(numbers), ops.map(
    lambda z: "{0}-{1}".format(z[0], z[1]))).subscribe(lambda i: print(i))
예제 #15
0
 def create():
     return e1.pipe(
         ops.zip(e2),
         ops.map(sum))
예제 #16
0
 def create():
     return e2.pipe(
         ops.zip(e1),
         ops.map(sum))
예제 #17
0
 def create():
     return o1.pipe(ops.zip(o2))
예제 #18
0
 def mapper(_xs):
     return _xs.pipe(
             ops.zip(_xs.pipe(ops.skip(1))),
             ops.map(sum)
             )
op.catch()
op.retry()

"""Utility"""
op.delay()
op.materialize()
op.time_interval()
op.timeout()
op.timestamp()

"""Conditional and Boolean"""
op.all()
op.contains()
op.default_if_empty()
op.sequence_equal()
op.skip_until()
op.skip_while()
op.take_until()
op.take_while()

"""Connectable"""
op.publish()
op.ref_count()
op.replay()

"""Combining"""
op.combine_latest()
op.merge()
op.start_with()
op.zip()
예제 #20
0
import rx
from rx import operators as ops

letters = rx.from_(["Alpha", "Beta", "Gamma", "Delta", "Epsilon"])
intervals = rx.interval(1.0)

letters.pipe(ops.zip(intervals),
             ops.map(lambda z: z[0])).subscribe(lambda s: print(s))

input("Press any key to quit\n")
예제 #21
0
 def mapper(ys):
     return ys.pipe(
             ops.zip(ys),
             ops.map(sum),
             )