Exemplo n.º 1
0
def publish_hit(credentials, isSandbox, ename, num_hits, lvlset, adminToken,
                db, mode, no_ifs, individual, with_new_var_powerup, mc=None,
                email=None, maxlvls=None, colSwap=False, replay=False):
    title = "Play a Math Puzzle Game For Science!"
    max_assignments = 1

    keywords = "game, math, programming"

    description = \
	""" NOTE: PLEASE DON'T ACCEPT MORE THAN ONE HIT AT A TIME! First finish your current HIT before looking for others!\n """ + \
	"""Help us evaluate our verification game InvGen! Each level is structured as a math puzzle, where you try to come up with correct expressions. Your work directly helps with the verification of programs! This HIT involves playing at least two non-tutorial levels of our game. Played it before? Come play again! You will bypass the tutorial and get new levels! New player? Come try it out! We aim to pay about $10/hr. More specifically: (a) $1.50 for the HIT, which involves playing the game for at least 2 non-tutorial levels (b) $1.50 bonus for doing the tutorial, which you only do the first time (c) $0.75 bonus for each non-tutorial level you pass beyond two."""

    mastersQualType = "2ARFPLSP75KLA8M8DH1HTEQVJT3SY6" if isSandbox else \
                      "2F1QJWKUDD8XADTFD2Q0G6UTO95ALH"

    quals = [] if isSandbox else\
        [
           NumberHitsApprovedRequirement("GreaterThanOrEqualTo", 1000),
           PercentAssignmentsApprovedRequirement("GreaterThanOrEqualTo", 97),
           Requirement(mastersQualType, "Exists")
        ]

    if mc is None:
      mc = connect(credentials, isSandbox)
    balance = mc.get_account_balance()
    print("Balance:", balance[0])
    exp = Experiment(ename, True)
    print("Running under experiment", ename)

    for i in range(num_hits):
        port = get_unused_port()
        srid = exp.create_unique_server_run_id()
        p = start_server(port, ename, srid, lvlset, adminToken, db, email,
            maxlvls, colSwap, replay)
        print("Started server run", srid, "on port", port, "with pid", p.pid)
        start_url =\
            "https://zoidberg.ucsd.edu:{0}/mturk_landing.html?mode=" + mode
        if (no_ifs):
            start_url += "&noifs"
        if individual:
            start_url += "&individual=1"
        if with_new_var_powerup:
            start_url += "&nvpower=1"
        q = ExternalQuestion(start_url.format(port), 1024)
        kind = "ExternalQuestion"
        r = mc.create_hit(question=q,
                          lifetime=timedelta(7),
                          max_assignments=max_assignments,
                          title=title,
                          description=description,
                          keywords=keywords,
                          reward=HIT_REWARD,
                          duration=timedelta(0, 45*60),
                          qualifications=Qualifications(quals))
        assert len(r) == 1
        print("Created", kind, "HIT", r[0].HITId)
        exp.add_session(ServerRun(srid, r[0].HITId, p.pid, port))
    return exp
Exemplo n.º 2
0
#! /usr/bin/env python
from traceback import print_exc
from lib.invgame_server.mturk_util import error, connect, mkParser

p = mkParser("Expire a HIT")
p.add_argument('HITId', type=str, help='ID Of the HIT To expire.')
args = p.parse_args()

try:
    mc = connect(args.credentials_file, args.sandbox)
    r = mc.expire_hit(args.HITId)
except Exception as e:
    print_exc()
    error("Failed...")
Exemplo n.º 3
0
                   help="The event/survey database to use")
    p.add_argument(
        "--sandbox",
        action="store_true",
        help="Whether to use the production or sandbox MTurk endpoint")

    args = p.parse_args()

    if ('mysql+pymysql://' in args.db):
        # if "mysql+mysqldb://" in args.db:
        sessionF = open_mysql_db(args.db)
    else:
        sessionF = open_sqlite_db(args.db)
    session = sessionF()

    mc = mturk_util.connect(args.credentials_file, args.sandbox)

    hitq = session.query(
        func.json_extract(Event.payload, "$.hitId").label("hit")).subquery()
    q = session.query(hitq.c.hit) \
      .filter(hitq.c.hit.notin_(session.query(SurveyData.hit)))
    for hit, in q.distinct():
        print("Loading new HIT %s..." % hit, end=' ')

        try:
            getSurveyData(session, mc, hit)
        except MTurkRequestError:
            print("error")
        else:
            print("done")