def get_default_network(fname=None,full=True): 
  if fname is None:
    # TODO: create line network
    'todo'
  fin = open('{0}/{1}'.format(data_dir(),fname), "r")
  res = {}
  incomingLinksByNode = defaultdict(list)
  outgoingLinksByNode = defaultdict(list)
  # In a first step, create the links without information about 
  # incoming or outgoing links
  for line in fin:
    print 'end of line is ', line[-1]
    dct = json.loads(line.strip())
    link_id = decode_link_id(dct['id'])
    geom = None
    if full:
      geom = [decode_Coordinate(dct_c) for dct_c in dct['geom']['points']]
    start_node = decode_node_id(dct['startNodeId'])
    end_node = decode_node_id(dct['endNodeId'])
    # Python magic: the mutable lists in the default dictionary will get
    # filled while we build the structure
    incomingLinksByNode[end_node].append(link_id)
    outgoingLinksByNode[start_node].append(link_id)
    res[link_id] = DefaultLink(link_id, geom, dct['length'], 
                              outgoingLinksByNode[end_node], 
                              incomingLinksByNode[start_node])
    print 'finished line', line
  fin.close()
  return res
Example #2
0
def list_traj_filenames(date):
  dir_tpl = '${data_dir}/trajectories/${date}/'
  dir_name = Template(dir_tpl).substitute(date=date, data_dir=data_dir())
  if os.path.exists(dir_name):
    files = list(os.listdir(dir_name))
  else:
    print 'no data for {0}'.format(date)
    files = []
  return files