Exemplo n.º 1
0
def add_phone(data):
    name, phone = data

    result_name = session.query(Contact).filter(
        Contact.contact_name == name).first()

    result_phone = session.query(Phone).filter(Phone.phone == phone).first()

    if result_name and result_phone:
        info = '\n\tEntered contact with phone already exist'
    else:
        try:
            new_contact_name = Contact(contact_name=name)
            session.add(new_contact_name)
            session.commit()

            new_contact_phone = Phone(phone=phone,
                                      contact_id=new_contact_name.id)
            session.add(new_contact_phone)
            session.commit()

            info = '\n\tContact has been successfully added to addressbook'
        except Exception as e:
            print(e)
            info = '\n\tCheck entered data.'

    return info
Exemplo n.º 2
0
def get_models():
    models = {}
    for person in session.query(Person).all():
        if person.person not in models:
            models[person.person] = []
        models[person.person].append(np.array(json.loads(person.marks)))
    return models
Exemplo n.º 3
0
def show_all_contacts():
    result = session.query(Contact.id, Contact.contact_name,
                           Phone.phone).join(Phone).all()
    output = ''
    for el in result:
        output += f'\t{el[1]} - {el[-1]}\n'
    return output
Exemplo n.º 4
0
def show_one_contact_data(data):
    name, _ = data
    result = session.query(
        Contact.id, Contact.contact_name,
        Phone.phone).join(Phone).filter(Contact.contact_name == name).all()
    if result:
        output = ''
        for el in result:
            output += f'\t{el[1]} - {el[-1]}\n'
    else:
        output = '\tThere is not such contact.'
    return output
Exemplo n.º 5
0
def delete_contact(data):
    name, _ = data
    result = session.query(Contact).filter(Contact.contact_name == name).all()

    if result:

        for _ in range(len(result)):

            result = session.query(Contact).filter(
                Contact.contact_name == name).first()
            id = result.id

            if result:
                result = session.query(Contact).get(id)
                session.delete(result)
                session.commit()

        output = f'\tAll info for contact {name} were deleted'

    else:
        output = '\tThere is not such contact.'

    return output
Exemplo n.º 6
0
def change_phone(data):
    name, phone = data
    result = session.query(
        Contact.id, Contact.contact_name, Phone.phone,
        Phone.id).join(Phone).filter(Contact.contact_name == name).all()

    contact_phones = {}

    if result:
        output = ''
        for el in result:
            contact_phones[el[-1]] = el[2]

            output += f'\tContact data: {el[1]} - {el[2]}. Phone id - {el[-1]}\n'
    else:
        output = '\tThere is not such contact.'
    print('=' * 75)
    print(output)

    user_imput = int(input('Enter phone <id> for phone you want to change: '))
    if user_imput in contact_phones.keys():
        new_phone = input('Enter new contact phone number: ')

        raw_phone = re.search(r'38(097|098|096|068|067|063|068|099)\d{7}',
                              new_phone)
        new_phone = raw_phone.group() if raw_phone else False
        if new_phone:
            new = session.query(Phone).get(user_imput)
            new.phone = new_phone
            session.add(new)
            session.commit()
            output = '\tContact was successfully changed.'
        else:
            output = '\tInvalid phone format. Repeat command'
    else:
        output = '\tThere is not such contact. Repeat command'
    return output
Exemplo n.º 7
0
if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-p', '--predictor',    required=False, help="large or small", default="large")
    parser.add_argument('-m', '--model',        required=False, help="model name")
    parser.add_argument('-l', '--list-models',  required=False, help="list trained models", action='count')
    parser.add_argument('-r', '--remove-model', required=False, help="remove trained model", type=str)

    parser.add_argument('-t', '--train',        required=False, help="train model name")
    parser.add_argument('-i', '--images',       required=False, help="dir with images or list images")

    parser.add_argument('-g', '--adjust-gamma', required=False, help="set adjust gamma", type=float, default=1.0)
    parser.add_argument('-c', '--calibrate-adjust-gamma', required=False, help="show window for calibrate adjust gamma", action='count')

    args = parser.parse_args()

    log.info('started')
    cap = get_cap()

    if args.train:
        train(args.train, args.images)
    elif args.calibrate_adjust_gamma:
        calibrate_adjust(cap, args.adjust_gamma)
    else:
        if args.model:
            marks = [np.array(json.loads(mark.marks)) for mark in session.query(Person.marks).filter(Person.person == args.model).all()]
            run(cap, {args.model: marks}, args.adjust_gamma, args.predictor)
        else:
            models = get_models()
            while True:
                list(run(cap, models, args.adjust_gamma, args.predictor))