Esempio n. 1
0
    def __import_beacons(self, lines):
        """
        Importe les donnees relative aux balises a partir d un fichier texte
        passe en entree et les stocke dans la BDD
        :param lines: fichier texte contenant les balises a importer
        :return: None
        """
        logging.debug("Importation des balises")
        l_beacons = self.__line_search(lines, "NBeacons:", "########## Layers")

        if l_beacons == []:
            print("Aucune balise dans le fichier")

        for beacon in l_beacons:
            # Attention: la position est une str ici, pas un entier
            (b_name, b_x_pos, b_y_pos) = beacon.split()[0:3]
            ### chercher du becon
            r_beacon = self.session.query(mod.Beacon)\
                                   .filter(mod.Beacon.name==b_name)\
                                   .first()
            if r_beacon is None:
                # Ajout de la balise a la bdd si elle n'y est pas deja
                r_beacon = mod.Beacon(name = b_name, 
                                      pos_x = int(b_x_pos)/8.0,
                                      pos_y = int(b_y_pos)/8.0)
            else:
                # Cas ou une balise portant le meme nom est dans la bdd
                r_beacon.pos_x = int(b_x_pos)/8.0
                r_beacon.pos_y = int(b_y_pos)/8.0
            self.session.add(r_beacon)
        logging.debug("%d balises ont été importées" % len(l_beacons))
Esempio n. 2
0
def initdb(username, password):
    db.create_all()
    import binascii
    u = models.User(email=username, password_hash=bcrypt.generate_password_hash(binascii.hexlify(password)), role=0, status=1)
    db.session.add(u)
    db.session.commit()
    print 'Database initialized.'
    # remove below for production
    t = models.Target(name='demo', guid='aedc4c63-8d13-4a22-81c5-d52d32293867')
    db.session.add(t)
    db.session.commit()
    b = models.Beacon(target_guid='aedc4c63-8d13-4a22-81c5-d52d32293867', agent='HTML', ip='1.2.3.4', port='80', useragent='Mac OS X', comment='this is a comment.', lat='38.2531419', lng='-85.7564855', acc='5')
    db.session.add(b)
    db.session.commit()
    b = models.Beacon(target_guid='aedc4c63-8d13-4a22-81c5-d52d32293867', agent='HTML', ip='5.6.7.8', port='80', useragent='Mac OS X', comment='this is a comment.', lat='34.855117', lng='-82.114192', acc='1')
    db.session.add(b)
    db.session.commit()
Esempio n. 3
0
        train_generator = utils.seq_batch_generator(training_instances,
                                                    item_dict,
                                                    config.batch_size)
        validate_generator = utils.seq_batch_generator(validate_instances,
                                                       item_dict,
                                                       config.batch_size,
                                                       False)
        test_generator = utils.seq_batch_generator(testing_instances,
                                                   item_dict,
                                                   config.batch_size, False)

        # Initialize the network
        print(" + Initialize the network")
        net = models.Beacon(sess, config.emb_dim, config.rnn_unit,
                            config.alpha, MAX_SEQ_LENGTH, item_probs,
                            adj_matrix, config.top_k, config.batch_size,
                            config.rnn_cell_type, config.dropout_rate,
                            config.seed, config.learning_rate, config.pooling)

        print(" + Initialize parameters")
        sess.run(tf.global_variables_initializer())

        print("================== TRAINING ====================")
        print("@Start training")
        procedure.train_network(sess, net, train_generator, validate_generator,
                                config.nb_epoch, total_train_batches,
                                total_validate_batches, config.display_step,
                                config.early_stopping_k, config.epsilon,
                                tensorboard_dir, model_dir, test_generator,
                                total_test_batches)