本文整理汇总了Python中psiturk.psiturk_config.PsiturkConfig.load_config方法的典型用法代码示例。如果您正苦于以下问题:Python PsiturkConfig.load_config方法的具体用法?Python PsiturkConfig.load_config怎么用?Python PsiturkConfig.load_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psiturk.psiturk_config.PsiturkConfig
的用法示例。
在下文中一共展示了PsiturkConfig.load_config方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: qualify
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import load_config [as 别名]
def qualify(qualification, value, worker):
"""Assign a qualification to a worker."""
# create connection to AWS
from boto.mturk.connection import MTurkConnection
config = PsiturkConfig()
config.load_config()
aws_access_key_id = config.get('AWS Access', 'aws_access_key_id')
aws_secret_access_key = config.get('AWS Access', 'aws_secret_access_key')
conn = MTurkConnection(aws_access_key_id, aws_secret_access_key)
def get_workers_with_qualification(qualification):
"""Get workers with the given qualification."""
results = []
continue_flag = True
page = 1
while(continue_flag):
new_results = conn.get_qualifications_for_qualification_type(
qualification,
page_size=100,
page_number=page)
if(len(new_results) == 0):
continue_flag = False
else:
results.extend(new_results)
page = page + 1
return results
results = get_workers_with_qualification(qualification)
workers = [x.SubjectId for x in results]
# assign the qualification
click.echo(
"Assigning qualification {} with value {} to worker {}".format(
qualification,
value,
worker))
if worker in workers:
result = conn.update_qualification_score(qualification, worker, value)
else:
result = conn.assign_qualification(qualification, worker, value)
if result:
click.echo(result)
# print out the current set of workers with the qualification
results = get_workers_with_qualification(qualification)
click.echo("{} workers with qualification {}:".format(
len(results),
qualification))
values = [r.IntegerValue for r in results]
unique_values = list(set([r.IntegerValue for r in results]))
for v in unique_values:
click.echo("{} with value {}".format(
len([val for val in values if val == v]),
v))
示例2: ad_address
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import load_config [as 别名]
def ad_address(mode, hit_id):
if mode == "debug":
address = '/complete'
elif mode in ["sandbox", "live"]:
CONFIG = PsiturkConfig()
CONFIG.load_config()
username = os.getenv('psiturk_access_key_id', CONFIG.get("psiTurk Access", "psiturk_access_key_id"))
password = os.getenv('psiturk_secret_access_id', CONFIG.get("psiTurk Access", "psiturk_secret_access_id"))
try:
req = requests.get('https://api.psiturk.org/api/ad/lookup/' + hit_id,
auth=(username, password))
except:
raise ValueError('api_server_not_reachable')
else:
if req.status_code == 200:
hit_address = req.json()['ad_id']
else:
raise ValueError("something here")
if mode == "sandbox":
address = 'https://sandbox.ad.psiturk.org/complete/' + str(hit_address)
elif mode == "live":
address = 'https://ad.psiturk.org/complete/' + str(hit_address)
else:
raise ValueError("Unknown mode: {}".format(mode))
return Response(dumps({"address": address}), status=200)
示例3: __init__
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import load_config [as 别名]
def __init__(self):
config = PsiturkConfig()
config.load_config()
self.access_key = config.get("psiTurk Access", "psiturk_access_key_id")
self.secret_key = config.get("psiTurk Access", "psiturk_secret_access_id")
self.local_port = config.getint("Server Parameters", "port")
self.is_open = False
self.tunnel_port = 8000 # Set by tunnel server
self.tunnel_host = "tunnel.psiturk.org"
self.tunnel_server = os.path.join(os.path.dirname(__file__), "tunnel/ngrok")
self.tunnel_config = os.path.join(os.path.dirname(__file__), "tunnel/ngrok-config")
示例4: __init__
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import load_config [as 别名]
def __init__(self, config=None):
if not config:
config = PsiturkConfig()
config.load_config()
self.access_key = config.get('psiTurk Access', 'psiturk_access_key_id')
self.secret_key = config.get('psiTurk Access', 'psiturk_secret_access_id')
self.local_port = config.getint('Server Parameters', 'port')
self.is_open = False
self.tunnel_port = 8000 # Set by tunnel server
self.tunnel_host = 'tunnel.psiturk.org'
self.tunnel_server = os.path.join(os.path.dirname(__file__),
"tunnel/ngrok")
self.tunnel_config = os.path.join(os.path.dirname(__file__),
"tunnel/ngrok-config")
示例5: deploy
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import load_config [as 别名]
def deploy(verbose):
"""Deploy app using Heroku to MTurk."""
# Load psiTurk configuration.
config = PsiturkConfig()
config.load_config()
# Set the mode.
config.set("Experiment Configuration", "mode", "deploy")
config.set("Server Parameters", "logfile", "-")
# Ensure that psiTurk is not in sandbox mode.
config.set("Shell Parameters", "launch_in_sandbox_mode", "false")
# Do shared setup.
deploy_sandbox_shared_setup(verbose=verbose)
示例6: sandbox
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import load_config [as 别名]
def sandbox(verbose, app):
"""Deploy app using Heroku to the MTurk Sandbox."""
# Load psiTurk configuration.
config = PsiturkConfig()
config.load_config()
# Set the mode.
config.set("Experiment Configuration", "mode", "sandbox")
config.set("Server Parameters", "logfile", "-")
# Ensure that psiTurk is in sandbox mode.
config.set("Shell Parameters", "launch_in_sandbox_mode", "true")
# Do shared setup.
deploy_sandbox_shared_setup(verbose=verbose, app=app)
示例7: awaken
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import load_config [as 别名]
def awaken(app, databaseurl):
"""Restore the database from a given url."""
config = PsiturkConfig()
config.load_config()
database_size = config.get('Database Parameters', 'database_size')
subprocess.call(
"heroku addons:create heroku-postgresql:{} --app {}".format(
database_size,
app),
shell=True)
subprocess.call("heroku pg:wait --app {}".format(app), shell=True)
conn = boto.connect_s3(
config.get('AWS Access', 'aws_access_key_id'),
config.get('AWS Access', 'aws_secret_access_key'),
)
bucket = conn.get_bucket(app)
key = bucket.lookup('database.dump')
url = key.generate_url(expires_in=300)
cmd = "heroku pg:backups restore"
subprocess.call(
"{} '{}' DATABASE_URL --app {} --confirm {}".format(
cmd,
url,
app,
app),
shell=True)
subprocess.call(
"heroku addons:create rediscloud:250 --app {}".format(app),
shell=True)
# Scale up the dynos.
scale_up_dynos(app)
示例8: backup
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import load_config [as 别名]
def backup(app):
"""Dump the database."""
dump_path = dump_database(app)
config = PsiturkConfig()
config.load_config()
conn = boto.connect_s3(
config.get('AWS Access', 'aws_access_key_id'),
config.get('AWS Access', 'aws_secret_access_key'),
)
bucket = conn.create_bucket(
app,
location=boto.s3.connection.Location.DEFAULT
)
k = boto.s3.key.Key(bucket)
k.key = 'database.dump'
k.set_contents_from_filename(dump_path)
url = k.generate_url(expires_in=0, query_auth=False)
log("The database backup URL is...")
print(url)
示例9: scale_up_dynos
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import load_config [as 别名]
def scale_up_dynos(id):
"""Scale up the Heroku dynos."""
# Load psiTurk configuration.
config = PsiturkConfig()
config.load_config()
dyno_type = config.get('Server Parameters', 'dyno_type')
num_dynos_web = config.get('Server Parameters', 'num_dynos_web')
num_dynos_worker = config.get('Server Parameters', 'num_dynos_worker')
log("Scaling up the dynos...")
subprocess.call(
"heroku ps:scale web=" + str(num_dynos_web) + ":" +
str(dyno_type) + " --app " + id, shell=True)
subprocess.call(
"heroku ps:scale worker=" + str(num_dynos_worker) + ":" +
str(dyno_type) + " --app " + id, shell=True)
clock_on = config.getboolean('Server Parameters', 'clock_on')
if clock_on:
subprocess.call(
"heroku ps:scale clock=1:" + dyno_type + " --app " + id,
shell=True)
示例10: PsiturkConfig
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import load_config [as 别名]
from wallace import db, models
import imp
import inspect
from operator import attrgetter
import datetime
from rq import Queue
from worker import conn
from sqlalchemy import and_, exc
# Load the configuration options.
config = PsiturkConfig()
config.load_config()
myauth = PsiTurkAuthorization(config)
# Explore the Blueprint.
custom_code = Blueprint(
'custom_code', __name__,
template_folder='templates',
static_folder='static')
# Initialize the Wallace database.
session = db.get_session()
# Connect to the Redis queue for notifications.
q = Queue(connection=conn)
# Specify the experiment.
示例11: PsiTurkRecruiter
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import load_config [as 别名]
class PsiTurkRecruiter(Recruiter):
"""Recruit participants from Amazon Mechanical Turk."""
def __init__(self):
"""Set up the connection to MTurk and psiTurk web services."""
# load the configuration options
self.config = PsiturkConfig()
self.config.load_config()
class FakeExperimentServerController(object):
def is_server_running(self):
return "yes"
self.server = FakeExperimentServerController()
# Get keys from environment variables or config file.
self.aws_access_key_id = os.getenv("aws_access_key_id", self.config.get("AWS Access", "aws_access_key_id"))
self.aws_secret_access_key = os.getenv(
"aws_secret_access_key", self.config.get("AWS Access", "aws_secret_access_key")
)
self.aws_region = os.getenv("aws_region", self.config.get("AWS Access", "aws_region"))
def open_recruitment(self, n=1):
"""Open recruitment for the first HIT, unless it's already open."""
from psiturk.amt_services import MTurkServices, RDSServices
from psiturk.psiturk_shell import PsiturkNetworkShell
from psiturk.psiturk_org_services import PsiturkOrgServices
psiturk_access_key_id = os.getenv(
"psiturk_access_key_id", self.config.get("psiTurk Access", "psiturk_access_key_id")
)
psiturk_secret_access_id = os.getenv(
"psiturk_secret_access_id", self.config.get("psiTurk Access", "psiturk_secret_access_id")
)
web_services = PsiturkOrgServices(psiturk_access_key_id, psiturk_secret_access_id)
aws_rds_services = RDSServices(self.aws_access_key_id, self.aws_secret_access_key, self.aws_region)
self.amt_services = MTurkServices(
self.aws_access_key_id,
self.aws_secret_access_key,
self.config.getboolean("Shell Parameters", "launch_in_sandbox_mode"),
)
self.shell = PsiturkNetworkShell(
self.config,
self.amt_services,
aws_rds_services,
web_services,
self.server,
self.config.getboolean("Shell Parameters", "launch_in_sandbox_mode"),
)
try:
participants = Participant.query.all()
assert participants
except Exception:
# Create the first HIT.
self.shell.hit_create(
n,
self.config.get("HIT Configuration", "base_payment"),
self.config.get("HIT Configuration", "duration"),
)
else:
# HIT was already created, no need to recreate it.
print "Reject recruitment reopening: experiment has started."
def recruit_participants(self, n=1):
"""Extend the HIT to recruit more people."""
auto_recruit = os.environ["auto_recruit"] == "true"
if auto_recruit:
print "Starting Wallace's recruit_participants."
hit_id = str(Participant.query.with_entities(Participant.hitid).first().hitid)
print "hit_id is {}.".format(hit_id)
is_sandbox = self.config.getboolean("Shell Parameters", "launch_in_sandbox_mode")
if is_sandbox:
host = "mechanicalturk.sandbox.amazonaws.com"
else:
host = "mechanicalturk.amazonaws.com"
mturkparams = dict(
aws_access_key_id=self.aws_access_key_id, aws_secret_access_key=self.aws_secret_access_key, host=host
)
self.mtc = MTurkConnection(**mturkparams)
#.........这里部分代码省略.........
示例12: configure_hit
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import load_config [as 别名]
def configure_hit(self, hit_config):
''' Configure HIT '''
# configure question_url based on the id
experiment_portal_url = hit_config['ad_location']
frame_height = 600
mturk_question = ExternalQuestion(experiment_portal_url, frame_height)
# Qualification:
quals = Qualifications()
approve_requirement = hit_config['approve_requirement']
quals.add(
PercentAssignmentsApprovedRequirement("GreaterThanOrEqualTo",
approve_requirement))
if hit_config['us_only']:
quals.add(LocaleRequirement("EqualTo", "US"))
# Create a HIT type for this HIT.
hit_type = self.mtc.register_hit_type(
hit_config['title'],
hit_config['description'],
hit_config['reward'],
hit_config['duration'],
keywords=hit_config['keywords'],
approval_delay=None,
qual_req=None)[0]
# Check the config file to see if notifications are wanted.
config = PsiturkConfig()
config.load_config()
try:
url = config.get('Server Parameters', 'notification_url')
all_event_types = [
"AssignmentAccepted",
"AssignmentAbandoned",
"AssignmentReturned",
"AssignmentSubmitted",
"HITReviewable",
"HITExpired",
]
self.mtc.set_rest_notification(
hit_type.HITTypeId,
url,
event_types=all_event_types)
except:
pass
# Specify all the HIT parameters
self.param_dict = dict(
hit_type=hit_type.HITTypeId,
question=mturk_question,
lifetime=hit_config['lifetime'],
max_assignments=hit_config['max_assignments'],
title=hit_config['title'],
description=hit_config['description'],
keywords=hit_config['keywords'],
reward=hit_config['reward'],
duration=hit_config['duration'],
approval_delay=None,
questions=None,
qualifications=quals,
response_groups=[
'Minimal',
'HITDetail',
'HITQuestion',
'HITAssignmentSummary'
])
示例13: deploy_sandbox_shared_setup
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import load_config [as 别名]
def deploy_sandbox_shared_setup(verbose=True, web_procs=1):
"""Set up Git, push to Heroku, and launch the app."""
if verbose:
OUT = None
else:
OUT = open(os.devnull, 'w')
(id, tmp) = setup(debug=False, verbose=verbose)
# Log in to Heroku if we aren't already.
log("Making sure that you are logged in to Heroku.")
ensure_heroku_logged_in()
# Change to temporary directory.
cwd = os.getcwd()
os.chdir(tmp)
# Commit Heroku-specific files to tmp folder's git repo.
cmds = ["git init",
"git add --all",
'git commit -m "Experiment ' + id + '"']
for cmd in cmds:
subprocess.call(cmd, stdout=OUT, shell=True)
time.sleep(0.5)
# Load psiTurk configuration.
config = PsiturkConfig()
config.load_config()
# Initialize the app on Heroku.
log("Initializing app on Heroku...")
subprocess.call(
"heroku apps:create " + id +
" --buildpack https://github.com/thenovices/heroku-buildpack-scipy",
stdout=OUT,
shell=True)
database_size = config.get('Database Parameters', 'database_size')
# Set up postgres database and AWS/psiTurk environment variables.
cmds = [
"heroku addons:create heroku-postgresql:{}".format(database_size),
"heroku pg:wait",
"heroku addons:create redistogo:small",
"heroku addons:create papertrail",
"heroku config:set HOST=" +
id + ".herokuapp.com",
"heroku config:set aws_access_key_id=" +
config.get('AWS Access', 'aws_access_key_id'),
"heroku config:set aws_secret_access_key=" +
config.get('AWS Access', 'aws_secret_access_key'),
"heroku config:set aws_region=" +
config.get('AWS Access', 'aws_region'),
"heroku config:set psiturk_access_key_id=" +
config.get('psiTurk Access', 'psiturk_access_key_id'),
"heroku config:set psiturk_secret_access_id=" +
config.get('psiTurk Access', 'psiturk_secret_access_id'),
"heroku config:set auto_recruit=" +
config.get('Experiment Configuration', 'auto_recruit'),
]
for cmd in cmds:
subprocess.call(cmd + " --app " + id, stdout=OUT, shell=True)
# Set the notification URL in the cofig file to the notifications URL.
config.set(
"Server Parameters",
"notification_url",
"http://" + id + ".herokuapp.com/notifications")
# Set the database URL in the config file to the newly generated one.
log("Saving the URL of the postgres database...")
db_url = subprocess.check_output(
"heroku config:get DATABASE_URL --app " + id, shell=True)
config.set("Database Parameters", "database_url", db_url.rstrip())
subprocess.call("git add config.txt", stdout=OUT, shell=True),
time.sleep(0.25)
subprocess.call(
'git commit -m "Save URLs for database and notifications"',
stdout=OUT,
shell=True)
time.sleep(0.25)
# Launch the Heroku app.
log("Pushing code to Heroku...")
subprocess.call("git push heroku HEAD:master", stdout=OUT,
stderr=OUT, shell=True)
dyno_type = config.get('Server Parameters', 'dyno_type')
num_dynos_web = config.get('Server Parameters', 'num_dynos_web')
num_dynos_worker = config.get('Server Parameters', 'num_dynos_worker')
#.........这里部分代码省略.........
示例14: debug
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import load_config [as 别名]
def debug(verbose):
"""Run the experiment locally."""
(id, tmp) = setup(debug=True, verbose=verbose)
# Drop all the tables from the database.
db.init_db(drop_all=True)
# Switch to the temporary directory.
cwd = os.getcwd()
os.chdir(tmp)
# Load psiTurk configuration.
config = PsiturkConfig()
config.load_config()
# Set the mode to debug.
config.set("Experiment Configuration", "mode", "debug")
config.set("Shell Parameters", "launch_in_sandbox_mode", "true")
config.set(
"Server Parameters",
"logfile",
os.path.join(cwd, config.get("Server Parameters", "logfile")))
# Swap in the HotAirRecruiter
os.rename("wallace_experiment.py", "wallace_experiment_tmp.py")
with open("wallace_experiment_tmp.py", "r+") as f:
with open("wallace_experiment.py", "w+") as f2:
f2.write("from wallace.recruiters import HotAirRecruiter\n")
for idx, line in enumerate(f):
if re.search("\s*self.recruiter = (.*)", line):
p = line.partition("self.recruiter =")
f2.write(p[0] + p[1] + ' HotAirRecruiter\n')
else:
f2.write(line)
os.remove("wallace_experiment_tmp.py")
# Set environment variables.
aws_vars = ['aws_access_key_id', 'aws_secret_access_key', 'aws_region']
for var in aws_vars:
if var not in os.environ:
os.environ[var] = config.get('AWS Access', var)
pt_vars = ['psiturk_access_key_id', 'psiturk_secret_access_id']
for var in pt_vars:
if var not in os.environ:
os.environ[var] = config.get('psiTurk Access', var)
if "HOST" not in os.environ:
os.environ["HOST"] = config.get('Server Parameters', 'host')
# Start up the local server
log("Starting up the server...")
# Try opening the psiTurk shell.
try:
p = pexpect.spawn("psiturk")
p.expect_exact("]$")
p.sendline("server on")
p.expect_exact("Experiment server launching...")
# Launche the experiment.
time.sleep(4)
host = config.get("Server Parameters", "host")
port = config.get("Server Parameters", "port")
subprocess.call(
'curl --data "" http://{}:{}/launch'.format(host, port),
shell=True)
log("Here's the psiTurk shell...")
p.interact()
except Exception:
print "\nCouldn't open the psiTurk shell. Internet connection okay?"
log("Completed debugging of experiment " + id + ".")
os.chdir(cwd)
示例15: PsiturkConfig
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import load_config [as 别名]
from psiturk.psiturk_config import PsiturkConfig
import subprocess
CONFIG = PsiturkConfig()
CONFIG.load_config()
sections = ['psiTurk Access','AWS Access']
for section in sections:
for item in CONFIG.items(section):
#print 'heroku config:set ' + '='.join(item)
subprocess.call('heroku config:set ' + '='.join(item), shell=True)
subprocess.call('heroku config:set ON_HEROKU=true', shell=True)