def buildgraph(cursor, include_last_hop=False, include_target=False, only_connected=True):
 graph = {}
 entry_nodes = set()
 for host in cursor:
  if ('traces' not in host):
   continue
  for trace in host['traces']:
   hops = trace['hops']
   hops.sort(key=(lambda hop: hop['ttl']))
   if (not hops):
    continue
   entry_nodes.add(hops[0]['ipaddr'])
   if ((not include_last_hop) and (not include_target)):
    if (hops[(-1)]['ipaddr'] == host['addr']):
     hops.pop()
    if (not include_last_hop):
     hops.pop()
   for (i, hop) in enumerate(hops[1:]):
    if ((not only_connected) or ((hop['ttl'] - hops[i]['ttl']) == 1)):
     graph.setdefault(hops[i]['ipaddr'], set()).update([hop['ipaddr']])
 return (graph, entry_nodes)

def buildgraph ( cursor , include_last_hop = False , include_target = False , only_connected = True ) : graph = { } entry_nodes = set ( ) for host in cursor : if ( 'traces' not in host ) : continue for trace in host [ 'traces' ] : hops = trace [ 'hops' ] hops . sort ( key = ( lambda hop : hop [ 'ttl' ] ) ) if ( not hops ) : continue entry_nodes . add ( hops [ 0 ] [ 'ipaddr' ] ) if ( ( not include_last_hop ) and ( not include_target ) ) : if ( hops [ ( - 1 ) ] [ 'ipaddr' ] == host [ 'addr' ] ) : hops . pop ( ) if ( not include_last_hop ) : hops . pop ( ) for ( i , hop ) in enumerate ( hops [ 1 : ] ) : if ( ( not only_connected ) or ( ( hop [ 'ttl' ] - hops [ i ] [ 'ttl' ] ) == 1 ) ) : graph . setdefault ( hops [ i ] [ 'ipaddr' ] , set ( ) ) . update ( [ hop [ 'ipaddr' ] ] ) return ( graph , entry_nodes )
builds a graph by getting host documents from the database cursor .