code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
max_fuzzy_matches_to_check = 100
query = name.upper()
start = time.time()
args = {
"Query": query,
"MustBeRequestable": False,
"MustBeOwnedByCaller": True,
"MaxResults": max_fuzzy_matches_to_check,
}
results = self.... | def get_qualification_type_by_name(self, name) | Return a Qualification Type by name. If the provided name matches
more than one Qualification, check to see if any of the results
match the provided name exactly. If there's an exact match, return
that Qualification. Otherwise, raise an exception. | 3.890156 | 3.814928 | 1.019719 |
return self._is_ok(
self.mturk.associate_qualification_with_worker(
QualificationTypeId=qualification_id,
WorkerId=worker_id,
IntegerValue=score,
SendNotification=notify,
)
) | def assign_qualification(self, qualification_id, worker_id, score, notify=False) | Score a worker for a specific qualification | 2.954963 | 2.907035 | 1.016487 |
result = self.get_current_qualification_score(name, worker_id)
current_score = result["score"] or 0
new_score = current_score + 1
qtype_id = result["qtype"]["id"]
self.assign_qualification(qtype_id, worker_id, new_score, notify)
return {"qtype": result["qtype"],... | def increment_qualification_score(self, name, worker_id, notify=False) | Increment the current qualification score for a worker, on a
qualification with the provided name. | 2.746811 | 2.649162 | 1.03686 |
try:
response = self.mturk.get_qualification_score(
QualificationTypeId=qualification_id, WorkerId=worker_id
)
except ClientError as ex:
error = str(ex)
if "does not exist" in error:
raise WorkerLacksQualification(
... | def get_qualification_score(self, qualification_id, worker_id) | Return a worker's qualification score as an iteger. | 3.032028 | 2.982271 | 1.016684 |
qtype = self.get_qualification_type_by_name(name)
if qtype is None:
raise QualificationNotFoundException(
'No Qualification exists with name "{}"'.format(name)
)
try:
score = self.get_qualification_score(qtype["id"], worker_id)
... | def get_current_qualification_score(self, name, worker_id) | Return the current score for a worker, on a qualification with the
provided name. | 3.456202 | 3.500112 | 0.987455 |
return self._is_ok(
self.mturk.delete_qualification_type(QualificationTypeId=qualification_id)
) | def dispose_qualification_type(self, qualification_id) | Remove a qualification type we created | 4.680242 | 4.633288 | 1.010134 |
done = False
next_token = None
while not done:
if next_token is not None:
response = self.mturk.list_workers_with_qualification_type(
QualificationTypeId=qualification_id,
MaxResults=MAX_SUPPORTED_BATCH_SIZE,
... | def get_workers_with_qualification(self, qualification_id) | Get workers with the given qualification. | 2.009912 | 1.984548 | 1.01278 |
frame_height = 600
mturk_question = self._external_question(ad_url, frame_height)
qualifications = self.build_hit_qualifications(
approve_requirement, us_only, blacklist
)
# We need a HIT_Type in order to register for REST notifications
hit_type_id = ... | def create_hit(
self,
title,
description,
keywords,
reward,
duration_hours,
lifetime_days,
ad_url,
notification_url,
approve_requirement,
max_assignments,
us_only,
blacklist=None,
annotation=None,
) | Create the actual HIT and return a dict with its useful properties. | 3.482423 | 3.319433 | 1.049102 |
self.create_additional_assignments_for_hit(hit_id, number)
if duration_hours is not None:
self.update_expiration_for_hit(hit_id, duration_hours)
return self.get_hit(hit_id) | def extend_hit(self, hit_id, number, duration_hours=None) | Extend an existing HIT and return an updated description | 3.003785 | 2.635296 | 1.139828 |
try:
self.mturk.update_expiration_for_hit(HITId=hit_id, ExpireAt=0)
except Exception as ex:
raise MTurkServiceException(
"Failed to expire HIT {}: {}".format(hit_id, str(ex))
)
return True | def expire_hit(self, hit_id) | Expire a HIT, which will change its status to "Reviewable",
allowing it to be deleted. | 3.085814 | 2.763429 | 1.116661 |
assignment = self.get_assignment(assignment_id)
worker_id = assignment["worker_id"]
amount_str = "{:.2f}".format(amount)
try:
return self._is_ok(
self.mturk.send_bonus(
WorkerId=worker_id,
BonusAmount=amount_str... | def grant_bonus(self, assignment_id, amount, reason) | Grant a bonus to the MTurk Worker.
Issues a payment of money from your account to a Worker. To
be eligible for a bonus, the Worker must have submitted
results for one of your HITs, and have had those results
approved or rejected. This payment happens separately from the
reward y... | 2.95569 | 2.799281 | 1.055875 |
try:
response = self.mturk.get_assignment(AssignmentId=assignment_id)
except ClientError as ex:
if "does not exist" in str(ex):
return None
raise
return self._translate_assignment(response["Assignment"]) | def get_assignment(self, assignment_id) | Get an assignment by ID and reformat the response. | 2.999177 | 2.966321 | 1.011076 |
try:
return self._is_ok(
self.mturk.approve_assignment(AssignmentId=assignment_id)
)
except ClientError as ex:
assignment = self.get_assignment(assignment_id)
raise MTurkServiceException(
"Failed to approve assignme... | def approve_assignment(self, assignment_id) | Approving an assignment initiates two payments from the
Requester's Amazon.com account:
1. The Worker who submitted the results is paid
the reward specified in the HIT.
2. Amazon Mechanical Turk fees are debited. | 3.270975 | 3.236529 | 1.010643 |
# Create __init__.py if it doesn't exist (needed for Python 2)
init_py = os.path.join(path, "__init__.py")
if not os.path.exists(init_py):
open(init_py, "a").close()
# Retain already set experiment module
if sys.modules.get("dallinger_experiment") is not None:
return
dirnam... | def initialize_experiment_package(path) | Make the specified directory importable as the `dallinger_experiment` package. | 2.984603 | 2.771335 | 1.076955 |
return {
"type": self.type,
"recruiter": self.recruiter_id,
"assignment_id": self.assignment_id,
"hit_id": self.hit_id,
"mode": self.mode,
"end_time": self.end_time,
"base_pay": self.base_pay,
"bonus": self.... | def json_data(self) | Return json description of a participant. | 2.855474 | 2.614122 | 1.092326 |
if type is None:
type = Question
if not issubclass(type, Question):
raise TypeError("{} is not a valid question type.".format(type))
return type.query.filter_by(participant_id=self.id).all() | def questions(self, type=None) | Get questions associated with this participant.
Return a list of questions associated with the participant. If
specified, ``type`` filters by class. | 3.487457 | 3.342402 | 1.043399 |
nodes = self.nodes(failed="all")
infos = []
for n in nodes:
infos.extend(n.infos(type=type, failed=failed))
return infos | def infos(self, type=None, failed=False) | Get all infos created by the participants nodes.
Return a list of infos produced by nodes associated with the
participant. If specified, ``type`` filters by class. By default, failed
infos are excluded, to include only failed nodes use ``failed=True``,
for all nodes use ``failed=all``. ... | 4.383187 | 3.696137 | 1.185883 |
return {
"number": self.number,
"type": self.type,
"participant_id": self.participant_id,
"question": self.question,
"response": self.response,
} | def json_data(self) | Return json description of a question. | 3.164688 | 2.613711 | 1.210803 |
return {
"type": self.type,
"max_size": self.max_size,
"full": self.full,
"role": self.role,
} | def json_data(self) | Return json description of a participant. | 4.530262 | 3.968869 | 1.141449 |
if type is None:
type = Node
if not issubclass(type, Node):
raise TypeError("{} is not a valid node type.".format(type))
if failed not in ["all", False, True]:
raise ValueError("{} is not a valid node failed".format(failed))
if participant_... | def nodes(self, type=None, failed=False, participant_id=None) | Get nodes in the network.
type specifies the type of Node. Failed can be "all", False
(default) or True. If a participant_id is passed only
nodes with that participant_id will be returned. | 1.875647 | 1.844598 | 1.016832 |
return len(self.nodes(type=type, failed=failed)) | def size(self, type=None, failed=False) | How many nodes in a network.
type specifies the class of node, failed
can be True/False/all. | 6.130409 | 5.158339 | 1.188446 |
if type is None:
type = Info
if failed not in ["all", False, True]:
raise ValueError("{} is not a valid failed".format(failed))
if failed == "all":
return type.query.filter_by(network_id=self.id).all()
else:
return type.query.filt... | def infos(self, type=None, failed=False) | Get infos in the network.
type specifies the type of info (defaults to Info). failed { False,
True, "all" } specifies the failed state of the infos. To get infos
from a specific node, see the infos() method in class
:class:`~dallinger.models.Node`. | 2.865127 | 2.406192 | 1.190731 |
if status not in ["all", "pending", "received"]:
raise ValueError(
"You cannot get transmission of status {}.".format(status)
+ "Status can only be pending, received or all"
)
if failed not in ["all", False, True]:
raise ValueE... | def transmissions(self, status="all", failed=False) | Get transmissions in the network.
status { "all", "received", "pending" }
failed { False, True, "all" }
To get transmissions from a specific vector, see the
transmissions() method in class Vector. | 1.937237 | 1.825737 | 1.061071 |
if failed not in ["all", False, True]:
raise ValueError("{} is not a valid vector failed".format(failed))
if failed == "all":
return Vector.query.filter_by(network_id=self.id).all()
else:
return Vector.query.filter_by(network_id=self.id, failed=faile... | def vectors(self, failed=False) | Get vectors in the network.
failed = { False, True, "all" }
To get the vectors to/from to a specific node, see Node.vectors(). | 2.941333 | 2.416676 | 1.217099 |
# get type
if type is None:
type = Node
if not issubclass(type, Node):
raise ValueError(
"{} is not a valid neighbor type,"
"needs to be a subclass of Node.".format(type)
)
# get direction
if direction ... | def neighbors(self, type=None, direction="to", failed=None) | Get a node's neighbors - nodes that are directly connected to it.
Type specifies the class of neighbour and must be a subclass of
Node (default is Node).
Connection is the direction of the connections and can be "to"
(default), "from", "either", or "both". | 2.645552 | 2.561941 | 1.032636 |
if failed is not None:
raise ValueError(
"You should not pass a failed argument to is_connected."
"is_connected is "
"unusual in that a failed argument cannot be passed. This is "
"because there is inherent uncertainty in what ... | def is_connected(self, whom, direction="to", failed=None) | Check whether this node is connected [to/from] whom.
whom can be a list of nodes or a single node.
direction can be "to" (default), "from", "both" or "either".
If whom is a single node this method returns a boolean,
otherwise it returns a list of booleans | 2.432009 | 2.394733 | 1.015566 |
if type is None:
type = Info
if not issubclass(type, Info):
raise TypeError(
"Cannot get infos of type {} " "as it is not a valid type.".format(type)
)
if failed not in ["all", False, True]:
raise ValueError("{} is not a ... | def infos(self, type=None, failed=False) | Get infos that originate from this node.
Type must be a subclass of :class:`~dallinger.models.Info`, the default is
``Info``. Failed can be True, False or "all". | 3.453585 | 2.751143 | 1.255327 |
if failed is not None:
raise ValueError(
"You should not pass a failed argument to received_infos. "
"received_infos is "
"unusual in that a failed argument cannot be passed. This is "
"because there is inherent uncertainty in ... | def received_infos(self, type=None, failed=None) | Get infos that have been sent to this node.
Type must be a subclass of info, the default is Info. | 3.927725 | 3.707545 | 1.059387 |
if failed not in ["all", False, True]:
raise ValueError("{} is not a valid transmission failed".format(failed))
if type is None:
type = Transformation
if failed == "all":
return type.query.filter_by(node_id=self.id).all()
else:
r... | def transformations(self, type=None, failed=False) | Get Transformations done by this Node.
type must be a type of Transformation (defaults to Transformation)
Failed can be True, False or "all" | 3.143134 | 2.483493 | 1.26561 |
if self.failed is True:
raise AttributeError("Cannot fail {} - it has already failed.".format(self))
else:
self.failed = True
self.time_of_death = timenow()
self.network.calculate_full()
for v in self.vectors():
v.fail... | def fail(self) | Fail a node, setting its status to "failed".
Also fails all vectors that connect to or from the node.
You cannot fail a node that has already failed, but you
can fail a dead node.
Set node.failed to True and :attr:`~dallinger.models.Node.time_of_death`
to now. Instruct all not-... | 5.457089 | 3.378973 | 1.615014 |
# check direction
if direction not in ["to", "from", "both"]:
raise ValueError(
"{} is not a valid direction for connect()".format(direction)
)
# make whom a list
whom = self.flatten([whom])
# make the connections
new_vec... | def connect(self, whom, direction="to") | Create a vector from self to/from whom.
Return a list of newly created vector between the node and whom.
``whom`` can be a specific node or a (nested) list of nodes. Nodes can
only connect with nodes in the same network. In addition nodes cannot
connect with themselves or with Sources. ... | 2.294207 | 2.118244 | 1.08307 |
if lst == []:
return lst
if isinstance(lst[0], list):
return self.flatten(lst[0]) + self.flatten(lst[1:])
return lst[:1] + self.flatten(lst[1:]) | def flatten(self, lst) | Turn a list of lists into a list. | 1.923964 | 1.809639 | 1.063176 |
whats = set()
for what in self.flatten([what]):
if what is None:
what = self._what()
if inspect.isclass(what) and issubclass(what, Info):
whats.update(self.infos(type=what))
else:
whats.add(what)
to_who... | def transmit(self, what=None, to_whom=None) | Transmit one or more infos from one node to another.
"what" dictates which infos are sent, it can be:
(1) None (in which case the node's _what method is called).
(2) an Info (in which case the node transmits the info)
(3) a subclass of Info (in which case the node transmits ... | 2.361325 | 2.16099 | 1.092705 |
if self.failed is True:
raise AttributeError("Cannot fail {} - it has already failed.".format(self))
else:
self.failed = True
self.time_of_death = timenow()
for t in self.transmissions():
t.fail() | def fail(self) | Fail a vector. | 5.883403 | 5.81244 | 1.012209 |
return {
"type": self.type,
"origin_id": self.origin_id,
"network_id": self.network_id,
"contents": self.contents,
} | def json_data(self) | The json representation of an info. | 3.644925 | 3.225394 | 1.130071 |
if relationship not in ["all", "parent", "child"]:
raise ValueError(
"You cannot get transformations of relationship {}".format(relationship)
+ "Relationship can only be parent, child or all."
)
if relationship == "all":
retur... | def transformations(self, relationship="all") | Get all the transformations of this info.
Return a list of transformations involving this info. ``relationship``
can be "parent" (in which case only transformations where the info is
the ``info_in`` are returned), "child" (in which case only
transformations where the info is the ``info_... | 2.657024 | 2.573631 | 1.032403 |
return {
"vector_id": self.vector_id,
"origin_id": self.origin_id,
"destination_id": self.destination_id,
"info_id": self.info_id,
"network_id": self.network_id,
"receive_time": self.receive_time,
"status": self.status,... | def json_data(self) | The json representation of a transmissions. | 2.835563 | 2.454016 | 1.155479 |
return {
"info_in_id": self.info_in_id,
"info_out_id": self.info_out_id,
"node_id": self.node_id,
"network_id": self.network_id,
} | def json_data(self) | The json representation of a transformation. | 3.168052 | 3.054977 | 1.037013 |
dist = get_distribution("dallinger")
src_base = os.path.join(dist.location, dist.project_name)
return src_base | def dallinger_package_path() | Return the absolute path of the root directory of the installed
Dallinger package:
>>> utils.dallinger_package_location()
'/Users/janedoe/projects/Dallinger3/dallinger' | 4.254812 | 7.50984 | 0.566565 |
return "".join(random.choice(chars) for x in range(size)) | def generate_random_id(size=6, chars=string.ascii_uppercase + string.digits) | Generate random id numbers. | 3.934053 | 2.467069 | 1.594626 |
tempdir = tempfile.mkdtemp()
output_file = os.path.join(tempdir, "stderr")
original_cmd = " ".join(cmd)
p = subprocess.Popen(cmd, stdout=out, stderr=subprocess.PIPE)
t = subprocess.Popen(["tee", output_file], stdin=p.stderr, stdout=out)
t.wait()
p.communicate()
p.stderr.close()
... | def run_command(cmd, out, ignore_errors=False) | We want to both send subprocess output to stdout or another file
descriptor as the subprocess runs, *and* capture the actual exception
message on errors. CalledProcessErrors do not reliably contain the
underlying exception in either the 'message' or 'out' attributes, so
we tee the stderr to a temporary ... | 2.329204 | 2.329793 | 0.999747 |
if verbose:
if chevrons:
click.echo("\n❯❯ " + msg)
else:
click.echo(msg)
time.sleep(delay) | def log(msg, delay=0.5, chevrons=True, verbose=True) | Log a message to stdout. | 3.157955 | 3.106722 | 1.016491 |
if verbose:
if chevrons:
click.secho("\n❯❯ " + msg, err=True, fg="red")
else:
click.secho(msg, err=True, fg="red")
time.sleep(delay) | def error(msg, delay=0.5, chevrons=True, verbose=True) | Log a message to stdout. | 2.531249 | 2.46025 | 1.028858 |
def decorator(func):
def wrapper(*args, **kwargs):
def _handle_timeout(signum, frame):
config = get_config()
if not config.ready:
config.load()
message = {
"subject": "Idle Experiment.",
... | def report_idle_after(seconds) | Report_idle_after after certain number of seconds. | 4.067362 | 3.937201 | 1.033059 |
if app is None:
raise TypeError("Select an experiment using the --app parameter.")
elif app[0:5] == "dlgr-":
raise ValueError(
"The --app parameter requires the full "
"UUID beginning with {}-...".format(app[5:13])
)
return app | def verify_id(ctx, param, app) | Verify the experiment id. | 10.365453 | 8.508847 | 1.218197 |
# Check required files
ok = True
mb_to_bytes = 1000 * 1000
expected_files = ["config.txt", "experiment.py"]
for f in expected_files:
if os.path.exists(f):
log("✓ {} is PRESENT".format(f), chevrons=False, verbose=verbose)
else:
log("✗ {} is MISSING".forma... | def verify_directory(verbose=True, max_size_mb=50) | Ensure that the current directory looks like a Dallinger experiment, and
does not appear to have unintended contents that will be copied on
deployment. | 2.892337 | 2.835531 | 1.020034 |
ok = True
if not os.path.exists("experiment.py"):
return False
# Bootstrap a package in a temp directory and make it importable:
temp_package_name = "TEMP_VERIFICATION_PACKAGE"
tmp = tempfile.mkdtemp()
clone_dir = os.path.join(tmp, temp_package_name)
to_ignore = shutil.ignore_p... | def verify_experiment_module(verbose) | Perform basic sanity checks on experiment.py. | 3.591529 | 3.500356 | 1.026047 |
ok = True
config = get_config()
if not config.ready:
config.load()
# Check base_payment is correct
try:
base_pay = config.get("base_payment")
except KeyError:
log("✗ No value for base_pay.", delay=0, chevrons=False, verbose=verbose)
else:
dollarFormat = "... | def verify_config(verbose=True) | Check for common or costly errors in experiment configuration. | 3.695049 | 3.620938 | 1.020467 |
conflicts = False
reserved_files = [
os.path.join("templates", "complete.html"),
os.path.join("templates", "error.html"),
os.path.join("templates", "error-complete.html"),
os.path.join("templates", "launch.html"),
os.path.join("templates", "thanks.html"),
os... | def verify_no_conflicts(verbose=True) | Warn if there are filenames which conflict with those deployed by
Dallinger, but always returns True (meaning "OK"). | 3.098656 | 2.878397 | 1.076522 |
results = (
verify_directory(verbose),
verify_experiment_module(verbose),
verify_config(verbose),
verify_no_conflicts(verbose),
)
ok = all(results)
return ok | def verify_package(verbose=True) | Perform a series of checks on the current directory to verify that
it's a valid Dallinger experiment. | 6.616908 | 5.684026 | 1.164124 |
error = "The current directory is not a valid Dallinger experiment."
@wraps(f)
def wrapper(**kwargs):
if not verify_directory(kwargs.get("verbose")):
raise click.UsageError(error)
return f(**kwargs)
return wrapper | def require_exp_directory(f) | Decorator to verify that a command is run inside a valid Dallinger
experiment directory. | 4.755084 | 3.499052 | 1.358964 |
from logging.config import fileConfig
fileConfig(
os.path.join(os.path.dirname(__file__), "logging.ini"),
disable_existing_loggers=False,
) | def dallinger() | Dallinger command-line utility. | 2.62667 | 2.709758 | 0.969338 |
debugger = DebugDeployment(Output(), verbose, bot, proxy, exp_config)
log(header, chevrons=False)
debugger.run() | def debug(verbose, bot, proxy, exp_config=None) | Run the experiment locally. | 18.973341 | 17.097183 | 1.109735 |
if app:
verify_id(None, None, app)
log(header, chevrons=False)
_deploy_in_mode("sandbox", app=app, verbose=verbose, log=log) | def sandbox(verbose, app) | Deploy app using Heroku to the MTurk Sandbox. | 13.350412 | 12.626293 | 1.05735 |
if not (workers and qualification and value):
raise click.BadParameter(
"Must specify a qualification ID, value/score, and at least one worker ID"
)
mturk = _mturk_service_from_config(sandbox)
if by_name:
result = mturk.get_qualification_type_by_name(qualification)
... | def qualify(workers, qualification, value, by_name, notify, sandbox) | Assign a qualification to 1 or more workers | 2.845371 | 2.770802 | 1.026912 |
if not (workers and qualification):
raise click.BadParameter(
"Must specify a qualification ID or name, and at least one worker ID"
)
mturk = _mturk_service_from_config(sandbox)
if by_name:
result = mturk.get_qualification_type_by_name(qualification)
if resu... | def revoke(workers, qualification, by_name, reason, sandbox) | Revoke a qualification from 1 or more workers | 2.827651 | 2.796517 | 1.011133 |
log("The database backup URL is...")
backup_url = data.backup(app)
log(backup_url)
log("Scaling down the web servers...")
heroku_app = HerokuApp(app)
heroku_app.scale_down_dynos()
log("Removing addons...")
addons = [
"heroku-postgresql",
# "papertrail",
"h... | def hibernate(app) | Pause an experiment and remove costly resources. | 6.24054 | 6.023995 | 1.035947 |
hit_list = list(_current_hits(_mturk_service_from_config(sandbox), app))
out = Output()
out.log(
"Found {} hits for this experiment id: {}".format(
len(hit_list), ", ".join(h["id"] for h in hit_list)
)
) | def hits(app, sandbox) | List hits for an experiment id. | 7.570366 | 6.180076 | 1.224963 |
success = []
failures = []
service = _mturk_service_from_config(sandbox)
hits = _current_hits(service, app)
for hit in hits:
hit_id = hit["id"]
try:
service.expire_hit(hit_id)
success.append(hit_id)
except MTurkServiceException:
failur... | def expire(app, sandbox, exit=True) | Expire hits for an experiment id. | 3.131779 | 2.910696 | 1.075955 |
if expire_hit:
ctx.invoke(expire, app=app, sandbox=sandbox, exit=False)
HerokuApp(app).destroy() | def destroy(ctx, app, expire_hit, sandbox) | Tear down an experiment server. | 5.540165 | 5.514644 | 1.004628 |
id = app
config = get_config()
config.load()
bucket = data.user_s3_bucket()
key = bucket.lookup("{}.dump".format(id))
url = key.generate_url(expires_in=300)
heroku_app = HerokuApp(id, output=None, team=None)
heroku_app.addon("heroku-postgresql:{}".format(config.get("database_size"... | def awaken(app, databaseurl) | Restore the database from a given url. | 4.731131 | 4.624347 | 1.023092 |
log(header, chevrons=False)
data.export(str(app), local=local, scrub_pii=(not no_scrub)) | def export(app, local, no_scrub) | Export the data. | 13.476737 | 12.98253 | 1.038067 |
if replay:
exp_config = exp_config or {}
exp_config["replay"] = True
log(header, chevrons=False)
loader = LoaderDeployment(app, Output(), verbose, exp_config)
loader.run() | def load(app, verbose, replay, exp_config=None) | Import database state from an exported zip file and leave the server
running until stopping the process with <control>-c. | 8.621885 | 8.310096 | 1.037519 |
heroku_app = HerokuApp(dallinger_uid=app)
webbrowser.open(heroku_app.dashboard_url)
webbrowser.open("https://requester.mturk.com/mturk/manageHITs")
heroku_app.open_logs()
check_call(["open", heroku_app.db_uri])
while _keep_running():
summary = get_summary(app)
click.clear()
... | def monitor(app) | Set up application monitoring. | 5.700409 | 5.895464 | 0.966914 |
if debug is None:
verify_id(None, None, app)
(id, tmp) = setup_experiment(log)
if debug:
url = debug
else:
heroku_app = HerokuApp(dallinger_uid=app)
worker = generate_random_id()
hit = generate_random_id()
assignment = generate_random_id()
a... | def bot(app, debug) | Run the experiment bot. | 6.428323 | 5.845476 | 1.099709 |
verbose = True
log(
"Verifying current directory as a Dallinger experiment...",
delay=0,
verbose=verbose,
)
ok = verify_package(verbose=verbose)
if ok:
log("✓ Everything looks good!", delay=0, verbose=verbose)
else:
log("☹ Some problems were found.", ... | def verify() | Verify that app is compatible with Dallinger. | 6.131752 | 4.860807 | 1.261468 |
infos = Info.query.all()
sketches = [json.loads(info.contents) for info in infos]
return jsonify(drawings=sketches) | def getdrawings() | Get all the drawings. | 6.651891 | 6.453125 | 1.030802 |
config = _config()
html = "<html><head></head><body><h1>Dallinger Experiment in progress</h1><dl>"
for item in sorted(config.as_dict().items()):
html += '<dt style="font-weight:bold;margin-top:15px;">{}</dt><dd>{}</dd>'.format(
*item
)
html += "</dl></body></html>"
r... | def index() | Index route | 4.098577 | 4.135909 | 0.990974 |
data_out = {}
data_out["status"] = "success"
data_out.update(data)
js = dumps(data_out, default=date_handler)
return Response(js, status=200, mimetype="application/json") | def success_response(**data) | Return a generic success response. | 2.843872 | 2.643642 | 1.07574 |
last_exception = sys.exc_info()
if last_exception[0]:
db.logger.error(
"Failure for request: {!r}".format(dict(request.args)),
exc_info=last_exception,
)
data = {"status": "error"}
if simple:
data["message"] = error_text
else:
data["html... | def error_response(
error_type="Internal server error",
error_text="",
status=400,
participant=None,
simple=False,
request_data="",
) | Return a generic server error response. | 2.70282 | 2.675875 | 1.01007 |
config = _config()
if error_text is None:
error_text =
if participant is not None:
hit_id = (participant.hit_id,)
assignment_id = (participant.assignment_id,)
worker_id = participant.worker_id
participant_id = participant.id
else:
hit_id = request.... | def error_page(
participant=None,
error_text=None,
compensate=True,
error_type="default",
request_data="",
) | Render HTML for error page. | 2.034356 | 1.998284 | 1.018052 |
exp = Experiment(session)
return dict(experiment=exp, env=os.environ) | def inject_experiment() | Inject experiment and enviroment variables into the template context. | 12.973334 | 7.489792 | 1.732135 |
try:
exp = Experiment(db.init_db(drop_all=False))
except Exception as ex:
return error_response(
error_text="Failed to load experiment in /launch: {}".format(str(ex)),
status=500,
simple=True,
)
try:
exp.log("Launching experiment...", ... | def launch() | Launch the experiment. | 3.319855 | 3.28479 | 1.010675 |
if participant is None:
return False
status = participant.status
marked_done = participant.end_time is not None
ready_for_external_submission = (
status in ("overrecruited", "working") and marked_done
)
assignment_complete = status in ("submitted", "approved")
return as... | def should_show_thanks_page_to(participant) | In the context of the /ad route, should the participant be shown
the thanks.html page instead of ad.html? | 6.469396 | 6.352417 | 1.018415 |
if not ("hitId" in request.args and "assignmentId" in request.args):
raise ExperimentError("hit_assign_worker_id_not_set_in_mturk")
config = _config()
# Browser rule validation, if configured:
browser = ValidatesBrowser(config)
if not browser.is_supported(request.user_agent.string):
... | def advertisement() | This is the url we give for the ad for our 'external question'. The ad has
to display two different things: This page will be called from within
mechanical turk, with url arguments hitId, assignmentId, and workerId.
If the worker has not yet accepted the hit:
These arguments will have null values, ... | 3.634154 | 3.479635 | 1.044407 |
exp = Experiment(session)
state = {
"status": "success",
"summary": exp.log_summary(),
"completed": exp.is_complete(),
}
unfilled_nets = (
models.Network.query.filter(models.Network.full != true())
.with_entities(models.Network.id, models.Network.max_size)
... | def summary() | Summarize the participants' status codes. | 3.106025 | 3.061731 | 1.014467 |
exp = Experiment(session)
try:
value = exp.public_properties[prop]
except KeyError:
abort(404)
return success_response(**{prop: value}) | def experiment_property(prop) | Get a property of the experiment by name. | 5.197695 | 5.050491 | 1.029146 |
config = _config()
return render_template(
"consent.html",
hit_id=request.args["hit_id"],
assignment_id=request.args["assignment_id"],
worker_id=request.args["worker_id"],
mode=config.get("mode"),
) | def consent() | Return the consent form. Here for backwards-compatibility with 2.x. | 3.529752 | 3.553409 | 0.993342 |
exp = Experiment(session)
# get the parameter
try:
value = request.values[parameter]
except KeyError:
# if it isnt found use the default, or return an error Response
if default is not None:
return default
elif optional:
return None
el... | def request_parameter(parameter, parameter_type=None, default=None, optional=False) | Get a parameter from a request.
parameter is the name of the parameter you are looking for
parameter_type is the type the parameter should have
default is the value the parameter takes if it has not been passed
If the parameter is not found and no default is specified,
or if the parameter is found... | 2.255808 | 2.286678 | 0.9865 |
details = request_parameter(parameter="details", optional=True)
if details:
setattr(thing, "details", loads(details))
for p in range(5):
property_name = "property" + str(p + 1)
property = request_parameter(parameter=property_name, optional=True)
if property:
... | def assign_properties(thing) | Assign properties to an object.
When creating something via a post request (e.g. a node), you can pass the
properties of the object in the request. This function gets those values
from the request and fills in the relevant columns of the table. | 3.731691 | 4.509402 | 0.827536 |
# Lock the table, triggering multiple simultaneous accesses to fail
try:
session.connection().execute("LOCK TABLE participant IN EXCLUSIVE MODE NOWAIT")
except exc.OperationalError as e:
e.orig = TransactionRollbackError()
raise e
missing = [p for p in (worker_id, hit_id, a... | def create_participant(worker_id, hit_id, assignment_id, mode) | Create a participant.
This route is hit early on. Any nodes the participant creates will be
defined in reference to the participant object. You must specify the
worker_id, hit_id, assignment_id, and mode in the url. | 3.629224 | 3.680634 | 0.986032 |
try:
ppt = models.Participant.query.filter_by(id=participant_id).one()
except NoResultFound:
return error_response(
error_type="/participant GET: no participant found", status=403
)
# return the data
return success_response(participant=ppt.__json__()) | def get_participant(participant_id) | Get the participant with the given id. | 5.442827 | 5.298127 | 1.027312 |
try:
net = models.Network.query.filter_by(id=network_id).one()
except NoResultFound:
return error_response(error_type="/network GET: no network found", status=403)
# return the data
return success_response(network=net.__json__()) | def get_network(network_id) | Get the network with the given id. | 4.816476 | 4.839704 | 0.995201 |
# Get the participant.
try:
ppt = models.Participant.query.filter_by(id=participant_id).one()
except NoResultFound:
return error_response(
error_type="/question POST no participant found", status=403
)
question = request_parameter(parameter="question")
respo... | def create_question(participant_id) | Send a POST request to the question table.
Questions store information at the participant level, not the node
level.
You should pass the question (string) number (int) and response
(string) as arguments. | 4.544168 | 4.342163 | 1.046522 |
exp = Experiment(session)
# get the parameters
node_type = request_parameter(
parameter="node_type", parameter_type="known_class", default=models.Node
)
connection = request_parameter(parameter="connection", default="to")
failed = request_parameter(parameter="failed", parameter_typ... | def node_neighbors(node_id) | Send a GET request to the node table.
This calls the neighbours method of the node
making the request and returns a list of descriptions of
the nodes (even if there is only one).
Required arguments: participant_id, node_id
Optional arguments: type, connection
After getting the neighbours it al... | 4.119694 | 3.816566 | 1.079424 |
exp = Experiment(session)
# Get the participant.
try:
participant = models.Participant.query.filter_by(id=participant_id).one()
except NoResultFound:
return error_response(error_type="/node POST no participant found", status=403)
# Make sure the participant status is working
... | def create_node(participant_id) | Send a POST request to the node table.
This makes a new node for the participant, it calls:
1. exp.get_network_for_participant
2. exp.create_node
3. exp.add_node_to_network
4. exp.node_post_request | 3.991425 | 3.274418 | 1.218972 |
exp = Experiment(session)
# get the parameters
direction = request_parameter(parameter="direction", default="all")
failed = request_parameter(parameter="failed", parameter_type="bool", default=False)
for x in [direction, failed]:
if type(x) == Response:
return x
# execu... | def node_vectors(node_id) | Get the vectors of a node.
You must specify the node id in the url.
You can pass direction (incoming/outgoing/all) and failed
(True/False/all). | 4.821931 | 4.488251 | 1.074345 |
exp = Experiment(session)
# get the parameters
info_type = request_parameter(
parameter="info_type", parameter_type="known_class", default=models.Info
)
if type(info_type) == Response:
return info_type
# check the node exists
node = models.Node.query.get(node_id)
i... | def node_received_infos(node_id) | Get all the infos a node has been sent and has received.
You must specify the node id in the url.
You can also pass the info type. | 4.919893 | 4.941094 | 0.995709 |
details = request_parameter(parameter="details", optional=True)
if details:
details = loads(details)
# check the node exists
node = models.Node.query.get(node_id)
if node is None:
return error_response(error_type="/info POST, node does not exist")
db.logger.debug(
... | def tracking_event_post(node_id) | Enqueue a TrackingEvent worker for the specified Node. | 6.437219 | 6.173476 | 1.042722 |
# get the parameters and validate them
contents = request_parameter(parameter="contents")
info_type = request_parameter(
parameter="info_type", parameter_type="known_class", default=models.Info
)
for x in [contents, info_type]:
if type(x) == Response:
return x
# ... | def info_post(node_id) | Create an info.
The node id must be specified in the url.
You must pass contents as an argument.
info_type is an additional optional argument.
If info_type is a custom subclass of Info it must be
added to the known_classes of the experiment class. | 5.193417 | 4.722436 | 1.099733 |
exp = Experiment(session)
# get the parameters
direction = request_parameter(parameter="direction", default="incoming")
status = request_parameter(parameter="status", default="all")
for x in [direction, status]:
if type(x) == Response:
return x
# check the node exists
... | def node_transmissions(node_id) | Get all the transmissions of a node.
The node id must be specified in the url.
You can also pass direction (to/from/all) or status (all/pending/received)
as arguments. | 4.466949 | 4.251375 | 1.050707 |
exp = Experiment(session)
what = request_parameter(parameter="what", optional=True)
to_whom = request_parameter(parameter="to_whom", optional=True)
# check the node exists
node = models.Node.query.get(node_id)
if node is None:
return error_response(error_type="/node/transmit, node ... | def node_transmit(node_id) | Transmit to another node.
The sender's node id must be specified in the url.
As with node.transmit() the key parameters are what and to_whom. However,
the values these accept are more limited than for the back end due to the
necessity of serialization.
If what and to_whom are not specified they w... | 2.368203 | 2.210022 | 1.071574 |
exp = Experiment(session)
# get the parameters
transformation_type = request_parameter(
parameter="transformation_type",
parameter_type="known_class",
default=models.Transformation,
)
if type(transformation_type) == Response:
return transformation_type
# ch... | def transformation_get(node_id) | Get all the transformations of a node.
The node id must be specified in the url.
You can also pass transformation_type. | 4.633194 | 4.728286 | 0.979889 |
participants = models.Participant.query.filter_by(
assignment_id=participant.assignment_id
).all()
duplicates = [
p for p in participants if (p.id != participant.id and p.status == "working")
]
for d in duplicates:
q.enqueue(worker_function, "AssignmentAbandoned", None, ... | def check_for_duplicate_assignments(participant) | Check that the assignment_id of the participant is unique.
If it isnt the older participants will be failed. | 4.61152 | 4.471219 | 1.031379 |
participant_id = request.args.get("participant_id")
if not participant_id:
return error_response(
error_type="bad request", error_text="participantId parameter is required"
)
try:
_worker_complete(participant_id)
except KeyError:
return error_response(
... | def worker_complete() | Complete worker. | 3.740963 | 3.533367 | 1.058753 |
participant_id = request.args.get("participant_id")
if not participant_id:
return error_response(
error_type="bad request", error_text="participantId parameter is required"
)
try:
_worker_failed(participant_id)
except KeyError:
return error_response(
... | def worker_failed() | Fail worker. Used by bots only for now. | 3.991275 | 3.925212 | 1.01683 |
_config()
try:
db.logger.debug(
"rq: worker_function working on job id: %s", get_current_job().id
)
db.logger.debug(
"rq: Received Queue Length: %d (%s)", len(q), ", ".join(q.job_ids)
)
except AttributeError:
db.logger.debug("Debug worker_... | def worker_function(
event_type, assignment_id, participant_id, node_id=None, details=None
) | Process the notification. | 3.154542 | 3.109773 | 1.014396 |
cmd = ["heroku", "apps", "--json"]
if self.team:
cmd.extend(["--team", self.team])
return json.loads(self._result(cmd)) | def all_apps(self) | Capture a backup of the app. | 4.736571 | 4.6797 | 1.012153 |
cmd = ["heroku", "apps:create", self.name, "--buildpack", "heroku/python"]
# If a team is specified, assign the app to the team.
if self.team:
cmd.extend(["--team", self.team])
self._run(cmd)
# Set HOST value
self.set_multiple(
HOST=self... | def bootstrap(self) | Creates the heroku app and local git remote. Call this once you're
in the local repo you're going to use. | 7.137854 | 6.06716 | 1.176474 |
cmd = ["heroku", "addons:create", name, "--app", self.name]
self._run(cmd) | def addon(self, name) | Set up an addon | 6.399279 | 6.632127 | 0.964891 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.