Skip to main content

Hello,

 

I’m looking for a way to classify (order) the lists within a list attribute. Essentially I need all lists that have a “phase” value of ‘R’ to be on listattribute{0}…all list values that have a “phase” value of ‘Y’ to be stored in listattribute{1}…and all list values that have a “phase” value of ‘B’ to be stored in listattribute{2}.

 

Using List Sorter, I am able to accomplish this as long as there is a list for all three phases. The data sometime has only 1 or 2 phase values (example: Y and B, but no R). If I sort the lists that only have two phase values, “Phase” = ‘Y’ ends up in listattribute{0}.

 

How do a force a blank list value for ‘R’, so that ‘Y’ still gets stored in listattribute{1} and ‘B’ gets stored in listattribute{2}?.... listattribute{0} could remain blank

 

 

These lists need to be structured correctly so that I can run them through an XML Templater and have them placed in the correct spot in the XML.

 

Update - I have attached the workspace and the xml template that calls the various list values for the parent transformer bank object

 

Thanks for reading!

Unfortunately the ListSorter has a long-standing issue where it's not possible to sort on multiple keys, sometimes not even by chaining them one after another (see https://knowledge.safe.com/content/idea/72018/listsorter-to-support-multiple-sort-by-criteria.html)

My recommendation would be to implement any custom sorting or ordering mechanism in Python. The alternative, which perhaps is easier but is often much slower, is to explode the lists, sort the list items using the regular Sorter and then re-build the lists at the end.


Where is the list being created in the first place? Perhaps there is the option to try and address it there instead?


@bhornung

 

 

As the sorting seem not based on any "natural" type I would simply check every list for its phases.

I would add 1 element or more for the missing phase(s).

Add a attribute (SortKey) or map it.

Sortkey = (R=0, Y=1,etc) which are the desired indices and create listattribute{Sortkey} and then listsort on that.

Basically you are telling which attribute is supposed to go to which (list)index.

 

You could also consider to not make the schema list_index-specific (?)

 

You could post some sample data


@bhornung

 

 

As the sorting seem not based on any "natural" type I would simply check every list for its phases.

I would add 1 element or more for the missing phase(s).

Add a attribute (SortKey) or map it.

Sortkey = (R=0, Y=1,etc) which are the desired indices and create listattribute{Sortkey} and then listsort on that.

Basically you are telling which attribute is supposed to go to which (list)index.

 

You could also consider to not make the schema list_index-specific (?)

 

You could post some sample data

I am essentially using a sort key for the list sorter, but because there is no list for R=0 , the list sorter will put y=1 as list{0}. I'm now looking into a way that I can add a blank list entry, assign it a r=0, then sort the list so that list{0} is blank except the sortkey value.

Essentially what I am trying to do is take a set of transformer records that have a 'transformerbank' id field and aggregate them so that I have one record (bank level) that contains a list of the 1-3 transformers that exist on the bank. That list must be ordered correctly so that it can be predictably inserted in the correct place in the XML template.


Where is the list being created in the first place? Perhaps there is the option to try and address it there instead?

Essentially what I am trying to do is take a set of transformer records that have a 'transformerbank' id field and aggregate them so that I have one record (bank level) that contains a list of the 1-3 transformers that exist on the bank. That list must be ordered correctly so that it can be predictably inserted in the correct place in the XML template.


Unfortunately the ListSorter has a long-standing issue where it's not possible to sort on multiple keys, sometimes not even by chaining them one after another (see https://knowledge.safe.com/content/idea/72018/listsorter-to-support-multiple-sort-by-criteria.html)

My recommendation would be to implement any custom sorting or ordering mechanism in Python. The alternative, which perhaps is easier but is often much slower, is to explode the lists, sort the list items using the regular Sorter and then re-build the lists at the end.

I guess my challenge is that I need a blank list entry on list{0} if there is no transformer on phase = R. I'm not sure how to add that blank list entry (placeholder).


Essentially what I am trying to do is take a set of transformer records that have a 'transformerbank' id field and aggregate them so that I have one record (bank level) that contains a list of the 1-3 transformers that exist on the bank. That list must be ordered correctly so that it can be predictably inserted in the correct place in the XML template.

Without a close look at the data it's hard to say what the best way to do this is, I'm presuming you're talking about having to shift all the list attributes, so everything has to shift together. I'd probably try rebuilding the list in python.

So zip all the list items together, then recreate the list in the correct order filling in the blanks. Could get messy depending on the numbers of list attributes you are working with

Quick example attached

add_to_list.fmw


Although @egomm 's python method would have worked, I had a large collection of attributes that i would have had to hard code and maintain for years to come.

 

 

Instead I found that I could use three separate ListSearch transformers to find each of the three phase values and then use the transformer's 'copy list elements' function to separate and assign them to their own collection of attributes (ex: PhsY_field1, PhsY_filed2 etc...). I then used these defined attributes to populate the XML template.

 


I think you're looking for values/elements that has common and generate them into a list. Maybe listcombiner is suitable to perform this. Reference from https://hub.safe.com/publishers/pacific-spatial-solutions/transformers/listcombiner


Reply