예제 #1
0
 def __init__(self,
              username,
              firstname,
              lastname,
              gender,
              wins=0,
              defeats=0):
     Person.__init__(self, lastname, firstname, gender)
     self.wins = wins
     self.defeats = defeats
     self.username = username
예제 #2
0
def create_user():
    data = request.get_json()
    if '' in dict(data).values():
        return jsonify({'message': 'Please fill out all fields!'})
    person = Person(first_name=data['first_name'],
                    last_name=data['last_name'],
                    hours_worked=data['hours_worked'])
    db.session.add(person)
    db.session.commit()
    return jsonify({'message': 'New user created!'})
예제 #3
0
파일: Database.py 프로젝트: wlockwood/lits
    def get_all_people(self):
        sql = "SELECT * from Person"
        dbresponse = self.connection.execute(sql)
        results = dbresponse.fetchall()

        output = []
        for p_row in results:
            person_id = p_row["id"]
            found_encodings = self.get_encodings_by_person_id(person_id)
            output.append(Person(person_id, p_row["name"], found_encodings))

        return output
예제 #4
0
    def test_multiple_pictures_per_known(self):
        # Requires more convoluted test setup for the known person
        known_images = []
        encode_faces(known_images)
        test_person = Person("will")
        test_person.encodings = [
            enc for im in known_images for enc in im.encodings_in_image
        ]  # Flat?

        unknown_images = encode_faces(self.will_as_unknown.filepath)
        best_matches = match_best([test_person],
                                  unknown_images[0].encodings_in_image)
        self.assertEqual(
            1, len(best_matches),
            "couldn't match a face using multiple images for known person")

        unknown_images = encode_faces(self.sam_will_trail.filepath)
        best_matches = match_best([test_person],
                                  unknown_images[0].encodings_in_image)
        self.assertEqual(
            1, len(best_matches),
            "couldn't match a face using multiple images for known person")
예제 #5
0
파일: Database.py 프로젝트: wlockwood/lits
    def get_person_by_name(self, name: str) -> Optional[Person]:
        sql = "SELECT * FROM Person WHERE name = ?"
        dbresponse = self.connection.execute(sql, [name])
        results = dbresponse.fetchall()

        if len(results) < 1:
            return None
        if len(results) > 1:
            raise Exception(f"Multiple people found with name {name}")
        row = results[0]
        person_id = row["id"]
        encodings = self.get_encodings_by_person_id(person_id)

        return Person(person_id, row["name"], encodings)
예제 #6
0
 def getUserById(self, person_id):
     cursor = self.connection.cursor()
     cursor.execute("SELECT * FROM person WHERE person_id=%s", [person_id])
     row = cursor.fetchall()
     user = Person()
     user.set_fields(row[0][0], row[0][1], row[0][2], row[0][3], row[0][4],
                     row[0][5])
     user.set_password_hash(row[0][6])
     return user
예제 #7
0
 def getUserByLogin(self, login):
     cursor = self.connection.cursor()
     print(login)
     cursor.execute("SELECT * FROM person WHERE login=%(str)s",
                    {"str": login})
     row = cursor.fetchall()
     if len(row) == 0:
         return None
     user = Person()
     user.set_fields(row[0][0], row[0][1], row[0][2], row[0][3], row[0][4],
                     row[0][5])
     user.set_password_hash(row[0][6])
     print(user.name + " " + user.login + " " + user.password_hash)
     return user
예제 #8
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('login')
     parser.add_argument('password')
     parser.add_argument('name')
     parser.add_argument('surname')
     parser.add_argument('patronymic')
     parser.add_argument('bday')
     args = parser.parse_args()
     login = str(args['login'])
     password = str(args['password'])
     name = str(args["name"])
     surname = str(args["surname"])
     patronymic = str(args["patronymic"])
     bday = str(args["bday"])
     user = database_controller.getUserByLogin(login)
     if user is None:
         user = Person()
         user.set_fields(None, name, surname, patronymic, bday, login)
         user.set_password(password)
         database_controller.insert_person(user)
         user = database_controller.getUserByLogin(login)
     login_user(user, remember=True)
     return json.dumps("Login success")
예제 #9
0
class TestFaceRecognizer(unittest.TestCase):
    my_dir = path.dirname(__file__)

    known_image = ImageFile(test_data_path + "known.jpg", skip_md_init=True)
    test_face = FaceEncoding(-1, encode_faces(known_image.filepath)[0])
    test_person = Person(-1, "will", [test_face])

    will_as_unknown = ImageFile(test_data_path + "man.jpg", skip_md_init=True)
    mushroom = ImageFile(test_data_path + "mushroom.jpg", skip_md_init=True)
    multiple_people = ImageFile(test_data_path + "people.jpg",
                                skip_md_init=True)
    different_person = ImageFile(test_data_path + "woman right.jpg",
                                 skip_md_init=True)

    # Should match when same person
    def test_one_to_one_match(self):
        self.will_as_unknown.encodings_in_image = [
            FaceEncoding(-1, fe)
            for fe in encode_faces(self.will_as_unknown.filepath)
        ]
        best_matches = match_best([self.test_person],
                                  self.will_as_unknown.encodings_in_image)
        self.assertEqual(len(best_matches), 1,
                         "face didn't match itself in another picture")

    @unittest.skip("Not yet implemented")
    def test_multiple_pictures_per_known(self):
        # Requires more convoluted test setup for the known person
        known_images = []
        encode_faces(known_images)
        test_person = Person("will")
        test_person.encodings = [
            enc for im in known_images for enc in im.encodings_in_image
        ]  # Flat?

        unknown_images = encode_faces(self.will_as_unknown.filepath)
        best_matches = match_best([test_person],
                                  unknown_images[0].encodings_in_image)
        self.assertEqual(
            1, len(best_matches),
            "couldn't match a face using multiple images for known person")

        unknown_images = encode_faces(self.sam_will_trail.filepath)
        best_matches = match_best([test_person],
                                  unknown_images[0].encodings_in_image)
        self.assertEqual(
            1, len(best_matches),
            "couldn't match a face using multiple images for known person")

    # Should work with multiple matches in picture
    def test_multiple_unknown_in_picture(self):
        unknown_faces = [
            FaceEncoding(-1, fe)
            for fe in encode_faces(self.multiple_people.filepath)
        ]
        best_matches = match_best([self.test_person], unknown_faces)
        self.assertEqual(
            1, len(best_matches),
            "face didn't match with itself in a picture with other people as well"
        )

    # Shouldn't match on different person
    def test_no_match(self):
        unknown_faces = [
            FaceEncoding(-1, fe)
            for fe in encode_faces(self.different_person.filepath)
        ]
        best_matches = match_best([self.test_person], unknown_faces)
        self.assertEqual(0, len(best_matches),
                         "face matched against a different face")

    # Shouldn't match on a mushroom
    def test_not_a_person(self):
        unknown_faces = [
            FaceEncoding(-1, fe) for fe in encode_faces(self.mushroom.filepath)
        ]
        faces_found = len(unknown_faces)
        self.assertEqual(0, faces_found,
                         "found a face match when looking at a mushroom")
예제 #10
0
class TestDatabase(unittest.TestCase):
    # DB Info
    test_db_path = "test.db"

    # Set up a basic image to test with
    test_image_path = test_data_path + "known.jpg"
    test_image = ImageFile(test_image_path)
    base_test_image = ImageFile(
        test_image_path
    )  # Will be copied, since many DB calls are writing to the input image
    base_test_image.encodings_in_image = [
        FaceEncoding(-1, enc) for enc in encode_faces(base_test_image.filepath)
    ]

    test_person = Person(-1, "Will", base_test_image.encodings_in_image)

    base_test_image.matched_people = [test_person]
    test_person.encodings = [base_test_image.encodings_in_image[0]]

    def setUp(self):
        self.test_db = Database(self.test_db_path)

        # Clean out the database
        self.test_db.connection.executescript("DELETE FROM Image")
        self.test_db.connection.executescript("DELETE FROM Person")
        self.test_db.connection.executescript("DELETE FROM Encoding")
        self.test_db.connection.executescript("DELETE FROM PersonEncoding")
        self.test_db.connection.executescript("DELETE FROM ImageEncoding")

        # Clone the test image to reduce time spent encoding
        self.this_test_image: ImageFile = deepcopy(self.base_test_image)

    def test_add_image(self):
        # This will fail if anything else does, which isn't ideal, but I want to make sure it's thorough
        new_image_id = self.test_db.add_image(self.this_test_image, [])
        dbresponse = self.test_db.connection.execute("SELECT * FROM Image")
        result = dbresponse.fetchall()
        test_row = result[0]

        self.assertEqual(
            1, len(result),
            "Wrong number of images inserted when trying to add one")
        second_image_id = self.test_db.add_image(self.this_test_image, [])
        self.assertEqual(new_image_id, second_image_id,
                         "Inserted same file twice, got different Ids")
        self.assertEqual(os.path.getsize(self.this_test_image.filepath),
                         test_row["size_bytes"])

    def test_encoding_ops(self):
        self.test_db.connection.executescript("DELETE FROM Encoding")
        self.assertRaises(
            Exception,
            self.test_db.add_encoding,
            [self.this_test_image.encodings_in_image],
            msg=
            "Expected a failure while trying to add an unassociated encoding, but succeeded."
        )

        # Strip and store an encoding
        test_encoding = self.this_test_image.encodings_in_image[0].encoding
        self.this_test_image.encodings_in_image = []
        id_of_partial_image = self.test_db.add_image(self.this_test_image,
                                                     [test_encoding])
        self.test_db.connection.commit()
        new_enc = self.test_db.add_encoding(test_encoding,
                                            associate_id=id_of_partial_image,
                                            image=True)

        dbresponse = self.test_db.connection.execute("SELECT * FROM Encoding")
        result = dbresponse.fetchall()

        retrieved_encoding_bytes = result[0]["encoding"]
        retrieved_encoding: numpy.ndarray = numpy.frombuffer(
            retrieved_encoding_bytes, "float64")

        self.assertTrue(numpy.array_equal(test_encoding, retrieved_encoding),
                        "Encoding didn't survive being stored and retrieved")
예제 #11
0
    def __str__(self):
        athleteInfo = Person.__str__(self)
        #athleteInfo += str(self._exercises)

        return athleteInfo
예제 #12
0
    def __init__(self, name, surname, sex, birthDate, height, mass):
        Person.__init__(self, name, surname, sex, birthDate, height, mass)

        database = Pushup()
        self.pushups = database.getPushupsByAthlete(self._name)
예제 #13
0
from Model.Person import Person
from Database.QueryDB import *
from View.IndexView import showinsertmessage

if __name__ == "__main__":
    
    # Model (Person : name, lnam , age , address , nationalcode, ...)
    obj_person = Person("nima", "safari", "tehran")
    # print(obj_person.retname())
    
    # Add database : insert 
    obj_database = Connection()
    retconn = obj_database.connecting_to_database()
    # Create Table
    # obj_database.createtable_company()

    obj_mysqlauery = MySQLQuerys(retconn)
    obj_mysqlauery.insert()
    # show : selectall:  "select * from Person"
    # show : selectone: "select * from Person where userid=123
    # delete : delete : "delete from Person where userid=123"
    # update : "update Person set value("", "", "")"
    print(showinsertmessage())