How to best create flex repeater parameter dictionaries?

Hello.

I am learning Perspective, to build dashboards for a factory setting.

I often find myself wanting to create a flex repeater, where the elements in the flex repeater depend on parameters of a view.

Eg, I have a parameterized view which takes in a list of machine names (it is further embedded into a larger dashboard). This view includes a chart of machine performance, as well as some KPIs. These KPI labels are created as a flex repeater. Each KPI label view takes a machine name as an input, and displays the boxed percentage.

However, going from the list of strings I pass into the parameterized view, to the list of objects required in the flex repeater, is a bit of a hassle. Right now, I have the current setup:

The "instances" prop on my flex repeater is bound with the expression

runScript("perspective_functions.list_to_list_of_dicts", 50000,{view.params.machine_names}, "machine_name")

and the associated script is

def list_to_list_of_dicts(list_of_items, key_name) :
	out_list = []
	
	for item in list_of_items :
		out_list.append({
			key_name: item
			})
	
	return out_list

However, this feels a bit bulky -- I'm not sure how much to worry about the performance impacts of these scripts (although I've mitigated this somewhat by having them call only rarely -- the machines should be constant over a session)

Is there a clever way I can do this solely within the expression language, without having to resort to scripting?

Not in base Ignition, there is no iteration in the expression language.

HOWEVER, pturmel's Integration Toolkit adds this functionality, if you are allowed to install 3rd party modules. I daresay it is an absolute necessity on any production system.

https://www.automation-pros.com/toolkit/doc/

For a cleaner looking script you can do list comprehensions.

def list_to_list_of_dicts(list_of_items, key_name):
	return [{key_name: item} for item in list_of_items]
4 Likes

Alright.

I will bring this up with my boss, as an option. We're just getting started with Ignition, and are looking to set ourselves up for success early on.

That post also seems to link to a bunch of other great resources about performance.

Thank you!