Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def edit_assignment(assignment, new_config):
for k, v in list(new_config.items()):
setattr(assignment, k, v)
db_session.add(assignment)
db_session.commit()
def campaign():
from psiturk.models import Campaign
parameters = {
'codeversion': '1.0',
'mode': 'sandbox',
'goal': 100,
'minutes_between_rounds': 1,
'assignments_per_round': 10,
'hit_reward': 1.00,
'hit_duration_hours': 1,
}
new_campaign = Campaign(**parameters)
from psiturk.db import db_session
db_session.add(new_campaign)
db_session.commit()
return new_campaign
exp.networks()[0].max_size,
len(exp.networks()[0].nodes(failed=True)),
p_times[-1]),
end="\r")
else:
print("Running simulated experiment... participant {} of {}, {} participants failed.".format(
num_completed_participants+1,
exp.networks()[0].max_size,
len(exp.networks()[0].nodes(failed=True))),
end="\r")
sys.stdout.flush()
worker_id = str(random.random())
assignment_id = str(random.random())
from psiturk.models import Participant
p = Participant(workerid=worker_id, assignmentid=assignment_id, hitid=hit_id)
self.db.add(p)
self.db.commit()
p_id = p.uniqueid
p_ids.append(p_id)
p_start_time = timenow()
while True:
assign_start_time = timenow()
network = exp.get_network_for_participant(participant_id=p_id)
if network is None:
break
else:
agent = exp.make_node_for_participant(
participant_id=p_id,
network=network)
exp.add_node_to_network(
def do_it():
from psiturk.psiturk_shell import PsiturkNetworkShell
import psiturk.experiment_server_controller as control
from psiturk.psiturk_config import PsiturkConfig
import psiturk.experiment_server_controller
mocker.patch.object(psiturk.experiment_server_controller.ExperimentServerController, 'is_port_available', lambda *args, **kwargs: True)
mocker.patch.object(PsiturkNetworkShell,'get_intro_prompt', lambda *args, **kwargs: '')
mocker.patch.object(PsiturkNetworkShell,'update_hit_tally', lambda *args, **kwargs: None)
mocker.patch.object(PsiturkNetworkShell,'_confirm_dialog', lambda *args, **kwargs: True)
config = PsiturkConfig()
config.load_config()
server = control.ExperimentServerController(config)
launch_in_sandbox_mode = True
quiet = False
shell = PsiturkNetworkShell(
config, server,
launch_in_sandbox_mode,
quiet=quiet)
shell.persistent_history_file = None
shell.echo = True
stubber.assert_no_pending_responses()
return shell
def campaign():
from psiturk.models import Campaign
parameters = {
'codeversion': '1.0',
'mode': 'sandbox',
'goal': 100,
'minutes_between_rounds': 1,
'assignments_per_round': 10,
'hit_reward': 1.00,
'hit_duration_hours': 1,
}
new_campaign = Campaign(**parameters)
from psiturk.db import db_session
db_session.add(new_campaign)
db_session.commit()
return new_campaign
def edit_assignment(assignment, new_config):
for k, v in list(new_config.items()):
setattr(assignment, k, v)
db_session.add(assignment)
db_session.commit()
def test_wrapper_get_all_hits_all_studies(self, amt_services_wrapper, create_dummy_hit, list_hits, helpers):
create_dummy_hit('3XJOUITW8URHJMX7F00H20LGRIAQTX')
create_dummy_hit('3BFNCI9LYKQ2ENUY4MLKKW0NSU437W')
from psiturk.db import db_session
from psiturk.models import Hit
Hit.query.filter_by(hitid='3BFNCI9LYKQ2ENUY4MLKKW0NSU437W').delete()
db_session.commit()
hits = list_hits(all_studies=False)
assert '3BFNCI9LYKQ2ENUY4MLKKW0NSU437W' not in [
hit.options['hitid'] for hit in hits]
hits = list_hits(all_studies=True)
assert '3BFNCI9LYKQ2ENUY4MLKKW0NSU437W' in [
hit.options['hitid'] for hit in hits]
def do_it():
import psiturk.experiment
reload(psiturk.experiment)
psiturk.experiment.app.wsgi_app = FlaskTestClientProxy(
psiturk.experiment.app.wsgi_app)
return psiturk.experiment.app
yield do_it
def do_it():
from psiturk.psiturk_shell import PsiturkNetworkShell
import psiturk.experiment_server_controller as control
from psiturk.psiturk_config import PsiturkConfig
import psiturk.experiment_server_controller
mocker.patch.object(psiturk.experiment_server_controller.ExperimentServerController, 'is_port_available', lambda *args, **kwargs: True)
mocker.patch.object(PsiturkNetworkShell,'get_intro_prompt', lambda *args, **kwargs: '')
mocker.patch.object(PsiturkNetworkShell,'update_hit_tally', lambda *args, **kwargs: None)
mocker.patch.object(PsiturkNetworkShell,'_confirm_dialog', lambda *args, **kwargs: True)
config = PsiturkConfig()
config.load_config()
server = control.ExperimentServerController(config)
launch_in_sandbox_mode = True
quiet = False
shell = PsiturkNetworkShell(
config, server,
launch_in_sandbox_mode,
quiet=quiet)
shell.persistent_history_file = None
def do_it():
from psiturk.psiturk_shell import PsiturkNetworkShell
import psiturk.experiment_server_controller as control
from psiturk.psiturk_config import PsiturkConfig
import psiturk.experiment_server_controller
mocker.patch.object(psiturk.experiment_server_controller.ExperimentServerController, 'is_port_available', lambda *args, **kwargs: True)
mocker.patch.object(PsiturkNetworkShell,'get_intro_prompt', lambda *args, **kwargs: '')
mocker.patch.object(PsiturkNetworkShell,'update_hit_tally', lambda *args, **kwargs: None)
mocker.patch.object(PsiturkNetworkShell,'_confirm_dialog', lambda *args, **kwargs: True)
config = PsiturkConfig()
config.load_config()
server = control.ExperimentServerController(config)
launch_in_sandbox_mode = True
quiet = False
shell = PsiturkNetworkShell(
config, server,
launch_in_sandbox_mode,
quiet=quiet)
shell.persistent_history_file = None
shell.echo = True
stubber.assert_no_pending_responses()
return shell