Solve discrepancy between objet lists and sets - ordered / unordered

I have a function in typescript and also in python that takes a list of objects - not a set - and applies a reduce logic before returning a new list of results.

The results depend on the list’s order. Lists are ordered wheras sets are not.

While the order in widgets like the object selector seems to matter, it is lost when being assigned to an object set variable.

What would be the recommended way of actually retaining the order of objects and maybe also manually re-ordering them by drag and drop?

I also intend to store the object keys in an array property in the ontology so that the ordered list can be reloaded at a later point in time to do the computation again.

Best,
Florian

Hi Florian,

I’ve found a few solutions to this:

  1. Convert your code to return a FunctionsMap with the order key as an integer that can be used in many of the widgets to order the results. Depending on how caching works on your stack and in your particular workflow, this might result in the function being called twice, sequentially. This could lead to subpar performance, but if the result is valuable to the user it could be a reasonable solution.
  2. You could add an empty property to the Object type with an uninviting name (_ordr or something) and leaving that out of any other workflows. Set this variable with your function and use it to order the results. An automation can be set to clear this variable, if you do not want it to persist.
  3. If there are many users in parallel, the ‘_ordr’ property can be converted into an array where you store the the user id and the ordering. Your function can find this and overwrite it. For a low number of results, this operation should be relatively trivial, and your ordering function’s FunctionsMap can then return the value for each object, that corresponds to the user’s key – this breaks it up into two functions (retrieval and front-end ordering), but should be pretty performant.
  4. Implementing a meta Object would probably be my preferred approach. Especially if you want each user to store multiple results. Here you can get away with just storing the Object primary keys in the array and resolve these along with their index. Should be quite performant too, as this is all working on indexed properties.

Some of these are based around the solution being implemented in a Workshop-module, but let me know if you need a few pointers on how to implement this workflow somewhere else.

Oh, last solution:

If you choose to store these searches on the Object type itself, you could use a uuid as the searchId where the rank is stored. This could then be used with the orderBy call to the Ontology. Not fully sure whether this is more performant than solution 4, and is a little more messy compared to the meta Object.

Curious how you choose to proceed.

Let me give it a thought… I’ll update you here but it might take a while… Sorting, the simplest and yet most difficult problem of all :smiley:

1 Like

I discovered, that you can use the object list widget to solve my issue. Simply activate the “enable ordering” and choose whether you want your order as a string array or directly written back via some kind of action.

awesome!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.