예제 #1
0
def die_and_explode():
    request_str = ''
    for k,v in request.items(): request_str += str(k) + ' ' + str(v) + '\n'
    message = 'Got a bad live hit with\n workerid %s\n hitid %s\n assid %s\n testing %s\n hitlen %s' \
              % (request.vars.workerId,
                 request.vars.hitId,
                 request.vars.assignmentId,
                 request.vars.testing,
                 str(len(db(db.hits.hitid == request.vars.hitId).select())))
    message = message + '\n\n' + request_str
    logger.error(message)
    send_me_mail(message)

    # If there's a hit on amazon that we don't know about, oh no!
    # Big bug in our shit!  We better delete this m**********r so
    # that nobody else tries to do it.
    if request.vars.hitId \
       and not len(db(db.hits.hitid == request.vars.hitId).select()) > 0:
        try:
            log('########### BAD HIT #############')
            turk.expire_hit(request.vars.hitId)
            log('Expired this hit. ' + request.vars.hitId)
        except:
            log('###### GRRRRR we could not expire this hit %s!  Fix!!' % request.vars.hitId)
    redirect(URL(r=request, f='error'))
예제 #2
0
파일: __init__.py 프로젝트: jbragg/utility
def die_and_explode():
    request_str = ''
    for k,v in request.items(): request_str += str(k) + ' ' + str(v) + '\n'
    message = 'Got a bad live hit with\n workerid %s\n hitid %s\n assid %s\n testing %s\n hitlen %s' \
              % (request.vars.workerId,
                 request.vars.hitId,
                 request.vars.assignmentId,
                 request.vars.testing,
                 str(len(db(db.hits.hitid == request.vars.hitId).select())))
    message = message + '\n\n' + request_str
    logger.error(message)
    send_me_mail(message)

    # If there's a hit on amazon that we don't know about, oh no!
    # Big bug in our shit!  We better delete this m**********r so
    # that nobody else tries to do it.
    if request.vars.hitId \
       and not len(db(db.hits.hitid == request.vars.hitId).select()) > 0:
        try:
            log('########### BAD HIT #############')
            turk.expire_hit(request.vars.hitId)
            log('Expired this hit. ' + request.vars.hitId)
        except:
            log('###### GRRRRR we could not expire this hit %s!  Fix!!' % request.vars.hitId)
    redirect(URL(r=request, f='error'))
예제 #3
0
def load_live_hit():
    log('Loading a live hit!')
    if request.vars.live == None: raise Exception('not live')
    if not (request.hitid and db.hits(hitid=request.hitid)):
        raise Exception("This hit %s does not exist in utiliscope database!"
                        % request.hitid)


    # Load hit from the database.  Get the basics.
    hit = db.hits(hitid = request.hitid)
    request.study = db.studies[hit.study]
    if hit.othervars and sj.loads(hit.othervars):
        othervars = sj.loads(hit.othervars)
        request.update(othervars)
        request.vars.update(othervars)
    request.task = hit.task
    # Set up the task options, now that we know the task:
    make_request_vars_convenient() 

    # Now BRANCH.  If this is a preview, show the preview page.
    if is_preview():
        record_action('preview')
        log('this is preview. giving it a preview page.')
        if options['mystery_task']:
            request.controller, request.function = 'utiliscope','preview'
            response.view = '%s/%s.%s' % (request.controller, request.function, 'html')
        # And get outa here!
        return None

    # Else, continue processing the accepted HIT!
    if not (request.workerid and request.assid):
        raise Exception('bad workerid or assid')

    # Load the experimental conditions.
    if not request.study.conditions:
        raise Exception('No conditions for this study')
    request.condition = sample_from_conditions(
        sj.loads(request.study.conditions),
        request.workerid)
    if not request.vars.ajax:
        log('Sampled %s' % request.condition)
    for k,v in request.condition.items():
        request[k] = v
    request.condition_id = get_condition(request.condition)

    # Take note of this assignment.  If it's brand new, fire the "hit
    # accepted" event.
    if not db.assignments(assid=request.assid):
        debug('Worker accepted a fresh hit!')
        record_action('accept')
    update_ass(assid=request.assid,
               hitid=request.hitid,
               workerid=request.workerid,
               status='accepted to us',
               condition=request.condition_id if request.condition_id else None)

    record_action('display', '%s/%s' % (request.controller, request.function))

    # If this worker has passed the work limit, tell them they're done.
    work_limit = request.max_hits or request.work_limit
    if work_limit and hits_done(request.workerid, request.study) >= work_limit:
        request.controller, request.function = 'utiliscope','done'
        response.view = '%s/%s.%s' % (request.controller, request.function, 'html')
        record_action('work quota reached')
        debug('Too many for %s' % request.workerid)
        try:
            turk.expire_hit(request.hitid)
        except TurkAPIError as e:
            logger.error(str(e.value))
        return

    return
예제 #4
0
파일: __init__.py 프로젝트: jbragg/utility
def load_live_hit():
    log('Loading a live hit!')
    if request.vars.live == None: raise Exception('not live')
    if not (request.hitid and db.hits(hitid=request.hitid)):
        raise Exception("This hit %s does not exist in utiliscope database!"
                        % request.hitid)


    # Load hit from the database.  Get the basics.
    hit = db.hits(hitid = request.hitid)
    request.study = db.studies[hit.study]
    if hit.othervars and fromjson(hit.othervars):
        othervars = fromjson(hit.othervars)
        request.update(othervars)
        request.vars.update(othervars)
    request.task = hit.task
    # Set up the task options, now that we know the task:
    make_request_vars_convenient() 

    # Now BRANCH.  If this is a preview, show the preview page.
    if is_preview():
        record_action('preview')
        log('this is preview. giving it a preview page.')
        if options['mystery_task']:
            request.function = 'preview'
            if not os.path.exists('applications/utility/views/%s/preview.html' % request.controller):
                request.controller = 'utiliscope'
            response.view = '%s/%s.%s' % (request.controller, request.function, 'html')
        # And get outa here!
        return None

    # Else, continue processing the accepted HIT!
    if not (request.workerid and request.assid):
        raise Exception('bad workerid or assid')

    # Load the experimental conditions.
    if not request.study.conditions:
        raise Exception('No conditions for this study')
    choose_condition()

    if not request.vars.ajax:
        copy = request.condition.copy()
        if 'hit_params' in copy: copy['hit_params'] = None
        log('Sampled %s' % copy)
    for k,v in request.condition.items():
        request[k] = v
    request.condition_id = get_condition(request.condition)

    # Take note of this assignment.  If it's brand new, fire the "hit
    # accepted" event.
    if not db.assignments(assid=request.assid):
        debug('Worker accepted a fresh hit!')
        record_action('accept')
    update_ass(assid=request.assid,
               hitid=request.hitid,
               workerid=request.workerid,
               status='accepted to us',
               condition=request.condition_id if request.condition_id else None)

    record_action('display', '%s/%s' % (request.controller, request.function))

    # If this worker has passed the work limit, tell them they're done.
    work_limit = request.max_hits or request.work_limit
    if work_limit and hits_done(request.workerid, request.study) >= work_limit:
        request.controller, request.function = 'utiliscope','done'
        response.view = '%s/%s.%s' % (request.controller, request.function, 'html')
        record_action('work quota reached')
        debug('Too many for %s' % request.workerid)
        try:
            turk.expire_hit(request.hitid)
        except TurkAPIError as e:
            logger.error(str(e.value))
        return

    return