Exemplo n.º 1
0
def dashboard():
    if 'mode' in request.form:
        if request.form['mode'] == 'add':
            if ('workerid' in request.form) and ('bonus' in request.form):
                if (LegitWorker.query.filter(
                        LegitWorker.amt_worker_id ==
                        request.form['workerid']).count() == 0):
                    newworker = LegitWorker(workerid=request.form['workerid'])
                    newworker.set_bonus(float(request.form['bonus']))
                    db_session.add(newworker)
                    db_session.commit()
                else:
                    flash('That worker has already been added!', 'error')
        elif request.form['mode'] == 'delete':
            if ('index' in request.form):
                current_app.logger.info('deleting')
                try:
                    lw = LegitWorker.query.filter(
                        LegitWorker.index == int(request.form['index'])).one()
                    db_session.delete(lw)
                    db_session.commit()
                except:
                    flash(
                        u'Sorry, was unable to delete that worker.  Perhaps they were already deleted!',
                        'error')
        elif request.form['mode'] == 'refresh':
            failed_workers = []
            workers = LegitWorker.query.all()
            for lw in workers:
                try:
                    user = Participant.query.filter(
                        Participant.workerid == lw.amt_worker_id).one()
                    if user.status == BONUSED:
                        try:
                            lw.paid()
                            db_session.add(lw)
                            db_session.commit()
                        except Exception as ex:
                            current_app.logger.error(
                                'Could not update worker %s to paid status: %s',
                                lw.amt_worker_id, ex)
                            failed_workers.append(w.amt_worker_id)
                except NoResultFound:
                    pass  # hasn't submitted yet...
                if len(failed_workers) > 0:
                    display_str = u'Could not update the following workers:'
                    for w in failed_workers:
                        display_str += '\n%s' % (w)
                    flash(display_str, 'error')
    try:
        workers = LegitWorker.query.all()
        return render_template('dashboard.html', workers=workers)
    except TemplateNotFound:
        abort(404)
Exemplo n.º 2
0
def dashboard():
    if 'mode' in request.form:
        if request.form['mode']=='add':
            if ('workerid' in request.form) and ('bonus' in request.form):
                if (LegitWorker.query.filter(LegitWorker.amt_worker_id == request.form['workerid']).count() == 0):
                    newworker = LegitWorker(workerid=request.form['workerid'])
                    newworker.set_bonus(float(request.form['bonus']))
                    db_session.add(newworker)
                    db_session.commit()
                else:
                    flash('That worker has already been added!', 'error')
        elif request.form['mode']=='delete':
            if ('index' in request.form):
                current_app.logger.info('deleting')
                try:
                    lw=LegitWorker.query.filter(LegitWorker.index == int(request.form['index'])).one()
                    db_session.delete(lw)
                    db_session.commit()
                except:
                    flash(u'Sorry, was unable to delete that worker.  Perhaps they were already deleted!', 'error')
        elif request.form['mode']=='refresh':
            failed_workers = []
            workers = LegitWorker.query.all()
            for lw in workers:
                try:
                    user = Participant.query.filter(Participant.workerid == lw.amt_worker_id).one()
                    if user.status == BONUSED:
                        try:
                            lw.paid()
                            db_session.add(lw)
                            db_session.commit()
                        except Exception as ex:
                            current_app.logger.error('Could not update worker %s to paid status: %s',
                                                lw.amt_worker_id,
                                                ex)
                            failed_workers.append(w.amt_worker_id)  
                except NoResultFound:
                    pass # hasn't submitted yet... 
                if len(failed_workers) > 0:
                    display_str = u'Could not update the following workers:'
                    for w in failed_workers:
                        display_str += '\n%s' % (w)
                    flash(display_str, 'error')
    try:
        workers = LegitWorker.query.all()
        return render_template('dashboard.html', workers = workers)
    except TemplateNotFound:
        abort(404)
Exemplo n.º 3
0
def dashboard():
    if "mode" in request.form:
        if request.form["mode"] == "add":
            if ("workerid" in request.form) and ("bonus" in request.form):
                newworker = LegitWorker(workerid=request.form["workerid"])
                newworker.set_bonus(float(request.form["bonus"]))
                db_session.add(newworker)
                db_session.commit()
        elif request.form["mode"] == "delete":
            if "index" in request.form:
                current_app.logger.info("deleting")
                try:
                    lw = LegitWorker.query.filter(LegitWorker.index == int(request.form["index"])).one()
                    db_session.delete(lw)
                    db_session.commit()
                except:
                    flash(u"Sorry, was unable to delete that worker.  Perhaps they were already deleted!", "error")
    try:
        workers = LegitWorker.query.all()
        return render_template("dashboard.html", workers=workers)
    except TemplateNotFound:
        abort(404)
Exemplo n.º 4
0
def dashboard():
    if 'mode' in request.form:
        if request.form['mode']=='add':
            if ('workerid' in request.form) and ('bonus' in request.form):
                newworker = LegitWorker(workerid=request.form['workerid'])
                newworker.set_bonus(float(request.form['bonus']))
                db_session.add(newworker)
                db_session.commit()
        elif request.form['mode']=='delete':
            if ('index' in request.form):
                current_app.logger.info('deleting')
                try:
                    lw=LegitWorker.query.filter(LegitWorker.index == int(request.form['index'])).one()
                    db_session.delete(lw)
                    db_session.commit()
                except:
                    flash(u'Sorry, was unable to delete that worker.  Perhaps they were already deleted!', 'error')
    try:
        workers = LegitWorker.query.all()
        return render_template('dashboard.html', workers = workers)
    except TemplateNotFound:
        abort(404)
Exemplo n.º 5
0
def compensate():
    #getrequest parts
    try:
        workerId = request.args['workerId']
    except: #keyError: now workerId was provided
        #render dat entry page
        try:
            return render_template('compensateentry.html')
        except TemplateNotFound:
            abort(404)
    if workerId == "":
        try:
            return render_template('compensateentry.html')
        except TemplateNotFound:
            abort(404)

    # Messages. Maybe move into the template?
    messages = {
        "hitSubbed": {"type": "success", 
                    "title": "Your HIT is under review.", 
                    "content": "It looks like you already submitted your HIT. We'll take action on it soon!"},
        "returnHIT": {"type": "info",
                    "title":"Please return your HIT.",
                    "content":"In order to recieve compensation, please submit or return your HIT then refresh this page. Thanks."},
        "notEnough": {"type": "info",
                    "title":"Sorry; you're not eligible for payment.",
                    "content": "It looks like you didn't make it far enough into the experiment to be eligible for payment. However, we've removed you from our list of participants so if we ever run the experiment again, you may participate!"},
        "takeDummy": {"type": "info",
                    "title":"Please complete the Compensation HIT.",
                    "content": """Because you haven't submitted work for us in the past, we need you to complete a 'dummy' compensation HIT. Follow these instructions:
                    <ol>
                        <li>Return the HIT if you have not yet done so.
                        <li>Go here: <a href="https://www.mturk.com/mturk/searchbar?selectedSearchType=hitgroups&requesterId=AH1PO6KC4YRE3" target="_blank">CPL's HITs on MTurk</a>
                        <li>Take and submit the HIT called "Psiturk Compensation HIT - DO NOT TAKE UNLESS INSTRUCTED TO DO SO"
                        <li>Wait 3-5 minutes and refresh this page.
                    </ol>"""},
        "success": {"type": "success",
                 "title": "We have credited your account.",
                 "content": "Thanks - you've been given a bonus of $%s for your time."},
        "alreadyPayed": {"type": "success",
                       "title": "You've been payed.",
                       "content": "Our records show you have already been payed for this HIT. Thanks for your participation!"},
        "fatal": {"type": "warning",
                "title": "Something went wrong.",
                "content": """Please contact us at <a href="mailto:[email protected]">[email protected]</a> and include the following information:
                <ul>
                    <li>worker id: %(workerid)s
                    <li>assignmentid: %(assignmentid)s
                </ul>
                """}
        }

    # Get the row of the worker in the database
    worker = Participant.query.\
            filter(Participant.workerid == workerId).first()
            # filter(Participant.assignmentid == assignmentId,
            #     Participant.hitid == hitId).first()

    # If the worker is in the db, check status
    if worker:
        #grab the rest of the info
        hitId = worker.hitid
        assignmentId = worker.assignmentid

        #if worker has already submitted,
        if worker.status in [4]:
            message = messages['hitSubbed']
        #if the worker was already bonused
        elif worker.status in [5,7]:
            message = messages['alreadyPayed']
        #if the worker's HIT is still in progress, tell them to turn it in 
        elif worker.status in [0,1,2,3]:
            message = messages['returnHIT']
        #if the worker did in fact quit early (meaning they can't finish it)
        else: # worker.status == 6
            #get trialCount and conditionNum
            conditionNum = ""
            trialCount = 0
            if hasattr(worker, 'datastring'):
                try: # get condition
                    workerobj = loads(worker.datastring)
                    conditionNum = workerobj['questiondata']['realCondition']
                except:
                    #print "malformed datastring for worker", worker.workerid
                    pass
                try: #count trials
                    trials = workerobj['data']
                    for trial in trials:
                        trialCount += int(trial['trialdata']['phase'] == 'TEST')
                except:
                    # print "no data"
                    pass
            #If they didn't complete any trials, 
            # remove them from db and display sorry
            print "Num trials completed:", trialCount
            if trialCount == 0:
                db_session.delete(worker)
                db_session.commit()
                message = messages['notEnough']
            else: #they completed some of the trials
                #min bonus is 1 c.
                amount = max(0.01,round(float(trialCount)/[417,818][conditionNum]*2.50,2))
                amount = min(amount, 2.50) #sanity check
                try:
                    bonusAssignment = getAnAssignmentId(workerId)
                    worker_bonus(bonusAssignment, amount, 'auto bonus system')
                    
                    #update worker
                    worker.status = 7
                    db_session.add(worker)
                    db_session.commit()

                    message = messages['success']
                    message['content'] = message['content'] % amount
                except NoAMTConnection:
                    abort(503)
                except WorkerAlreadyCredited:
                    message = messages['alreadyPayed']
                except CreditTransactionError:
                    message = messages['fatal']
                    message['content'] = message['content'] % {"workerid": workerId, "assignmentid": assignmentId}
                except WorkerNotRegistered:
                    message = messages['takeDummy']
    else:
        message = messages['notEnough']

    try:
        return render_template('compensate.html', message = message, workerId = workerId)
    except TemplateNotFound:
        abort(404)