<commit_before>import wallace
from custom_sources import WarOfTheGhostsSource


class Bartlett1932(wallace.experiments.Experiment):
    def __init__(self, session):
        super(Bartlett1932, self).__init__(session)

        self.task = "Transmission chain"
        self.num_agents = 10
        self.num_steps = self.num_agents - 1
        self.network = wallace.networks.Chain(self.session)
        self.process = wallace.processes.RandomWalkFromSource(self.network)
        self.recruiter = wallace.recruiters.PsiTurkRecruiter

        # Setup for first time experiment is accessed
        if not self.network.sources:
            source = WarOfTheGhostsSource()
            self.network.add_node(source)
            print "Added initial source: " + str(source)

    def newcomer_arrival_trigger(self, newcomer):

        # Set the newcomer to invisible.
        newcomer.is_visible = False

        self.network.add_agent(newcomer)

        # If this is the first participant, link them to the source.
        if len(self.network) == 0:
            source = self.network.sources[0]
            source.connect_to(newcomer)
            self.network.db.commit()

        # Run the next step of the process.
        self.process.step()

    def transmission_reception_trigger(self, transmissions):
        # Mark transmissions as received
        for t in transmissions:
            t.mark_received()

    def information_creation_trigger(self, info):

        agent = info.origin
        agent.is_visible = True
        self.network.db.add(agent)
        self.network.db.commit()

        if self.is_experiment_over():
            # If the experiment is over, stop recruiting and export the data.
            self.recruiter().close_recruitment()
        else:
            # Otherwise recruit a new participant.
            self.recruiter().recruit_new_participants(n=1)

    def is_experiment_over(self):
        return self.network.links == self.num_agents<commit_msg>Squash bug in experiment stopping rule<commit_after>import wallace
from custom_sources import WarOfTheGhostsSource


class Bartlett1932(wallace.experiments.Experiment):
    def __init__(self, session):
        super(Bartlett1932, self).__init__(session)

        self.task = "Transmission chain"
        self.num_agents = 10
        self.num_steps = self.num_agents - 1
        self.network = wallace.networks.Chain(self.session)
        self.process = wallace.processes.RandomWalkFromSource(self.network)
        self.recruiter = wallace.recruiters.PsiTurkRecruiter

        # Setup for first time experiment is accessed
        if not self.network.sources:
            source = WarOfTheGhostsSource()
            self.network.add_node(source)
            print "Added initial source: " + str(source)

    def newcomer_arrival_trigger(self, newcomer):

        # Set the newcomer to invisible.
        newcomer.is_visible = False

        self.network.add_agent(newcomer)

        # If this is the first participant, link them to the source.
        if len(self.network) == 0:
            source = self.network.sources[0]
            source.connect_to(newcomer)
            self.network.db.commit()

        # Run the next step of the process.
        self.process.step()

    def transmission_reception_trigger(self, transmissions):
        # Mark transmissions as received
        for t in transmissions:
            t.mark_received()

    def information_creation_trigger(self, info):

        agent = info.origin
        agent.is_visible = True
        self.network.db.add(agent)
        self.network.db.commit()

        if self.is_experiment_over():
            # If the experiment is over, stop recruiting and export the data.
            self.recruiter().close_recruitment()
        else:
            # Otherwise recruit a new participant.
            self.recruiter().recruit_new_participants(n=1)

    def is_experiment_over(self):
        return len(self.network.links) == self.num_agents
{'fraction_non_alphanumeric': 0.08161209068010075, 'fraction_numerical': 0.007052896725440806, 'mean_word_length': 2.4410745233968805, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1083247', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1079, 'n_words': 262}