Python быстрый способ проверить N точек в одной и той же «области» - PullRequest
0 голосов
/ 09 ноября 2019

У меня на телефоне приложение для нажатия.

Я хочу взять последние N точек, чтобы он не нажимал одно и то же "место" снова и снова.

Я думаю, это так. должно быть примерно так:

enter image description here

Этого я хочу избежать. Я полагаю, что центр циркуляции должен быть центром всех точек? Как определить радиус?

Я думаю, что вычисление последних N точек можно использовать для вычисления "новых" N точек после того, как сделан новый щелчок, чтобы снизить производительность.

Любые предложения? Спасибо

1 Ответ

0 голосов
/ 11 ноября 2019
    def clicking_loop_protection(self, x, y, methods):
        '''
        :param x:
        :param y:
        :param method: 'xpath'/'point' it can be both
        :return:
        '''

        def centroid(points):
            _len = len(points)

            x_coords = [p[0] for p in points]
            y_coords = [p[1] for p in points]

            centroid_x = sum(x_coords) / _len
            centroid_y = sum(y_coords) / _len
            return centroid_x, centroid_y

        def calculate_points_distance(x1, y1, x2, y2):
            dist = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
            return dist

        point_res = True

        if 'point' in methods:
            # add current point
            _point = (x, y)
            try:
                self.points_history[self.points_history_index] = _point
            except IndexError:
                self.points_history.append(_point)

            if len(self.points_history) == self.points_history_length:
                centroid_point_x, centroid_point_y = centroid(self.points_history)
                radius = self.displayWidth/10

                for point in self.points_history:
                    # distance from centroid should be less than radius (to fail the test)
                    distance = calculate_points_distance(centroid_point_x, centroid_point_y, point[0], point[1])
                    if distance > radius:
                        point_res = True  # pass test !
                        break
                    else:
                        point_res = False

            self.points_history_index += 1
            self.points_history_index %= self.points_history_length

        return xpath_res and point_res
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...