components.attributemanager Module

This module contains the classes for attributes.

class components.attributemanager.AttributeManager(description, questionable_attributes, get_members_attribute=None, gendered_questions=False)

Bases: components.picklablebase.PicklableBase, Generic[components.attributemanager.AttributeType]

A class to keep track on a specific attribute of components.Member instances and what questions can be asked based on it.

Note

Instances of this class are comparable by means of equality by description. They are also comparable to strings by the same definition.

Note

If :meth:get_members_attribute returns a list, it will not be treated as a single value but instead as the member having multiple values for this attribute.

description

A description of the attribute the instance manages.

questionable_attributes

A list of components.AttributeManager instances that manages attributes, which are available as questions for the attribute this instance manages.

gendered_questions

Whether questions with tis attribute as hint should try to list only members with the same gender as the hint member.

Parameters
  • description (str) – A description of the attribute the instance manages.

  • questionable_attributes (List[Union[AttributeManager, str]]) – A list of components.AttributeManager instances that manages attributes, which are available as questions for the attribute this instance manages.

  • get_members_attribute (Optional[Callable[[ForwardRef], Union[~AttributeType, List[~AttributeType], None]]]) –

    A callable that extracts the attribute managed by this class from a components.Member instance. Defaults to

    lambda member: member[self.description]
    

  • gendered_questions (bool) – Optional. Whether questions with tis attribute as hint should try to list only members with the same gender as the hint member. Defaults to False.

property available_members: FrozenSet[Member]

All the members that have the attribute managed by this instance.

Return type

FrozenSet[ForwardRef]

build_question_with(attribute_manager: components.attributemanager.AttributeManager, multiple_choice: Literal[False], exclude_members: Iterable[Member] = None) Tuple[Member, AttributeType, Union[Any, List[Any]]]
build_question_with(attribute_manager: components.attributemanager.AttributeManager, multiple_choice: Literal[True], exclude_members: Iterable[Member] = None) Tuple[Member, AttributeType, Tuple[Any, Any, Any, Any], int]

Builds a question where this instance is serving as hint and attribute_manager servers as question. For multiple choice questions the output is a 4-tuple of

  1. The member serving as hint

  2. The attribute to be given as hint

  3. The attributes to be given as options for the answer

  4. The index of the correct answer.

For free text questions, the output is a 3-tuple of

  1. The member serving as hint

  2. The attribute to be given as hint

  3. The correct answer/a list of correct answers.

Parameters
  • attribute_manager (AttributeManager) – The manager describing the attribute serving as question.

  • multiple_choice (bool) – Whether this is a multiple choice question or not. Defaults to True

  • exclude_members (Iterable[Member]) – Optional. Members to exclude from serving as hint. Only relevant, if multiple_choice is True

Raises
  • ValueError – If attribute_manager is not a valid question for this instance in general

  • ValueError – If attribute_manager is currently not questionable for this instance

Return type

Union[Tuple[Member, AttributeType, Tuple[Any, Any, Any, Any], int], Tuple[Member, AttributeType, Any]]

distinct_values_for_member(attribute_manager, member)

Given an attribute manager and a member from it’s available members, this returns a set of the distinct attribute values appearing across the members m in available_members who satisfy:

  1. not self.members_share_attribute(member, m)

  2. not attribute_manager.members_share_attribute(member, m)

If self.get_members_attribute(member) is None, will just return an empty set.

Parameters
  • attribute_manager (AttributeManager) – The manager describing the attribute serving as hint.

  • member (Member) – The member.

Return type

Set[AttributeType]

draw_hint_member(attribute_manager, multiple_choice=True, exclude_members=None)

Draws a member to build a question for.

Parameters
  • attribute_manager (AttributeManager) – The manager describing the attribute serving as question.

  • multiple_choice (bool) – Whether this is a multiple choice question or not. Defaults to True

  • exclude_members (Iterable[Member]) – Optional. Members to exclude from serving as hint.

Raises
  • ValueError – If attribute_manager is not a valid question for this instance in general

  • ValueError – If attribute_manager is currently not questionable for this instance

Return type

Member

draw_question_attributes(attribute_manager, member)

Draws question attributes for the given member. The first output is a 4-tuple of the drawn options. The second output is the index of the correct answer, i.e. the attribute of member.

Parameters
  • attribute_manager (AttributeManager) – The manager describing the attribute serving as hint.

  • member (ForwardRef) – The member that defines the correct answer.

Return type

Tuple[Tuple[~AttributeType, ~AttributeType, ~AttributeType, ~AttributeType], int]

get_members_attribute(member)

Gives the attribute of member that is managed by this instance.

Parameters

member (ForwardRef) – The member.

Return type

Union[~AttributeType, List[~AttributeType], None]

is_hintable_with(attribute_manager, multiple_choice=True, exclude_members=None)

If the attribute managed by this instance can be used as hint where the question is the attribute managed by attribute_manager.

Parameters
  • attribute_manager (AttributeManager) – The manager describing the attribute serving as question.

  • multiple_choice (bool) – Whether this is a multiple choice question or not. Defaults to True

  • exclude_members (Iterable[Member]) – Optional. Members to exclude from serving as hint.

Return type

bool

is_hintable_with_member(attribute_manager, member, multiple_choice=True)

If the given members attribute managed by this instance can be used as hint where the question is the attribute managed by attribute_manager.

Parameters
  • attribute_manager (AttributeManager) – The manager describing the attribute serving as question.

  • member (Member) – The member.

  • multiple_choice (bool) – Whether this is a multiple choice question or not. Defaults to True

Return type

bool

kick_member(member)

Kicks a member, if present.

Parameters

member (ForwardRef) – The member to kick.

Return type

None

members_share_attribute(member1, member2)

Checks if member1 and member2 share the attribute described by this instance. This usually means a check by equality except in the case, where the attribute is given by a list. In this case, True is returned, if the lists have at least one common element.

Parameters
  • member1 (Member) – Member 1.

  • member2 (Member) – Member 2.

Return type

bool

register_member(member)

Registers a new member.

Note

Copies the member so changes to the instance wont directly affect the orchestra. Use update_member() to update the information about this member.

Parameters

member (ForwardRef) – The new member

Return type

None

unique_attributes_of(member)

Given a member this returns a list of attribute values managed by this instance that only appear for that member, making it the unique correct answer for it.

Note

This method is called only for requests for free text questions. Therefore subclasses may decide to return something different from get_members_attribute().

Parameters

member (Member) – The member.

Return type

List[AttributeType]

update_member(member)

Updates the information of a member.

Note

As register_user(), this will copy the member. To update the information again, call this method again.

Parameters

member (ForwardRef) – The member with new information.

Return type

None

class components.attributemanager.ChangingAttributeManager(description, questionable_attributes, get_members_attribute=None, gendered_questions=False)

Bases: components.attributemanager.AttributeManager

Subclass of AttributeManager that updates it’s members attributes once a day. This is needed, for attributes like age, which can change on a daily basis.

description

A description of the attribute the instance manages.

questionable_attributes

A list of components.AttributeManager instances that manages attributes, which are available as questions for the attribute this instance manages.

gendered_questions

Whether questions with tis attribute as hint should try to list only members with the same gender as the hint member.

Parameters
  • description (str) – A description of the attribute the instance manages.

  • questionable_attributes (List[Union[AttributeManager, str]]) – A list of components.AttributeManager instances that manages attributes, which are available as questions for the attribute this instance manages.

  • get_members_attribute (Optional[Callable[[ForwardRef], Union[~AttributeType, List[~AttributeType], None]]]) –

    A callable that extracts the attribute managed by this class from a components.Member instance. Defaults to

    lambda member: member[self.description]
    

  • gendered_questions (bool) – Optional. Whether questions with tis attribute as hint should try to list only members with the same gender as the hint member. Defaults to False.

class components.attributemanager.NameManager(description, questionable_attributes, get_members_attribute=None)

Bases: components.attributemanager.AttributeManager

Subclass of AttributeManager for first and full names. This is needed, as the gender of a member needs to be taken into account.

description

A description of the attribute the instance manages.

questionable_attributes

A list of components.AttributeManager instances that manages attributes, which are available as questions for the attribute this instance manages.

Parameters
  • description (str) – A description of the attribute the instance manages.

  • questionable_attributes (List[Union[AttributeManager, str]]) – A list of components.AttributeManager instances that manages attributes, which are available as questions for the attribute this instance manages.

  • get_members_attribute (Optional[Callable[[ForwardRef], Union[~AttributeType, List[~AttributeType], None]]]) –

    A callable that extracts the attribute managed by this class from a components.Member instance. Defaults to

    lambda member: member[self.description]
    

distinct_values_for_member(attribute_manager, member)

If the member has a gender, this acts just like AttributeManager.distinct_values_for_member(). If it does not, an empty set is returned.

Parameters
  • attribute_manager (AttributeManager) – The manager describing the attribute serving as hint.

  • member (Member) – The member.

Return type

Set[AttributeType]

kick_member(member)

Kicks a member, if present.

Parameters

member (ForwardRef) – The member to kick.

Return type

None

register_member(member)

Registers a new member.

Note

Copies the member so changes to the instance wont directly affect the orchestra. Use update_member() to update the information about this member.

Parameters

member (ForwardRef) – The new member

Return type

None

class components.attributemanager.PhotoManager(description, questionable_attributes)

Bases: components.attributemanager.NameManager

Subclass of AttributeManager for photo file IDs. This is needed, as the gender of a member needs to be taken into account.

description

A description of the attribute the instance manages.

questionable_attributes

A list of components.AttributeManager instances that manages attributes, which are available as questions for the attribute this instance manages.

Parameters
  • description (str) – A description of the attribute the instance manages.

  • questionable_attributes (List[Union[AttributeManager, str]]) – A list of components.AttributeManager instances that manages attributes, which are available as questions for the attribute this instance manages.

distinct_values_for_member(attribute_manager, member)

If the member has a gender, this acts just like AttributeManager.distinct_values_for_member(). If it does not, an empty set is returned.

Parameters
  • attribute_manager (AttributeManager) – The manager describing the attribute serving as hint.

  • member (Member) – The member.

Return type

Set[AttributeType]

static get_members_attribute(member)

Gives the attribute of member that is managed by this instance.

Parameters

member (ForwardRef) – The member.

Return type

Optional[str]