Exemplo n.º 1
0
def run(cabinmode=False, script=None, execute=None, quiet=False):
    using_libedit = 'libedit' in readline.__doc__
    if using_libedit:
        print colorize('\n'.join([
            'libedit version of readline detected.',
            'readline will not be well behaved, which may cause all sorts',
            'of problems for the psiTurk shell. We highly recommend installing',
            'the gnu version of readline by running "sudo pip install gnureadline".',
            'Note: "pip install readline" will NOT work because of how the OSX',
            'pythonpath is structured.'
        ]), 'red', False)
    sys.argv = [sys.argv[0]] # Drop arguments which were already processed in command_line.py
    #opt = docopt(__doc__, sys.argv[1:])
    config = PsiturkConfig()
    config.load_config()
    server = control.ExperimentServerController(config)
    if cabinmode:
        shell = PsiturkShell(config, server)
        shell.check_offline_configuration()
    else:
        shell = PsiturkNetworkShell(
            config, server, \
            config.getboolean('Shell Parameters', 'launch_in_sandbox_mode'),
            quiet=quiet)

    if script:
        with open(script, 'r') as temp_file:
            for line in temp_file:
                shell.onecmd_plus_hooks(line)
    elif execute:
        shell.onecmd_plus_hooks(execute)
    else:
        shell.cmdloop()
Exemplo n.º 2
0
def run(cabinmode=False, script=None, execute=None, quiet=False):
    using_libedit = 'libedit' in readline.__doc__
    if using_libedit:
        print colorize('\n'.join([
            'libedit version of readline detected.',
            'readline will not be well behaved, which may cause all sorts',
            'of problems for the psiTurk shell. We highly recommend installing',
            'the gnu version of readline by running "sudo pip install gnureadline".',
            'Note: "pip install readline" will NOT work because of how the OSX',
            'pythonpath is structured.'
        ]), 'red', False)
    sys.argv = [sys.argv[0]] # Drop arguments which were already processed in command_line.py
    #opt = docopt(__doc__, sys.argv[1:])
    config = PsiturkConfig()
    config.load_config()
    server = control.ExperimentServerController(config)
    if cabinmode:
        shell = PsiturkShell(config, server)
        shell.check_offline_configuration()
    else:
        shell = PsiturkNetworkShell(
            config, server, \
            config.getboolean('Shell Parameters', 'launch_in_sandbox_mode'), 
            quiet=quiet)

    if script:
        with open(script, 'r') as temp_file:
            for line in temp_file:
                shell.onecmd_plus_hooks(line)
    elif execute:
        shell.onecmd_plus_hooks(execute)
    else:
        shell.cmdloop()
Exemplo n.º 3
0
def setup_example():
    print "Copying", static_dir, "to", static_target
    dir_util.copy_tree(static_dir, static_target)
    print "Copying", templates_dir, "to", templates_target
    dir_util.copy_tree(templates_dir, templates_target)
    print "Creating default configuration file"
    config = PsiturkConfig()
Exemplo n.º 4
0
 def __init__(self, config=None, web_services=None, tunnel=None, sandbox=None):
     
     if not config:
         config = PsiturkConfig()
         config.load_config()
     self.config = config
     
     if web_services:
         self._cached_web_services = web_services
     
     if not tunnel:
         tunnel = TunnelServices(config)
     self.tunnel = tunnel
 
     if not sandbox:
         sandbox = config.getboolean('Shell Parameters', 'launch_in_sandbox_mode')
     self.sandbox = sandbox
Exemplo n.º 5
0
 def __init__(self, config=None, web_services=None, tunnel=None, sandbox=None):
     
     if not config:
         config = PsiturkConfig()
         config.load_config()
     self.config = config
     
     if web_services:
         self._cached_web_services = web_services
     
     if not tunnel:
         tunnel = TunnelServices(config)
     self.tunnel = tunnel
 
     if not sandbox:
         sandbox = config.getboolean('Shell Parameters', 'launch_in_sandbox_mode')
     self.sandbox = sandbox
Exemplo n.º 6
0
def install_from_exchange():
    parser = argparse.ArgumentParser(
        description=
        'Download experiment from the psiturk.org experiment exchange (http://psiturk.org/ee).'
    )
    parser.add_argument('exp_id',
                        metavar='exp_id',
                        type=str,
                        help='the id number of the experiment in the exchange')
    args = parser.parse_args()
    config = PsiturkConfig()
    ee = ExperimentExchangeServices()
    ee.download_experiment(args.exp_id)
Exemplo n.º 7
0
try:
    from collections import Counter
except ImportError:
    from counter import Counter

# Importing flask
from flask import Flask, render_template, request, Response, jsonify

# Database setup
from db import db_session, init_db
from models import Participant
from sqlalchemy import or_

from psiturk_config import PsiturkConfig

config = PsiturkConfig()

# Set up logging
logfilepath = os.path.join(os.getcwd(),
                           config.get("Server Parameters", "logfile"))

loglevels = [logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL]
loglevel = loglevels[config.getint('Server Parameters', 'loglevel')]
logging.basicConfig( filename=logfilepath, format='%(asctime)s %(message)s', level=loglevel )

# config.get( 'Mechanical Turk Info', 'aws_secret_access_key' )

# constants
USING_SANDBOX = config.getboolean('HIT Configuration', 'using_sandbox')
CODE_VERSION = config.get('Task Parameters', 'code_version')
Exemplo n.º 8
0
except ImportError:
    from counter import Counter

# Importing flask
from flask import Flask, render_template, render_template_string, request, jsonify

# Database setup
from db import db_session, init_db
from models import Participant
from sqlalchemy import or_

from psiturk_config import PsiturkConfig
from experiment_errors import ExperimentError
from psiturk.user_utils import nocache

config = PsiturkConfig()
config.load_config()

# Set up logging
logfilepath = os.path.join(os.getcwd(),
                           config.get("Server Parameters", "logfile"))

loglevels = [logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL]
loglevel = loglevels[config.getint('Server Parameters', 'loglevel')]
logging.basicConfig( filename=logfilepath, format='%(asctime)s %(message)s', level=loglevel )


# Status codes
NOT_ACCEPTED = 0
ALLOCATED = 1
STARTED = 2
Exemplo n.º 9
0
# myapp.mycustomapplication
from gunicorn.app.base import Application
from gunicorn import util
import multiprocessing
from psiturk_config import PsiturkConfig
import os
import hashlib

config = PsiturkConfig()
config.load_config()

class ExperimentServer(Application):
    '''
    Custom Gunicorn Server Application that serves up the Experiment application
    '''

    def __init__(self):
        '''__init__ method
        Load the base config and assign some core attributes.
        '''
        self.load_user_config()
        self.usage = None
        self.callable = None
        self.options = self.user_options
        self.prog = None
        self.do_load_config()
        if 'OPENSHIFT_SECRET_TOKEN' in os.environ:
            my_ip = os.environ['OPENSHIFT_APP_DNS']
            print "Now serving on " + os.environ['OPENSHIFT_APP_DNS']
        else:
            print "Now serving on", "http://" + self.options["bind"]
Exemplo n.º 10
0
import datetime
import io, csv, json
from sqlalchemy import Column, Integer, String, DateTime, Float, Text

from db import Base
from psiturk_config import PsiturkConfig

config = PsiturkConfig()
config.load_config()

TABLENAME = config.get('Database Parameters', 'table_name')
CODE_VERSION = config.get('Task Parameters', 'experiment_code_version')

class Participant(Base):
    """
    Object representation of a participant in the database.
    """
    __tablename__ = TABLENAME

    uniqueid =Column(String(128), primary_key=True)
    assignmentid =Column(String(128), nullable=False)
    workerid = Column(String(128), nullable=False)
    hitid = Column(String(128), nullable=False)
    ipaddress = Column(String(128))
    browser = Column(String(128))
    platform = Column(String(128))
    language = Column(String(128))
    cond = Column(Integer)
    counterbalance = Column(Integer)
    codeversion = Column(String(128))
Exemplo n.º 11
0
# Setup flask
from flask import Flask, render_template, render_template_string, request, \
    jsonify

# Setup database
from db import db_session, init_db
from models import Participant
from sqlalchemy import or_, exc

from psiturk_config import PsiturkConfig
from experiment_errors import ExperimentError
from psiturk.user_utils import nocache

# Setup config
CONFIG = PsiturkConfig()
CONFIG.load_config()

# Setup logging
LOG_FILE_PATH = os.path.join(os.getcwd(), CONFIG.get("Server Parameters", \
    "logfile"))

LOG_LEVELS = [
    logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR,
    logging.CRITICAL
]
LOG_LEVEL = LOG_LEVELS[CONFIG.getint('Server Parameters', 'loglevel')]
logging.basicConfig(filename=LOG_FILE_PATH,
                    format='%(asctime)s %(message)s',
                    level=LOG_LEVEL)
Exemplo n.º 12
0
except ImportError:
    from counter import Counter

# Importing flask
from flask import Flask, render_template, request, Response, jsonify
from flask.ext.socketio import SocketIO, emit

# Database setup
from db import db_session, init_db
from models import Participant
from sqlalchemy import or_

from psiturk_config import PsiturkConfig
from experiment_errors import ExperimentError

config = PsiturkConfig()
config.load_config()

# Set up logging
logfilepath = os.path.join(os.getcwd(),
                           config.get("Server Parameters", "logfile"))

loglevels = [logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL]
loglevel = loglevels[config.getint('Server Parameters', 'loglevel')]
logging.basicConfig( filename=logfilepath, format='%(asctime)s %(message)s', level=loglevel )


# Status codes
NOT_ACCEPTED = 0
ALLOCATED = 1
STARTED = 2
Exemplo n.º 13
0
# myapp.mycustomapplication
from gunicorn.app.base import Application
from gunicorn import util
import multiprocessing
from psiturk_config import PsiturkConfig

config = PsiturkConfig()


class ExperimentServer(Application):
    '''
    Custom Gunicorn Server Application that serves up the Experiment application
    '''
    def __init__(self):
        '''__init__ method
        Load the base config and assign some core attributes.
        '''
        self.load_user_config()
        self.usage = None
        self.callable = None
        self.options = self.user_options
        self.prog = None
        self.do_load_config()
        print "Now serving on", "http://" + self.options["bind"]

    def init(self, *args):
        '''init method
        Takes our custom options from self.options and creates a config
        dict which specifies custom settings.
        '''
        cfg = {}
Exemplo n.º 14
0
# Import flask
import os, sys, subprocess
import argparse
from flask import Flask, Response, render_template, request, jsonify
import urllib2
from psiturk_config import PsiturkConfig
from models import Participant
import experiment_server_controller as control
from amt_services import MTurkServices
from db import db_session
from functools import wraps

config = PsiturkConfig()

server_controller = control.ExperimentServerController(
    config.getint("Server Parameters", "port"),
    hostname=config.get("Server Parameters", "host"))

app = Flask("Psiturk_Dashboard",
            template_folder=os.path.join(os.path.dirname(__file__),
                                         "templates_dashboard"),
            static_folder=os.path.join(os.path.dirname(__file__),
                                       "static_dashboard"))

#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Authentication functions
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


def check_auth(username, password):
    """This function is called to check if a username /
Exemplo n.º 15
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.ext.declarative import declarative_base
from psiturk_config import PsiturkConfig

config = PsiturkConfig()
config.load_config()

DATABASE = config.get('Database Parameters', 'database_url')

if 'mysql' in config.get('Database Parameters', 'database_url').lower():
    try:
        __import__('imp').find_module('MySQLdb')
    except ImportError:
        print("Sorry, to use a MySQL database you need to install "
              "the `mysql-python` python package.  Try `pip install "
              "mysql-python`. Hopefully it goes smoothly for you. "
              "Installation can be tricky on some systems.")
        exit()

engine = create_engine(DATABASE, echo=False)
db_session = scoped_session(
    sessionmaker(autocommit=False, autoflush=False, bind=engine))

Base = declarative_base()
Base.query = db_session.query_property()


def init_db():
    #print "Initalizing db if necessary."
    Base.metadata.create_all(bind=engine)
Exemplo n.º 16
0
try:
    from collections import Counter
except ImportError:
    from counter import Counter

# Importing flask
from flask import Flask, render_template, request, Response, jsonify

# Database setup
from db import db_session, init_db
from models import Participant
from sqlalchemy import or_

from psiturk_config import PsiturkConfig

config = PsiturkConfig()

# Set up logging
logfilepath = os.path.join(os.getcwd(),
                           config.get("Server Parameters", "logfile"))

loglevels = [
    logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR,
    logging.CRITICAL
]
loglevel = loglevels[config.getint('Server Parameters', 'loglevel')]
logging.basicConfig(filename=logfilepath,
                    format='%(asctime)s %(message)s',
                    level=loglevel)

# config.get( 'Mechanical Turk Info', 'aws_secret_access_key' )
Exemplo n.º 17
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.ext.declarative import declarative_base

from psiturk_config import PsiturkConfig

config = PsiturkConfig()

DATABASE = config.get('Database Parameters', 'database_url')

engine = create_engine(DATABASE, echo=False) 
db_session = scoped_session(sessionmaker(autocommit=False,
                                         autoflush=False,
                                         bind=engine))

Base = declarative_base()
Base.query = db_session.query_property()

def init_db():
    print "Initalizing db if necessary."
    Base.metadata.create_all(bind=engine)
Exemplo n.º 18
0
# Setup flask
from flask import Flask, render_template, render_template_string, request, \
    jsonify

# Setup database
from db import db_session, init_db
from models import Participant
from sqlalchemy import or_, exc

from psiturk_config import PsiturkConfig
from experiment_errors import ExperimentError
from psiturk.user_utils import nocache

# Setup config
CONFIG = PsiturkConfig()
CONFIG.load_config()

# Setup logging
LOG_FILE_PATH = os.path.join(os.getcwd(), CONFIG.get("Server Parameters", \
    "logfile"))

LOG_LEVELS = [logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR,
              logging.CRITICAL]
LOG_LEVEL = LOG_LEVELS[CONFIG.getint('Server Parameters', 'loglevel')]
logging.basicConfig(filename=LOG_FILE_PATH, format='%(asctime)s %(message)s',
                    level=LOG_LEVEL)

# Status codes
NOT_ACCEPTED = 0
ALLOCATED = 1
Exemplo n.º 19
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.ext.declarative import declarative_base

from psiturk_config import PsiturkConfig

config = PsiturkConfig()
config.load_config()

DATABASE = config.get('Database Parameters', 'database_url')

engine = create_engine(DATABASE, echo=False) 
db_session = scoped_session(sessionmaker(autocommit=False,
                                         autoflush=False,
                                         bind=engine))

Base = declarative_base()
Base.query = db_session.query_property()

def init_db():
    #print "Initalizing db if necessary."
    Base.metadata.create_all(bind=engine)
Exemplo n.º 20
0
import datetime
import io, csv, json
from sqlalchemy import Column, Integer, String, DateTime, Boolean, Text

from db import Base
from psiturk_config import PsiturkConfig

config = PsiturkConfig()

TABLENAME = config.get('Database Parameters', 'table_name')
CODE_VERSION = config.get('Task Parameters', 'code_version')


class Participant(Base):
    """
    Object representation of a participant in the database.
    """
    __tablename__ = TABLENAME

    uniqueid = Column(String(128), primary_key=True)
    assignmentid = Column(String(128), nullable=False)
    workerid = Column(String(128), nullable=False)
    hitid = Column(String(128), nullable=False)
    ipaddress = Column(String(128))
    browser = Column(String(128))
    platform = Column(String(128))
    language = Column(String(128))
    cond = Column(Integer)
    counterbalance = Column(Integer)
    codeversion = Column(String(128))
    beginhit = Column(DateTime)
Exemplo n.º 21
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.ext.declarative import declarative_base
from psiturk_config import PsiturkConfig

config = PsiturkConfig()
config.load_config()

DATABASE = config.get('Database Parameters', 'database_url')

if 'mysql' in config.get('Database Parameters', 'database_url').lower():
	try:
		 __import__('imp').find_module('MySQLdb')
	except ImportError:
		print("Sorry, to use a MySQL database you need to install "
			  "the `mysql-python` python package.  Try `pip install "
			  "mysql-python`. Hopefully it goes smoothly for you. "
			  "Installation can be tricky on some systems.")
		exit()

engine = create_engine(DATABASE, echo=False, pool_recycle=3600) 
db_session = scoped_session(sessionmaker(autocommit=False,
                                         autoflush=False,
                                         bind=engine))

Base = declarative_base()
Base.query = db_session.query_property()

def init_db():
    #print "Initalizing db if necessary."
Exemplo n.º 22
0
Arquivo: db.py Projeto: yuelxx/psiTurk
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.ext.declarative import declarative_base
from psiturk_config import PsiturkConfig
import re, os

config = PsiturkConfig()
config.load_config()

r = re.compile("OPENSHIFT_(.+)_DB_URL")  # Might be MYSQL or POSTGRESQL
matches = filter(r.match, os.environ)
if matches:
    DATABASE = "{}{}".format(os.environ[matches[0]],
                             os.environ['OPENSHIFT_APP_NAME'])
else:
    DATABASE = config.get('Database Parameters', 'database_url')

if 'mysql://' in DATABASE.lower():
    try:
        __import__('imp').find_module('pymysql')
    except ImportError:
        print("To use a MySQL database you need to install "
              "the `pymysql` python package.  Try `pip install "
              "pymysql`.")
        exit()
    # internally use `mysql+pymysql://` so sqlalchemy talks to
    # the pymysql package
    DATABASE = DATABASE.replace('mysql://', 'mysql+pymysql://')

engine = create_engine(DATABASE, echo=False, pool_recycle=3600)
db_session = scoped_session(
Exemplo n.º 23
0
# Import flask
import os, sys, subprocess
import argparse
from flask import Flask, Response, render_template, request, jsonify
import urllib2
from psiturk_config import PsiturkConfig
from models import Participant
import experiment_server_controller as control
from amt_services import MTurkServices
from db import db_session
from functools import wraps

config = PsiturkConfig()

server_controller = control.ExperimentServerController(config.getint("Server Parameters", "port"), hostname=config.get("Server Parameters", "host"))

app = Flask("Psiturk_Dashboard",
            template_folder=os.path.join(os.path.dirname(__file__), "templates_dashboard"), 
            static_folder=os.path.join(os.path.dirname(__file__), "static_dashboard"))


#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Authentication functions
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

def check_auth(username, password):
    """This function is called to check if a username /
    password combination is valid.
    """
    true_user = config.get('Dashboard Parameters', 'login_username')
    true_pass = config.get('Dashboard Parameters', 'login_pw')
Exemplo n.º 24
0
import datetime
import io, csv, json
from sqlalchemy import Column, Integer, String, DateTime, Boolean, Text

from db import Base
from psiturk_config import PsiturkConfig

config = PsiturkConfig()

TABLENAME = config.get('Database Parameters', 'table_name')
CODE_VERSION = config.get('Task Parameters', 'code_version')

class Participant(Base):
    """
    Object representation of a participant in the database.
    """
    __tablename__ = TABLENAME
   
    uniqueid =Column(String(128), primary_key=True)
    assignmentid =Column(String(128), nullable=False)
    workerid = Column(String(128), nullable=False)
    hitid = Column(String(128), nullable=False)
    ipaddress = Column(String(128))
    browser = Column(String(128))
    platform = Column(String(128))
    language = Column(String(128))
    cond = Column(Integer)
    counterbalance = Column(Integer)
    codeversion = Column(String(128))
    beginhit = Column(DateTime)
Exemplo n.º 25
0
Arquivo: db.py Projeto: virvw/psiTurk
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.ext.declarative import declarative_base
from psiturk_config import PsiturkConfig

config = PsiturkConfig()
config.load_config()

DATABASE = config.get("Database Parameters", "database_url")

if "mysql" in config.get("Database Parameters", "database_url").lower():
    try:
        __import__("imp").find_module("MySQLdb")
    except ImportError:
        print(
            "Sorry, to use a MySQL database you need to install "
            "the `mysql-python` python package.  Try `pip install "
            "mysql-python`. Hopefully it goes smoothly for you. "
            "Installation can be tricky on some systems."
        )
        exit()

engine = create_engine(DATABASE, echo=False)
db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=engine))

Base = declarative_base()
Base.query = db_session.query_property()


def init_db():
    # print "Initalizing db if necessary."