Schemas#

class twon_lss.schemas.feed.Feed[source]#

Represents a collection of posts that can be displayed to users.

The Feed class manages collections of posts and provides methods to filter and access posts based on various criteria. It supports iteration and length operations for easy manipulation.

The class supports iteration and length operations:
  • Iterate through posts: for post in feed:

  • Get feed length: len(feed)

items#

A list of Post objects contained in the feed. (default: []).

Type:

List[Post]

Example

>>> from src.twon_lss.schemas import Feed
... feed = Feed(
...     items=[post1, post2, post3]  # list of Post objects
... )
... user_feed = feed.get_items_by_user(user)
... for post in feed:
...     print(post)
__init__(**data)#

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

Return type:

None

__new__(**kwargs)#
class twon_lss.schemas.interaction.Interaction[source]#

Represents user interactions with posts.

The Interaction class models various types of user engagement with posts, including reads, likes, and shares, with automatic timestamping.

user#

A User object representing who performed the interaction.

Type:

User

type#

An InteractionTypes enum value specifying the interaction type (read, like, or share).

Type:

InteractionTypes

timestamp#

The timestamp when the interaction occurred, automatically set to current time if not provided.

Type:

datetime.datetime

Example

>>> from src.twon_lss.schemas import Interaction, InteractionTypes
... interaction = Interaction(
...    user=user,
...    type=InteractionTypes.like
... )
__init__(**data)#

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

Return type:

None

__new__(**kwargs)#
class twon_lss.schemas.network.Network[source]#

Represents the social network structure using NetworkX.

The Network class models the connections and relationships between users in the social media simulation using a NetworkX graph structure. The class supports iteration over the network users.

graph#

A NetworkX Graph object representing the network connections between users (default: empty graph).

Type:

networkx.Graph

Example

>>> from src.twon_lss.schemas import Network
... import networkx as nx
... graph = nx.Graph()
... network = Network.from_graph(graph)
... neighbors = network.get_neighbors(user)
... for user in network:
...    print(user)
__init__(**data)#

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

Return type:

None

__new__(**kwargs)#
class twon_lss.schemas.post.Post[source]#

Models a social media post/comment for the simulation.

The Post class represents individual posts or comments within the social media simulation, supporting nested comment structures and user interactions.

id#

A unique identifier of the post as either a string or integer.

Type:

str | int

user#

A User object representing the author of the post.

Type:

User

content#

The text content of the post as a string.

Type:

str

interactions#

A list of Interaction objects representing user interactions (default: []).

Type:

List[Interaction]

comments#

A list of Post objects representing comments, allowing for nested comment structures (default: []).

Type:

List[Post]

timestamp#

The timestamp of post creation (default: current datetime.now).

Type:

datetime.datetime

Example

… from src.twon_lss.schemas import Post … post = Post( … id=”P001”, … user=user, … content=”This is a sample post content”, … interactions=[], # list of Interaction objects … comments=[], # list of Post objects … )

__init__(**data)#

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

Return type:

None

__new__(**kwargs)#
class twon_lss.schemas.user.User[source]#

Represents a user in the simulation.

The User class models individual users within the social media simulation, each with a unique identifier and an agent that controls their behavior.

id#

A unique identifier of the user as either a string or integer.

Type:

int | str

agent#

An AgentInterface object that controls the user’s behavior in the simulation.

Type:

AgentInterface

Example

>>> from src.twon_lss.schemas import User
... user = User(
...     id="U001",
...     agent=None
... )
__init__(**data)#

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

Return type:

None

__new__(**kwargs)#