Skip to content

Chore

Chore(name, start_time, dst_sensitivity, active, execution_mode, frequency, tasks)

Bases: TM1Object

Abstraction of TM1 Chore

Source code in TM1py/Objects/Chore.py
def __init__(
    self,
    name: str,
    start_time: ChoreStartTime,
    dst_sensitivity: bool,
    active: bool,
    execution_mode: str,
    frequency: ChoreFrequency,
    tasks: Iterable[ChoreTask],
):
    self._name = name
    self._start_time = start_time
    self._dst_sensitivity = dst_sensitivity
    self._active = active
    self._execution_mode = execution_mode
    self._frequency = frequency
    self._tasks = list(tasks)

MULTIPLE_COMMIT = 'MultipleCommit' class-attribute instance-attribute

SINGLE_COMMIT = 'SingleCommit' class-attribute instance-attribute

active property

body property

body_as_dict property

dst_sensitivity property writable

execution_mode property writable

execution_path property

1 chore together with its executed processes Use case: building out a tree of chores and their processes (and again the processes that are called by the latter (if any)).

Returns:

Type Description
Dict

dictionary containing chore name as the key and a list of process names as the value

frequency property writable

name property writable

start_time property writable

tasks property writable

activate()

Source code in TM1py/Objects/Chore.py
def activate(self):
    self._active = True

add_task(task)

Source code in TM1py/Objects/Chore.py
def add_task(self, task: ChoreTask):
    self._tasks.append(task)

construct_body()

construct self.body (json) from the class attributes

Returns:

Type Description
str

String, TM1 JSON representation of a chore

Source code in TM1py/Objects/Chore.py
def construct_body(self) -> str:
    """
    construct self.body (json) from the class attributes
    :return: String, TM1 JSON representation of a chore
    """
    body_as_dict = collections.OrderedDict()
    body_as_dict["Name"] = self._name
    body_as_dict["StartTime"] = self._start_time.start_time_string
    body_as_dict["DSTSensitive"] = self._dst_sensitivity
    body_as_dict["Active"] = self._active
    body_as_dict["ExecutionMode"] = self._execution_mode
    body_as_dict["Frequency"] = self._frequency.frequency_string
    body_as_dict["Tasks"] = [task.body_as_dict for task in self._tasks]
    return json.dumps(body_as_dict, ensure_ascii=False)

deactivate()

Source code in TM1py/Objects/Chore.py
def deactivate(self):
    self._active = False

from_dict(chore_as_dict) classmethod

Alternative constructor

Parameters:

Name Type Description Default
chore_as_dict Dict

Chore as dict

required

Returns:

Type Description
Chore

Chore, an instance of this class

Source code in TM1py/Objects/Chore.py
@classmethod
def from_dict(cls, chore_as_dict: Dict) -> "Chore":
    """Alternative constructor

    :param chore_as_dict: Chore as dict
    :return: Chore, an instance of this class
    """
    return cls(
        name=chore_as_dict["Name"],
        start_time=ChoreStartTime.from_string(chore_as_dict["StartTime"]),
        dst_sensitivity=chore_as_dict["DSTSensitive"],
        active=chore_as_dict["Active"],
        execution_mode=chore_as_dict["ExecutionMode"],
        frequency=ChoreFrequency.from_string(chore_as_dict["Frequency"]),
        tasks=[ChoreTask.from_dict(task, step) for step, task in enumerate(chore_as_dict["Tasks"])],
    )

from_json(chore_as_json) classmethod

Alternative constructor

Parameters:

Name Type Description Default
chore_as_json str

string, JSON. Response of /Chores('x')/Tasks?$expand=*

required

Returns:

Type Description
Chore

Chore, an instance of this class

Source code in TM1py/Objects/Chore.py
@classmethod
def from_json(cls, chore_as_json: str) -> "Chore":
    """Alternative constructor

    :param chore_as_json: string, JSON. Response of /Chores('x')/Tasks?$expand=*
    :return: Chore, an instance of this class
    """
    chore_as_dict = json.loads(chore_as_json)
    return cls.from_dict(chore_as_dict)

insert_task(new_task)

Source code in TM1py/Objects/Chore.py
def insert_task(self, new_task: ChoreTask):
    task_list = self.tasks
    for task in task_list[new_task._step :]:
        task._step = task._step + 1
    task_list.insert(new_task._step, new_task)
    self.tasks = task_list

reschedule(days=0, hours=0, minutes=0, seconds=0)

Source code in TM1py/Objects/Chore.py
def reschedule(self, days: int = 0, hours: int = 0, minutes: int = 0, seconds: int = 0):
    self._start_time.add(days=days, hours=hours, minutes=minutes, seconds=seconds)