The calculations to perform for this plugin when “analyze_data” mode is enabled set as an dictionary variable ANALYZE_DATA
.
Use an OrderedDict to ensure calculations are run in the order defined in the plugin.
This should be a dictionary that defines a mapping of “calculation_name” => “calculation string”.
The dictionary key “calculation_name” is a string set to the name to use to store the result of “calculation string”.
The dictionary value “calculation string” is a string set to a snippet of python code that does something.
Each “calculation string” must always set a result
variable to be consumed by the plugin system, for example:
1 2 3 4 5 6 7 8 9 | NAME = "plugin_name"
ANALYZE_DATA = OrderedDict()
ANALYZE_DATA["two_plus_five"] = """
# add 2 and 5 to set result to 7
result = 2 + 5
"""
|
Note
Each “calculation_name” is the same name that must be used in layout files when pulling in data to the PPTX file dynamically using fetch
. Given the example above, you could use {{ fetch('plugin_name', 'two_plus_five') }}
to insert the result of this calculation string into any placeholder item on a slide.
Each “calculation string” is run from within the context of a tanium_hat.plugin.Plugin
. This means that each calculation has a number of helper methods available to by using foo = self.helper_method(arg1, arg2, etc)
. Helper methods provided in Plugin:
tanium_hat.plugin.Plugin.load_json_file()
- loads a JSON file from config[data_path] and returns it as a python objecttanium_hat.plugin.Plugin.load_csv_as_df()
- loads a CSV file from config[data_path] and returns it as a pandas dataframetanium_hat.plugin.Plugin.clean_df()
- Clean a pandas dataframe of any rows that match values in columns and return the cleaned pandas dataframetanium_hat.plugin.Plugin.get_result()
- Get a previously calculated result by name and return the resulttanium_hat.plugin.Plugin.force_int()
- Force value to inttanium_hat.plugin.Plugin.force_float()
- Force value to floattanium_hat.plugin.Plugin.resolve_dict_path()
- Resolve path by string from a dictionary and return the result