Maximum of a Set

(imported topic written by JasonWalker)

I’m building a client-side parser to try to determine which action was executed most recently. Sparing the gore of getting a set of actions from the client, I’m going to narrow this down to the simplest form. Given a plural set, I want to find which “item 0” goes with the maximum “item 1”. With the following example, how can I return “c”?:

q: (“a”,“Mon, 19 May 2014 16:00:00 -0500” as time; “b”,“Mon, 19 May 2014 17:00:00 -0500” as time; “c”,“Mon, 19 May 2014 18:00:00 -0500” as time)

A: a, ( Mon, 19 May 2014 16:00:00 -0500 )

A: b, ( Mon, 19 May 2014 17:00:00 -0500 )

A: c, ( Mon, 19 May 2014 18:00:00 -0500 )

T: 0.063 ms

I: plural ( string, time )

q: items 1 of (“a”,“Mon, 19 May 2014 16:00:00 -0500” as time; “b”,“Mon, 19 May 2014 17:00:00 -0500” as time; “c”,“Mon, 19 May 2014 18:00:00 -0500” as time)

A: Mon, 19 May 2014 16:00:00 -0500

A: Mon, 19 May 2014 17:00:00 -0500

A: Mon, 19 May 2014 18:00:00 -0500

T: 0.061 ms

I: plural time

q: maximum of items 1 of (“a”,“Mon, 19 May 2014 16:00:00 -0500” as time; “b”,“Mon, 19 May 2014 17:00:00 -0500” as time; “c”,“Mon, 19 May 2014 18:00:00 -0500” as time)

A: Mon, 19 May 2014 18:00:00 -0500

T: 0.117 ms

I: singular time

If I try to use either (maximum of items 1 of it) of (my set), or if I try a “whose (item 1 of it = maximum of items 1 of it)”, the inspector breaks down the set and evaluates on each element in the set; so I get plural results (actually, I get every result), as in

q: (maximum of items 1 of it) of (“a”,“Mon, 19 May 2014 16:00:00 -0500” as time; “b”,“Mon, 19 May 2014 17:00:00 -0500” as time; “c”,“Mon, 19 May 2014 18:00:00 -0500” as time)

A: Mon, 19 May 2014 16:00:00 -0500

A: Mon, 19 May 2014 17:00:00 -0500

A: Mon, 19 May 2014 18:00:00 -0500

T: 0.154 ms

I: plural time

If I try to coerce a “set”, I can’t seem to do that either. It seems I can’t use tuples in a set?

q: elements of set of (“a”;“b”;“c”)

A: a

A: b

A: c

T: 0.064 ms

I: plural string

q: elements of set of (“a”;“b”;“c”)

A: a

A: b

A: c

T: 0.064 ms

I: plural string

q: elements of set of (“a”,1; “b”,2; “c”,3)

E: The operator “set” is not defined.

Any advice?

(imported comment written by MattPeterson)

I had a similiar problem. I ended up having to call my set twice to get it to work. This is definitely not ideal, but might help spark ideas. Please let me know if you come up with something.

Here is a simplified expample of my problem.

q: (item 1 of it, item 0 of it) of (it whose (item 0 of it = ((maximum of (items 0 of it as integer)) as string)) of (“1”,“a”;“2”,“b”;“3”,“c”))

A: a, 1

A: b, 2

A: c, 3

T: 0.138 ms

I: plural ( string, string )

Here is what I had to do to get results.

q: (item 1 of it, item 0 of it) of ((“1”,“a”;“2”,“b”;“3”,“c”) whose (item 0 of it = ((maximum of (item 0 of it as integer) of ((“1”,“a”;“2”,“b”;“3”,“c”))) as string)))

A: c, 3

T: 0.145 ms

I: plural ( string, string )

(imported comment written by JasonWalker)

Yeah, I’ve come across logic like that before. I’m still hoping someone has a better suggestion, because where I’m showing (“1”,“a”;“2”,“b”;“3”,“c”) in the example, the real problem involves a few hundred characters of a query that pulls all the actions on the client and takes almost a minute to execute.

(imported comment written by JasonWalker)

(mutters to self) As long as BigFix thinks the only variable anyone ever needs is “it”, maybe we should do a feature request to add “this” and “that” as variables to.

(imported comment written by jgstew)

Being able to get the parent object of “it” would solve a lot of relevance issues like this.