Members & MemberLists¶
When you start to implement certain business logic - either in the form of rules, or when you build your own data processing logic - you will instantly recognize then you have to deal a lot with dimension members and lists of members. The classes Member and MemberList provide many convenience features to make working with members and member lists as easy as possible.
All methods that do not requires arguments have been implemented as properties. This allows easy chaining of subsequent methods and makes your code (hopefully) a bit more readable. Here”s an example:
db = Database("life_is_beautiful")
...
animals = db.dimension["animals"]
the_first_bear = animals.member.filter("*bear*").first
sub_species = the_first_bear.leaves
Member¶
- class tinyolap.member.Member(dimension, member_name, cube=None, idx_dim: int = - 1, idx_member: int = - 1, member_level: int = - 1)
Represents a Member of a Dimension. Members are immutable. Useful for building business logic and navigation through dimensions and data space.
- child(index: int = 0) tinyolap.member.Member
Returns the 1st or subsequent child of a member. Equal to method
down
.member = cube.dimensions("months").member("Q3") jul = member.down() # 'Jul' is the first child of 'Q3' in the months dimension. aug = member.down(1) # 'Aug' is the second child of 'Q3' in the months dimension.
- Raises
KeyError – Raised, if a parent with the given index is not defined for the Member.
- Returns
A new Member object.
- property children: tinyolap.member.MemberList
Returns a list of all direct children of the member. If the member does not have children, then an empty array will be returned.
- Returns
List of children.
- property children_count: int
Returns the number of children the Member has.
- Returns
The number of children the Member has.
- property cube
Returns the Cube object the Member is associated to. If the Member object is not derived from a Cube or Cell,
None
will be returned.
- property dimension
Returns the Dimension object the Member is associated to.
- down(index: int = 0) tinyolap.member.Member
Returns the 1st or subsequent child of a member. Equal to method
child
.member = cube.dimensions("months").member("Q3") jul = member.down() # 'Jul' is the first child of 'Q3' in the months dimension. aug = member.down(1) # 'Aug' is the second child of 'Q3' in the months dimension.
- Raises
KeyError – Raised, if a parent with the given index is not defined for the Member.
- Returns
A new Member object.
- property first: tinyolap.member.Member
Returns the first Member of the dimension by its ordinal position.
member = cube.dimensions("months").member("Jul") jan = member.first # 'Jan' is the first month defined in the 'months' dimension.
- Returns
A new Member object.
- property full_name: str
Returns the full qualified name of the member, incl. dimension
- property has_children: bool
Checks if a Member has at least one child.
- Returns
True
is the member has at least one child,False
otherwise.
- property has_cube: bool
Returns
True
if the Member object has been derived from a Cube or Cell context, and the Cube property will return an existing Cube instance. IfFalse
is returned, then the Cube property will returnNone`
- property has_next: bool
Check if a Member has a next Member, meaning it is not already the last member of the dimension.
- property has_parents: bool
Check if a Member has at least one parent Member, meaning it is not already a top level member without parents.
- property has_previous: bool
Check if a Member has a previous Member, meaning it is not already the first member of the dimension.
- property is_child: bool
Checks if a Member is a child of some other (any other) member.
- Returns
True
is the member is a child,False
otherwise.
- is_child_of(other_member) bool
Checks if a Member is a direct child of another member.
- Returns
True
is the other member is a direct child,False
otherwise.
- property is_leaf: bool
Checks if a member is a leaf (base level) member.
- Returns
True
is the member is a leaf (base level) member,False
otherwise.
- property is_parent: bool
Checks if a Member is a parent of some other member.
- Returns
True
is the member is a parent,False
otherwise.
- is_parent_of(other_member) bool
Checks if a Member is a direct parent of another member.
- Returns
True
is the other member is a direct parent,False
otherwise.
- property is_root: bool
Checks if a Member is a root member, meaning the member has no further parents.
- Returns
True
is the member is a root member,False
otherwise.
- property last: tinyolap.member.Member
Returns the last Member of the dimension by its ordinal position.
member = cube.dimensions("months").member("Jul") year = member.last # 'Year Total' is the last member defined in the months dimension.
- Returns
A new Member object.
- property leaves: tinyolap.member.MemberList
Returns a list of all leaf (base level) member_defs of the member. This method will travers the member hierarchy and collect all leaf member_defs. If the member itself is a leaf member, then a member list with only the member itself will be returned.
- Returns
List of leaf (base level) member_defs.
- property level: int
Returns the level of member. 0 indicates base level member_defs, higher values aggregated member_defs.
- Returns
Level of the member.
- property name: str
Returns the name of the member.
- property next: tinyolap.member.Member
Returns the next Member of the dimension by its ordinal position.
member = cube.dimensions("months").member("Jul") aug = member.next # 'Aug' is the next month defined after 'Jul' in the months dimension.
- Returns
A new Member object.
- property ordinal: int
Returns the ordinal position of the member within the overall list of member.
- parent(index: int = 0) tinyolap.member.Member
Returns the 1st or subsequent parent of a member. Equal to method
up
.member = cube.dimensions("months").member("Jul") q3 = member.parent() # 'Q3' is the first parent of 'Jul' in the months dimension.
- Raises
KeyError – Raised, if a parent with the given index is not defined for the Member or if no parent exists.
- Returns
A new Member object.
- property parents: tinyolap.member.MemberList
Returns a list of all direct parents of the member. If the member does not have parents, then an empty array will be returned.
- Returns
List of parents.
- property parents_count: int
Returns the number of parents the Member has.
- Returns
The number of parents the Member has.
- property previous: tinyolap.member.Member
Returns the previous Member of the dimension by its ordinal position.
member = cube.dimensions("months").member("Jul") jun = member.previous # 'Jun' is the previous month of 'Jul' in dimension 'months'.
- Returns
A new Member object.
- root(index: int = 0) tinyolap.member.Member
Returns the 1st or subsequent root member of a member.
member = cube.dimensions("months").member("Jul") year = member.root() # 'Year Total' is the first root level parent of 'Jul' in the months dimension.
- Raises
KeyError – Raised, if a root with the given index is not defined for the Member.
- Returns
A new Member object.
- property roots: tinyolap.member.MemberList
Returns a list of all root (top level) member_defs of the member. This method will travers the parent hierarchy and collect all root member_defs. If the member itself is a root member, then a member list with only the member itself will be returned.
- Returns
List of root (base level) member_defs.
- up(index: int = 0) tinyolap.member.Member
Returns the 1st or subsequent parent of a member. Equal to method
parent
.member = cube.dimensions("months").member("Jul") q3 = member.up() # 'Q3' is the first parent of 'Jul' in the months dimension.
- Raises
KeyError – Raised, if a parent with the given index is not defined for the Member or if no parent exists.
- Returns
A new Member object.
MemberList¶
- class tinyolap.member.MemberList(dimension, members)
Represents a list of Member objects.
- append(other: tinyolap.member.MemberList) tinyolap.member.MemberList
Appends another list of members. :param other: The member list to be appended. :return:
- contains(item) bool
Checks whether a specific member (or member name) is contained in the member list.
- count(x) int
Return the total number of occurrences of the member x in the member list. :param x: The member to be counted. :return: The number of occurrences.
- difference(other) tinyolap.member.MemberList
Return the difference of two member lists as a new member list. (i.e. all elements that are in this set but not the others.)
- property distinct: tinyolap.member.MemberList
Returns a member list with distinct values. Doublets will be removed. :return:
- filter(pattern: str)
Provides wildcard pattern matching and filtering on the names of the members in the member list.
matches everything
? matches any single character [seq] matches any character in seq [!seq] matches any character not in seq
- Parameters
pattern – The wildcard pattern to filter the member list.
- Returns
The filtered member list.
- property first: tinyolap.member.Member
Returns the first member in the member list.
- intersection(other) tinyolap.member.MemberList
Return the intersection of two member lists as a new member list. (i.e. all elements that are in both sets.)
- property last: tinyolap.member.Member
Returns the last member in the member list
- match(regular_expression_string: str)
Provides regular expression pattern matching and filtering on the names of the members in the member list.
- Parameters
regular_expression_string – The regular expression string to filter the member list.
- Returns
The filtered member list.
- property names: tuple[str]
Returns a list (tuple) of the member_defs names.
- to_list() list[tinyolap.member.Member]
Returns a mutable list of the member in the member list.
- to_name_list() list[str]
Returns a mutable list of the member’s names in the member list.
- union(other) tinyolap.member.MemberList
Return the union of to member lists as a new member list. (i.e. all elements that are in either set.)