Esempio n. 1
0
 def getContractDetails(
         self, assetType: AssetType,
         contract: IBContract) -> Observable[IBContractDetails]:
     log.info(contract)
     if assetType == AssetType.FUTURE:
         return self.__ibClient.getContractDetail(contract).pipe(
             ops.filter(lambda x: x is not None),
             ops.buffer_with_time(2),
             ops.take(1),
         )
     elif assetType == AssetType.STOCK:
         return self.__ibClient.getContractDetail(contract).pipe(
             ops.filter(lambda x: x is not None),
             ops.buffer_with_time(1),
             ops.take(1),
         )
Esempio n. 2
0
    def start(self):
        # report more image when back pressure
        self.subjects.image_producer.pipe(
            operators.observe_on(self.scheduler),
            operators.combine_latest(
                self.subjects.analyzer_back_pressure_detected),
            operators.filter(
                lambda x: x[1]),  # only operate when back pressure
            operators.buffer_with_time(1.0),  # in 1 sec
            operators.filter(lambda x: len(x) > 3),  # more than 3 emission
            operators.throttle_first(3.0),  # report every 3 seconds
            operators.take_until(self._stop),
        ).subscribe(self.report_back_pressure_emission)

        self.subjects.image_producer.pipe(
            operators.observe_on(
                self.scheduler),  # prevent blocking the upstream subject
            operators.filter(self.back_pressure_barrier),
            operators.buffer_with_count(5),
            bp_drop_report_full(self.subjects.analyzer_back_pressure_detected,
                                3, 1),
            operators.take_until(self._stop),
        ).subscribe(ErrorToConsoleObserver(self.produce_fake_analyze_data))
        super(TestAnalyzer, self).start()
Esempio n. 3
0
scheduler = TestScheduler()
ts = 0.1
rx.from_marbles('--(a1)-(b2)---(c3)|', timespan=ts).subscribe(print_value)
rx.from_marbles('(a6)---(b5)(c4)|', timespan=ts).subscribe(print_value)
time.sleep(2)
print('--')

# Interval 을 이용한 옵저버블 생성
rx.interval(0.3).pipe(ops.take_until(rx.timer(3))).subscribe(print_value)
time.sleep(4)
print('--')

# 버퍼
print('-- buffer')
rx.from_(range(2000)).pipe(ops.buffer(
    rx.interval(0.001))).subscribe(on_next=lambda buffer: print(
        '# of items in buffer {}'.format(len(buffer))))
time.sleep(2)

print('-- buffer with count')
rx.from_(range(10)).pipe(ops.buffer_with_count(3)).subscribe(print_value)

print('-- buffer with time')
rx.interval(1).pipe(
    ops.take_until(rx.timer(10)),
    ops.buffer_with_time(3),
).subscribe(print_value)
time.sleep(12)
print('--')
Esempio n. 4
0
import rx
import rx.operators as ops
from rx.subject import Subject
import time
import threading

numbers = Subject()
dispoable = numbers.pipe(ops.buffer_with_time(0.2, timeshift=0.4)).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"))

numbers.on_next(1)
numbers.on_next(2)
t1 = threading.Timer(0.250, lambda: numbers.on_next(3))
t1.start()
t2 = threading.Timer(0.450, lambda: numbers.on_next(4))
t2.start()
t3 = threading.Timer(0.750, lambda: dispoable.dispose())
t3.start()
Esempio n. 5
0
import rx
import rx.operators as ops
from rx.subject import Subject
import time
import threading

numbers = Subject()
dispoable = numbers.pipe(ops.buffer_with_time(0.2)).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"))

numbers.on_next(1)
numbers.on_next(2)
t1 = threading.Timer(0.250, lambda: numbers.on_next(3))
t1.start()
t2 = threading.Timer(0.450, lambda: numbers.on_next(4))
t2.start()
t3 = threading.Timer(0.750, lambda: dispoable.dispose())
t3.start()
Esempio n. 6
0
    return r


def incoming():
    for i in range(0, 1000):
        value = random.randint(0, 10)
        delay = random.randint(0, 3)
        sleep(float(delay))
        callback(value)


x = threading.Thread(target=incoming)
x.start()

searcher = mysubject.pipe(
    ops.buffer_with_time(1)
    #ops.map(lambda x: x*2), \
    #ops.filter(lambda i : i > 10)
)


# called every buffer interval
def send_response(x):
    print("send response", x)


def on_error(ex):
    print("E", ex)


searcher.subscribe(send_response, on_error)
 def create():
     return xs.pipe(
         ops.buffer_with_time(100, 70),
         ops.map(lambda x: ",".join([str(a) for a in x]))
     )
 def create():
     return xs.pipe(ops.buffer_with_time(100),
                    ops.map(lambda x: ",".join([str(a) for a in x])))