Exemplo n.º 1
0
    def statistic(self):
        now = time.time()
        if now > self.last_statistic_time + 60:
            rtt = 0
            sent = 0
            received = 0
            for stat in self.second_stats:
                rtt = max(rtt, stat["rtt"])
                sent += stat["sent"]
                received += stat["received"]
            self.minute_stat = {"rtt": rtt, "sent": sent, "received": received}
            self.second_stats = queue.deque()
            self.last_statistic_time = now

        if len(self.rtts):
            rtt = max(self.rtts)
        else:
            rtt = 0

        self.second_stat = {
            "rtt": rtt,
            "sent": self.total_sent - self.last_sent,
            "received": self.total_received - self.last_received
        }
        self.rtts = []
        self.last_sent = self.total_sent
        self.last_received = self.total_received
        self.second_stats.append(self.second_stat)
def plot_radar_raw_data_message(xep, baseband=True, frames_number=1):
    def read_frame():
        """Gets frame data from module"""
        d = xep.read_message_data_float()  # wait until get data
        frame = np.array(d.data)
        # print('frame length:' + str(len(frame)))
        # Convert the resulting frame to a complex array if downconversion is enabled
        if baseband:
            n = len(frame)
            frame = abs((frame[:n // 2] + 1j * frame[n // 2:]))
        return frame

    # initialization function: plot the background of each frame

    def init():
        for i in range(len(frames)):
            lines[0].set_data(x, Y[i])
            lines[0].set_3d_properties(frames[i])
        return lines

    def update_lines(ii):
        q.appendleft(read_frame())
        for i in range(len(lines)):
            lines[i].set_data(x, Y[i])
            lines[i].set_3d_properties(q[i])
        fig.canvas.draw()
        return lines

    frames = np.array([read_frame() for i in range(frames_number)])
    rangebins_number = len(frames[0])
    fps = xep.x4driver_get_fps()

    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    # ax.axis('off')
    # keep graph in frame (FIT TO YOUR DATA), can be adjusted
    ax.set_xlabel('Range Bins Number: ' + str(rangebins_number))
    ax.set_ylabel('Frames Number: ' + str(frames_number))
    # ax.set_zlabel('Power')
    ax.set_zlim3d(0 if baseband else -0.08, 0.08)

    x = np.arange(rangebins_number)
    y = np.arange(frames_number)
    X, Y = np.meshgrid(x, y)
    q = queue.deque(frames, frames_number)
    colors = ['b'] * frames_number
    colors[0] = 'r'
    lines = [
        ax.plot(x, Y[i], frames[i], '-', color=colors[i])[0]
        for i in range(frames_number)
    ]
    anim = FuncAnimation(fig,
                         update_lines,
                         interval=1,
                         init_func=init,
                         blit=True)
    plt.show()
Exemplo n.º 3
0
    def __init__(self,
                 logger,
                 config,
                 ip_manager,
                 connection_manager,
                 http1worker=Http1Worker,
                 http2worker=Http2Worker):
        self.logger = logger
        self.config = config
        self.ip_manager = ip_manager
        self.connection_manager = connection_manager
        self.connection_manager.set_ssl_created_cb(self.on_ssl_created_cb)

        self.http1worker = http1worker
        self.http2worker = http2worker

        self.request_queue = queue.Queue()
        self.workers = []
        self.working_tasks = {}
        self.h1_num = 0
        self.h2_num = 0
        self.last_request_time = time.time()
        self.task_count_lock = threading.Lock()
        self.task_count = 0
        self.running = True

        # for statistic
        self.success_num = 0
        self.fail_num = 0
        self.continue_fail_num = 0
        self.last_fail_time = 0
        self.rtts = []
        self.last_sent = self.total_sent = 0
        self.last_received = self.total_received = 0
        self.second_stats = queue.deque()
        self.last_statistic_time = time.time()
        self.second_stat = {"rtt": 0, "sent": 0, "received": 0}
        self.minute_stat = {"rtt": 0, "sent": 0, "received": 0}

        self.trigger_create_worker_cv = SimpleCondition()
        self.wait_a_worker_cv = simple_queue.Queue()

        threading.Thread(target=self.dispatcher).start()
        threading.Thread(target=self.create_worker_thread).start()
        threading.Thread(target=self.connection_checker).start()