Objects (package)

The package contains objects representing syntactical blocks of a TM1 rule. All contained classes are derived from a common ancestor TM1RuleToken. The root class contains essential method convert providing the splicing conversion. Derived classes redefine this method to achieve desired splicing conversion. Contained objects are described in following paragraphs.

TM1RuleToken (class in TM1RuleToken.py)

The class represents any string (token) contained within the associated rule with starting and ending position enumerated as number of characters from the rule beginning. This reflects notation in which parser enumerates parsed tokens when calling custom actions in Parser/TM1RuleParser.

The class defines convert method that is by default returning original text as returned from Parser/TM1RuleParser during the rule parsing (token passthrough). However this method is overloaded in classes descending from this base class to achieve correct splicing.

The class defines following attributes:

Attribute

Type

Usage

Attribute

Type

Usage

text

str

Text as parsed by Parser/TM1RuleParser when calling custom actions that cover all cases except for TM1 calculation rule and feeder commands.

start

int

Global position of the text start (inclusive) within the TM1 rule, calculated as zero based number of characters from start of the rule.

end

int

Global position of the text end (inclusive) within the TM1 rule, calculated as zero based number of characters from start of the rule.

The class exposes following methods:

Method

Usage

Method

Usage

update

Method updates intrinsic attributes of the object by text, eventually start and end attributes if provided.

len

Method returns length of text attribute as number of contained characters.

get_text

Method returns original value of text attribute.

convert

Method returns original value of text attribute.

TM1CalcRule (class in TM1CalcRule.py, derived from TM1RuleToken)

This class represents entire TM1 calculation rule or a feeder command. It breaks down the calculation rule or a feeder into two essential parts - area statement (part before equal sign) and statement (part following equal sign, sign inclusive).

The class redefines convert method by returning string obtained by concatenating result of convert method of associated area statement and statement. Each object of this class is aware of which regions the associated rule is encapsulated in and it has link to a directive resolver used to return all directives applying to the associated rule. This is essential information to be able to properly splice the associated rule by applying conversion based on region membership and associated directives.

The class defines following attributes:

Attribute

Type

Usage

Attribute

Type

Usage

area_statement

TM1RuleAreaStatement

Link to associated area statement of the TM1 rule or the feeder statement.

statement

TM1RuleToken

Link to token following the area statement including equal sign.

directives_resolver

TM1DirectiveResolver

Link to directive resolver to identify all splicing directives that apply to the TM1 rule.

scopes

List[str]

List of region names in which the TM1 rule or feeder statement is encapsulated.

The class exposes following methods:

Method

Usage

Method

Usage

convert

Method returns concatenated string composed from result of convert method of associated area_statement and statement.

TM1RuleAreaStatement (class in TM1RuleAreaStatement.py, derived from TM1RuleToken)

The class represents area statement of TM1 calculation rule or a feeder command. The area statement is decomposed to dimensions and hierarchy:element pairs belonging to each of the dimensions. This implies that the rule has to contain full specification of each element in the area statement. Not following this pattern in TM1 development will result in an error during splicing of the rule.

The convert method implements splicing of dimensional elements based on directives that apply to the associated TM1CalcRule. Once the directives are applied, the convert method will return modified area statement based on apply method output.

The class defines following attributes:

Attribute

Type

Usage

Attribute

Type

Usage

pre_format

str

Whitespaces between [ and dimension/hierarchy/element indices.

post_format

str

Whitespaces between dimension/hierarchy/element indices and ].

directives_resolver

TM1DirectiveResolver

Link to directive resolver to identify all splicing directives that apply to the area statement of the TM1 rule.

orig_dim_elem_dict

Dict[str, str]

Dictionary containing list of hierarchy/element pairs indexed by dimension, relating to dimension/hierarchy/elements as defined in the rule statement.

converted_dim_elem_dict

Dict[str, str]

Dictionary containing list of hierarchy/element pairs indexed by dimension, relating to dimension/hierarchy/elements after splicing.

applied_directives

bool

Flag indicating whether the splicing directives have been applied.

calc_rule

TM1CalcRule

Link to TM1CalcRule instance owning the area statement.

The class exposes following methods:

Method

Usage

Method

Usage

set_calc_rule

Setter for calc_rule attribute.

get_dimensions

Returns list of keys from orig_dim_elem_dict, represents list of dimensions extracted from dimension/hierarchy/elements as defined in the rule statement.

get_elements

Returns list of hierarchy/elements pairs from orig_dim_elem_dict related to supplied dimension, represents list of elements associated with supplied dimension as extracted from dimension/hierarchy/elements as in the rule statement

add_converted_dimension

Constructs converted_dim_elem_dict by either adding or merging new elements into the dictionary. The method is called from TM1DirectiveResolver during application of directives to the rule statement in method apply_directives.

apply_directives

The method will call apply_directives of associated directives_resolver object If directives haven't been applied.

convert

This method constructs and returns entire area statement after the directives have been applied by using converted_dim_elem_dict.