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

Node Phyton - More than one relation

  • 1.  Node Phyton - More than one relation

    Employee
    Posted 10-30-2012 09:10

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

    Originally posted by: zon

    Hi guys,

    I need your help, to understand how can I use my Phython node to find match using more than one field.

    This is my current code. At this moment, I'm using only one field to match: PREFIX vs. net_b_number_normalized.

    ######################################
    import braininfo

    def setup(brainNodeControlObj, BrainNodeClass):
    ''' Must return a class that inherits from BrainNodeClass. '''
    class BrainNode(BrainNodeClass):
    def initialize(self):
    ''' Called at node initialization, before first pump.'''
    super(BrainNode, self).initialize()

    self.lookupList = list()
    self.destHash = list()
    inRec = self.inputs[1].read()
    while inRec:
    self.lookupList.append(inRec)
    self.destHash.append(inRec["PREFIX"])
    inRec = self.inputs[1].read()

    metadata = self.inputs[0].metadata
    metadata.append("UOOM_EVT", "String")
    metadata.append("REPEAT_EVT","String")
    metadata.append("PRECOCHAMADA_EVT", "String")
    metadata.append("UOOM1_MIN_SEC", "String")
    metadata.append("REPEAT1_MIN_SEC", "String")
    metadata.append("PRECOCHAMADA1_MIN_SEC", "String")
    metadata.append("CHARGE_TYPE1_MIN_SEC", "String")
    metadata.append("UOOM1_SEC", "String")
    metadata.append("REPEAT1_SEC", "String")
    metadata.append("PRECOCHAMADA1_SEC", "String")
    metadata.append("CHARGE_TYPE1_SEC", "String")
    metadata.append("UOOM2_MIN_SEC", "String")
    metadata.append("REPEAT2_MIN_SEC", "String")
    metadata.append("PRECOCHAMADA2_MIN_SEC", "String")
    metadata.append("UOOM2_SEC", "String")
    metadata.append("REPEAT2_SEC", "String")
    metadata.append("PRECOCHAMADA2_SEC", "String")
    metadata.append("UOOM3_MIN_SEC", "String")
    metadata.append("REPEAT3_MIN_SEC", "String")
    metadata.append("PRECOCHAMADA3_MIN_SEC", "String")
    metadata.append("UOOM3_SEC", "String")
    metadata.append("REPEAT3_SEC", "String")
    metadata.append("PRECOCHAMADA3_SEC", "String")
    metadata.append("OUTCTP", "String")
    metadata.append("OPERADORA", "String")
    metadata.append("DIRECCAOCHAMADA", "String")
    metadata.append("PREFIX", "String")
    metadata.append("TIER_ID", "String")
    metadata.append("POI_ID", "String")
    metadata.append("TRUNK_ID", "String")
    self.outputs[0].metadata = metadata

    def finalize(self, val):
    ''' Called at node end, after last pump call. '''
    super(BrainNode, self).finalize(val)

    def pump(self, quant):
    ''' Will continue to be called until False is returned.

    Only a small amount of work should be done in pump without checking
    quant.permitsRunning. When that returns False, return from pump
    with a True value to be called again, a False value when finished.'''
    while quant.permitsRunning(self):
    # your code here
    inRec = self.inputs[0].read()

    if not inRec:
    return False

    dest = inRec['net_b_number_normalized']

    found = False
    i=0
    while not found and i<len(self.destHash):
    # rec = self.lookupList[i]
    # prefix = rec["COSTCODE"]
    prefix = self.destHash[i]
    if dest.startswith(prefix):
    found = True
    rec = self.lookupList[i]
    i = i+1

    outRec = self.outputs[0].newRecord()
    outRec._copyFrom(inRec)
    if found:
    outRec["UOOM_EVT"] = rec["UOOM_EVT"]
    outRec["REPEAT_EVT"] = rec["REPEAT_EVT"]
    outRec["PRECOCHAMADA_EVT"] = rec["PRECOCHAMADA_EVT"]
    outRec["UOOM1_MIN_SEC"] = rec["UOOM1_MIN_SEC"]
    outRec["REPEAT1_MIN_SEC"] = rec["REPEAT1_MIN_SEC"]
    outRec["PRECOCHAMADA1_MIN_SEC"] = rec["PRECOCHAMADA1_MIN_SEC"]
    outRec["CHARGE_TYPE1_MIN_SEC"] = rec["CHARGE_TYPE1_MIN_SEC"]
    outRec["UOOM1_SEC"] = rec["UOOM1_SEC"]
    outRec["REPEAT1_SEC"] = rec["REPEAT1_SEC"]
    outRec["PRECOCHAMADA1_SEC"] = rec["PRECOCHAMADA1_SEC"]
    outRec["CHARGE_TYPE1_SEC"] = rec["CHARGE_TYPE1_SEC"]
    outRec["UOOM2_MIN_SEC"] = rec["UOOM2_MIN_SEC"]
    outRec["REPEAT2_MIN_SEC"] = rec["REPEAT2_MIN_SEC"]
    outRec["PRECOCHAMADA2_MIN_SEC"] = rec["PRECOCHAMADA2_MIN_SEC"]
    outRec["UOOM2_SEC"] = rec["UOOM2_SEC"]
    outRec["REPEAT2_SEC"] = rec["REPEAT2_SEC"]
    outRec["PRECOCHAMADA2_SEC"] = rec["PRECOCHAMADA2_SEC"]
    outRec["UOOM3_MIN_SEC"] = rec["UOOM3_MIN_SEC"]
    outRec["REPEAT3_MIN_SEC"] = rec["REPEAT3_MIN_SEC"]
    outRec["PRECOCHAMADA3_MIN_SEC"] = rec["PRECOCHAMADA3_MIN_SEC"]
    outRec["UOOM3_SEC"] = rec["UOOM3_SEC"]
    outRec["REPEAT3_SEC"] = rec["REPEAT3_SEC"]
    outRec["PRECOCHAMADA3_SEC"] = rec["PRECOCHAMADA3_SEC"]
    outRec["OUTCTP"] = rec["OUTCTP"]
    outRec["OPERADORA"] = rec["OPERADORA"]
    outRec["DIRECCAOCHAMADA"] = rec["DIRECCAOCHAMADA"]
    outRec["PREFIX"] = rec["PREFIX"]
    outRec["TIER_ID"] = rec["TIER_ID"]
    outRec["POI_ID"] = rec["POI_ID"]
    outRec["TRUNK_ID"] = rec["TRUNK_ID"]
    self.outputs[0].write(outRec)

    # finished your quantum, you want pump called again
    return True

    # If you implement your logic here, you don't need code below. If you want
    # to inherit, and add more logic at next level, uncomment below code

    # py3File = brainNodeControlObj.properties.getString("ls.brain .node.BrainPython.python3ImplementationFile")
    # braininfo.loadModule(py3File, "py3", brainNodeControlObj)
    # import py3
    # BrainNodeImpl = py3.setup(brainNodeControlObj, BrainNode)
    # return BrainNodeImpl

    return BrainNode
    ##################################################

    How can I introduce another field to this match, for instance: TRUNK_ID.
    How can I do it? With this field, is a one-on-one match; not like the field that I'm using right now, the prefix, which is a match by the destination number that fits.

    Many thanks for your help,

    Regards
    Natanael


  • 2.  RE: Node Phyton - More than one relation

    Employee
    Posted 10-30-2012 10:43

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

    Originally posted by: xathras

    Natanael,

    Could you create a dummy graph and upload to here with a BRD with some data?
    As an FYI, when you paste the code online it loses all the indentation, so its not as straight forward as looking at your code. Python is pretty anal about indentation (if you were not aware).

    Also, is there a reason why you are doing in python and not a join node?

    Regards
    Wayne
    Attachments:
    example.brg


  • 3.  RE: Node Phyton - More than one relation

    Employee
    Posted 10-30-2012 11:48

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

    Originally posted by: zon

    Hi Wayne,

    Thanks for your fast reply.
    I'm using python, because the field I'm using for match (destination numbers vs. prefix) is not a field where the match is direct.
    For example: imagine, in a call, the b-number 707202303.
    My ref data, with whom I want to cross ref, has the prefix 7072.
    So I'm using python to see the hightest exact match, by seeing first the entire b-number, and then, it takes out the last number, and tries to find the match...and so on.

    Attached is the sample brg

    Regards,
    Natanael
    ZON
    Attachments:
    MDA Cost sample.zip


  • 4.  RE: Node Phyton - More than one relation

    Employee
    Posted 10-30-2012 14:15

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

    Originally posted by: mmarinelli

    There is an prototype node in the Lavastorm Labs forum which may be useful here. The Substring Lookup node will allow you to match keys where one is a substring of the other. The node is described here: http://community.lavastorm.com/showt...bstring-Lookup, and can be downloaded as part of the Lavastorm Labs prototype library here: http://community.lavastorm.com/showt...brary-Released

    These nodes are experimental so they may not have the stability or performance profile of an official Lavastorm release, and they are not officially supported, but I think at the very least the code for this node should point you in the right direction.


  • 5.  RE: Node Phyton - More than one relation

    Employee
    Posted 10-30-2012 20:32

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

    Originally posted by: xathras

    Hmm interesting. I did a puzzle like this in my uni days, but not in python. Let me have a think on this one. Regex would of been a good fit for this scenario i think.
    I used to work as a billing data analyst for a teleco company and had to complete an exercise to look up dialing codes to regions to get the best fit. Maybe i still have my notes


  • 6.  RE: Node Phyton - More than one relation

    Employee
    Posted 10-31-2012 02:25

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

    Originally posted by: zon

    I'm not allow to access the link you sent.

    Yeh, it would be great if you can find your notes.
    As soon as you have any news, let me know.

    Natanael
    ZON


  • 7.  RE: Node Phyton - More than one relation

    Employee
    Posted 10-31-2012 07:36

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

    Originally posted by: mmarinelli

    Natanael, in order to obtain the prototype library you have to join the Lab Experimenter group (apologies, I had assumed that you were already a member). This link provides instructions on how to request membership for this group: http://community.lavastorm.com/showt...ining-Overview


  • 8.  RE: Node Phyton - More than one relation

    Employee
    Posted 10-31-2012 08:46

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

    Originally posted by: zon

    Ok, will do.

    But, if you can help me alter the python, it would be great, because I use that node in almost every project that I have.

    Natanael


  • 9.  RE: Node Phyton - More than one relation

    Employee
    Posted 11-06-2012 08:31

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

    Originally posted by: zon

    Hi,

    I've tried to use the node Substring Lookup, but is not running when I click F5.
    I've put in the InputKey field net_b_number_normalized and in lookupkey field PREFIX, and in match type "start with".

    Is not working...can you help?

    Regards,
    Natanael


  • 10.  RE: Node Phyton - More than one relation

    Employee
    Posted 11-06-2012 10:02

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

    Originally posted by: mmarinelli

    Sure, I can try to help, but it would be helpful to know how exactly it is not working. Could you provide an error message / log or a screen shot of what you're seeing?


  • 11.  RE: Node Phyton - More than one relation

    Employee
    Posted 11-06-2012 10:28

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

    Originally posted by: zon

    See the image below...can I do that?
    Multiple fields?

    And, what if I want that the final table, brings fields from the lookup key...how do I do it?

    Regards,
    Natanael
    Attachments:
    Doc1.zip


  • 12.  RE: Node Phyton - More than one relation

    Employee
    Posted 11-06-2012 12:00

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

    Originally posted by: mmarinelli

    The node you are using isn't coded to handle multiple input fields on each side of the join. It currently only works with a single field from each data set, but you could alter the code to use arrays for each side when performing a join. If you don't want to change the code, you could probably accomplish what you're trying to do using a sequence of nodes (one for each field you want to compare).


  • 13.  RE: Node Phyton - More than one relation

    Employee
    Posted 11-07-2012 02:51

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

    Originally posted by: zon

    Ok.

    Sorry to ask, but did you managed to look at my phyton node?
    I think for me it would be easier to change my phyton node for now, and after, try to include this new node.

    Cheers,
    Natanael


  • 14.  RE: Node Phyton - More than one relation

    Employee
    Posted 11-09-2012 08:00

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

    Originally posted by: zon

    Hi,

    I tried to use the new node again, only with one field, but it turned out error.
    >>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<
    ERROR processing data:
    heap allocation failed: m_pchData

    Installing log (11/09/2012 12:05:45) ...
    2012-11-09 12:50:34; Level: 4; Type: 0; Desc: "heap allocation failed: m_pchData"; File: "../../../include/jigsaw\Buffer.h"; Line: 27; Context: ""
    Uninstalling log (11/09/2012 12:50:34) ...
    >>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<

    Do you know why?

    Regards,
    Natanael
    ZON


  • 15.  RE: Node Phyton - More than one relation

    Employee
    Posted 11-15-2012 13:52

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

    Originally posted by: rboccuzzi

    Natanael, I tried taking a look at your sample graph attached above, but you didn't include the necessary base libraries, so I wasn't able to see what you are doing.

    From your Python error above, it sounds like you just ran out of memory. Looking at your Python code above, it seems you are loading the entire second input into memory. How many records are on your second input? I looks like you loaded them into a hash until you ran out of space. You could try loading the MINIMUM you need into memory, so maybe just the thing you are matching against and an ID, and then you can do a straight up join after? This would limit what you are storing into memory in your hash, and you should be able to get a lot more rows in memory.

    Also, it sounds like you might be trying to do something very similar to what is discussed in this thread here, matching country prefix codes. I think the libraries that Mick posted might do what you are looking for.

    Cheers
    Rich