Control Steps

All steps can be imported directly from the ppc_robot_lib.steps.control module.

class DeleteTableStep(table)[source]

Deletes a table with the given name.

Example:

>>> from ppc_robot_lib.steps.control import DeleteTableStep
>>> DeleteTableStep("unnecessary_table")

Context Manipulation

Each ppc_robot_lib.work_set.WorkSet has an associated context dictionary. This dictionary can be used by functions and steps that has access to the work set.

Context can be changed using the following steps:

class ContextClearStep[source]

Clears all entries present in the context of the current ppc_robot_lib.work_set.WorkSet.

class ContextUpdateStep(data)[source]

Updates the current ppc_robot_lib.work_set.WorkSet context. Accepts either an dictionary with keys to update, or a callable.

When callable is given, it is called with the current context as an argument. If the callable has an argument named task_ctx, whole task context is passed as the second named argument. If the callable returns an dictionary that is not the current context, it is applied to the current context.

Example:

>>> from ppc_robot_lib.steps.control import ContextUpdateStep
>>> ContextUpdateStep({'counter': 0})
>>> def context_counter_inc(context):
...     context['counter'] += 1
...     return {'new_key': True}
>>> ContextUpdateStep(context_counter_inc)

The final value of context will be equal to:

{'counter': 1, 'new_key': True}
Parameters:

data (dict[str, Any] | Callable[[dict[str, Any]], dict[str, Any] | None]) – Dictionary with keys to update or a callable that will update the context.

Client Account Loops

Loops over the list of accounts specified by a selector. Suitable for MCC reports.

class ForEachClientUnionStep(selector, inner_table, output_table=None, steps=None, parallel_workers=None)[source]

Executes the given list of steps for each client account specified by the selector. Then takes a table specified by the inner_table argument of each client and merges them together (union) into output_table.

selector can be instance of the following classes:

  • ppc_robot_lib.client_selector.PredefinedClientSelector: iterates over a given set of Client IDs. Useful when the user has to select for which accounts the report should run.

When executed, it runs the given set of steps once for each client. Each execution begins with an empty ppc_robot_lib.work_set.WorkSet. A table of given name (account_performance) should be produced in each of these WorkSets. Suppose that the execution produced the following two tables:

ExternalCustomerId

Impressions

Clicks

111222333

256

16

ExternalCustomerId

Impressions

Clicks

444555666

128

32

After all executions are done, the tables are merged (like in SQL’s UNION) together:

ExternalCustomerId

Impressions

Clicks

111222333

256

16

444555666

128

32

Parameters:
  • selector (ClientSelectorInterface) – Account selector.

  • inner_table (str) – Name of the table that is merged from each client. The table must be produced by steps.

  • output_table (str) – Name of the output table.

  • steps (Iterable[AbstractStep]) – Steps to execute for each client.