Esempio n. 1
0
    def monitor(self):
        self.check_is_top21()
        self.check_latency()

        if self.bp.is_top21 is False:
            msg = 'bp with name %s NOT FOUND!!! @ %s' % (BP_NAME,
                                                         get_current_time())
            print("in is top21 ", get_current_time())
            send_message(msg)
        if self.bp.is_new_top21 is True:
            msg = 'Congratulations! %s become the new top 21 ! @ %s' % (
                BP_NAME, get_current_time())
            print('in is new top21', get_current_time())
            send_message(msg)
            call()
        if self.bp.is_top21 is True:
            self.notify_count += 1
            if self.notify_count % 64 == 0:
                if self.check_is_producing():
                    msg = '%s in good condition :) @%s' % (BP_NAME,
                                                           get_current_time())
                    print('produing....', get_current_time())
                    self.notify_count = 0
                    send_message(msg)
                else:
                    msg = '%s DOWN :( @%s' % (BP_NAME, get_current_time())
                    print('down...', get_current_time())
                    send_message(msg)
                    call()
Esempio n. 2
0
 def check_latency(self):
     self.latency_count += 1
     if self.latency_count % 30 == 0:  # call every one minute
         latency = self.lr.get_latency()
         if latency != -1:
             if 2000 < latency <= 4000:
                 msg = "bp %s's latency %s ms is too high !!! @ %s" % (
                     BP_NAME, latency, get_current_time())
                 print(msg)
                 send_message(msg)
                 self.latency_count = 0
             elif latency > 4000:
                 msg = "bp %s is stucking now. The latency is %s ms !!! @ %s" % (
                     BP_NAME, latency, get_current_time())
                 print(msg)
                 send_message(msg)
                 self.latency_count = 0
                 call()
             elif 0 < latency <= 2000:
                 msg = "bp %s has normal latency %s ms!!! @ %s" % (
                     BP_NAME, latency, get_current_time())
                 print(msg)
                 send_message(msg)
                 self.latency_count = 0
             else:
                 self.latency_count = 0
Esempio n. 3
0
def report_volume_anomalies(th,
                            notify,
                            i=-1,
                            threshold={
                                1: 10,
                                2: 10,
                                3: 10,
                                5: 10,
                                15: 10,
                                30: 20
                            },
                            pthreshold=1.2,
                            show=True,
                            beep=True,
                            call=False,
                            text=False,
                            flag=True):
    anomaly = False
    for market in th.keys():
        timestamp, delta = detect_volume_anomaly(th[market], i, threshold,
                                                 pthreshold)
        va = [(n, v, p) for n, v, p in delta if v and p]
        if va:
            anomaly = True
            ts = time.strftime('%H:%M:%S', timestamp)
            if show:
                if not flag:
                    print('')
                    flag = True
            for n, v, p in va:
                if show:
                    print(ts.ljust(13), market.ljust(10),
                          str(n).ljust(9), '{:.2g}'.format(v).ljust(9),
                          '{:.3g}'.format(p).ljust(9))
                if notify[market][n]:
                    notify[market][n] = False
                    if beep:
                        d = 0.25
                        f = 440
                        os.system(
                            'play --no-show-progress --null --channels 1 synth {} sine {}'
                            .format(d, f))
                    if call:
                        phone.call('me')
                    if text:
                        n = len(va)
                        txt_msg = 'TIME:{}, MARKET:{}, PERIOD:{}, BUY:{:.2f}, PRICE:{:.2g}, VD:{}'.format(
                            ts, market, n, buy, price, int(vd))
                        phone.text('me', txt_msg)
    return anomaly
Esempio n. 4
0
            cv2.drawContours(drawing, [res], 0, (0, 255, 0), 2)
            cv2.drawContours(drawing, [hull], 0, (0, 0, 255), 3)

            isFinishCal, cnt = calculateFingers(res, drawing)
            if triggerSwitch is True:
                if isFinishCal is True and cnt <= 4:
                    print(cnt)
                if cnt == 1:
                    sos_counter += 1
                if cnt == 3:
                    nearby_places_counter += 1
                    # app('System Events').keystroke(' ')  # simulate pressing blank space

        cv2.imshow('output', drawing)
        if sos_counter >= 10 and sos_called_counter == 0:
            phone.call('+917903535980')
            sos_counter = 0
            sos_called_counter += 1
        if nearby_places_counter == 10:
            latitude, longitude = get_location()
            new_nearby_places.get_Nearest_Petrol_Station(
                latitude, longitude, "petrol-station")
            nearby_places_counter = 0
    # Keyboard OP
    k = cv2.waitKey(10)
    if k == 27:  # press ESC to exit
        camera.release()
        cv2.destroyAllWindows()
        break
    elif k == ord('b'):  # press 'b' to capture the background
        bgModel = cv2.createBackgroundSubtractorMOG2(0, bgSubThreshold)