Example #1
0
def output(httpin):
    """
    Every controller must have this output function atleast. This is the entry point.
    Input is a dict of POST/GET variables and any other extra keys added during URL parsing
    Output must be a dict of Key-Value pairs that would be substituted in template using YAPTU.
    
    """

    if KEY_NAME in httpin:
        name = httpin[KEY_NAME]
    else:
        name = "Anonymous"

    if KEY_CITY in httpin:
        city = httpin[KEY_CITY]
    else:
        city = "Hyderabad, India"

    if KEY_AGE in httpin:
        age = httpin[KEY_AGE]
    else:
        age = "22"

    force = "force" in httpin and httpin["force"] == "1"

    # rows = cur.execute("SELECT * FROM users WHERE name=%s", name).fetchall()
    rows = []

    if len(rows) == 0 and not force:
        error(
            "Oops! You are not registered. You must be registered to see this page. Or try with <a href='./?force=1'>force</a>!"
        )

    return {"USER": name, "AGE": age, "CITY": city}
def locateKeypoints():

    images = fmng.loadImages(593)
    globalError = []

    rejectedImages = 0

    for index, image in enumerate(images):

        print 'Processing [ %s : %s ]' % (index, len(images))

        currentImage, cropLeft, cropTop = locateFace(image)

        if currentImage is -1:
            pass
            rejectedImages += 1
        else:
            pupils = locatePupils(currentImage, cropLeft, cropTop)
            mouth = locateMouth(currentImage, pupils, cropLeft, cropTop)
            keypoints = [pupils[0], pupils[1], mouth]
            fmng.writeDetectedKeypoints(index, keypoints)
            fmng.writeCropPoints(index, [cropLeft, cropTop, len(currentImage[0]), len(currentImage)])
            localError = error.keypointDetectionErrorRate(image, index, keypoints)
            if localError[0] <= 10 and localError[1] <= 10 and localError[2] <= 10:
                globalError.append(localError)
                images[index] = currentImage
                if plot:
                    render.landmarks(currentImage, keypoints, 255, cropLeft, cropTop)
            else:
                 rejectedImages += 1

    print 'Rejection: %s out of %s' % (rejectedImages, len(images))

    if plot:
        render.error(globalError)
Example #3
0
def output(httpin):
    """
    Every controller must have this output function atleast. This is the entry point.
    Input is a dict of POST/GET variables and any other extra keys added during URL parsing
    Output must be a dict of Key-Value pairs that would be substituted in template using YAPTU.
    
    """

    if KEY_NAME in httpin:
        name = httpin[KEY_NAME]
    else:
        name = 'Anonymous'

    if KEY_CITY in httpin:
        city = httpin[KEY_CITY]
    else:
        city = 'Hyderabad, India'

    if KEY_AGE in httpin:
        age = httpin[KEY_AGE]
    else:
        age = '22'

    force = ('force' in httpin and httpin['force'] == '1')

    #rows = cur.execute("SELECT * FROM users WHERE name=%s", name).fetchall()
    rows = []

    if len(rows) == 0 and not force:
        error(
            "Oops! You are not registered. You must be registered to see this page. Or try with <a href='./?force=1'>force</a>!"
        )

    return {'USER': name, 'AGE': age, 'CITY': city}
Example #4
0
def worker_set_message(name):
    msg = request.form.get('message', '')
    worker = worker_manager.get(name)
    if not worker:
        return error(status_code=404)
    worker.set_message(msg.strip())
    return ok()
Example #5
0
def worker_poll_output(name):
    worker = worker_manager.get(name)
    if not worker:
        return error(status_code=404)
    output = worker.poll_output()
    return ok({
        'output': output,
        'is_running': worker.is_running,
        'return_code': worker.return_code,
    })
Example #6
0
def workers_status(name):
    worker = worker_manager.get(name)
    if not worker:
        return error(status_code=404)

    return ok({
        'status': {
            'name': worker.name,
            'poll_output_url': url_for('.worker_poll_output', name=name),
            'deploy_url': url_for('.worker_deploy', name=name),
            'kill_url': url_for('.worker_kill', name=name),
            'set_message_url': url_for('.worker_set_message', name=name),
            'is_running': worker.is_running,
            'return_code': worker.return_code,
            'message': worker.message,
        }
    })
Example #7
0
# Get page name from URL
page = urlparse(os.environ['REQUEST_URI']).path.lstrip('/')

if page == "": 
    page = DEFAULT_PAGE

# If the URL is like <domain>/hello/123/xyz, then you would want to parse it here.
# and save the URL components into httpin object with proper keys so that controllers
# can make use of it.
if page.startswith('hello'):
    components = page.split("/")
    if len(components) > 1:
        page   = components[0]
        httpin.update({'name' : components[1],
                       'age'  : components[2],
                       'city' : components[3]})

if page not in VALID_PAGES:
    error("Invalid Page - %s!" % page)
    

# Loads the appropriate controller
module = 'controllers.'+page
__import__(module)
controller = sys.modules[module]

# Get the data from the controller
values_dict = controller.output(httpin)

# Render 
push_html(render(page, values_dict))
Example #8
0
def worker_kill(name):
    worker = worker_manager.get(name)
    if not worker:
        return error(status_code=404)
    worker.kill()
    return ok()
Example #9
0
def worker_deploy(name):
    worker = worker_manager.get(name)
    if not worker:
        return error(status_code=404)
    worker.run()
    return ok()