<commit_before># "agents" are just functions

import random
from questionnaire import qtypes, q3, survey

def global_safe_insert(lst):
    def helper(crap, index, item):
        if len(lst) <= index :
            lst.extend([None for x in range(index-len(lst)+1)])
            lst[index]=item
    return helper

class RandAgent:
    opts = []
    __safe_insert = global_safe_insert(opts)
    def take_survey(self, survey):
        #returns tuple of responses to question object
        return [(self.respond(q), q.quid) for q in survey.questions]
    def respond(self, q):
        return self.opts[q.qtype](q)
    def __init__(self):
        self.__safe_insert(qtypes["freetext"]
                           , lambda _ :  "junk")
        self.__safe_insert(qtypes["radio"]
                           , lambda q : [random.choice(q.options)])
        self.__safe_insert(qtypes["check"]
                           , lambda q : [opt for (choose, opt) in \
                                         zip(bin(random.choice(range(1,pow(2, len(q.options)))))[2:].zfill(len(q.options))
                                             ,q.options) if \
                                         choose=='1'])
        self.__safe_insert(qtypes["dropdown"]
                           , lambda q : [random.choice(q.options)])
      
class CollegeStudent:
    opts = []
    __safe_insert = global_safe_insert(opts)
#    def respond_

a1 = RandAgent()

if __name__ == "__main__" :
    print a1.take_survey(survey)<commit_msg>three agents; college students are uniform. todo is to give their responses a distribution<commit_after># "agents" are just functions

import random
from questionnaire import qtypes, q1, q2, q3, q4, survey

def global_safe_insert(lst):
    def helper(crap, index, item):
        if len(lst) <= index :
            lst.extend([None for x in range(index-len(lst)+1)])
            lst[index]=item
    return helper

class Agent:
    def take_survey(self, survey):
        #returns tuple of responses to question object
        return [(q.quid, self.respond(q)) for q in survey.questions]
    def respond(self, q):
        return [q.options[0]]

class LazyAgent(Agent):
    pass

class RandAgent(Agent):
    opts = []
    __safe_insert = global_safe_insert(opts)
    def respond(self, q):
        return self.opts[q.qtype](q)
    def __init__(self):
        self.__safe_insert(qtypes["freetext"]
                           , lambda _ :  "junk")
        self.__safe_insert(qtypes["radio"]
                           , lambda q : [random.choice(q.options)])
        self.__safe_insert(qtypes["check"]
                           , lambda q : [opt for (choose, opt) in \
                                         zip(bin(random.choice(range(1,pow(2, len(q.options)))))[2:].zfill(len(q.options))
                                             ,q.options) if \
                                         choose=='1'])
        self.__safe_insert(qtypes["dropdown"]
                           , lambda q : [random.choice(q.options)])

      
class CollegeStudent(Agent):
    opts = {q1 : lambda q : [q.options[1]]
            , q2 : lambda q : [opt for opt in q.options if opt.otext=="Democrat"]
            , q3 : lambda q : q.options
            , q4 : lambda q : [q.options[len(q.options)-5]]
        }
    __safe_insert = global_safe_insert(opts)
    def respond(self, q):
        return self.opts[q](q)
        

rando = RandAgent()
lazy = LazyAgent()
college = CollegeStudent()

if __name__ == "__main__" :
    print rando.take_survey(survey)
    print lazy.take_survey(survey)
    print college.take_survey(survey)
{'fraction_non_alphanumeric': 0.1192457016084304, 'fraction_numerical': 0.0066555740432612314, 'mean_word_length': 1.968724279835391, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4471926', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1057, 'n_words': 252}