Exemplo n.º 1
0
    def clean_points(self):
        points = []

        if not self.cleaned_data.get('points'):
            return points

        try:
            json_points = json.loads(self.cleaned_data.get('points'))

            if not json_points:
                return points

            for p in json_points:
                _id = p.get('properties').get('id')

                if _id:
                    point = models.Point.objects.get(id=_id)
                else:
                    point = models.Point()

                point.coords = Point(p.get('coordinates'))
                point.address = p.get('properties').get('address')

                points.append(point)

            return points
        except ValueError:
            pass

        return points
Exemplo n.º 2
0
    def test_basic_u(self):

        np.random.seed(401)

        z_ref = -1
        width = 10
        length = 10

        # planes
        x_planes = []
        x_offsets = np.cumsum(np.random.randint(1, 3, 6)) - width / 2
        for x in x_offsets:
            x_planes.append(models.Plane.from_axis_distance(axis=np.array([1, 0, 0]), distance=x))
        y_planes = []
        y_offsets = np.cumsum(np.random.randint(1, 3, 5)) - length / 2
        for y in y_offsets:
            y_planes.append(models.Plane.from_axis_distance(axis=np.array([0, 1, 0]), distance=y))

        # boundaries
        boundaries = [simulator.rectangle(x_planes[4], x=np.mean([y_offsets[3], y_offsets[2]]), y=0, w=y_offsets[3]-y_offsets[2]-0.3, h=2),
                      simulator.rectangle(x_planes[5], x=np.mean([y_offsets[4], y_offsets[1]]), y=0, w=y_offsets[4]-y_offsets[1]-0.5, h=2),
                      simulator.rectangle(y_planes[1], x=-np.mean([x_offsets[5], x_offsets[1]]), y=0, w=x_offsets[5]-x_offsets[1]-0.4, h=2),
                      simulator.rectangle(y_planes[2], x=-np.mean([x_offsets[4], x_offsets[1]]), y=0, w=x_offsets[4]-x_offsets[1]-0.2, h=2),
                      simulator.rectangle(y_planes[3], x=-np.mean([x_offsets[4], x_offsets[1]]), y=0, w=x_offsets[4]-x_offsets[1]-0.25, h=2),
                      simulator.rectangle(y_planes[4], x=-np.mean([x_offsets[5], x_offsets[1]]), y=0, w=x_offsets[5]-x_offsets[1]-0.1, h=2)
                      ]

        # evidence
        evidence_index = [((2, 2), (1, 1)),
                          ((4, 2), (2, 1)),
                          ((5, 2), (4, 1)),
                          ((5, 4), (4, 2)),
                          ((4, 4), (3, 3)),
                          ((3, 4), (2, 3)),
                          ((2, 4), (1, 3)),
                          ((3, 1), (2, 0))]

        evidence = [models.Point(np.array([-2, 3, 0]))]
        for ev in evidence_index:
            tr_corner = np.array([x_offsets[ev[0][0]], y_offsets[ev[0][1]]])
            bl_corner = np.array([x_offsets[ev[1][0]], y_offsets[ev[1][1]]])
            diff = tr_corner - bl_corner

            center = np.mean(np.array([tr_corner, bl_corner]), axis=0)
            ellipse = simulator.ellipse(float(diff[0]) / 2, float(diff[1]) / 2, 3).rigid(np.eye(2), center)
            evidence.append(ellipse)

        # construct
        cell_complex = models.CellComplex2D(z_ref=z_ref, width=width, length=length, evidence=evidence)
        # cell_complex = models.CellComplex2D(z_ref=z_ref, width=width, length=length)
        for p in x_planes + y_planes:
            cell_complex.insert_partition(p)
        for b in boundaries:
            cell_complex.insert_boundary(b)

        speculator = estimators.FloorPlanSpeculator(cell_complex, horizon=1)
        scene_graph = speculator.floorplan()
        # scene_graph = cell_complex.cell_graph()

        cell_complex.draw(scene_graph)
Exemplo n.º 3
0
def insert_Points_into_DB():
    point_1 = models.Point(
        score=5,
        question=
        'Из какого мультфильма строчки песни: Взгляни вокруг, оглянись назад, духи с тобой связаться хотят',
        wrong_answer='Скуби-Ду;Гравити Фолз;Рик и Морти',
        right_answer='Шаман Кинг',
        reaction=
        'Неверно, это начало опенинга к аниме Шаман Кинг;Верно, а у тебя хорошее детство было :Р'
    )
    point_2 = models.Point(
        score=5,
        question=
        'Из какого фильма строчка песни: Со мною вот что происходит, ко мне мой лучший друг не ходит',
        wrong_answer='Двенадцать стульев;Полосатый рейс;Кавказская пленница',
        right_answer='Ирония судьбы',
        reaction=
        'Неверно, это начальная песня советского фильма Ирония Судьбы;Верно!')
    point_3 = models.Point(
        score=10,
        question=
        'Из какого мультфильма строчка песни: But the meteor men beg to differ',
        wrong_answer='Холодное сердце;Ледниковый период;Би муви',
        right_answer='Шрек',
        reaction=
        'Неверно, это же All stars из Шрека;Верно, да ты фанат Шрека!!!')
    point_4 = models.Point(
        score=10,
        question=
        'Из какого фильма строчка песни: And the last known survivor stalks his prey in the night',
        wrong_answer='Телохранитель;Бойцовский клуб;Терминатор',
        right_answer='Рокки',
        reaction=
        'Неверно, это Eye of the tiger, знаменитая песня из Рокки;Верно!')
    point_1.save()
    point_2.save()
    point_3.save()
    point_4.save()
Exemplo n.º 4
0
    def save_points(self):
        geo_json = self.cleaned_data.get('geo_json')
        points = []

        for p in geo_json.get('points', []):
            point = models.Point()
            point.helprequest = self.instance
            point.user = self.instance.requester
            point.coords = Point(p.get('coordinates'))
            point.address = p.get('properties').get('address')
            points.append(point)

        self.instance.point_set.bulk_create(points)
        return points
Exemplo n.º 5
0
    plt.show()


def iterateClusters(vectors, clusters, old=[]):
    new = assignCluster(vectors, clusters)
    iterateClusters(vectors, new, clusters)


if __name__ == "__main__":
    vectors = []
    clusters = []
    k = 7  # Number of clusters
    data = helpers.readData('data_1024.csv', '\t')

    for coord in zip(data['Distance_Feature'], data['Speeding_Feature']):
        vector = models.Point(coord, None)
        vectors.append(vector)

    clusters = generateClusters(vectors, k)

    coordList = [
    ]  # Used for detecting duplicates, once a duplicate is shown the loop will break.

    while True:
        clusters = assignCluster(vectors, clusters)

        for y in clusters:
            coordList.append(y.coordinates)
            print(str(y.coordinates) + '\n -------')

        if len(helpers.listDuplicates(coordList)) != 0:
Exemplo n.º 6
0
    def get(self):

        template = JINJA_ENVIRONMENT.get_template('game.html')

        team_one_name = self.request.get('one')
        team_two_name = self.request.get('two')

        hypeTable = models.HypeTable.query(
            ndb.OR(models.HypeTable.teamOneName == team_one_name,
                   models.HypeTable.teamOneName == team_two_name)).fetch()[0]

        team_one_coordinates = models.GeoData.query(
            models.GeoData.teamName ==
            hypeTable.teamOneName).fetch()[0].coordinates.split('|')
        team_two_coordinates = models.GeoData.query(
            models.GeoData.teamName ==
            hypeTable.teamTwoName).fetch()[0].coordinates.split('|')

        team_one_points = [
            models.Point(point) for point in team_one_coordinates
        ]
        team_two_points = [
            models.Point(point) for point in team_two_coordinates
        ]

        team_one_top_list = models.TopTweet.query(
            team_one_name == models.TopTweet.teamName).fetch()
        team_two_top_list = models.TopTweet.query(
            team_two_name == models.TopTweet.teamName).fetch()

        team_one_top = team_one_top_list[0] if len(
            team_one_top_list) > 0 else {}
        team_two_top = team_two_top_list[0] if len(
            team_two_top_list) > 0 else {}

        latest_tweets = models.LatestTweets.query(
            ndb.OR(models.LatestTweets.teamName == team_one_name,
                   models.LatestTweets.teamName == team_two_name)).fetch()
        random.shuffle(latest_tweets)

        template_values = {
            'game_title': hypeTable.gameTitle,
            'game_time': hypeTable.gameTime,
            'game_location': hypeTable.gameLocation,
            'team_one_color': hypeTable.teamOneColor,
            'team_two_color': hypeTable.teamTwoColor,
            'team_one_name': hypeTable.teamOneName,
            'team_two_name': hypeTable.teamTwoName,
            'team_one_total': hypeTable.teamOneTweetTotal,
            'team_two_total': hypeTable.teamTwoTweetTotal,
            'team_one_hype': hypeTable.teamOneHype,
            'team_two_hype': hypeTable.teamTwoHype,
            'team_one_image': hypeTable.teamOneImage,
            'team_two_image': hypeTable.teamTwoImage,
            'team_one_hashtags': hypeTable.teamOneHashTags.split(','),
            'team_two_hashtags': hypeTable.teamTwoHashTags.split(','),
            'team_one_tweets': team_one_points,
            'team_two_tweets': team_two_points,
            'team_one_top': team_one_top,
            'team_two_top': team_two_top,
            'latest_tweets': latest_tweets,
            'hype_history': hypeTable.gameHypeHistory,
            'time_history': hypeTable.gameTimeHistory
        }
        self.response.write(template.render(template_values))
def print(*args, **kwargs):
    """ custom print function, adding functionality for Points """
    new_args = []
    for arg in args:
        if builtins.isinstance(arg, models.Point):
            new_args.append("({0}, {1})".format(arg.x, arg.y))
        else:
            new_args.append(arg)

    builtins.print(*new_args, **kwargs)


p = 2**256 - 2**32 - 2**9 - 2**8 - 2**7 - 2**6 - 2**4 - 1
curve = models.Curve(a=0, b=7, p=p)

G_x = int("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
          16)
G_y = int("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",
          16)

G = models.Point(G_x, G_y, curve)

priv_key0 = 17  # should pick a huge number for priv_key
pub_key0 = G * priv_key0

priv_key1 = 23
pub_key1 = G * priv_key1

print(pub_key0, pub_key1)
print(pub_key0 * priv_key1 == pub_key1 * priv_key0)  # should print True