Exemplo n.º 1
0
def organisation_delete():
    """
    This function deletes the organisation whose organisation code is entered
    :return: Displays 'Deleted Successfully'
    """
    test_connection = sql_connection()
    if test_connection[0] == 130:
        return redirect(
            url_for('error',
                    error_str=test_connection[1],
                    error_code=test_connection[0]))

    org_code = request.form['code']
    check = extract_info(functions.s_org_table, functions.s_org_code, org_code)
    if check[0] == 228:
        org_id = check[1][0][functions.s_org_id]
        try:
            del_org(org_id)
            try:
                return render_template('delete.html')
            except:
                return redirect(
                    url_for('error',
                            error_str=sys.exc_info()[1],
                            error_code=render_issue))
        except:
            return redirect(
                url_for('error',
                        error_str=sys.exc_info()[1],
                        error_code=delete_issue))
    return redirect(url_for('error', error_str=check[1], error_code=check[0]))
Exemplo n.º 2
0
def upload_file(username):
    """
    This function takes an image as input and detects the faces in it. Also it updates the database accordingly.
    :param username: User Name of the user who is uploading the image
    :return: Displays necessary data as JSON object containing all the necessary details of the faces detected
    """
    start = time.time()
    upload_folder = os.path.basename('temp_img_dir')
    app.config['UPLOAD_FOLDER'] = upload_folder

    time_now = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    cameracode = request.form['camcode']
    camera_id = cameracode[3:]

    info = extract_info(functions.s_cam_table, functions.s_cam_id, camera_id)[1]

    if info[0] == 128:
        return redirect(url_for('error', error_str=info[1], error_code=info[0]))

    if len(info) == 0:
        return redirect(url_for('error', error_str=errordict[113], error_code=113))

    if str(info[0][functions.s_mrkdel]) == '1':
        return redirect(url_for('error', error_str=errordict[114], error_code=114))

    bucket_id = info[0][functions.s_buc_id]
    oid = info[0][functions.s_org_id]
    bucket_code = 'BUC' + str(bucket_id).zfill(9)
    o_code = 'ORG' + str(oid).zfill(5)

    file = request.files['image']
    imgtxn_id = str((functions.initial_transaction(bucket_id, oid, camera_id))[1]).zfill(10)
    file.filename = (imgtxn_id + '_' + time_now + '.jpg').replace(' ', '_')
    f = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
    file.save(f)

    time_capture = get_datetime(functions.dir_path + functions.temp_img_dir + file.filename)
    if len(time_capture) == 0:
        time_capture = time_now

    img_path = '/Organisations' + o_code + '/' + bucket_code + '/' + cameracode + '_dump/' + file.filename
    full_img_txn(imgtxn_id, img_path, time_capture, time_now)

    json1 = input_image(cameracode, time_now, imgtxn_id, bucket_id, oid, camera_id, time_capture)
    json_2 = json.loads(json1)
    end = time.time()
    time_taken = start - end
    res = json.dumps(json_2, indent=4, sort_keys=True) + str(time_taken)
    return render_template('result.html', value=res, username=username)
Exemplo n.º 3
0
def user_new():
    """
    This function checks the values entered to create a new user and if everything is fine, it creates one.
    :return: Displays 'User Name' of the user created
    """
    test_connection = sql_connection()
    if test_connection[0] == 130:
        return redirect(
            url_for('error',
                    error_str=test_connection[1],
                    error_code=test_connection[0]))

    username = request.form[user_form[0]]
    password = request.form[user_form[1]]
    email = request.form[user_form[2]]
    orgcode = request.form[user_form[3]]
    display_name = request.form[user_form[4]]
    created_date_time = str(datetime.datetime.now())
    check = extract_info(functions.s_org_table, functions.s_org_code, orgcode)
    if check[0] == 228:
        oid = check[1][0][functions.s_org_id]
        nextcheck = create_new_user(username, password, email,
                                    created_date_time, oid, display_name)
        if nextcheck[0] == 212:
            try:
                return render_template('code_gen.html',
                                       name='User Name',
                                       value=username)
            except:
                return redirect(
                    url_for('error',
                            error_str=sys.exc_info()[1],
                            error_code=render_issue))
        else:
            return redirect(
                url_for('error',
                        error_str=nextcheck[1],
                        error_code=nextcheck[0]))
    return redirect(url_for('error', error_str=check[1], error_code=check[0]))
Exemplo n.º 4
0
def camera_new():
    """
    This function checks the values entered to create a new camera and if everything is fine, it creates one.
    :return: Displays 'Camera Code' of the camera created
    """
    test_connection = sql_connection()
    if test_connection[0] == 130:
        return redirect(
            url_for('error',
                    error_str=test_connection[1],
                    error_code=test_connection[0]))

    name = request.form[camera_form[0]]
    ctype = request.form[camera_form[1]]
    bucket_code = request.form[camera_form[2]]
    created_date_time = str(datetime.datetime.now())

    check = extract_info(functions.s_buc_table, functions.s_buc_code,
                         bucket_code)
    if check[0] == 228:
        check1 = add_new_camera(name, bucket_code, ctype, created_date_time)
        if check1[0] == 202:
            camera_code = check1[1]
            try:
                return render_template('code_gen.html',
                                       name='Camera Code',
                                       value=camera_code)
            except:
                return redirect(
                    url_for('error',
                            error_str=sys.exc_info()[1],
                            error_code=render_issue))
        else:
            return redirect(
                url_for('error', error_str=check1[1], error_code=check1[0]))
    return redirect(url_for('error', error_str=check[1], error_code=check[0]))
import json
import numpy as np
import time

# home path
home = str(Path.home())

# time this script is ran
ts = time.gmtime()
time = time.strftime("%Y-%m-%d_%H:%M:%S", ts)

# directory where molecule files are stored
file_dir = os.path.join(home, 'Desktop/project/example_molecules/')

# function extracts atomic coordinates
information = functions.extract_info(file_dir)

# load bond details from database
database = atom_database.database

# add covalent radii information to each atom
chosen_atom = information['pyridine']

# work out the molecular connectivity
atom_pairing = functions.atomic_pairs(chosen_atom)
pair_list = atom_pairing['index'].tolist()

# choose molecule to view (needs a GUI button here), needs to be a function embedded in tkinter!!

# preparing spatial coordinates for plotting
xs = chosen_atom["x"].tolist()
Exemplo n.º 6
0
import json
import numpy as np
import time

# home path
home = str(Path.home())

# time this script is ran
ts = time.gmtime()
time = time.strftime("%Y-%m-%d_%H:%M:%S", ts)

# directory where molecule files are stored
file_dir = os.path.join(home, 'Desktop/project/example_molecules/')

# function extracts atomic coordinates
information = extract_info(file_dir)

# load bond details from database
database = atom_database.database

# add covalent radii information to each atom
chosen_atom = information['pyridine']

# work out the molecular connectivity
atom_pairing = atomic_pairs(chosen_atom)
pair_list = atom_pairing['index'].tolist()

# choose molecule to view (needs a GUI button here), needs to be a function embedded in tkinter!!

# preparing spatial coordinates for plotting
xs = chosen_atom["x"].tolist()