LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Agg : GroupMax by Default?

    Employee
    Posted 06-24-2008 15:05

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: johnpelz

    Is there a way to use the GroupMax function by "default" on ALL input fields (besides GroupBy field) without having to explicitly write out every field?

    Something like:

    emit groupMax(*)
    where lastInGroup

    INPUT DATA
    ID A1 A2 A3 A4 A5
    AA 0 0 0 1 0
    AA 1 0 0 0 0
    AA 0 1 0 0 0
    BB 1 0 0 0 0
    BB 0 0 1 0 0

    DESIRED RESULT
    ID A1 A2 A3 A4 A5
    AA 1 1 0 1 0
    BB 1 0 1 0 0

    Unfortunately, there are several input fields and they can be dynamic across runs, so doing a groupMax on each field is NOT an option.

    Thoughts?


  • 2.  RE: Agg : GroupMax by Default?

    Employee
    Posted 07-09-2008 18:17

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: rboccuzzi

    Unfortunately, no. The groupMax function specifically takes a field. And in the case given above, there would be no way to know what the output fields would be called. You will have to programatically iterate through the input fields and create the output fields from it. If you are going to dynamically have your output fields created in that way, you probably will have to use a python node in this case. I recommend creating a general purpose node that will take a list of fields to group and create an output field for each one, so you can use it in multiple cases. Once you develop that, feel free to post it If you need any help with that node, let me know, I would be glad to assist.

    $Rich


  • 3.  RE: Agg : GroupMax by Default?

    Employee
    Posted 07-10-2008 13:58

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: rboccuzzi

    Here is another way that might be helpful. Using an Agg and BRAINscript, this produces a tally for each field, but not as a seperate field, but as a string. It might be sufficient though, and you can tease that out easily later.

    # For this example, we assume that the
    # first field is the field that we are
    # grouping on, and every other field is
    # an int field we want to tally
    # so this is a list of input field names
    # that we are tallying and can be
    # created you could populate
    fieldsToTally = inputFields(1).slice(1)

    # Reset counters on each new group
    if firstInGroup then
    tallies = list()

    if lastInGroup then
    result = ""

    i = 0
    while i < len(fieldsToTally) {
    if firstInGroup then
    tallies = tallies.append(0)

    fname = fieldsToTally[i]
    fvalue = fname.field()
    cvalue = tallies[i] + fvalue
    tallies = tallies.setItem(i, cvalue)

    if lastInGroup then {
    s = "%s : %d".format(fname, cvalue)
    result = result.joinStrings(s, "; ")
    }
    i = i + 1
    }

    emit id, result
    where lastInGroup