<commit_before>import os
from ConfigParser import SafeConfigParser

class PsiturkConfig(SafeConfigParser):
    def __init__(self, filename="config.txt", **kwargs):
        self.parent = SafeConfigParser
        self.parent.__init__(self, **kwargs)
        self.filename = filename

    def load_config(self):
        if not os.path.exists(self.filename):
            print "ERROR - no config.txt file in the current directory. \n\nAre you use this directory is a valid psiTurk experiment?  If you are starting a new project run 'psiturk-setup-example' in an empty directory."
            exit()
        self.read(self.filename)

    def write(self):
        with open(self.filename, 'w') as fp:
            self.parent.write(self, fp)

    def set(self, section, field, value,  *args, **kwargs):
        """
        Set the given field in the given section to the given value. 
        Return True if the server needs to be rebooted.
        """
        self.parent.set(self, section, field, str(value), *args, **kwargs)
        self.write()
        if section in ["Server Parameters","Task Parameters"]:
            return True
        else:
            return False

    #def read(self):
    #    super(ConfigParser, self).read(self.filename)

    def get_serialized(self):
        # Serializing data is necessary to communicate w/ backbone frontend.
        return self._sections

    def set_serialized(self, config_model):
        restart_server = False
        for section, fields in config_model.iteritems():
            for field in fields:
                if self.set(section, field, config_model[section][field]):
                    restart_server = True
        return restart_server


    def write_default_config(self):
        sections = ['AWS Access', 'Secure Ad Server', 'HIT Configuration', 'Database Parameters',
                    'Server Parameters', 'Task Parameters']
        map(self.add_section, sections)

        # AWS Access Section
        self.set('AWS Access', 'aws_access_key_id', 'YourAccessKeyId')
        self.set('AWS Access', 'aws_secret_access_key', 'YourSecretAccessKey')
        self.set('AWS Access', 'aws_region', 'us-east-1')

        # Secure Ad Server
        self.set('Secure Ad Server', 'contact_email', '<EMAIL>')

        # HIT Configuration
        self.set('HIT Configuration', 'title', 'Stroop task')
        self.set('HIT Configuration', 'description', 'Judge the color of a series of words.')
        self.set('HIT Configuration', 'keywords', 'Perception, Psychology')
        self.set('HIT Configuration', 'max_assignments', '10')
        self.set('HIT Configuration', 'lifetime', '24')
        self.set('HIT Configuration', 'reward', '1')
        self.set('HIT Configuration', 'duration', '2')
        self.set('HIT Configuration', 'US_only', 'true')
        self.set('HIT Configuration', 'Approve_Requirement', '95')
        self.set('HIT Configuration', 'using_sandbox', 'true')

        # Database Parameters
        self.set('Database Parameters', 'database_url', 'sqlite:///participants.db')
        self.set('Database Parameters', 'table_name', 'turkdemo')

        #Server Parameters
        self.set('Server Parameters', 'host', 'localhost')
        self.set('Server Parameters', 'port', '22362')
        self.set('Server Parameters', 'cutoff_time', '30')
        self.set('Server Parameters', 'logfile', 'server.log')
        self.set('Server Parameters', 'loglevel', '2')
        self.set('Server Parameters', 'debug', 'true')
        self.set('Server Parameters', 'login_username', 'examplename')
        self.set('Server Parameters', 'login_pw', '<PASSWORD>')
        self.set('Server Parameters', 'threads', 'auto')
        
        # Task Parameters
        self.set('Task Parameters', 'experiment_code_version', '1.0')
        self.set('Task Parameters', 'num_conds', '1')
        self.set('Task Parameters', 'num_counters', '1')<commit_msg>moving a few things around, and making new psiTurk access section<commit_after>import os
from ConfigParser import SafeConfigParser

class PsiturkConfig(SafeConfigParser):
    def __init__(self, filename="config.txt", **kwargs):
        self.parent = SafeConfigParser
        self.parent.__init__(self, **kwargs)
        self.filename = filename

    def load_config(self):
        if not os.path.exists(self.filename):
            print "ERROR - no config.txt file in the current directory. \n\nAre you use this directory is a valid psiTurk experiment?  If you are starting a new project run 'psiturk-setup-example' in an empty directory."
            exit()
        self.read(self.filename)

    def write(self):
        with open(self.filename, 'w') as fp:
            self.parent.write(self, fp)

    def set(self, section, field, value,  *args, **kwargs):
        """
        Set the given field in the given section to the given value. 
        Return True if the server needs to be rebooted.
        """
        self.parent.set(self, section, field, str(value), *args, **kwargs)
        self.write()
        if section in ["Server Parameters","Task Parameters"]:
            return True
        else:
            return False

    #def read(self):
    #    super(ConfigParser, self).read(self.filename)

    def get_serialized(self):
        # Serializing data is necessary to communicate w/ backbone frontend.
        return self._sections

    def set_serialized(self, config_model):
        restart_server = False
        for section, fields in config_model.iteritems():
            for field in fields:
                if self.set(section, field, config_model[section][field]):
                    restart_server = True
        return restart_server


    def write_default_config(self):
        sections = ['AWS Access', 'psiTurk Access', 'HIT Configuration', 'Database Parameters',
                    'Server Parameters', 'Task Parameters']
        map(self.add_section, sections)

        # AWS Access Section
        self.set('AWS Access', 'aws_access_key_id', 'YourAccessKeyId')
        self.set('AWS Access', 'aws_secret_access_key', 'YourSecretAccessKey')
        self.set('AWS Access', 'aws_region', 'us-east-1')

        # psiTurk Access
        self.set('psiTurk Access', 'psiturk_access_key_id', 'YourAccessKeyId')
        self.set('psiTurk Access', 'psiturk_secret_access_id', 'YourSecretAccessKey')

        # HIT Configuration
        self.set('HIT Configuration', 'title', 'Stroop task')
        self.set('HIT Configuration', 'description', 'Judge the color of a series of words.')
        self.set('HIT Configuration', 'keywords', 'Perception, Psychology')
        self.set('HIT Configuration', 'max_assignments', '10')
        self.set('HIT Configuration', 'lifetime', '24')
        self.set('HIT Configuration', 'reward', '1')
        self.set('HIT Configuration', 'duration', '2')
        self.set('HIT Configuration', 'US_only', 'true')
        self.set('HIT Configuration', 'Approve_Requirement', '95')
        self.set('HIT Configuration', 'using_sandbox', 'true')
        self.set('HIT Configuration', 'contact_email', '<EMAIL>')

        # Database Parameters
        self.set('Database Parameters', 'database_url', 'sqlite:///participants.db')
        self.set('Database Parameters', 'table_name', 'turkdemo')

        #Server Parameters
        self.set('Server Parameters', 'host', 'localhost')
        self.set('Server Parameters', 'port', '22362')
        self.set('Server Parameters', 'cutoff_time', '30')
        self.set('Server Parameters', 'logfile', 'server.log')
        self.set('Server Parameters', 'loglevel', '2')
        self.set('Server Parameters', 'debug', 'true')
        self.set('Server Parameters', 'login_username', 'examplename')
        self.set('Server Parameters', 'login_pw', 'examplepassword')
        self.set('Server Parameters', 'threads', 'auto')
        
        # Task Parameters
        self.set('Task Parameters', 'experiment_code_version', '1.0')
        self.set('Task Parameters', 'num_conds', '1')
        self.set('Task Parameters', 'num_counters', '1')
{'fraction_non_alphanumeric': 0.13014294592914855, 'fraction_numerical': 0.005220633934120571, 'mean_word_length': 2.8682692307692306, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3796502', 'n_tokens_mistral': 2287, 'n_tokens_neox': 2211, 'n_words': 624}