API

This page documents the inheritable classes provided by the ATK, and their various attributes and public functions.

class Algorithm([cl=None[, params=None]])
Parameters:
  • cl (ChainLedger) – ChainLedger object instantiation
  • params (dict) – Python dictionary containing values for algorithm inputs
  • errors (list) – List of errors generated by an algorithm
  • logger – Python logging object
  • name (string) – Name of algorithm
run()

Override this function with your algorithm logic.

raise_client_error(err)
Parameters:err (string) – String containing the error message
Returns:AlgorithmException object
Return type:AlgorithmException

Raise an error to the calling application, such as a web browser.

class AlgorithmChain(path, passed_chain)
Parameters:
  • atk_path (string) – Folder location for the current algorithm project
  • chain_name (string) – Name of the algorithm chain as it appears in the chain definition
  • chain_definition (dict) – Python dictionary containing chain definition
get_request_dict()
Return type:dict

Return a dict containing all algorithms in the current chain and their default parameter values as if making a request to run a chain (e.g.: from a web form).

class ChainLedger(status_key)
Parameters:
  • status_key (string) – Unique ID for chain run, used for obtaining status and history
  • metadata (dict) – key, value pairs placed on the Check Ledger by algorithms
  • history (list) – array of metadata, ordered by chain run order
  • chain_percent (int) – percent progress of chain run
  • batch_percent (int) – percent progress of batch run
add_to_metadata(key, value)
Parameters:
  • key (string) – metadata key used for later retrieval
  • value (any) – value to be saved with the key

Add a key, value pair to the Chain Ledger

get_from_metadata(key)
Parameters:key (string) – metadata key used to retrieve the item
Returns:value of key in metadata
Return type:any

Return a value placed in Chain Ledger metadata under key.

get_from_history(history_index, key)
Parameters:
  • history_index (int) – position in the Chain Ledger history for the algorithm sought
  • key (string) – key to be located in metadata
Returns:

value in metadata history under key

Return type:

any

Search the Chain Ledger history for a key in metadata, based on the index of the algorithm in the history list.

search_history(key, algorithm_name)
Parameters:
  • key (string) – key to search for
  • algorithm_name (string) – name of algorithm to to find in history
Returns:

a set of items matching the algorithm, key pair

Return type:

list

Search the history for a particular metadata key coming from an algorithm, however many times it occurs.

is_algo_in_history(algorithm_name)
Parameters:algorithm_name (string) – name of algorithm to search
Return type:boolean

Return True if algorithm name appears in the history, otherwise return False.

set_status(status[, percent=0])
Parameters:status (string) – status message for calling application

Set a key in app.config with the Chain Ledger status_key as its name, and create a dictionary of status information, setting the app.config[key] value equal to that dictionary. Example:

{
    "all_msg": "",
    "latest_msg": "",
    "algorithm_percent_complete": 0,
    "chain_percent_complete": 0,
    "batch_percent_complete": 0
}
get_results_folder()
Returns:location of results folder
Return type:string

Provide the location of the results folder for files to be saved during an algorithm chain run

get_temp_folder()
Returns:location of temp folder
Return type:string

Provide the location of the temp folder for files to be saved during an algorithm chain run. These files will be deleted at the end of the chain run.

clear_temp_folder()

Delete all files and folders within the chain temp folder

class AlgorithmTestCase

Test Case template class to use for conducting unit tests of algorithms. Inherits from unittest.TestCase.

check_metadata(key, value)
Parameters:
  • key (string) – key in metadata to validate by
  • value (any) – value to validate
Return type:

boolean

Return True if value is the same as that found on the metadata. Otherwise return False.

check_status(status)
Parameters:status (string) – string to validate
Return type:boolean

Return True if status is the same as that found on the app.config dictionary under the Chain Ledger status key. Otherwise return False.