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.  assigning name to a field based on split values....

    Employee
    Posted 11-10-2014 09:29

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

    Originally posted by: dhrobertson

    I have a problem whereby I need to be able to allocate some names to the field 'Team', based on the 4 columns at the end.

    there was a percentage split calculated in order to establish that, for example, out of 4 rows that state Addenbrookes, 1 record needs the Team to say Der, 2 of the rows for Addenbrookes need to say RA and 1 record needs to say SPA. it does not matter which rows are assigned to which teams, just that the split is correct.

    the same goes for the others rows....
    so 5 rows for birmingham need to have the team specified as Gas and the last 3 need, the team needs to be changed from Unspecified, to RA.

    Team:string, Register:string, Der:int, Gas:int, RA:int, SPA:int
    Unspecified, Aberdeen, 0, 0, 0, 1
    Unspecified, Addenbrookes, 0, 1, 2, 1
    Unspecified, Addenbrookes, 0, 1, 2, 1
    Unspecified, Addenbrookes, 0, 1, 2, 1
    Unspecified, Addenbrookes, 0, 1, 2, 1
    Unspecified, Liverpool, 0, 0, 2, 0
    Unspecified, Liverpool, 0, 0, 2, 0
    Unspecified, Amersham, 0, 0, 0, 1
    Unspecified, Antrim, 0, 0, 1, 0
    Unspecified, Barnsley, 0, 0, 0, 1
    Unspecified, Birmingham, 0, 5, 3, 0
    Unspecified, Birmingham, 0, 5, 3, 0
    Unspecified, Birmingham, 0, 5, 3, 0
    Unspecified, Birmingham, 0, 5, 3, 0
    Unspecified, Birmingham, 0, 5, 3, 0
    Unspecified, Birmingham, 0, 5, 3, 0
    Unspecified, Birmingham, 0, 5, 3, 0
    Unspecified, Birmingham, 0, 5, 3, 0

    clearly some sort of aggregation needs to happen based around the register field. in my mind some sort of iterative process for each of the Register groupings, which decrements each of the last 4 columns in turn, at the same time changing the Team from Unspecified for the relevant team name.

    I have looked at various LavaStorm scripts available, dealing with holding variables across rows, but I'm at a loss as to how to work it out. It could be that I'm trying to make it too complicated and there is a very simple way to do this, but I'm too new at this to know what to do....

    any help would be much appreciated...

    regards

    Doug


  • 2.  RE: assigning name to a field based on split values....

    Employee
    Posted 11-10-2014 11:14

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

    Originally posted by: ryeh

    See the attached. I first aggregated the records by Register. I will assume that all records with the same register will always contain the same values. The filter node reads in the INT values and outputs the record 'n' times with the corresponding Team name.

    I do think there may be ways to dynamically do this, i.e. not have to manually write WHILE loops for each of the fields with integer-type data. I started on it, but realized it would take longer than just a few minutes. This is a crude first attempt.

    Roger.
    Attachments:
    assignTeam.brg


  • 3.  RE: assigning name to a field based on split values....

    Employee
    Posted 11-10-2014 11:32

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

    Originally posted by: ryeh

    This version utilizes nested WHILE loops to loop through the number of fields containing integer data types and then the number specified in those fields. It's not completely dynamic, as you still need to define the outputs. The second filter just outputs the Team and Register.
    Attachments:
    assignTeam1.brg


  • 4.  RE: assigning name to a field based on split values....

    Employee
    Posted 11-11-2014 03:38

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

    Originally posted by: dhrobertson

    Thank you so much for this script ryeh. it is really helpful. I have been trying to get me head around the script as to exactly what it seems to be doing which I think I'm getting a handle on. I'm interested in the first lines whereby you emit "a" and "5" to and then you have where 1 == 0 . is this some sort of initialization of some kind? although I could use your script as is, I really would like to understand exactly what is going on as this is probably something I will need to replicate time and time again and having a good grasp of the concept obviously helps in remembering for the future
    again, thanks for the graph and any fleshing out of the key concepts in the graph, would be fantastic if you can spare the time!

    doug


  • 5.  RE: assigning name to a field based on split values....

    Employee
    Posted 11-11-2014 05:03

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

    Originally posted by: stonysmith

    When you do almost any kind of looping, you want the FIRST execution of the output statement to NOT write anything out.
    Subsequent 'do output' commands will ignore any where condition you put on the output statement.

    This loop will output 4 records: 1,2,3,4
    The first 'emit i=long(0)' has the effect of setting the data type for the column, but because of the 'where false', it won't write a record before the while loop kicks in.

    output 1 {
    emit i=long(0)
    where false
    }

    i=1
    while i < 5 {
    do output 1 {emit i as counter}
    i=i+1
    }


  • 6.  RE: assigning name to a field based on split values....

    Employee
    Posted 11-11-2014 18:28

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

    Originally posted by: ryeh

    My keen colleague, Andy Cooper, would like to point out that if all you care about is the team count, then a 'Pivot Names to Data' node would do just the trick. After adding a filter to rename some fields, you would get something like:

    Team Register Count
    SPA Aberdeen 1
    Gas Addenbrookes 1
    RA Addenbrookes 2
    SPA Addenbrookes 1
    SPA Amersham 1
    RA Antrim 1
    SPA Barnsley 1
    Gas Birmingham 5
    RA Birmingham 3
    RA Liverpool 2


    You can then take this result to create an output very similar to the previous solutions.
    Attachments:
    assignTeam2.brg