ArangoDB: For a graph till Level3 how to get all the transaction between the nodes and also print reverse transactions if any - arangodb

I want to get all transaction between the nodes for a graph till level3 and I have written the following code:
where Account/123--> is a node in the graph G1 which represents the Account number of a person in a bank.
FOR v, e, p IN 3..3 OUTBOUND "Account/123" Graph "G1"
FILTER v._from == "Account/123"
RETURN CONCAT_SEPARATOR(" -> ", p.vertices[*]._key)

Related

Large number of rows in Kusto

Scenario:
I have a graph edge list stored as Kusto Table. I need to divide them into groups(connected components)
I am running Kusto Python Plugins to run DFS and assign a group number to each edge in the same table(extending another column)
Sometimes there can be a large number of rows, millions of rows. Once the groups has been formed, we can return the table to the c# API in a paginated manner, but how to run the python script in such large number of rows?
Sometimes it takes 2 or more minutes to run. Can I decrease this time, given that we know that these scripts run in the sandbox in kusto cluster?
Please suggest some startergy.
Problem Statement: Given a table containing list of people who gave and borrowed money. Now we have to form groups of people which are connected to each other. Eg if A gives money to B and C. C gives money to D . Then A,B,C,D are connected
Pseudo Code:
Payment // table Payment has columns- LenderName,LenderPhone,BorrowerName,BorrowerPhone
|evaluate python(
typeof(*,GroupNo:int),
```
class Node:
def __init__(self,name,phone):
self.name=name
self.phone=phone
def __eq__(self,other):
return self.name==other.name and self.phone==other.phone
def __ne__(self,other):
return not self.__eq__(other)
def __hash__(self):
return hash((self.name,self.phone))
def get_adjacency_list(connections):
# Personis a dataframe with columns- LenderName,LenderPhone,BorrowerName,BorrowerPhone
adjacency_list=dict()#dictionary of Node-->Set<Nodes>
for index, row in connections.iterrows():
node1=Node(row["LenderName"],row["LenderPhone"])
node2=Node(row["BorrowerName"],row["BorrowerPhone"])
if(node1 not in adjacency_list):
adjacency_list[node1]=set()
if(node2 not in adjacency_list):
adjacency_list[node2]=set()
adjacency_list[node1].add(node2)
adjacency_list[node2].add(node1)
return adjacency_list
def run_dfs(node,group_no,visited,graph_list,groups):
visited.add(node)
groups[node]=group_no
for next_node in graph_list[node]:
if next_node not in visited:
visited.add(next_node)
run_dfs(next_node,group_no,visited,graph_list,groups)
def get_groups(graph_list):
groups=dict()
visited=set()
group_no=0
for node in graph_list.keys():
print(node)
if node not in visited:
group_no+=1
run_dfs(node,group_no,visited,graph_list,groups)
return groups
graph_list=get_adjacency_list(df)
groups=get_groups(graph_list)
result=df;
result["GroupNo"]=df.apply(lambda row: groups.get(Node(row["LenderName"],row["LenderPhone"]),-1),axis=1)
```
)

Pysnmp Walk Cisco Prime for Name and AP Connection Count

I'm using pysnmp to retrieve OID info from Cisco devices. The below code prints out all names of the 1k+ access points associated with the IP.
a = nextCmd(SnmpEngine(), CommunityData('myComm'), UdpTransportTarget((IP_Address, 161)), ContextData(), ObjectType(ObjectIdentity('1.3.6.1.4.1.14179.2.2.1.1.3')))
for errorIndication,errorStatus,errorIndex,varBinds in a:
for v in varBinds:
print(v)
The output looks like this
SNMPv2-SMI::enterprises.xxx.x.x.x.xx.x.160 = cftnnjguapnrs01v100c
SNMPv2-SMI::enterprises.xxx.x.x.x.xx.x.128 = nycmnykyapnrs01v100c
You can see the name payload at the end of the string. Next, I need to get the corresponding connection count for each. However, I don't know how to match the two afterwards. Is there a way to return a tuple for Name, Count, (Location?) in one request?

Arangodb: can I use a subquery to determine starting node for graph traversal

I am using arangodb to build a permissions system.
I would like to use a subquery to determine starting node for a graph traversal. This is what I attempted
FOR vert IN 1..5
OUTBOUND (
FOR v, e, p IN 1..2
OUTBOUND 'users/jill'
GranterGrant, GrantGrantee
FILTER e.edgeType == 'GrantGrantee'
AND v.type == 'User'
AND v._id == 'users/jim'
LIMIT 1
RETURN p.vertices[1]
)
RolePrivilege, GrantRole, GrantPrivilege
FILTER vert.type == 'Privilege'
AND vert._id == 'privileges/JournalRead'
LIMIT 1
RETURN vert._id
The inner query is meant to find a permissions grant node from jill to jim, and the outer query determines if there is a path from the grant node to the privilege JournalRead
The subquery works when run by itself, and returns a vertex that I would like to use as the starting node for the outer query. The outer query works if I hard code the starting node.
However, when I run the entire query above, arango responds with
Warnings:
[10], 'Invalid input for traversal: Only id strings or objects with _id are allowed'
Result:
[]
Note, I also tried RETURN p.vertices[1]._id within the subquery with the same outcome.
So, is it possible to use a subquery to determine the starting node of a graph traversal?
You can to get the list of starting nodes first and assign them to a variable instead of using a subquery.
So in you case, it would be something like:
let initialNodes = (
FOR v, e, p IN 1..2
OUTBOUND 'users/jill'
GranterGrant, GrantGrantee
FILTER e.edgeType == 'GrantGrantee'
AND v.type == 'User'
AND v._id == 'users/jim'
LIMIT 1
RETURN p.vertices[1]
)
FOR initialNode IN initialNodes
FOR vert IN 1..5
OUTBOUND initialNode
RolePrivilege, GrantRole, GrantPrivilege
FILTER vert.type == 'Privilege'
AND vert._id == 'privileges/JournalRead'
LIMIT 1
RETURN vert._id
Note that you are not limited to a single initial node. You can return multiple one in the subquery if needed.

Use one inline query to lead into another inline query? Telegram Bot (Python)

My bot passes a simple string (query.query) through a function that returns a "big" dictionary with many subdictionaries (each representing "card" data) inside it. As it works right now, all keys and values for all returned subdictionaries get displayed in-line (until pagination limit). So for example, writing "blue" will return the key:value pairs for all subdictionaries whose card name == "blue".
I want the bot to first display inline results for card names and, after the user chooses a card, for the bot to display the rest of the card data, so the user can choose what part to send in chat. This would look like:
User queries the word "blue" and makes card titles for "blue blob", "blue drake", "blue beard" appear in-line
User select "blue beard" from that menu, making bot then display available data for "blue-beard" in-line (stats, attack, etc.)
Here's a snippet of said code. Check the # comment to see where I think it all breaks down
#bot.inline_handler(lambda query: len(query.query) > 3)
def query_card(inline_query):
temp_names_list = []
results_list = []
try:
sound_dict = scrape(inline_query.query)
for key, sub_dict in sound_dict.items():
temp_names_list.append(types.InlineQueryResultArticle(id=key, title=sub_dict['Name'], input_message_content=types.InputTextMessageContent(sub_dict['Name'])))
bot.answer_inline_query(inline_query.id, temp_names_list, cache_time=1)
#The code breaks down here since I haven't found a way of passing the result to ^ this answer_inline_query into the next part of the loop:
for key, sub_dict in sound_dict.items():
for k, v in sub_dict.items():
if k == ['message']['text']:
results_list.append(types.InlineQueryResultArticle(id=key+k, title=k, input_message_content=types.InputTextMessageContent(sub_dict['Name']+"\'s ["+k+"] bit:\n"+v)))
#results_list.append(types.InlineQueryResultVoice(id=k, voice_url=v, title="^ "+sound_dict['Name']+"\'s ["+k+"] bit:\n"+v, caption=sound_dict['Name']+"\'s ["+k+"] bit"))
bot.answer_inline_query(inline_query.id, results_list, cache_time=1)
except Exception as e:
print(e)

How to get the root node's key of a graph in ArangoDB?

I have a graph in ArangoDB whose root node is 'X'. Now "a,b,c,d,e,f" are the siblings of 'X' direct or grand grand siblings. Now from a given siblings node "a,b,c,d,e or f" I want to get to node 'X'. Is there any general AQL query to traverse directly to the root node of any graph ?
To provide an exact example I would need to know a bit more, but this is one of several solutions.
Assuming that the nodes are connected by "child" edges and the direction of the edges go from parent to child. You would traverse the tree up or INBOUND
FOR v,e,p IN 1..50 INBOUND '(id of starting node a,b,etc.)' child RETURN p.vertices
If you know how many hops maximum to the root, change the 50 to that value.
This statement will return all of the paths and intermediate paths from the starting node through the child links to the head node. To return only the path to the head node, you would have to filter out the intermediate paths. This could be done with a check to see that there is no parent vertex.
FOR v,e,p IN 1..50 INBOUND '(id of starting node a,b,etc.)' child
FILTER LENGTH(EDGES(child,v._id,'inbound'))==0 RETURN p.vertices
which will filter out all paths that do not end at a root vertex.
RHSMan's answer helped me but here is cleaned up a bit
LET ref_people = (
FOR p IN people RETURN p._id
)
LET l = (
FOR id IN ref_people
FOR link IN links FILTER id == link._from RETURN id
)
RETURN MINUS(ref_people, l)
I came across this as I had the same problem but the above is outdated:
I did the following:
let ref_items = (for s in skills
return s._id)
let c = (for item in ref_skills
for sk in skill_skill
filter item == sk._to
return item)
return MINUS(ref_skills, c)

Resources