<commit_before>from sqlalchemy import ForeignKey, Column, String, desc
from .models import Node, Info
from information import State


class Environment(Node):

    """Defines an environment node.

    Environments are nodes that have a state and that receive a transmission
    from anyone that observes them.
    """

    __tablename__ = "environment"
    __mapper_args__ = {"polymorphic_identity": "environment"}

    # the unique environment id
    uuid = Column(String(32), ForeignKey("node.uuid"), primary_key=True)

    @property
    def state(self):
        """The state is the most recently created info of type State."""
        return State\
            .query\
            .filter_by(origin_uuid=self.uuid)\
            .order_by(desc(Info.creation_time))\
            .first()

    def get_observed(self, by_whom=None):
        """When observed, transmit the state."""
        self.transmit(to_whom=by_whom)

    def _what(self):
        return self.state

    def __repr__(self):
        """Print the environment in a nice format."""
        return "Environment-{}-{}".format(self.uuid[:6], self.type)
<commit_msg>get_observed returns the state<commit_after>from sqlalchemy import ForeignKey, Column, String, desc
from .models import Node, Info
from information import State


class Environment(Node):

    """Defines an environment node.

    Environments are nodes that have a state and that receive a transmission
    from anyone that observes them.
    """

    __tablename__ = "environment"
    __mapper_args__ = {"polymorphic_identity": "environment"}

    # the unique environment id
    uuid = Column(String(32), ForeignKey("node.uuid"), primary_key=True)

    @property
    def state(self):
        """The state is the most recently created info of type State."""
        return State\
            .query\
            .filter_by(origin_uuid=self.uuid)\
            .order_by(desc(Info.creation_time))\
            .first()

    def get_observed(self, by_whom=None):
        """When observed, transmit the state."""
        self.transmit(to_whom=by_whom)
        return self._what()

    def _what(self):
        return self.state

    def __repr__(self):
        """Print the environment in a nice format."""
        return "Environment-{}-{}".format(self.uuid[:6], self.type)

{'fraction_non_alphanumeric': 0.10743801652892562, 'fraction_numerical': 0.0026098303610265334, 'mean_word_length': 2.8397328881469117, 'pattern_counts': {'":': 2, '<': 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': '1272913', 'n_tokens_mistral': 662, 'n_tokens_neox': 624, 'n_words': 199}