<commit_before>from complexism.mcore import Observer, LeafModel
from complexism.element import Request
from complexism.agentbased import Population
from collections import namedtuple, OrderedDict

__author__ = 'TimeWz667'
__all__ = ['AgentBasedModel']

Record = namedtuple('Record', ('Ag', 'Tr', 'Time'))


class ObsABM(Observer):
    def __init__(self):
        Observer.__init__(self)
        self.ObsSt = list()
        self.ObsTr = list()
        self.Bes = list()
        self.Recs = list()

    def add_obs_state(self, st):
        self.ObsSt.append(st)

    def add_obs_transition(self, tr):
        self.ObsTr.append(tr)

    def add_obs_behaviour(self, beh):
        self.Bes.append(beh)

    def update_dynamic_Observations(self, model, flow, ti):
        for tr in self.ObsTr:
            flow[tr.Name] = sum([rec.Tr is tr for rec in self.Recs])
        self.Recs.clear()

    def read_statics(self, model, tab, ti):
        for st in self.ObsSt:
            tab[st.Name] = model.Pop.count(st)

        for be in self.Bes:
            model.Behaviours[be].fill(tab, model, ti)

    def record(self, ag, tr, ti):
        self.Recs.append(Record(ag.Name, tr, ti))


class AgentBasedModel(LeafModel):
    def __init__(self, name, dc, pc, meta=None, ag_prefix='Ag'):
        LeafModel.__init__(self, name, ObsABM(), meta)
        self.DCore = dc
        self.PCore = pc
        self.Pop = Population(dc, ag_prefix)
        self.Behaviours = OrderedDict()

    def add_obs_state(self, st):<commit_msg>Renew ABM<commit_after>from complexism.mcore import Observer, LeafModel
from complexism.element import Request
from complexism.agentbased import Population
from collections import namedtuple, OrderedDict

__author__ = 'TimeWz667'
__all__ = ['AgentBasedModel']

Record = namedtuple('Record', ('Ag', 'Todo', 'Time'))


class ObsABM(Observer):
    def __init__(self):
        Observer.__init__(self)
        self.Events = list()
        self.Behaviours = list()
        self.Functions = list()
        self.Records = list()

    def add_observing_event(self, todo):
        self.Events.append(todo)

    def add_observing_behaviour(self, beh):
        self.Behaviours.append(beh)

    def add_observing_function(self, func):
        self.Functions.append(func)

    def update_dynamic_Observations(self, model, flow, ti):
        for todo in self.Events:
            flow[todo] = sum([rec.Todo == todo for rec in self.Records])
        self.Records.clear()

    def read_statics(self, model, tab, ti):
        for be in self.Behaviours:
            model.Behaviours[be].fill(tab, model, ti)

        for func in self.Functions:
            func(model, tab, ti)

    def record(self, ag, evt, ti):
        self.Records.append(Record(ag.Name, evt.Todo, ti))


class AgentBasedModel(LeafModel):
    def __init__(self, name, dc, pc, meta=None, ag_prefix='Ag'):
        LeafModel.__init__(self, name, ObsABM(), meta)
        self.DCore = dc
        self.PCore = pc
        self.Pop = Population(dc, ag_prefix)
        self.Behaviours = OrderedDict()

    def add_obs_state(self, st):
{'fraction_non_alphanumeric': 0.11875405580791694, 'fraction_numerical': 0.001946787800129786, 'mean_word_length': 2.8779874213836476, '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': '6117127', 'n_tokens_mistral': 1038, 'n_tokens_neox': 990, 'n_words': 242}